55
66import numpy as np
77
8- from .base import DELAYED , _ValidHDU , ExtensionHDU
8+ from .base import DELAYED , _ValidHDU , ExtensionHDU , BITPIX2DTYPE , DTYPE2BITPIX
99from ..header import Header
1010from ..util import _is_pseudo_unsigned , _unsigned_zero , _is_int
1111from ..verify import VerifyWarning
1212
1313from ....extern .six import string_types
14- from ....utils import isiterable , lazyproperty
14+ from ....utils import isiterable , lazyproperty , deprecated
1515
1616
1717class _ImageBaseHDU (_ValidHDU ):
@@ -26,14 +26,6 @@ class _ImageBaseHDU(_ValidHDU):
2626 image data
2727 """
2828
29- # mappings between FITS and numpy typecodes
30- # TODO: Maybe make these module-level constants instead...
31- NumCode = {8 : 'uint8' , 16 : 'int16' , 32 : 'int32' , 64 : 'int64' ,
32- - 32 : 'float32' , - 64 : 'float64' }
33- ImgCode = {'uint8' : 8 , 'int16' : 16 , 'uint16' : 16 , 'int32' : 32 ,
34- 'uint32' : 32 , 'int64' : 64 , 'uint64' : 64 , 'float32' : - 32 ,
35- 'float64' : - 64 }
36-
3729 standard_keyword_comments = {
3830 'SIMPLE' : 'conforms to FITS standard' ,
3931 'XTENSION' : 'Image extension' ,
@@ -264,7 +256,7 @@ def data(self, data):
264256 self ._modified = True
265257
266258 if isinstance (data , np .ndarray ):
267- self ._bitpix = _ImageBaseHDU . ImgCode [data .dtype .name ]
259+ self ._bitpix = DTYPE2BITPIX [data .dtype .name ]
268260 self ._orig_bitpix = self ._bitpix
269261 self ._orig_bscale = 1
270262 self ._orig_bzero = 0
@@ -371,7 +363,7 @@ def _update_header_scale_info(self, dtype=None):
371363 if dtype is None :
372364 dtype = self ._dtype_for_bitpix ()
373365 if dtype is not None :
374- self ._header ['BITPIX' ] = _ImageBaseHDU . ImgCode [dtype .name ]
366+ self ._header ['BITPIX' ] = DTYPE2BITPIX [dtype .name ]
375367
376368 self ._bzero = 0
377369 self ._bscale = 1
@@ -409,7 +401,7 @@ def scale(self, type=None, option='old', bscale=1, bzero=0):
409401
410402 # Determine the destination (numpy) data type
411403 if type is None :
412- type = self . NumCode [self ._bitpix ]
404+ type = BITPIX2DTYPE [self ._bitpix ]
413405 _type = getattr (np , type )
414406
415407 # Determine how to scale the data
@@ -464,7 +456,7 @@ def scale(self, type=None, option='old', bscale=1, bzero=0):
464456 self .data = np .array (np .around (self .data ), dtype = _type )
465457
466458 # Update the BITPIX Card to match the data
467- self ._bitpix = _ImageBaseHDU . ImgCode [self .data .dtype .name ]
459+ self ._bitpix = DTYPE2BITPIX [self .data .dtype .name ]
468460 self ._bzero = self ._header .get ('BZERO' , 0 )
469461 self ._bscale = self ._header .get ('BSCALE' , 1 )
470462 self ._header ['BITPIX' ] = self ._bitpix
@@ -485,7 +477,7 @@ def _verify(self, option='warn'):
485477
486478 def _prewriteto (self , checksum = False , inplace = False ):
487479 if self ._scale_back :
488- self .scale (self . NumCode [self ._orig_bitpix ])
480+ self .scale (BITPIX2DTYPE [self ._orig_bitpix ])
489481
490482 self .update_header ()
491483 if not inplace and not self ._has_data :
@@ -580,7 +572,7 @@ def _get_scaled_image_data(self, offset, shape):
580572 supports alternate offset/shape for Section support.
581573 """
582574
583- code = _ImageBaseHDU . NumCode [self ._orig_bitpix ]
575+ code = BITPIX2DTYPE [self ._orig_bitpix ]
584576
585577 raw_data = self ._get_raw_data (shape , code , offset )
586578 raw_data .dtype = raw_data .dtype .newbyteorder ('>' )
@@ -662,7 +654,7 @@ def _summary(self):
662654 if self .shape and all (self .shape ):
663655 # Only show the format if all the dimensions are non-zero
664656 # if data is not touched yet, use header info.
665- format = self . NumCode [self ._bitpix ]
657+ format = BITPIX2DTYPE [self ._bitpix ]
666658 else :
667659 format = ''
668660
@@ -713,6 +705,14 @@ def _calculate_datasum(self, blocking):
713705 return super (_ImageBaseHDU , self )._calculate_datasum (
714706 blocking = blocking )
715707
708+ @deprecated ('1.1.0' , alternative = 'the module level constant BITPIX2DTYPE' )
709+ def NumCode (self ):
710+ return BITPIX2DTYPE
711+
712+ @deprecated ('1.1.0' , alternative = 'the module level constant DTYPE2BITPIX' )
713+ def ImgCode (self ):
714+ return DTYPE2BITPIX
715+
716716
717717class Section (object ):
718718 """
0 commit comments