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

Manual Extraction on Coadd2d Spectra: Unexpected AttributeError in numpy.fmod with dtype=object Arrays #1890

Open
jasonpeng17 opened this issue Jan 21, 2025 · 2 comments
Labels

Comments

@jasonpeng17
Copy link
Collaborator

When I attempted to manual extraction on my coadd2d spectra from Pypeit 1.17.1, I got the following error message:

Traceback (most recent call last):
 File "/Users/zixuanpeng/opt/anaconda3/envs/pypeit/bin/pypeit_coadd_2dspec", line 8, in <module>
  sys.exit(CoAdd2DSpec.entry_point())
       ^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/Users/zixuanpeng/opt/anaconda3/envs/pypeit/lib/python3.11/site-packages/pypeit/scripts/scriptbase.py", line 114, in entry_point
  cls.main(cls.parse_args())
 File "/Users/zixuanpeng/opt/anaconda3/envs/pypeit/lib/python3.11/site-packages/pypeit/scripts/coadd_2dspec.py", line 196, in main
  = coadd.reduce(pseudo_dict, show=args.show, show_peaks=args.peaks, basename=basename)
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/Users/zixuanpeng/opt/anaconda3/envs/pypeit/lib/python3.11/site-packages/pypeit/coadd2d.py", line 834, in reduce
  global_sky_pseudo, sobjs_obj = objFind.run(show_peaks=show or show_peaks, show_skysub_fit=show_skysub_fit)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/Users/zixuanpeng/opt/anaconda3/envs/pypeit/lib/python3.11/site-packages/pypeit/find_objects.py", line 351, in run
  sobjs_obj, self.nobj = self.find_objects(self.sciImg.image, self.sciImg.ivar,
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/Users/zixuanpeng/opt/anaconda3/envs/pypeit/lib/python3.11/site-packages/pypeit/find_objects.py", line 442, in find_objects
  self.find_objects_pypeline(image, ivar,
 File "/Users/zixuanpeng/opt/anaconda3/envs/pypeit/lib/python3.11/site-packages/pypeit/find_objects.py", line 944, in find_objects_pypeline
  sobjs_ech = findobj_skymask.ech_objfind(
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/Users/zixuanpeng/opt/anaconda3/envs/pypeit/lib/python3.11/site-packages/pypeit/core/findobj_skymask.py", line 1305, in ech_objfind
  obj_id = ech_fof_sobjs(sobjs_in_orders, slit_left, slit_righ, order_vec, plate_scale, fof_link=fof_link)
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/Users/zixuanpeng/opt/anaconda3/envs/pypeit/lib/python3.11/site-packages/pypeit/core/findobj_skymask.py", line 402, in ech_fof_sobjs
  = pydl.spheregroup(ra_fake, dec_fake, FOF_frac/1000.0)
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/Users/zixuanpeng/opt/anaconda3/envs/pypeit/lib/python3.11/site-packages/pypeit/core/pydl.py", line 1552, in spheregroup
  chunk = chunks(ra, dec, chunksize)
      ^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/Users/zixuanpeng/opt/anaconda3/envs/pypeit/lib/python3.11/site-packages/pypeit/core/pydl.py", line 1078, in __init__
  self.raMin, self.raMax = self.getraminmax(ra, self.raOffset)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/Users/zixuanpeng/opt/anaconda3/envs/pypeit/lib/python3.11/site-packages/pypeit/core/pydl.py", line 1158, in getraminmax
  currRa = np.fmod(ra + raOffset, 360.0)
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'numpy.float64' object has no attribute 'fmod'

The main issue here seems to be the ra numpy array contained both Python float and numpy.float64 as objects, but ra is explicitly set to dtype=object, meaning it contains Python objects instead of standard NumPy float64 elements (example attached below).

In [1]: ra
Out[1]: 
array([np.float64(0.00042043491510027374), 0.0004339080459770116,
       np.float64(0.0004477365176930186),
       np.float64(0.0004603022893073715),
       np.float64(0.0004648329181943401),
       np.float64(0.00046714450939566645),
       np.float64(0.0004692453942313854),
       np.float64(0.0004679435356018008),
       np.float64(0.0004739301929891501),
       np.float64(0.0005127088976754066)], dtype=object)

To avoid this bug, I need to change the line 1969 in findobj_skymask.py (

thisobj.SPAT_FRACPOS = float(f_ximg(thisobj.hand_extract_spec, thisobj.hand_extract_spat, grid=False)) # interpolate from ximg
) from

to

thisobj.SPAT_FRACPOS = np.float64(f_ximg(thisobj.hand_extract_spec, thisobj.hand_extract_spat, grid=False)) # interpolate from ximg

@kbwestfall
Copy link
Collaborator

Hi @jasonpeng17 . Thanks for reporting this issue! Can you pass along a minimal dataset that I can use to reproduce the error? You could e-mail me ([email protected]) or send me a direct message on the PypeIt Users Slack.

I really appreciate you providing a fix! But I'm confused by the error and want to make sure there isn't a different underlying problem that would remain after your solution.

@kbwestfall
Copy link
Collaborator

See #1894 .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants