FIDUCEO / FCDR_HIRS

Other
1 stars 2 forks source link

CURUC fitting may cause RuntimeError when optimisation fails #300

Open gerritholl opened 5 years ago

gerritholl commented 5 years ago

In some circumstances, apply_curuc may cause a RuntimeError to be raised, when calc_Δ_x, which tries to fit a Δ_x to the data, is failing to converge in the fitting, resulting in

RuntimeError: Optimal parameters not found: Number of calls to function has reached maxfev = 400.

The full traceback may look something like this:

  File "/group_workspaces/cems2/fiduceo/Users/gholl/anaconda3/envs/FCDR37b/bin/generate_fcdr", line 11, in <module>
    sys.exit(main())
  File "/group_workspaces/cems2/fiduceo/Users/gholl/anaconda3/envs/FCDR37b/lib/python3.7/site-packages/FCDR_HIRS/processing/generate_fcdr.py", line 925, in main
    fgen.process()
  File "/group_workspaces/cems2/fiduceo/Users/gholl/anaconda3/envs/FCDR37b/lib/python3.7/site-packages/FCDR_HIRS/processing/generate_fcdr.py", line 244, in process
    self.dd.center_time)
  File "/group_workspaces/cems2/fiduceo/Users/gholl/anaconda3/envs/FCDR37b/lib/python3.7/site-packages/FCDR_HIRS/processing/generate_fcdr.py", line 297, in make_and_store_piece
    (piece, sensRe) = self.get_piece(from_, to, return_more=True)
  File "/group_workspaces/cems2/fiduceo/Users/gholl/anaconda3/envs/FCDR37b/lib/python3.7/site-packages/FCDR_HIRS/processing/generate_fcdr.py", line 505, in get_piece
    robust=True, return_vectors=True, interpolate_lengths=True)
  File "/group_workspaces/cems2/fiduceo/Users/gholl/anaconda3/envs/FCDR37b/lib/python3.7/site-packages/FCDR_HIRS/metrology.py", line 1220, in calc_corr_scale_channel
    cutoff_e=n_e)
  File "/group_workspaces/cems2/fiduceo/Users/gholl/anaconda3/envs/FCDR37b/lib/python3.7/site-packages/FCDR_HIRS/metrology.py", line 766, in apply_curuc
    (Δ_l, Δ_l_full) = calc_Δ_x(R_ls_goodchans, return_vector=True)
  File "/group_workspaces/cems2/fiduceo/Users/gholl/anaconda3/envs/FCDR37b/lib/python3.7/site-packages/FCDR_HIRS/metrology.py", line 355, in calc_Δ_x
    p0=1) for c in r_xΔ["n_c"]])[..., 0],
  File "/group_workspaces/cems2/fiduceo/Users/gholl/anaconda3/envs/FCDR37b/lib/python3.7/site-packages/FCDR_HIRS/metrology.py", line 355, in <listcomp>
    p0=1) for c in r_xΔ["n_c"]])[..., 0],
  File "/group_workspaces/cems2/fiduceo/Users/gholl/anaconda3/envs/FCDR37b/lib/python3.7/site-packages/scipy/optimize/minpack.py", line 755, in curve_fit
    raise RuntimeError("Optimal parameters not found: " + errmsg)
RuntimeError: Optimal parameters not found: Number of calls to function has reached maxfev = 400.

It's almost certainly triggered by (very) bad input data, but I imagine it may potentially impact @jmittaz using it for AVHRR as well.

gerritholl commented 5 years ago

This happens at least 26 times when processing the full HIRS archive. At present it causes my processing scripts to crash and stop processing, so it may be that it occurs more than 26 times in total, within the same decad.

jmittaz commented 5 years ago

Happens for the AVHRR as well - impacted 700 orbits for NOAA-11 to MetOp-A (about 0.4%)

gerritholl commented 5 years ago

I think this happens when there are less than 3 valid input lines in whatever is given to CURUC. For HIRS, I am now not as conservative with the brokenline input, but this RuntimeError can still happen.