py_artecs.artecs_map
1class artecs_map : 2 """ 3A class to handle a temperature map from ARTECS. 4 5It reads the artecs_map from a fits file. 6 7 >>> AMAP=artecs_map("artecs_map.fits") 8 9Keywords in the map are returned as members of the class or using the method "parameter". 10 11Example: 12 13 >>> AMAP.temp 14 15returns the temperature map, 16 17 >>> AMAP.parameter('temp') 18 19returns the temperature map. 20 21 22 >>> AMAP.shape 23 24returns the shape of the map (rows, columns) 25 26 27 """ 28 @property 29 def filename(self) : 30 """ parameter: the filename """ 31 return self._filename 32 33 @property 34 def p(self) : 35 """ the fits file pointer, normally closed. 36 """ 37 return self._p 38 39 @property 40 def lst_lat(self) : 41 """ list of latitude bands """ 42 return self._lst_lat 43 44 @property 45 def lst_year(self) : 46 """ list of time intervals """ 47 return self._lst_year 48 49 @property 50 def shape(self) : 51 """ the shape of the 2D maps """ 52 return self._shape 53 54 @property 55 def TMGLOB(self) : 56 """ the mean surface temperature """ 57 return self._TMGLOB 58 59 def __init__(self,filename,closeFits=True,verbose=False) : 60 """ To instantiate the class pass the filename from which to load the Temperature map 61 62 >Keywords: 63 64 >>`verbose`: if True verbose output 65 66 >>`closeFits`: if True the fits file is closed after reading 67 """ 68 import numpy 69 try : 70 import pyfits 71 except : 72 from astropy.io import fits as pyfits 73 self._filename=filename 74 self._p=pyfits.open(filename) 75 self._key=[] 76 self._value=[] 77 self._descr=[] 78 mkd=True 79 for cc in self.p[0].header.cards : 80 if cc[0]!='COMMENT' : 81 self._key.append(cc[0]) 82 self._value.append(cc[1]) 83 self._descr.append(cc[2]) 84 else : 85 if mkd : 86 self._key.append(cc[0]) 87 self._value.append('\n'.join(self.p[0].header['COMMENT'])) 88 self._descr.append(None) 89 mkd=False 90 91 #: N of year intervals 92 self.N=self.parameter('N') 93 94 #: NS number of latitude bands 95 self.NS=self.parameter('NS') 96 97 #: the shape 98 self._shape=(self.NS,self.N) 99 100 self.year=self.p[1].data['year'] 101 self.lat=self.p[1].data['lat'] 102 self.temp=self.p[1].data['temp'] 103 self.year.shape=self.shape 104 self.lat.shape=self.shape 105 self.temp.shape=self.shape 106 107 #: the mean surfscr temperature 108 self._TMGLOB=self.temp.mean() 109 110 self._lst_lat=self.lat[0] 111 self._lst_year=self.year[:,0].T 112 113 if verbose : 114 print('Successfully opened and readed ',filename) 115 116 if closeFits : 117 self._p.close() 118 if verbose : 119 print('fits file closed ',filename) 120 121 122 def keys(self,maps=False) : 123 """ 124returns the list of quantities in the map 125 126Keywords: 127 128>`maps` (default False), if True returns just the list of of elements which are 2D maps 129 """ 130 if maps : 131 return ['year','lat','temp'] 132 else : 133 return self._key 134 def has_key(self,key) : 135 """True if required `key` is in the map""" 136 return key in self._key 137 def parameter(self,key) : 138 """returns a parameter from the fits file from its `key'""" 139 return self._value[self._key.index(key)] 140 def description(self,key) : 141 """returns the description of a parameter in the fits file from its `key'""" 142 return self._descr[self._key.index(key)] 143 #def bilinear_interpolation(self,lat,year) : 144 #"""returns bilinear interpolation of the map (not implemeted yet) """ 145 #raise Exception(
2class artecs_map : 3 """ 4A class to handle a temperature map from ARTECS. 5 6It reads the artecs_map from a fits file. 7 8 >>> AMAP=artecs_map("artecs_map.fits") 9 10Keywords in the map are returned as members of the class or using the method "parameter". 11 12Example: 13 14 >>> AMAP.temp 15 16returns the temperature map, 17 18 >>> AMAP.parameter('temp') 19 20returns the temperature map. 21 22 23 >>> AMAP.shape 24 25returns the shape of the map (rows, columns) 26 27 28 """ 29 @property 30 def filename(self) : 31 """ parameter: the filename """ 32 return self._filename 33 34 @property 35 def p(self) : 36 """ the fits file pointer, normally closed. 37 """ 38 return self._p 39 40 @property 41 def lst_lat(self) : 42 """ list of latitude bands """ 43 return self._lst_lat 44 45 @property 46 def lst_year(self) : 47 """ list of time intervals """ 48 return self._lst_year 49 50 @property 51 def shape(self) : 52 """ the shape of the 2D maps """ 53 return self._shape 54 55 @property 56 def TMGLOB(self) : 57 """ the mean surface temperature """ 58 return self._TMGLOB 59 60 def __init__(self,filename,closeFits=True,verbose=False) : 61 """ To instantiate the class pass the filename from which to load the Temperature map 62 63 >Keywords: 64 65 >>`verbose`: if True verbose output 66 67 >>`closeFits`: if True the fits file is closed after reading 68 """ 69 import numpy 70 try : 71 import pyfits 72 except : 73 from astropy.io import fits as pyfits 74 self._filename=filename 75 self._p=pyfits.open(filename) 76 self._key=[] 77 self._value=[] 78 self._descr=[] 79 mkd=True 80 for cc in self.p[0].header.cards : 81 if cc[0]!='COMMENT' : 82 self._key.append(cc[0]) 83 self._value.append(cc[1]) 84 self._descr.append(cc[2]) 85 else : 86 if mkd : 87 self._key.append(cc[0]) 88 self._value.append('\n'.join(self.p[0].header['COMMENT'])) 89 self._descr.append(None) 90 mkd=False 91 92 #: N of year intervals 93 self.N=self.parameter('N') 94 95 #: NS number of latitude bands 96 self.NS=self.parameter('NS') 97 98 #: the shape 99 self._shape=(self.NS,self.N) 100 101 self.year=self.p[1].data['year'] 102 self.lat=self.p[1].data['lat'] 103 self.temp=self.p[1].data['temp'] 104 self.year.shape=self.shape 105 self.lat.shape=self.shape 106 self.temp.shape=self.shape 107 108 #: the mean surfscr temperature 109 self._TMGLOB=self.temp.mean() 110 111 self._lst_lat=self.lat[0] 112 self._lst_year=self.year[:,0].T 113 114 if verbose : 115 print('Successfully opened and readed ',filename) 116 117 if closeFits : 118 self._p.close() 119 if verbose : 120 print('fits file closed ',filename) 121 122 123 def keys(self,maps=False) : 124 """ 125returns the list of quantities in the map 126 127Keywords: 128 129>`maps` (default False), if True returns just the list of of elements which are 2D maps 130 """ 131 if maps : 132 return ['year','lat','temp'] 133 else : 134 return self._key 135 def has_key(self,key) : 136 """True if required `key` is in the map""" 137 return key in self._key 138 def parameter(self,key) : 139 """returns a parameter from the fits file from its `key'""" 140 return self._value[self._key.index(key)] 141 def description(self,key) : 142 """returns the description of a parameter in the fits file from its `key'""" 143 return self._descr[self._key.index(key)] 144 #def bilinear_interpolation(self,lat,year) : 145 #"""returns bilinear interpolation of the map (not implemeted yet) """ 146 #raise Exception(
A class to handle a temperature map from ARTECS.
It reads the artecs_map from a fits file.
>>> AMAP=artecs_map("artecs_map.fits")
Keywords in the map are returned as members of the class or using the method "parameter".
Example:
>>> AMAP.temp
returns the temperature map,
>>> AMAP.parameter('temp')
returns the temperature map.
>>> AMAP.shape
returns the shape of the map (rows, columns)
60 def __init__(self,filename,closeFits=True,verbose=False) : 61 """ To instantiate the class pass the filename from which to load the Temperature map 62 63 >Keywords: 64 65 >>`verbose`: if True verbose output 66 67 >>`closeFits`: if True the fits file is closed after reading 68 """ 69 import numpy 70 try : 71 import pyfits 72 except : 73 from astropy.io import fits as pyfits 74 self._filename=filename 75 self._p=pyfits.open(filename) 76 self._key=[] 77 self._value=[] 78 self._descr=[] 79 mkd=True 80 for cc in self.p[0].header.cards : 81 if cc[0]!='COMMENT' : 82 self._key.append(cc[0]) 83 self._value.append(cc[1]) 84 self._descr.append(cc[2]) 85 else : 86 if mkd : 87 self._key.append(cc[0]) 88 self._value.append('\n'.join(self.p[0].header['COMMENT'])) 89 self._descr.append(None) 90 mkd=False 91 92 #: N of year intervals 93 self.N=self.parameter('N') 94 95 #: NS number of latitude bands 96 self.NS=self.parameter('NS') 97 98 #: the shape 99 self._shape=(self.NS,self.N) 100 101 self.year=self.p[1].data['year'] 102 self.lat=self.p[1].data['lat'] 103 self.temp=self.p[1].data['temp'] 104 self.year.shape=self.shape 105 self.lat.shape=self.shape 106 self.temp.shape=self.shape 107 108 #: the mean surfscr temperature 109 self._TMGLOB=self.temp.mean() 110 111 self._lst_lat=self.lat[0] 112 self._lst_year=self.year[:,0].T 113 114 if verbose : 115 print('Successfully opened and readed ',filename) 116 117 if closeFits : 118 self._p.close() 119 if verbose : 120 print('fits file closed ',filename)
To instantiate the class pass the filename from which to load the Temperature map
Keywords:
verbose
: if True verbose output
closeFits
: if True the fits file is closed after reading
123 def keys(self,maps=False) : 124 """ 125returns the list of quantities in the map 126 127Keywords: 128 129>`maps` (default False), if True returns just the list of of elements which are 2D maps 130 """ 131 if maps : 132 return ['year','lat','temp'] 133 else : 134 return self._key
returns the list of quantities in the map
Keywords:
maps
(default False), if True returns just the list of of elements which are 2D maps
135 def has_key(self,key) : 136 """True if required `key` is in the map""" 137 return key in self._key
True if required key
is in the map
138 def parameter(self,key) : 139 """returns a parameter from the fits file from its `key'""" 140 return self._value[self._key.index(key)]
returns a parameter from the fits file from its `key'
141 def description(self,key) : 142 """returns the description of a parameter in the fits file from its `key'""" 143 return self._descr[self._key.index(key)] 144 #def bilinear_interpolation(self,lat,year) : 145 #"""returns bilinear interpolation of the map (not implemeted yet) """ 146 #raise Exception(
returns the description of a parameter in the fits file from its `key'