-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added function to calculate column emission measure #110
Conversation
Pull Request Test Coverage Report for Build 190
💛 - Coveralls |
So in this case, what is the assumed geometry? Is that the loop is entirely contained within a single pixel and oriented completely along the LOS? |
Yes, single pixel, and the LOS depth is set equivalent to the length of a grid cell. This can be thought of as being oriented along the LOS, or simply that we've set the loop width equivalent to the grid cell width (done in e.g. Bradshaw et al 2012). Alternatively, we could take the loop width or cross-section as an input and calculate it that way. I would prefer to assume the loop fits in a pixel (spatially unresolved), or we would need to somehow specify pixel size. Not terribly hard to do, but requires a bit more work. |
I think a slightly more efficient way of doing this might be to use the weights = self.electron_density * self.ion_density * self.grid_widths
H, _, _ = np.histogram2d(self.grid_centers, self.electron_temperature, bins=(self.grid_edges, bins), weights=weights)
return bins, H.sum(axis=0) This avoids a loop of the coordinates which could be potentially slow for very long loops or in cases where the resolution is really high. |
Ok that sounds good to me and I'm completely fine with that. It is still a really useful convenience function. I think we just need to make this clear in the docstring. |
Codecov Report
@@ Coverage Diff @@
## master #110 +/- ##
==========================================
- Coverage 43.64% 43.41% -0.23%
==========================================
Files 10 10
Lines 456 463 +7
==========================================
+ Hits 199 201 +2
- Misses 257 262 +5
Continue to review full report at Codecov.
|
It's been updated. One minor annoyance: the EM and bin arrays that are returned have unequal length because of the final element of bins is interpreted as the right edge of the last bin. So to plot, you would need to use |
Yeah this is always the difficulty of dealing with histograms. I kind of prefer including the rightmost edge as it means your bins are always full specified and can all be or arbitrary width. It also means you can just do a quick plot of the values versus the bin center positions ( We could also just make An annoyance I've always had with matplotlib is that, while it is easy to compute and plot a histogram, it is a pain to plot a histogram from a set of bins and values. I've been just dragging around this snippet of code with me every time I make a histogram, def plot_hist(ax, vals, bins, **kwargs):
"""
Plot a histogram from bin values
Parameters
----------
ax : Matplotlib axis
vals : value in each bin
bins : Bin edges, including the rightmost edge
kwargs : Plotting keyword arguments
"""
ymin = ax.get_ylim()[0]
ax.step(bins[:-1], vals, where='post', **kwargs)
if 'label' in kwargs:
del kwargs['label']
ax.step(bins[-2:], [vals[-1], vals[-1]], where='pre', **kwargs)
ax.vlines(bins[0], ymin, vals[0], **kwargs)
ax.vlines(bins[-1], ymin, vals[-1], **kwargs) which makes sure to get the positioning of the bins correct and handles plotting the edges as well. |
I would prefer to have a default value for the binning. I noticed the same thing with Matplotlib when I was testing this. Since the plotting can be a bit vexing, it might be à propos to introduce a peek_EM or some such function to make the quick look even easier. This could also be modified to optionally calculate a volume EM or differential EM, which are just as easy to calculate if we use similar assumptions. |
In parse.py, in the Profile class, I've added a function to calculate the column emission measure for a profile snapshot.
etc. The function uses a default binning range of log T = [3.0,8.0), in steps of dlog T = 0.05.