njcuk9999 / apero-drs

A PipelinE to Reduce Observations - The DRS for SPIRou (CFHT)
MIT License
12 stars 0 forks source link

apero_ccf_nirps_he - `ValueError: Residuals are not finite in the initial point` while running the manual trigger #769

Closed leslie-05 closed 1 week ago

leslie-05 commented 1 month ago

Runstring: apero_ccf_nirps_he.py 2024-07-02 NIRPS_2024-07-03T01_05_49_748_pp_e2dsff_tcorr_A.fits --rv=nan --width=300.0 --step=0.25 --masknormmode=order --database=True --plot=0 --program=CCF[00389] --recipe_kind=rv-tcorr --parallel=True --shortname=CCF --crunfile=online_run.ini

Error Message in logfile: 23:20:03.803- |CCF[00389]|A[40-020-00005]: Processing CCF fiber A for Order 0 23:20:03.837-@$|CCF[00389]|W[10-020-00007]: Order 0 CCF mask for this order only has lines in invalid blaze locations. CCF set to NaNs 23:20:03.845- |CCF[00389]|A[40-020-00005]: Processing CCF fiber A for Order 1 23:20:03.986-!!|CCF[00389]|E[01-010-00001]: Unhandled error has occurred: Error <class 'ValueError'> 23:20:03.986-!!|CCF[00389]| 23:20:03.987-!!|CCF[00389]|Traceback (most recent call last): 23:20:03.988-!!|CCF[00389]| File "/cosmos99/nirps/git-bin/apero-drs-online/apero/core/utils/drs_startup.py", line 433, in run 23:20:03.989-!!|CCF[00389]| llmain = func(recipe, params) 23:20:03.990-!!|CCF[00389]| File "/cosmos99/nirps/git-bin/apero-drs-online/apero/recipes/nirps_he/apero_ccf_nirps_he.py", line 215, in main 23:20:03.991-!!|CCF[00389]| rv_props1 = velocity.compute_ccf_science(params, recipe, cargs) 23:20:03.992-!!|CCF[00389]| File "/cosmos99/nirps/git-bin/apero-drs-online/apero/science/velocity/gen_vel.py", line 782, in compute_ccf_science 23:20:03.993-!!|CCF[00389]| props = ccf_calculation_per_order(params, image, blaze, wavemap, berv, 23:20:03.994-!!|CCF[00389]| File "/cosmos99/nirps/git-bin/apero-drs-online/apero/science/velocity/gen_vel.py", line 1168, in ccf_calculation_per_order 23:20:03.995-!!|CCF[00389]| ccf_coeffs_ord, ccf_fit_ord, ccf_fit_names = fit_ccf_ea(params, fargs) 23:20:03.995-!!|CCF[00389]| File "/cosmos99/nirps/git-bin/apero-drs-online/apero/science/velocity/gen_vel.py", line 1404, in fit_ccfea 23:20:03.996-!!|CCF[00389]| result, = curve_fit(mp.gaussian_slope, rv, ccf, 23:20:03.997-!!|CCF[00389]| File "/cosmos99/nirps/bin/miniconda3/envs/apero-env-07/lib/python3.9/site-packages/scipy/optimize/_minpack_py.py", line 870, in curve_fit 23:20:03.998-!!|CCF[00389]| res = least_squares(func, p0, jac=jac, bounds=bounds, method=method, 23:20:03.999-!!|CCF[00389]| File "/cosmos99/nirps/bin/miniconda3/envs/apero-env-07/lib/python3.9/site-packages/scipy/optimize/_lsq/least_squares.py", line 837, in least_squares 23:20:04.000-!!|CCF[00389]| raise ValueError("Residuals are not finite in the initial point.") 23:20:04.001-!!|CCF[00389]|ValueError: Residuals are not finite in the initial point.

vandalt commented 1 week ago

Here is one additional runstring that caused this error:

apero_ccf_nirps_he.py 2024-08-08 NIRPS_2024-08-09T07_47_45_862_pp_e2dsff_tcorr_A.fits --rv=nan --width=300.0 --step=0.25 --masknormmode=order --database=True --plot=0 --program=CCF[01253] --recipe_kind=rv-tcorr --parallel=True --shortname=CCF --crunfile=online_run.ini
njcuk9999 commented 1 week ago

This seems to be a problem that the guess used for the CCF is not good (and the data is pretty bad too) probably unable to fit a gaussian to the data.

Need to have a good metric on whether we can measure a gaussian, or have a better guess (that doesn't go out-of-bounds) or catch more exceptions and skip these orders that fail.

njcuk9999 commented 1 week ago

This was due to the curve_fit sigma=sig term having nans in (we test the CCF for nans but didn't test the sig term) the curve_fiterror really doesn't help here!