Fix output file basename inconsistencies - #2192
Conversation
|
Dev-suite running.... |
rcooke-ast
left a comment
There was a problem hiding this comment.
Some changes request. Let's see what the dev suite outputs, but I've mentioned a possible issue concerning SOAR/Goodman. Everything else is pretty minor. Thanks!
| if args.mode == 'save': | ||
| folder = '{}_noisecheck'.format(file.split('.fits')[0]) | ||
| if not os.path.exists(folder): os.makedirs(folder) | ||
| folder = Path(f'{Path(file).with_suffix("")}_noisecheck') |
There was a problem hiding this comment.
Is it a concern that we add _noisecheck for both 1D and 2D checks (see above)? Should we also add 1D and 2D?
There was a problem hiding this comment.
Good question. I think the 1d script can accept either spec1d files or output files from 1D coadds. In the former, the spec1d is kept because it uses the original filename as the base. That won't be true for the latter, but its name can't get mixed up with the 2D file. For the 2D script, the output file will always be spec2d*_noisecheck.
This maintains the old behavior, so I think we should keep it unless you have a strong objection.
| telescope = telescopes.SOARTelescopePar() | ||
| url = 'https://noirlab.edu/science/programs/ctio/instruments/goodman-high-throughput-spectrograph' | ||
| allowed_extensions = [".fz"] | ||
| allowed_extensions = [".fits", ".fits.fz"] |
There was a problem hiding this comment.
Might want to think about this... You can download .fits and .fz files from the SOAR archive, and the headers are either 0-indexed on 1-indexed. So, I think we will want to explicitly keep .fz here.
There was a problem hiding this comment.
Good point. I had forgotten this. I'll restrict it back to .fits.fz. It needs to be the full extension, not just .fz to properly construct the basename now.
| # Test the allowed extensions for an oddball spectrograph | ||
| spec5 = load_spectrograph('soar_goodman_red') | ||
| assert spec5.allowed_extensions == [".fz"], 'Found wrong extensions' | ||
| assert spec5.allowed_extensions == [".fits", ".fits.fz"], 'Found wrong extensions' |
There was a problem hiding this comment.
Likewise , probably want to revert this.
| raise PypeItError(f'Missing FILENAME keyword in {spec2d_files[0]}. Set the basename ' | ||
| 'using the command-line option.') | ||
| raise PypeItError( | ||
| f'Missing FILENAME keyword in {spec2d_files[0]}. Set the basename using the ' |
There was a problem hiding this comment.
Hmmm... I'm not sure what the command-line option is (but then again, I've never used coadd2d). I just thought I'd flag it in case it's not obvious to the user what they need to do to get a basename from these messages.
There was a problem hiding this comment.
Good catch. The pypeit_coadd_2dspec script does have a --basename command-line option that can be used to override the default. So I think this message is still valid (even if it's placement is less than ideal).
| 'fpacked_file' | ||
|
|
||
| """ | ||
| _compression_suffixes = ('.gz', '.bz2', '.fz') |
There was a problem hiding this comment.
Not sure if we want to include the fz suffix here. Otherwise, the SOAR Goodman might not work.
There was a problem hiding this comment.
All the soar_goodman files in the dev-suite have the .fits.fz extension, so using .fz here is right for those files at least. Are files distributed that don't have the .fits part of the extension? The reason to have the .fz in the compression suffix list is to make sure *.fits.fz file strings are returned as *, not *.fits.
| # NOTE: This determination of obstime is exactly what is done inside of | ||
| # construct_basename when obstime is not provided. The only reason this is | ||
| # done here is because obstime is also returned by this function. | ||
| obstime = fitstbl.construct_obstime(frame) |
There was a problem hiding this comment.
Is it worthwhile uniting these here, or not worth the effort?
There was a problem hiding this comment.
I'm of two minds. obstime is used by pypeit_steps.extract_det as an argument passed to pypeit_steps.refframe_correct, but every other time it is returned it is ignored. So it seems like we could consolidate, but it feels like it's more trouble than its worth for now.
|
Tests pass |
kbwestfall
left a comment
There was a problem hiding this comment.
Thanks for the quick review, @rcooke-ast ! I've responded to everything. Two things to draw your attention to:
- Do you have strong feelings about adding the 1D/2D notation to the noise check? My edit maintains the old behavior and I think the 1D/2D will be included for most files because the output uses the input
spec1d/2dfiles as the root name. - Are there SOAR/Goodman files that have the
.fzextension without the preceding.fits? If so, I'll need to adjust, but otherwise things should work fine. All the dev-suite files include.fits.fz.
| if args.mode == 'save': | ||
| folder = '{}_noisecheck'.format(file.split('.fits')[0]) | ||
| if not os.path.exists(folder): os.makedirs(folder) | ||
| folder = Path(f'{Path(file).with_suffix("")}_noisecheck') |
There was a problem hiding this comment.
Good question. I think the 1d script can accept either spec1d files or output files from 1D coadds. In the former, the spec1d is kept because it uses the original filename as the base. That won't be true for the latter, but its name can't get mixed up with the 2D file. For the 2D script, the output file will always be spec2d*_noisecheck.
This maintains the old behavior, so I think we should keep it unless you have a strong objection.
| telescope = telescopes.SOARTelescopePar() | ||
| url = 'https://noirlab.edu/science/programs/ctio/instruments/goodman-high-throughput-spectrograph' | ||
| allowed_extensions = [".fz"] | ||
| allowed_extensions = [".fits", ".fits.fz"] |
There was a problem hiding this comment.
Good point. I had forgotten this. I'll restrict it back to .fits.fz. It needs to be the full extension, not just .fz to properly construct the basename now.
| # Test the allowed extensions for an oddball spectrograph | ||
| spec5 = load_spectrograph('soar_goodman_red') | ||
| assert spec5.allowed_extensions == [".fz"], 'Found wrong extensions' | ||
| assert spec5.allowed_extensions == [".fits", ".fits.fz"], 'Found wrong extensions' |
| raise PypeItError(f'Missing FILENAME keyword in {spec2d_files[0]}. Set the basename ' | ||
| 'using the command-line option.') | ||
| raise PypeItError( | ||
| f'Missing FILENAME keyword in {spec2d_files[0]}. Set the basename using the ' |
There was a problem hiding this comment.
Good catch. The pypeit_coadd_2dspec script does have a --basename command-line option that can be used to override the default. So I think this message is still valid (even if it's placement is less than ideal).
| 'fpacked_file' | ||
|
|
||
| """ | ||
| _compression_suffixes = ('.gz', '.bz2', '.fz') |
There was a problem hiding this comment.
All the soar_goodman files in the dev-suite have the .fits.fz extension, so using .fz here is right for those files at least. Are files distributed that don't have the .fits part of the extension? The reason to have the .fz in the compression suffix list is to make sure *.fits.fz file strings are returned as *, not *.fits.
| # NOTE: This determination of obstime is exactly what is done inside of | ||
| # construct_basename when obstime is not provided. The only reason this is | ||
| # done here is because obstime is also returned by this function. | ||
| obstime = fitstbl.construct_obstime(frame) |
There was a problem hiding this comment.
I'm of two minds. obstime is used by pypeit_steps.extract_det as an argument passed to pypeit_steps.refframe_correct, but every other time it is returned it is ignored. So it seems like we could consolidate, but it feels like it's more trouble than its worth for now.
|
Thanks, @kbwestfall! Sounds good, and I'm fine leaving noisecheck as it is (I've never used it before, and if others are happy with it as is, then we should leave it). The only thing to avoid with SOAR/Goodman is to not allow |
In the construction of the basename used for output file, we were not accounting for the different extensions possible for each spectrograph. I ran into this issue because #2184 adds a
setup_datacubescript that assumes all the raw files have.fitsextensions.This PR accomplishes two things:
PypeItMetaDataclass into its own stand-alone function. This makes it easier to construct the basename at any place in the code.As a by-product of these goals, I also extended the
io.remove_suffixfunction to respect additional compression extensions, instead of just working with.gzfiles. And, I removed the old use of.split('.fits')to remove the file suffix. Instead of the latter, I use eitherio.remove_suffixorPath.with_suffix.For the nit-gritty details, see the claude doc in the dev-suite.