1111from astropy .nddata import CCDData , NDData
1212from astropy .table import Table , vstack
1313from astropy .units import Quantity
14- from astropy .wcs import WCS
15- from astropy .wcs .utils import proj_plane_pixel_scales
1614from astropy .visualization import (
1715 AsymmetricPercentileInterval ,
1816 BaseInterval ,
1917 BaseStretch ,
2018 LinearStretch ,
2119 ManualInterval ,
2220)
21+ from astropy .wcs import WCS
22+ from astropy .wcs .utils import proj_plane_pixel_scales
2323from numpy .typing import ArrayLike
2424
2525from .interface_definition import ImageViewerInterface
@@ -114,7 +114,8 @@ def _resolve_catalog_label(self, catalog_label: str | None) -> str:
114114 catalog_label = user_keys [0 ]
115115 case _:
116116 raise ValueError (
117- "Multiple catalog styles defined. Please specify a catalog_label to get the style."
117+ "Multiple catalog styles defined. Please specify a "
118+ "catalog_label to get the style."
118119 )
119120
120121 return catalog_label
@@ -141,7 +142,8 @@ def get_stretch(self, image_label: str | None = None) -> BaseStretch:
141142 def set_stretch (self , value : BaseStretch , image_label : str | None = None ) -> None :
142143 if not isinstance (value , BaseStretch ):
143144 raise TypeError (
144- f"Stretch option { value } is not valid. Must be an Astropy.visualization Stretch object."
145+ f"Stretch option { value } is not valid. Must be an "
146+ "`astropy.visualization` Stretch object."
145147 )
146148 image_label = self ._resolve_image_label (image_label )
147149 if image_label not in self ._images :
@@ -169,7 +171,8 @@ def set_cuts(
169171 self ._cuts = value
170172 else :
171173 raise TypeError (
172- "Cuts must be an Astropy.visualization Interval object or a tuple of two values."
174+ "Cuts must be an Astropy.visualization Interval object or a tuple "
175+ "of two values."
173176 )
174177 image_label = self ._resolve_image_label (image_label )
175178 if image_label not in self ._images :
@@ -206,7 +209,8 @@ def cursor(self) -> str:
206209 def cursor (self , value : str ) -> None :
207210 if value not in self .ALLOWED_CURSOR_LOCATIONS :
208211 raise ValueError (
209- f"Cursor location { value } is not valid. Must be one of { self .ALLOWED_CURSOR_LOCATIONS } ."
212+ f"Cursor location { value } is not valid. Must be one of "
213+ f"{ self .ALLOWED_CURSOR_LOCATIONS } ."
210214 )
211215 self ._cursor = value
212216
@@ -296,7 +300,8 @@ def _resolve_image_label(self, image_label: str | None) -> str:
296300 image_label = user_keys [0 ]
297301 case _:
298302 raise ValueError (
299- "Multiple image labels defined. Please specify a image_label to get the style."
303+ "Multiple image labels defined. Please specify a image_label "
304+ "to get the style."
300305 )
301306
302307 return image_label
@@ -324,9 +329,9 @@ def load_image(
324329 if image_label in self ._images :
325330 del self ._images [image_label ]
326331
327- if isinstance (file , ( str , os .PathLike ) ):
332+ if isinstance (file , str | os .PathLike ):
328333 if isinstance (file , str ):
329- is_adsf = file .endswith (".asdf" )
334+ is_asdf = file .endswith (".asdf" )
330335 else :
331336 is_asdf = file .suffix == ".asdf"
332337 if is_asdf :
@@ -567,8 +572,8 @@ def remove_catalog(self, catalog_label: str | None = None) -> None:
567572
568573 try :
569574 del self ._catalogs [catalog_label ]
570- except KeyError :
571- raise ValueError (f"Catalog label { catalog_label } not found." )
575+ except KeyError as err :
576+ raise ValueError (f"Catalog label { catalog_label } not found." ) from err
572577
573578 def get_catalog (
574579 self ,
@@ -623,11 +628,12 @@ def set_viewport(
623628 fov = current_viewport .fov
624629
625630 # If either center or fov is None these checks will raise an appropriate error
626- if not isinstance (center , ( SkyCoord , tuple ) ):
631+ if not isinstance (center , SkyCoord | tuple ):
627632 raise TypeError (
628- "Invalid value for center. Center must be a SkyCoord or tuple of (X, Y)."
633+ "Invalid value for center. Center must be a SkyCoord or tuple "
634+ "of (X, Y)."
629635 )
630- if not isinstance (fov , ( Quantity , numbers .Real ) ):
636+ if not isinstance (fov , Quantity | numbers .Real ):
631637 raise TypeError (
632638 "Invalid value for fov. fov must be an angular Quantity or float."
633639 )
@@ -640,8 +646,9 @@ def set_viewport(
640646 # Check that the center and fov are compatible with the current image
641647 if self ._images [image_label ].wcs is None :
642648 if current_viewport .center is not None :
643- # If there is a WCS either input is fine. If there is no WCS then we only
644- # check wther the new center is the same type as the current center.
649+ # If there is a WCS either input is fine. If there is no WCS then we
650+ # only check wther the new center is the same type as the
651+ # current center.
645652 if isinstance (center , SkyCoord ) and not isinstance (
646653 current_viewport .center , SkyCoord
647654 ):
@@ -711,7 +718,8 @@ def get_viewport(
711718 # was not already sky, so we need to convert them or fail
712719 if viewport .wcs is None :
713720 raise ValueError (
714- "WCS is not set. Cannot convert pixel coordinates to sky coordinates."
721+ "WCS is not set. Cannot convert pixel coordinates to "
722+ "sky coordinates."
715723 )
716724 else :
717725 center = viewport .wcs .pixel_to_world (
@@ -726,7 +734,8 @@ def get_viewport(
726734 if isinstance (viewport .center , SkyCoord ):
727735 if viewport .wcs is None :
728736 raise ValueError (
729- "WCS is not set. Cannot convert sky coordinates to pixel coordinates."
737+ "WCS is not set. Cannot convert sky coordinates to "
738+ "pixel coordinates."
730739 )
731740 center = viewport .wcs .world_to_pixel (viewport .center )
732741 else :
0 commit comments