-
-
Notifications
You must be signed in to change notification settings - Fork 132
Spectral Region Enhancement #289
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
Conversation
|
The current version of code allows: Spectral region based on one range of values. Spectral region with two ranges of values: Combine two Spectral regions into one: In-place adding spectral regions: Get a single region: Get lower and upper bounds: Get lower bound: Get lower bound of a single sub-region: Delete a sub-region: Iterate over sub-regions: Slicing a SpectralRegion: Invert a SpectralRegion: For SpectralRegion invert, pretend you have a SpectralRegion with 3 sub-regions that define peaks in a spectrum. Then you want to get all the other parts of the spectrum NOT in those 3 sub-regions (between a lower and upper bound). That is the idea of invert. |
|
@eteq @hcferguson @robelgeda @nmearl This is a first pass at the functionality. @robelgeda are there other things you can think you might want for your specific methods? (extract from spectrum is still there). If there is general consensus that this is the right direction of functionality, then I will start adding tests for each and add documentation. |
|
@brechmos-stsci: As far as #286 goes this is really good and extensive. The only suggestion I have is that for
We should show the bounds of all the regions in the container along with the most max and min bounds. Other than that the summary looks very good to me. |
|
@brechmos-stsci and I just chatted a bit out-of-band about this. I'm writing down a summary of some of the key points so that we don't lose them. A baseline motivation for this is something like what one might otherwise use boolean array masks for: to cut out non-contiguous pieces of a spectrum that are to be used together, so it's not the same as having a list of regions. I've changed the title of this PR to reflect that a bit more. But since the motivation is to replace masks, it leads to the question of what to do for situations where we already have masks. For example, if you want the region surrounding some spectral line, the easiest thing to do is: so we would want the region implementation here to fairly easily mock that up. I'd propose as a way to do this:
The above could quite reasonably be separate from this PR though - it came up because it demonstrates that this PR's approach does not block that functionality. However (and this was my biggest hangup initially): this does not mean we can use something like bitmasks to replace spectral regions, though: spectral regions have utility independent of a spectrum (e.g., "near the wl of Halpha" is a spectral region regardless of whether you have a spectrum with the line), whereas bitmasks can only be assigned a |
|
@eteq said it above, but I want to re-iterate... My intent of spectral regions is that they are independent of a particular Spectrum1D object. Therefore, one could define a spectral region This is why I went with a list of 2-tuples rather than a mask implementation. |
|
This looks very good. And I agree that having spectral regions that are independent of the pixel sampling could be quite powerful. |
|
It sounds like there is general consensus that this is generally going in the right direction. I'll add in/fix tests add documentation. |
I would suggest that this remain the way it is regarding the bounds. The idea is that this is the bounds for the whole spectral region. If one wants to get the bounds for each sub-region one could just do: So, I would suggest this stays the way it is for now. If others have an opinion, I am happy to listen (and change!). |
|
That sounds good to me |
|
@eteq @crawfordsm @hcferguson @nmearl @hcferguson In the current implementation of The new enhanced I don't think it makes that much sense to create a single So, do you think the |
|
Seems sensible, although I can't immediately think of a science use case for doing this. Or maybe I can. Although this use case means we have to have a function |
|
The other use case I can think of is to compute the RMS in the baseline parts of the spectrum defined by a But maybe this all begs for the "extract" to go the other way, as you say. Maybe there does need to be an "extract flux" (and dispersion?) method defined in [a little later] I was thinking about this and I wonder if I should add methods into Spectrum1D:
Then one can use that information as in @hcferguson's examples (and mine above). |
|
In my example the function |
|
@hcferguson Maybe the flux, in your example, could take an operator too so one could do sum, mean, median, std etc but then with the proper machinery for fractional pixels (?). |
|
Well, in the case of |
Why not? If I knowing cut out regions around some absorption features, then my expectation would be that my dispersion solution would look like, e.g.,
This is kind of interesting. In one case, e.g., extracting information about the continuum, a list of
Can I just mention that this seems completely semantically backwards to me -- conceptually, I want to extract a region from a spectrum, not a spectrum from a region. I feel like |
|
I agree that However, in reading the APE, I inferred there was a design decision to try to keep the Spectrum1D object lightweight, without a lot of methods apart from arithmetic. I guess the rationale for that was so that it would be easier to serialize, although that wasn't mentioned explicitly? If so, one should be cautious about adding any new methods. |
|
Re:
and
I agree with @nmearl here - I think it does make sense to use The hardest thing is about what to do on the edges: my vote is for the edge pixels in the resulting spectra to have the flux (and appropriately error-propogated uncertainties) from assuming they are "fractional" pixels based on the region edge+wcs, as we've discussed previously. The plot might look a bit weird because the edge pixels are all going to be low, but Put another way, we get all of those accessors "for free" if we return a set of spectra, but we are just throwing the user back in the current situation of "deal with arrays" if we implement the methods.
What about returning a |
|
Re: @nmearl's
I think this might be flip-a-coin. It's like the unix problem of linking: are you linking file
|
|
So, there seem to be two things we need to decide on:
@nmearl says that a single spectrum should be returned regardless of the number of sub-regions. @eteq suggests a Decision (?): Return a single
@nmearl would like to see it @hcferguson says the APE suggests the @eteq the method could live in either but maybe it should be a more descriptive name. Decision (?): Make the method name more descriptive and leave in SpectralRegion. (So Spectrum1D remains light-weight). @eteq @hcferguson @nmearl @anyoneelse What do you guys think of the suggested "decisions" for points 1 and 2 above? (These are both reasonably fundamental but there is other work waiting on these so I would like to move this along a bit). |
|
FWIW I agree with @nmearl here:
Or maybe |
|
Based on the above comments I am going to:
If someone would like otherwise, feel free to comment. |
|
Re: @brechmos-stsci 's 2 - To get something out for 0.4, lets go with the function approach as you suggested in #289 (comment). It's a lot easier to "upgrade" that to one of the method-approaches later (the function then just turns into a method call). For later consideration: What about the case where someone wants a custom form of extraction? There was a case just like this for #210 ... In that case the best solution is definitely Re: item 1 - I realized |
|
After a short discussion with @eteq, I am going to have the output of But... I think there is a need for a Spectrum1D concatenate method that takes some number of Spectrum1D objects and outputs a single one. There are a lot of sketchy issues with that, but it could be useful for applying to the output of |
976d250 to
923c7f5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
This update will allow SpectralRegions to have multiple sub-regions defined that may not be continuous. Needed, for example, if one wants to define a "noise region" that encompasses the left side and right side of a spectrum but not the middle portion.
Fixes #286
Fixes #285
Fixes #287