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

reproject_and_coadd is picky with WCS #294

Open
meindertsma opened this issue Jun 10, 2022 · 4 comments
Open

reproject_and_coadd is picky with WCS #294

meindertsma opened this issue Jun 10, 2022 · 4 comments

Comments

@meindertsma
Copy link

meindertsma commented Jun 10, 2022

I'm trying to make a mosaic using reproject_and_coadd. I have fits files in Lum with proper wcs's, and want to use these for the rest of the filters as well, since they are all aligned, however I get the following error which confuses me:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-59-0b2ebe682520> in <module>
      8 for filt in filters:
      9     hdulist_list = [fits.open(combined_images[obj][filt]) for obj in objects] #list of images to combine in one filter
---> 10     data, footprint = reproject_and_coadd(hdulist_list, wcs, shape_out=shape, reproject_function=reproject_interp)
     11     display_image(data, 5, 99, scale='squared', figsize=(16, 12), title=f"Mosaic {filt}")
     12     write_to_fits(procdir, data, f"Mosaic_{filt}.fits", header=header)

/Software/users/modules/7/software/anaconda3/2020.07/lib/python3.8/site-packages/reproject/mosaicking/coadd.py in reproject_and_coadd(input_data, output_projection, shape_out, input_weights, hdu_in, reproject_function, hdu_weights, combine_function, match_background, background_reference, **kwargs)
    122         xc = np.array([-0.5, nx - 0.5, nx - 0.5, -0.5])
    123         yc = np.array([-0.5, -0.5, ny - 0.5, ny - 0.5])
--> 124         xc_out, yc_out = wcs_out.world_to_pixel(wcs_in.pixel_to_world(xc, yc))
    125 
    126         # Determine the cutout parameters

/Software/users/modules/7/software/anaconda3/2020.07/lib/python3.8/site-packages/astropy/wcs/wcsapi/high_level_api.py in world_to_pixel(self, *world_objects)
    183                 w = world_objects[ikey]
    184                 if not isinstance(w, klass):
--> 185                     raise ValueError("Expected the following order of world "
    186                                      "arguments: {}".format(', '.join([k.__name__ for (k, _, _) in classes.values()])))
    187 

ValueError: Expected the following order of world arguments: SkyCoord

I'm don't know where SkyCoord comes from or what I need to do with it, it is not in my fits files, and a list of one element doesn't have an ordering.
Also, reproject_function is not a keyword argument of reproject_and_coadd, but is required, I assume this is temporary.
Edit: It does work when I use the same files for the generating mosaic as for the wcs.

@meindertsma meindertsma changed the title Unhelpful error when using reproject_and_coadd reproject_and_coadd is picky with WCS Jun 11, 2022
@meindertsma
Copy link
Author

I found a workaround: adding the WCS information from the fits files uploaded to astrometry.net to the HDUs of the corresponding fits files in other filters made the issue disappear. It does make the code a lot more complicated though.

@astrofrog
Copy link
Member

@meindertsma - is there any way you could share the files you are using with me? If so you could send a link to them to thomas.robitaille@gmail.com - thanks!

@facero
Copy link

facero commented Feb 28, 2023

Hi,
Using the reproject_and_coadd for a project where I have thousands of file to stack, I found the same issue which I was able to track to one file not having a proper WCS. In fact the file was a calibration observation and thus had a physical WCS but no celestial WCS.
The minimal working example is :

files = [datadir+'acisf00065N004_full_img2.fits.gz', datadir+'acisf62130_000N003_full_img2.fits.gz']

hdr = fits.getheader(files[0])

mosaic, footprint = reproject_and_coadd(files, hdu_in=0, output_projection=hdr,
                                   reproject_function=reproject_interp, combine_function='sum')

The error printed is pretty cryptic

   215 w = world_objects[ikey]
    216 if not isinstance(w, klass):
--> 217     raise ValueError

ValueError: Expected the following order of world arguments: SkyCoord

I can add/send the files if needed.

I was able to fix the issue by a simple if wcs_in.has_celestial: in the coadd.py that ignores this file but maybe an Error should be showed. I could try a small PR if you think this is an ok solution.

What do you think @astrofrog ?

@astrofrog
Copy link
Member

An error would be great!

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

No branches or pull requests

3 participants