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

The repr of GenericMap raises an error if the WCS is an unknown type. #2452

Closed
Cadair opened this issue Feb 8, 2018 · 5 comments · Fixed by #3569
Closed

The repr of GenericMap raises an error if the WCS is an unknown type. #2452

Cadair opened this issue Feb 8, 2018 · 5 comments · Fixed by #3569
Labels
Effort Medium Requires a moderate time investment map Affects the map submodule Package Novice Requires little knowledge of the internal structure of SunPy Priority Low Slow action required

Comments

@Cadair
Copy link
Member

Cadair commented Feb 8, 2018

Make a WCS with some nonsense in CTYPE1 CTYPE2 and then call repr(smap)

@getsanjeev

This comment has been minimized.

@nabobalis

This comment has been minimized.

@getsanjeev

This comment has been minimized.

@Cadair
Copy link
Member Author

Cadair commented Feb 19, 2018

In [1]: from sunpy.data.sample import AIA_171_IMAGE; import sunpy.map; import matplotlib.pyplot as plt

In [2]: m = sunpy.map.Map(AIA_171_IMAGE)

In [3]: m.meta['CTYPE1'] = "STUART1"

In [4]: m.meta['CTYPE2'] = "STUART2"

In [5]: m
Out[5]: ---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/opt/miniconda/envs/sunpy-dev/lib/python3.6/site-packages/IPython/core/formatters.py in __call__(self, obj)
    700                 type_pprinters=self.type_printers,
    701                 deferred_pprinters=self.deferred_printers)
--> 702             printer.pretty(obj)
    703             printer.flush()
    704             return stream.getvalue()

/opt/miniconda/envs/sunpy-dev/lib/python3.6/site-packages/IPython/lib/pretty.py in pretty(self, obj)
    393                             if callable(meth):
    394                                 return meth(obj, self, cycle)
--> 395             return _default_pprint(obj, self, cycle)
    396         finally:
    397             self.end_group()

/opt/miniconda/envs/sunpy-dev/lib/python3.6/site-packages/IPython/lib/pretty.py in _default_pprint(obj, p, cycle)
    508     if _safe_getattr(klass, '__repr__', None) is not object.__repr__:
    509         # A user-provided repr. Find newlines and replace them with p.break_()
--> 510         _repr_pprint(obj, p, cycle)
    511         return
    512     p.begin_group(1, '<')

/opt/miniconda/envs/sunpy-dev/lib/python3.6/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
    699     """A pprint that just redirects to the normal repr function."""
    700     # Find newlines and replace them with p.break_()
--> 701     output = repr(obj)
    702     for idx,output_line in enumerate(output.splitlines()):
    703         if idx:

~/Git/sunpy/sunpy/map/mapbase.py in __repr__(self)
    247            dim=u.Quantity(self.dimensions),
    248            scale=u.Quantity(self.scale),
--> 249            coord=self.coordinate_frame,
    250            refpix=u.Quantity(self.reference_pixel),
    251            refcoord=u.Quantity((self.reference_coordinate.data.lon,

~/Git/sunpy/sunpy/map/mapbase.py in coordinate_frame(self)
    305         information for this Map.
    306         """
--> 307         return astropy.wcs.utils.wcs_to_celestial_frame(self.wcs)
    308 
    309     def _as_mpl_axes(self):

~/Git/astropy/astropy/wcs/utils.py in wcs_to_celestial_frame(wcs)
    203             if frame is not None:
    204                 return frame
--> 205     raise ValueError("Could not determine celestial frame corresponding to "
    206                      "the specified WCS object")
    207 

ValueError: Could not determine celestial frame corresponding to the specified WCS object

From this error, it looks like it's the coordinate_frame property that needs the fix. I think it should probably return None if the lookup fails.

@talsperre
Copy link
Contributor

I tried returning None if the lookup failed in coordinate_frame() function of mapbase.

try:
    return astropy.wcs.utils.wcs_to_celestial_frame(self.wcs)
except ValueError:
    return None

However, this leads to new errors such as AttributeError: 'NoneType' object has no attribute 'name' when calling repr(mapobj)

@nabobalis nabobalis added Package Novice Requires little knowledge of the internal structure of SunPy map Affects the map submodule Priority Low Slow action required Effort Medium Requires a moderate time investment labels Jan 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Effort Medium Requires a moderate time investment map Affects the map submodule Package Novice Requires little knowledge of the internal structure of SunPy Priority Low Slow action required
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants