CIERA-Transients / POTPyRI

GNU General Public License v3.0
6 stars 6 forks source link

Manual WCS solution fail #7

Open nabeelre opened 1 year ago

nabeelre commented 1 year ago

When the automatic WCS solution fails and one opts to manually redo WCS the pipeline crashes with the following traceback (I've included some previous output for context):

Please review the WCS plots and errors. Do you wish to manually redo wcs (yes or no)?  yes
2023-04-24 17:09:21,785 INFO Manually redoing WCS.
INFO:/Users/nabeelr/Desktop/School/Observations/SN2004et_H/2023.0401//red/MMIRS_log_20230424_170226.log:Manually redoing WCS.
Please enter the name of the catalog you wish to use. The options are "gaia" (GAIA DR3), "sdssdr12" (SDSSDR12), "2mass" (2MASS). 2mass
Searching 2mass catalog...
1284 records in 2mass catalog
1284 total records in catalog
Displaying interactive plot to select star for WCS solution.
First select star (red) and corresponding catalog match (green).
A message will confirm the selection of the star in the terminal.
Note: star selection is turned off in zoom/pan mode (you need to de-select the mode in order to select stars).
Close figure when finished.
Source star x = 1006.421612, y = 740.415973
Catalog star: RA = 308.878865, Dec = 60.123878
Source star x = 956.458762, y = 866.465166
Catalog star: RA = 308.864525, Dec = 60.126633
Source star x = 980.825090, y = 934.558268
Catalog star: RA = 308.856970, Dec = 60.125317
Please check and edit the .xy and .radec files in the case of errors. Hit any key to continue. 
Traceback (most recent call last):
  File "/Users/nabeelr/Developer/POTPyRI/main_pipeline.py", line 543, in <module>
    main()
  File "/Users/nabeelr/Developer/POTPyRI/main_pipeline.py", line 540, in main
    main_pipeline(args.telescope,args.data_path,args.cal_path,input_target=args.target,skip_red=args.skip_red,proc=args.proc,use_dome_flats=args.use_dome_flats,phot=args.phot,reset=args.reset)
  File "/Users/nabeelr/Developer/POTPyRI/main_pipeline.py", line 444, in main_pipeline
    wcs_error = solve_wcs.man_wcs(telescope, stack[k].replace('_wcs',''), cat, cat_stars_ra, cat_stars_dec)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nabeelr/Developer/POTPyRI/solve_wcs.py", line 89, in man_wcs
    header_new = apply_wcs_distortion(header_trans,starsx,starsy,catstarsra,catstarsdec)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nabeelr/Developer/POTPyRI/solve_wcs.py", line 187, in apply_wcs_distortion
    p1 = curve_fit(ptv_fit,(xi,eta),dra,p0=p0)[0]
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nabeelr/miniforge3/envs/pipeline/lib/python3.11/site-packages/scipy/optimize/_minpack_py.py", line 859, in curve_fit
    res = leastsq(func, p0, Dfun=jac, full_output=1, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nabeelr/miniforge3/envs/pipeline/lib/python3.11/site-packages/scipy/optimize/_minpack_py.py", line 413, in leastsq
    shape, dtype = _check_func('leastsq', 'func', func, x0, args, n)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nabeelr/miniforge3/envs/pipeline/lib/python3.11/site-packages/scipy/optimize/_minpack_py.py", line 26, in _check_func
    res = atleast_1d(thefunc(*((x0[:numinputs],) + args)))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nabeelr/miniforge3/envs/pipeline/lib/python3.11/site-packages/scipy/optimize/_minpack_py.py", line 501, in func_wrapped
    return func(xdata, *params) - ydata
           ^^^^^^^^^^^^^^^^^^^^
  File "/Users/nabeelr/Developer/POTPyRI/solve_wcs.py", line 177, in ptv_fit
    return np.sum([p[i]*d[i] for i in range(len(p))])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<__array_function__ internals>", line 200, in sum
  File "/Users/nabeelr/miniforge3/envs/pipeline/lib/python3.11/site-packages/numpy/core/fromnumeric.py", line 2324, in sum
    return _wrapreduction(a, np.add, 'sum', axis, dtype, out, keepdims=keepdims,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nabeelr/miniforge3/envs/pipeline/lib/python3.11/site-packages/numpy/core/fromnumeric.py", line 86, in _wrapreduction
    return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (3,) + inhomogeneous part.

I'm reducing MMIRS data on an M1-based MacBook running macOS 12.6.1.

SunilSimha commented 1 year ago

Hi, I'm running into this error as well. I did some digging and it appears that the failure is happening at line 188 of solve_wcs.py. This is in the apply_wcs_distortion function and it's a bug with the input for curve_fit:

curve_fit(ptv_fit,(xi,eta),dra,p0=p0)[0]

This is also the reason why the auto_WCS feature has been failing. I think it might have to do with curve_fit no longer accepting the inputs in the format assumed. @KerryPaterson, looks like you had last contributed to this snippet of code (commit 538330a). Could you please take a look? I'm unable to parse the intent of this line to suggest a fix.