Distribution of mass in the density-pressure plane - multidimensional-array

I need to plot the probability distribution function in the pressure-density plane of a gas, for which I have tridimensional data arrays describing its pressure and density at every point in my dominion.
I thought about using plt.contour and plt.imshow, or plt.scatter, to get the desired result but I keep getting confused about how to transform the tridimensional arrays I have for pressure and density into the x and y axis of my plot. Also as far as I understand the function z = f(x,y) I need to plot as a colormap should be the mass fraction of gas at every point in the pressure-density plane ... how do I get that from my pressure and density arrays?

Related

R: area under curve of ogive?

I have an algorithm that uses an x,y plot of sorted y data to produce an ogive.
I then derive the area under the curve to derive %'s.
I'd like to do something similar using kernel density estimation. I like how the upper/lower bounds are smoothed out using kernel densities (i.e. the min and max will extend slightly beyond my hard coded input).
Either way... I was wondering if there is a way to treat an ogive as a type of cumulative distribution function and/or use kernel density estimation to derive a cumulative distribution function given y data?
I apologize if this is a confusing question. I know there is a way to derive a cumulative frequency graph (i.e. ogive). However, I can't determine how to derive a % given this cumulative frequency graph.
What I don't want is an ecdf. I know how to do that, and I am not quite trying to capture an ecdf. But, rather integration of an ogive given two intervals.
I'm not exactly sure what you have in mind, but here's a way to calculate the area under the curve for a kernel density estimate (or more generally for any case where you have the y values at equally spaced x-values (though you can, of course, generalize to variable x intervals as well)):
library(zoo)
# Kernel density estimate
# Set n to higher value to get a finer grid
set.seed(67839)
dens = density(c(rnorm(500,5,2),rnorm(200,20,3)), n=2^5)
# How to extract the x and y values of the density estimate
#dens$y
#dens$x
# x interval
dx = median(diff(dens$x))
# mean height for each pair of y values
h = rollmean(dens$y, 2)
# Area under curve
sum(h*dx) # 1.000943
# Cumulative area
# cumsum(h*dx)
# Plot density, showing points at which density is calculated
plot(dens)
abline(v=dens$x, col="#FF000060", lty="11")
# Plot cumulative area under curve, showing mid-point of each x-interval
plot(dens$x[-length(dens$x)] + 0.5*dx, cumsum(h*dx), type="l")
abline(v=dens$x[-length(dens$x)] + 0.5*dx, col="#FF000060", lty="11")
UPDATE to include ecdf function
To address your comments, look at the two plots below. The first is the empirical cumulative distribution function (ECDF) of the mixture of normal distributions that I used above. Note that the plot of this data looks the same below as it does above. The second is a plot of the ECDF of a plain vanilla normal distribution, mean=0, sd=1.
set.seed(67839)
x = c(rnorm(500,5,2),rnorm(200,20,3))
plot(ecdf(x), do.points=FALSE)
plot(ecdf(rnorm(1000)))

3-D Cartesian points to 2-D hemispherical and calculate the area of 2-D Voronoi cells

I've been working on some functions in R and MatLab based on Qhull (the geometry package in R) to project local Cartesian X,Y,Z points within a circular plot to spherical (theta,phi,R), centered at 0,0,0. Since all of the Z values are positive in the original coordinates (X and Y are instead centered at 0), this gives me the hemispherical projection that I desire (the point colors are scaled by Z values), plotted with the radial.plot() function of R plotrix, using phi (azimuth angle) and theta (polar angle):
For the spherical transformation, after centering at 0,0,0, rather than using the calculations of Bourke (1996), I use the ISO specification listed on Wikipedia (not the physics convention).
r <- sqrt(x^2 + y^2 + z^2)
theta <- acos(z/r)
phi <- atan2(y,x)
I would like to know the area of Voronoi cells containing points of a given class in this hemispherical projection, preserving perspective distortion. While it is simple to calculate the 2-D Voronoi diagram for the 2-D Cartesian X,Y points, translating this Voronoi diagram to 2-D spherical may not produce the desired results, yes? Perhaps it would be best to compute the Voronoi diagram directly from the hemispherical projected points and then return the area of each cell.
Update: I've solved it. My solution will be shared in a new R package, which I will post here.
OP, Adam Erickson, published the gapfraction package which implements Erickson's hemispherical-Voronoi gap fraction algorithm.
The gapfraction package for R was designed for modeling understory
light in forests with light-detection-and-ranging (LiDAR) data. In
addition to metrics of canopy gap fraction (Po), angular canopy
closure (ACC), and vertical canopy cover (VCC), the package implements
a new canopy height model (CHM) algorithm, popular individual tree
crown (ITC) detection algorithms, and a number of other algorithms
that produce useful features for statistical modeling, including the
distance of trees from plot center.
For further details please consult: gapfraction: R functions for LiDAR canopy light transmission
Please see some simple demonstration of the code below:
# devtools::install_github("adam-erickson/gapfraction", dependencies=TRUE)
library(raster)
library(gapfraction)
data(las)
# This function implements Erickson's hemispherical-Voronoi gap fraction algorithm
# with four common lens geometries: equi-distant, equi-angular, stereographic, and orthographic
P.hv(
las = las,
model = "equidist",
thresh.val = 1.25,
thresh.var = "height",
reprojection = NA,
pol.deg = 5,
azi.deg = 45,
col = "height",
plots = TRUE,
plots.each = FALSE,
plots.save= FALSE
)
Output:

jfreechart xy series plot data points

In JFreechart xySeries I want to plot the lines using a very dense set of points in order to show curves with precision, however, I want to plot the points with less density. For example, I have 100 data points each one is 1 unit apart on the x axis, but I only want to plot the point every 5 unit. I do,however, want the lines to be connected every 1 unit in order to show the curve with high density.
Is this possible?
You can subclass XYLineAndShapeRenderer and override getItemShapeVisible(int series, int item).

Project an axis to a plane

How do I project the X axis to a plane if the plane is defined by three points?
The default local 1-direction is the projection of the global x-axis onto the surface. If the global x-axis is within 0.1° of being normal to the surface, the local 1-direction is the projection of the global z-axis onto the surface.
Let's suppose that these points are:
t1 = [-0.362879991531372, 0.357021987438202, -0.373737007379532]
t2 = [-0.383525013923645, 0.371621012687683, -0.383549988269806]
t3 = [-0.383534014225006, 0.34629300236702, -0.38544899225235]
Is the vector [0.78280971952246, -0.0307519963686645, 0.411184845614438] correct answer in this case? I've calculated the angle between the surf and x (1,0,0) is ~28°.
And can you give the entire procedure for the calculation, because I'm just puzzled.
Your diagram is a little unclear (for instance, it doesn't show t1, t2, t3), but it looks as if you want a vector tangent to the surface and in the XZ plane. If that's correct, then you have to calculate the partial derivative with respect to x (the slope in the x direction, which is easy if the surface really is a plane and you have three non-colinear points) and the y-component of your answer will be zero. If that's not correct, then please explain what "projection" you prefer.

how can i construct the bezier curve if i only have points in x axis?

how can i construct the bezier curve if i only have points in x axis?can i do this act or need points for x and y axes related to t parameter?
i want constructe a bezier curve(from degree N)in a given interval and known point in that interval(that are random), but i have points only in x axes!!Whether this is feasible?
Can you specify the slopes at the end-points. You will need to do this for any bezier curve, The fact that the data points are on the x-axis is irrelevant.

Resources