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

__call__() missing 1 required positional argument: 'delta_C' #196

Closed
pllim opened this issue Dec 24, 2018 · 2 comments
Closed

__call__() missing 1 required positional argument: 'delta_C' #196

pllim opened this issue Dec 24, 2018 · 2 comments

Comments

@pllim
Copy link
Contributor

pllim commented Dec 24, 2018

While testing ejeschke/ginga#719 , I encountered a similar error as #162 but I don't think it is just a documentation update. Not sure how to fix it. "cropped_asdfinfits.fits" was provided by @nden at ADASS 2018, which looks like a Horsehead Nebula in a FITS image with ASDF extension and GWCS.

>>> import asdf
>>> import astropy
>>> import gwcs
>>> import numpy as np
>>> from asdf.fits_embed import AsdfInFits
>>> from astropy.io import fits
>>> from ginga.AstroImage import AstroImage
>>> from ginga.util import wcs, wcsmod
>>> asdf.__version__
'2.4.0.dev1695'
>>> astropy.__version__
'3.1'
>>> gwcs.__version__
'0.10.dev444'
>>> wcsmod.use('astropy_ape14')
True
>>> fname = 'cropped_asdfinfits.fits'
>>> dstobj = AstroImage()
>>> with fits.open(fname) as fits_f:
...     with AsdfInFits.open(fits_f) as asdf_f:
...        dstobj.load_asdf(asdf_f)
# UserWarning: File was created with extension...
>>> ra2_deg  = 275.7449723279528
>>> dec2_deg = -12.834514357038893
>>> args = [ra2_deg, dec2_deg]
>>> skycrd = np.array([args], np.float_)
>>>  dstobj.wcs.wcs
<WCS(output_frame=icrs, input_frame=detector, forward_transform=Model: CompoundModel3
Name: linear_transform
Inputs: ('x0', 'x1')
Outputs: ('alpha_C', 'delta_C')
Model set size: 1
Expression: [0] & [1] | [2] | [3] | [4]
Components:
    [0]: <Shift(offset=-542.)>

    [1]: <Shift(offset=-507.5)>

    [2]: <AffineTransformation2D(matrix=[[-0.00002918, -0.00002043], [-0.0000204
3,  0.00002918]], translation=[0., 0.])>

    [3]: <Pix2Sky_Gnomonic()>

    [4]: <RotateNative2Celestial(lon=274.69266187, lat=-13.83266841, lon_pole=18
0.)>
Parameters:
    offset_0 offset_1 ...      lat_4       lon_pole_4
    -------- -------- ... ---------------- ----------
      -542.0   -507.5 ... -13.832668414231      180.0)>

>>> dstobj.wcs.wcs.world_to_pixel_values(skycrd)
...\gwcs\api.py
in world_to_pixel_values(self, *world_arrays)
     99         horizontal coordinate and ``y`` is the vertical coordinate.
    100         """
--> 101         result = self.invert(*world_arrays, with_units=False)
    102         return result
    103

...\gwcs\wcs.py
in invert(self, *args, **kwargs)
    294
    295         try:
--> 296             result = self.backward_transform(*args, **kwargs)
    297         except (NotImplementedError, KeyError):
    298             result = self._invert(*args, **kwargs)

TypeError: __call__() missing 1 required positional argument: 'delta_C'

Or the above use case without Ginga:

>>> import asdf
>>> import astropy
>>> import gwcs
>>> import numpy as np
>>> from asdf.fits_embed import AsdfInFits
>>> from astropy.io import fits
>>> asdf.__version__
'2.4.0.dev1695'
>>> astropy.__version__
'3.1'
>>> gwcs.__version__
'0.10.dev444'
>>> fname = 'cropped_asdfinfits.fits'
>>> with fits.open(fname) as fits_f:
...     with AsdfInFits.open(fits_f) as asdf_f:
...        w = asdf_f['wcs']
# UserWarning: File was created with extension...
>>> ra2_deg  = 275.7449723279528
>>> dec2_deg = -12.834514357038893
>>> args = [ra2_deg, dec2_deg]
>>> skycrd = np.array([args], np.float_)
>>>  w
<WCS(output_frame=icrs, input_frame=detector, forward_transform=Model: CompoundModel3
Name: linear_transform
Inputs: ('x0', 'x1')
Outputs: ('alpha_C', 'delta_C')
Model set size: 1
Expression: [0] & [1] | [2] | [3] | [4]
Components:
    [0]: <Shift(offset=-542.)>

    [1]: <Shift(offset=-507.5)>

    [2]: <AffineTransformation2D(matrix=[[-0.00002918, -0.00002043], [-0.0000204
3,  0.00002918]], translation=[0., 0.])>

    [3]: <Pix2Sky_Gnomonic()>

    [4]: <RotateNative2Celestial(lon=274.69266187, lat=-13.83266841, lon_pole=18
0.)>
Parameters:
    offset_0 offset_1 ...      lat_4       lon_pole_4
    -------- -------- ... ---------------- ----------
      -542.0   -507.5 ... -13.832668414231      180.0)>

>>> w.world_to_pixel_values(skycrd)
...\gwcs\api.py
in world_to_pixel_values(self, *world_arrays)
     99         horizontal coordinate and ``y`` is the vertical coordinate.
    100         """
--> 101         result = self.invert(*world_arrays, with_units=False)
    102         return result
    103

...\gwcs\wcs.py
in invert(self, *args, **kwargs)
    294
    295         try:
--> 296             result = self.backward_transform(*args, **kwargs)
    297         except (NotImplementedError, KeyError):
    298             result = self._invert(*args, **kwargs)

TypeError: __call__() missing 1 required positional argument: 'delta_C'

Is the provided image wrong? Or am I used ASDF + GWCS incorrectly? Please help. Thanks.

@nden
Copy link
Collaborator

nden commented Dec 24, 2018

@pllim The interface expects two coordinates , ra, dec. You are providing them as one array.
The low level astropy.wcs can work with two separate coordinate inputs, ra and dec or with one array of shape (n, 2), representing the two coordinates (which is what you are using above). APE14 defines the interface for both WCS objects (astropy.wcs and gwcs) to be using two inputs. So you need to modify

>>> w.world_to_pixel_values(skycrd)

to either

>>> w.world_to_pixel_values(*skycrd)

or
>>> w.world_to_pixel_values(ra, dec)

@pllim
Copy link
Contributor Author

pllim commented Dec 27, 2018

Yup, that's it. User error! Thanks!

@pllim pllim closed this as completed Dec 27, 2018
@spacetelescope spacetelescope deleted a comment from stscijgbot Jul 15, 2019
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

2 participants