Skip to content
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

STD STAR FIXES #1833

Merged
merged 20 commits into from
Aug 19, 2024
Merged

STD STAR FIXES #1833

merged 20 commits into from
Aug 19, 2024

Conversation

debora-pe
Copy link
Collaborator

These are kind of random fixes all related to problems with reading/using the standard star extracted spectrum. Users often brought up failures related to this, and I have tried to fix those.

  • Fix the error "Standard star trace does not match the number of orders in the echelle data" when using the standard star trace as a crutch for the object trace.
  • Added the possibility to not use the standard star trace as a crutch for the object trace even if a spectrum is available. For this the parameter use_std_trace was added.
  • fix the error "ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions..." occurring when unpacking the SpecObj spectrum but having an attribute of the SpecObj object that is None.
  • Added the possibility to use BOX extraction when computing the sensitivity function.

@codecov-commenter
Copy link

codecov-commenter commented Jul 29, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 52.38095% with 70 lines in your changes missing coverage. Please review.

Project coverage is 38.22%. Comparing base (50074c0) to head (4daf232).

Files Patch % Lines
pypeit/core/findobj_skymask.py 66.66% 24 Missing ⚠️
pypeit/sensfunc.py 12.50% 14 Missing ⚠️
pypeit/specobjs.py 41.66% 14 Missing ⚠️
pypeit/coadd1d.py 0.00% 5 Missing ⚠️
pypeit/par/pypeitpar.py 70.58% 5 Missing ⚠️
pypeit/pypeit.py 25.00% 3 Missing ⚠️
pypeit/scripts/sensfunc.py 60.00% 2 Missing ⚠️
pypeit/spectrographs/keck_hires.py 0.00% 2 Missing ⚠️
pypeit/spectrographs/keck_nires.py 0.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1833      +/-   ##
===========================================
- Coverage    38.23%   38.22%   -0.01%     
===========================================
  Files          208      208              
  Lines        48359    48414      +55     
===========================================
+ Hits         18488    18505      +17     
- Misses       29871    29909      +38     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@debora-pe debora-pe requested review from kbwestfall and profxj July 31, 2024 18:59
@debora-pe
Copy link
Collaborator Author

Tests pass with some unrelated failures

Test Summary
--------------------------------------------------------
--- PYTEST PYPEIT UNIT TESTS PASSED  256 passed, 63 warnings in 344.64s (0:05:44) ---
--- PYTEST UNIT TESTS FAILED  2 failed, 146 passed, 166 warnings in 1591.27s (0:26:31) ---
--- PYTEST VET TESTS PASSED  62 passed, 98 warnings in 5461.41s (1:31:01) ---
--- PYPEIT DEVELOPMENT SUITE FAILED 1/239 TESTS  ---
Failed tests:
    gemini_gmos/GN_E2V_MULTI_R400_600 pypeit
Skipped tests:
Testing Started at 2024-08-02T15:52:19.575626
Testing Completed at 2024-08-03T05:25:20.741316
Total Time: 13:33:01.165690

Copy link
Collaborator

@profxj profxj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great stuff!

- A new script, called `pypeit_extract_datacube`, allows 1D spectra of point
sources to be extracted from datacubes.
- The sensitivity function is now generated outside of datacube generation.
- The `grating_corr` column is now used to select the correct grating
correction file for each spec2d file when generating the datacube.
- Added the ``--extr`` parameter in the ``pypeit_sensfunc`` script (also as a SensFuncPar)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

'(i.e., faint sources). If provided, this overrides use of any ' \
'standards included in your pypeit file; the standard exposures ' \
'will still be reduced.'
descr['std_spec1d'] = 'A PypeIt spec1d file of a previously reduced standard star. ' \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!

@@ -245,7 +245,9 @@ def get_std_outfile(self, standard_frames):
# isolate where the name of the standard-star spec1d file is defined.
std_outfile = self.par['reduce']['findobj']['std_spec1d']
if std_outfile is not None:
if not Path(std_outfile).absolute().exists():
if not self.par['reduce']['findobj']['use_std_trace']:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do this vetting in pypeitpar.py ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is actually also done in pypeitpar.py. It may be redundant but I was just following what already existed, i.e., vetting the existence of the file here and in pypeitpar.py

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, validate is only called during instantiation. So if the parameter is changed by the code after the ParSet is instantiated (e.g., by the default_pypeit_par or config_specific_par spectrograph functions), the validation won't catch a file that doesn't exist. Something to refactor (in infinite time...).

else:
# if not, we need to use dtype="object"
return np.array(lst, dtype="object")[mask]
# TODO: The dtype="object" is needed for the case where one element of lst is not a list but None.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to have @kbwestfall 's eyes on this..

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is fine, but I'd have a full picture of why we need it. I.e., this ValueError must not have been something that is often tripped in the code. What cases cause it to be tripped? And are these cases that we must support, or are we just trying to keep the code from faulting here, even though the root cause is actually something at we should avoid?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kbwestfall the error "ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions..." happens pretty often, especially for echelle, but not only. I have found it happens when trying to unpack SpecObjs. For example, if we are trying to get all the OPT fluxes from a specific SpecObjs, and for one slit/order the OPT extraction failed (but not the BOX extraction) and therefore OPT_COUNTS is None, the list lst in this method would be something like [array, array, array, None, array], which makes np.array to fail and give the ValueError. With dtype='object' this error does not occur, but some functions later on in the code do not like to work with object arrays. I thought this was a compromise to deal with this situation.

I tried to fix the root cause partially in hires, by forcing standard star echelle data to have maximum one object per order and other science echelle data maximum 2 objects per order, since most of the failed OPT extraction are due to sky subtraction problems (caused by spurious detections). But anyway, I think we need a way to deal with this in general.

Copy link
Collaborator

@kbwestfall kbwestfall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some direct edits, and I had a few other very minor comments. I'm only setting "request changes" to make sure that we re-run tests.

pypeit/coadd1d.py Show resolved Hide resolved
pypeit/core/findobj_skymask.py Outdated Show resolved Hide resolved
@@ -245,7 +245,9 @@ def get_std_outfile(self, standard_frames):
# isolate where the name of the standard-star spec1d file is defined.
std_outfile = self.par['reduce']['findobj']['std_spec1d']
if std_outfile is not None:
if not Path(std_outfile).absolute().exists():
if not self.par['reduce']['findobj']['use_std_trace']:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, validate is only called during instantiation. So if the parameter is changed by the code after the ParSet is instantiated (e.g., by the default_pypeit_par or config_specific_par spectrograph functions), the validation won't catch a file that doesn't exist. Something to refactor (in infinite time...).

else:
# if not, we need to use dtype="object"
return np.array(lst, dtype="object")[mask]
# TODO: The dtype="object" is needed for the case where one element of lst is not a list but None.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is fine, but I'd have a full picture of why we need it. I.e., this ValueError must not have been something that is often tripped in the code. What cases cause it to be tripped? And are these cases that we must support, or are we just trying to keep the code from faulting here, even though the root cause is actually something at we should avoid?

@debora-pe
Copy link
Collaborator Author

@kbwestfall tests pass. The 2 failing unit tests are related to the problem that my computer has with setup_gui

Test Summary
--------------------------------------------------------
--- PYTEST PYPEIT UNIT TESTS PASSED  256 passed, 65 warnings in 342.08s (0:05:42) ---
--- PYTEST UNIT TESTS FAILED  2 failed, 146 passed, 166 warnings in 1696.99s (0:28:16) ---
--- PYTEST VET TESTS PASSED  62 passed, 106 warnings in 5455.17s (1:30:55) ---
--- PYPEIT DEVELOPMENT SUITE PASSED 239/239 TESTS  ---
Testing Started at 2024-08-15T15:06:11.414230
Testing Completed at 2024-08-16T04:21:25.327130
Total Time: 13:15:13.912900

Copy link
Collaborator

@kbwestfall kbwestfall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for running the tests!

@debora-pe
Copy link
Collaborator Author

merging

@debora-pe debora-pe merged commit 754cb17 into develop Aug 19, 2024
23 checks passed
@debora-pe debora-pe deleted the random_fixes branch August 19, 2024 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants