-
Notifications
You must be signed in to change notification settings - Fork 4
CALSPEC standards #31
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
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #31 +/- ##
==========================================
- Coverage 81.76% 80.32% -1.44%
==========================================
Files 6 6
Lines 351 366 +15
==========================================
+ Hits 287 294 +7
- Misses 64 72 +8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Any thoughts on this @lucasvalenzuela ? |
lucasvalenzuela
left a comment
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.
Thanks for the ping! I have left some comments on the code.
src/PhotometricFilters.jl
Outdated
| function __init__() | ||
| register(PYPHOT_DATADEP) | ||
| register(VEGA_DATADEP) | ||
| global vega_cache = @get_scratch!(joinpath("vega_standards")) |
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.
Since the joinpath call doesn't do anything, I would leave it away
| Downloads.download("https://ssb.stsci.edu/cdbs/calspec/" * name, fname) | ||
| end | ||
| return Vega(wavelength, flux, "vega.hdf5") | ||
| return Vega(fname) |
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.
Currently this leads to the unwanted behavior that Base.show for these Vega objects prints the following:
Vega magnitude system with reference spectrum /.../.julia/scratchspaces/.../vega_standards/alpha_lyr_stis_011.fits.
I would either add a second Vega(name, filename) method or automatically extract the name from the filename, though I think the latter approach would be less elegant.
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.
The following should resolve this:
function Vega(name::String = "alpha_lyr_stis_011", fname=splitext(name)[1] * ".fits")
name = splitext(name)[1]
if isfile(fname)
return FITSIO.FITS(fname, "r") do f
wavelength = read(f[2], "WAVELENGTH") .* u"angstrom"
flux = read(f[2], "FLUX") .* u"erg/s/cm^2/angstrom"
Vega(wavelength, flux, name)
end
end
# Load from CALSPEC database or local cache
fname = joinpath(vega_cache, fname)
if !isfile(fname)
Downloads.download("https://ssb.stsci.edu/cdbs/calspec/$name.fits", fname)
end
return Vega(name, fname)
end
Vega(name::AbstractString, args...) = Vega(string(name), args...)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.
Simply replacing Vega(wavelength, flux, name) with Vega(wavelength, flux, basename(name)) should accomplish this yes? The name in the struct is not used for anything but I think it's nice to track it for user info (e.g., so it's explicit where it came from).
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.
Oh yes, I think you're right. I keep forgetting about all the Filesystem functions in Julia...
Project.toml
Outdated
| [deps] | ||
| DataDeps = "124859b0-ceae-595e-8997-d05f6a7a8dfe" | ||
| DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" | ||
| Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6" |
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.
Any reason not to use HTTP.jl as it is already a dependency?
|
I like the scratchspace part of things, that seems very useful. Do you think that would also make sense for the SVO filters? I was also wondering if it would be handy to also have a "what's available" function for the spectra, similar to the function get_calspec_names()
response = HTTP.get("https://ssb.stsci.edu/cdbs/calspec/")
xml = read(IOBuffer(response.body), LazyNode)
calspec_names = String[]
for node in xml
if tag(node) == "a"
filename = value(children(node)[1])
calspec_name, ext = splitext(filename)
ext == ".fits" || continue
push!(calspec_names, calspec_name)
end
end
return calspec_names
endWhat do you think? |
HTTP.download issues an @info which messes with the doctest
|
Thanks for the review and contribution! I added your I am presently against a simple cache for the SVO filters as they are not necessarily static. The filters can be updated over time -- in fact, the detector type for the 2MASS filters was just changed from energy to photon to properly reflect the convention of the underlying filter curves. I like the cache for the CALSPEC stuff because they are generally static as a function of file name -- "alpha_lyr_stis_011.fits" should always contain the same data, and if they want to issue a new standard spectrum, they increment the "011" part. I can see an avenue for caching the filters that might look something like this: on first request, the SVO filter is downloaded and cached according to its identifier. It is used from the cache for future requests. We provide a method (something like I don't presently want to work on that, but what do you think? |
lucasvalenzuela
left a comment
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.
This looks good, just added two minor comments. I also noticed that Base.show for the Vega objects prints a full stop at the end of the line, which I don't think is generally used for printing types like that.
Besides those three points I think this is good to go!
|
And that is a good point on the static nature of the spectra vs the filters. I like your idea of letting the user cache the filters and update them every so often. I think I will tackle that when I find time to work on my filter project again (which will most likely still be a few months away, though). |
|
Actually I think I'll try to work on the filter caching this afternoon so I'm going to merge this. Feel free to open issues if there's anything else from this PR that needs to be fixed. |


@lucasvalenzuela Fixes #27 by supporting arbitrary spectral standards from CALSPEC. Files are automatically downloaded and cached into a scratchspace using Scratch.jl. I don't know if this will work for every single file in the extended CALSPEC catalog but I tried it with all the
alpha_lyrfiles and they all look good. I can write more extended tests if we want to test against a wider range of standard files.