Loading csst/common/data.py +32 −18 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ from collections import OrderedDict import astropy.io.fits as fits from astropy.io.fits import HDUList, PrimaryHDU from csst.common.CsstException import CsstException from csst.common.exception import CsstException __all__ = ["CsstData", "INSTRUMENT_LIST"] Loading @@ -12,9 +12,7 @@ INSTRUMENT_LIST = ["MSC", ] class CsstData: """ general CSST data class """ """ General CSST data class """ _primary_hdu = [] _l0data = [] # HDUList _l1hdr_global = [] Loading @@ -30,10 +28,12 @@ class CsstData: self.detector = detector def get_l0data(self, copy=True): """ obtain level 0 data from CsstData class copy: True: if the user want to copy the memory of the data to the new class; False: only reference of the data memory is written to the new class """ get level 0 data from CsstData class Parameters ---------- copy : bool if True, return a copy. """ if copy: return self._l0data.data.copy() Loading @@ -41,10 +41,14 @@ class CsstData: return self._l0data.data def get_l0keyword(self, ext="pri", key="INSTRUME"): """ obtain keywords of the fits header of level 0 image data from the CsstData class ext: the index of extension. if it equals to 'pri', looking up keywords from primary session, otherwise from extension sessions key: the name of the key """ get a specific keyword from fits header of level 0 image data Parameters ---------- ext: {"pri"| "img"} the HDU extension key: the key """ if ext == 'pri': try: Loading @@ -60,20 +64,30 @@ class CsstData: raise CsstException def set_l1keyword(self, key, value): raise NotImplementedError('check out whether ' + key + " is a valid key and " + value + " is valid value") """ set L1 keyword """ raise NotImplementedError("Well, not implemented...") def set_l1data(self, img): def set_l1data(self, *args, **kwargs): print('save image data to l2data') raise NotImplementedError def get_auxdata(self, name): """ get aux data Parameters ---------- """ print('Parent class returns zero image.') # return np.zeros_like(self.get_l0data()) return raise NotImplementedError def save_l1data(self, imgtype, filename): """ asve level 1 image and auxilary data to data file imgtype """ save L1 image and auxilary data to file Parameters ---------- imgtype: {} image type """ print("save L1 image to a fits file with name " + filename) try: Loading csst/common/CsstException.py→csst/common/exception.py +0 −2 Original line number Diff line number Diff line #import BaseException class CsstException(BaseException): def __init__(self): print('Exceoption raised.') csst/msc/data.py +17 −23 Original line number Diff line number Diff line Loading @@ -11,28 +11,28 @@ __all__ = ["CsstMscData", "CsstMscImgData"] class CsstMscData(CsstData): _l1img_types = {'sci': True, 'weight': True, 'flag': True} def __init__(self, primaryHDU, imgHDU, **kwargs): print('create CsstMscData') super(CsstData, self).__init__(primaryHDU, imgHDU, **kwargs) self._l1hdr_global = primaryHDU.header.copy() def __init__(self, priHDU, imgHDU, **kwargs): super(CsstData, self).__init__(priHDU, imgHDU, **kwargs) self._l1hdr_global = priHDU.header.copy() # self._l1hdr_global['SIMPLE'] = 'T' #/ conforms to FITS standard # self._l1hdr_global['NAXIS'] = 0kkjk self._l1data['sci'] = ImageHDU() self._l1data['weight'] = ImageHDU() self._l1data['flag'] = ImageHDU() def set_flat(self, flatimg): """ def set_flat(self, flat): """ set flat Parameters ---------- flatimg flat: flat image Returns ------- """ self._auxdata['flat'] = flatimg self._auxdata['flat'] = flat def set_bias(self, biasimg): self._auxdata['bias'] = biasimg Loading Loading @@ -80,32 +80,33 @@ class CsstMscData(CsstData): class CsstMscImgData(CsstMscData): def __init__(self, primaryHDU, imgHDU, **kwargs): def __init__(self, priHDU, imgHDU, **kwargs): # print('create CsstMscImgData') super(CsstMscData, self).__init__(primaryHDU, imgHDU, **kwargs) super(CsstMscData, self).__init__(priHDU, imgHDU, **kwargs) def __repr__(self): return "<CsstMscImgData: {} {}>".format(self.instrument, self.detector) @staticmethod def read(fitsfilename): """ create CSST Data instances def read(fp): """ read from fits file Parameters ---------- fitsfilename: the file name of fits files fp: the file path of fits file Returns ------- CsstMscImgData """ try: hl = fits.open(fitsfilename) hl = fits.open(fp) instrument = hl[0].header.get('INSTRUME') # strip or not? detector = hl[0].header.get('DETECTOR') # strip or not? print("@CsstMscImgData: reading data {} ...".format(fitsfilename)) print("@CsstMscImgData: reading data {} ...".format(fp)) assert instrument in INSTRUMENT_LIST if instrument == 'MSC' and 6 <= int(detector[3:5]) <= 25: # multi-band imaging Loading @@ -113,10 +114,3 @@ class CsstMscImgData(CsstMscData): return data except Exception as e: print(e) # def test(): # fp = MSC_MS_210527171000_100000279_16_raw.fits # # # if __name__=="__main__": Loading
csst/common/data.py +32 −18 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ from collections import OrderedDict import astropy.io.fits as fits from astropy.io.fits import HDUList, PrimaryHDU from csst.common.CsstException import CsstException from csst.common.exception import CsstException __all__ = ["CsstData", "INSTRUMENT_LIST"] Loading @@ -12,9 +12,7 @@ INSTRUMENT_LIST = ["MSC", ] class CsstData: """ general CSST data class """ """ General CSST data class """ _primary_hdu = [] _l0data = [] # HDUList _l1hdr_global = [] Loading @@ -30,10 +28,12 @@ class CsstData: self.detector = detector def get_l0data(self, copy=True): """ obtain level 0 data from CsstData class copy: True: if the user want to copy the memory of the data to the new class; False: only reference of the data memory is written to the new class """ get level 0 data from CsstData class Parameters ---------- copy : bool if True, return a copy. """ if copy: return self._l0data.data.copy() Loading @@ -41,10 +41,14 @@ class CsstData: return self._l0data.data def get_l0keyword(self, ext="pri", key="INSTRUME"): """ obtain keywords of the fits header of level 0 image data from the CsstData class ext: the index of extension. if it equals to 'pri', looking up keywords from primary session, otherwise from extension sessions key: the name of the key """ get a specific keyword from fits header of level 0 image data Parameters ---------- ext: {"pri"| "img"} the HDU extension key: the key """ if ext == 'pri': try: Loading @@ -60,20 +64,30 @@ class CsstData: raise CsstException def set_l1keyword(self, key, value): raise NotImplementedError('check out whether ' + key + " is a valid key and " + value + " is valid value") """ set L1 keyword """ raise NotImplementedError("Well, not implemented...") def set_l1data(self, img): def set_l1data(self, *args, **kwargs): print('save image data to l2data') raise NotImplementedError def get_auxdata(self, name): """ get aux data Parameters ---------- """ print('Parent class returns zero image.') # return np.zeros_like(self.get_l0data()) return raise NotImplementedError def save_l1data(self, imgtype, filename): """ asve level 1 image and auxilary data to data file imgtype """ save L1 image and auxilary data to file Parameters ---------- imgtype: {} image type """ print("save L1 image to a fits file with name " + filename) try: Loading
csst/common/CsstException.py→csst/common/exception.py +0 −2 Original line number Diff line number Diff line #import BaseException class CsstException(BaseException): def __init__(self): print('Exceoption raised.')
csst/msc/data.py +17 −23 Original line number Diff line number Diff line Loading @@ -11,28 +11,28 @@ __all__ = ["CsstMscData", "CsstMscImgData"] class CsstMscData(CsstData): _l1img_types = {'sci': True, 'weight': True, 'flag': True} def __init__(self, primaryHDU, imgHDU, **kwargs): print('create CsstMscData') super(CsstData, self).__init__(primaryHDU, imgHDU, **kwargs) self._l1hdr_global = primaryHDU.header.copy() def __init__(self, priHDU, imgHDU, **kwargs): super(CsstData, self).__init__(priHDU, imgHDU, **kwargs) self._l1hdr_global = priHDU.header.copy() # self._l1hdr_global['SIMPLE'] = 'T' #/ conforms to FITS standard # self._l1hdr_global['NAXIS'] = 0kkjk self._l1data['sci'] = ImageHDU() self._l1data['weight'] = ImageHDU() self._l1data['flag'] = ImageHDU() def set_flat(self, flatimg): """ def set_flat(self, flat): """ set flat Parameters ---------- flatimg flat: flat image Returns ------- """ self._auxdata['flat'] = flatimg self._auxdata['flat'] = flat def set_bias(self, biasimg): self._auxdata['bias'] = biasimg Loading Loading @@ -80,32 +80,33 @@ class CsstMscData(CsstData): class CsstMscImgData(CsstMscData): def __init__(self, primaryHDU, imgHDU, **kwargs): def __init__(self, priHDU, imgHDU, **kwargs): # print('create CsstMscImgData') super(CsstMscData, self).__init__(primaryHDU, imgHDU, **kwargs) super(CsstMscData, self).__init__(priHDU, imgHDU, **kwargs) def __repr__(self): return "<CsstMscImgData: {} {}>".format(self.instrument, self.detector) @staticmethod def read(fitsfilename): """ create CSST Data instances def read(fp): """ read from fits file Parameters ---------- fitsfilename: the file name of fits files fp: the file path of fits file Returns ------- CsstMscImgData """ try: hl = fits.open(fitsfilename) hl = fits.open(fp) instrument = hl[0].header.get('INSTRUME') # strip or not? detector = hl[0].header.get('DETECTOR') # strip or not? print("@CsstMscImgData: reading data {} ...".format(fitsfilename)) print("@CsstMscImgData: reading data {} ...".format(fp)) assert instrument in INSTRUMENT_LIST if instrument == 'MSC' and 6 <= int(detector[3:5]) <= 25: # multi-band imaging Loading @@ -113,10 +114,3 @@ class CsstMscImgData(CsstMscData): return data except Exception as e: print(e) # def test(): # fp = MSC_MS_210527171000_100000279_16_raw.fits # # # if __name__=="__main__":