Loading csst/common/__init__.py +0 −1 Original line number Diff line number Diff line __version__ = "0.0.1" No newline at end of file csst/common/data.py +18 −46 Original line number Diff line number Diff line Loading @@ -3,46 +3,16 @@ from collections import OrderedDict import astropy.io.fits as fits from astropy.io.fits import HDUList, PrimaryHDU from csst.msc.mscdata import CsstMscImgData from .CsstException import CsstException class CsstDataFactory: """ This class is designed to create CsstData and its inherited classes according to different kinds of input data format. """ INSTRUMENT_LIST = ["MSC", ] def __init__(self): pass def createData(self, fitsfilename): class CsstData: """ Parameters ---------- fitsfilename: the file name of fits files Returns ------- general CSST data class """ try: hl = fits.open(fitsfilename) instrument = hl[0].header.get('INSTRUME') # strip or not? detector = hl[0].header.get('DETECTOR') # strip or not? print(instrument, detector) if instrument == 'MSC' and int(detector[3:5]) >= 6 and int(detector[3:5]) <= 25: # multi-band imaging data = CsstMscImgData(hl[0], hl[1]) except Exception as e: print(e) return data class CsstData: _primary_hdu = [] _l0data = [] # HDUList _l1hdr_global = [] Loading @@ -50,28 +20,30 @@ class CsstData: _l2data = OrderedDict() # _auxdata = OrderedDict() def __init__(self, primaryHDU, imgHDU): def __init__(self, primaryHDU, imgHDU, instrument=None, detector=None): print('create CsstData') self._primary_hdu = primaryHDU self._l0data = imgHDU self.instrument = instrument self.detector = detector def get_l0data(self, *, copy): ''' 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 ''' """ if copy: return self._l0data.data.copy() else: return self._l0data.data def get_l0keyword(self, ext, key): ''' 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 ''' """ if ext == 'pri': try: value = self._primary_hdu.header.get(key) Loading @@ -84,7 +56,6 @@ class CsstData: print(e) else: raise CsstException return value def set_l1keyword(self, key, value): print('check out whether ' + key + " is a valid key and " + value + " is valid value") Loading @@ -94,13 +65,14 @@ class CsstData: def get_auxdata(self, name): print('Parent class returns zero image.') return np.zeros_like(get_l0data()) # return np.zeros_like(self.get_l0data()) return def save_l1data(self, imgtype, filename): ''' """ asve level 1 image and auxilary data to data file imgtype ''' """ print("save L1 image to a fits file with name " + filename) try: self._l1hdr_global.set('TYPE', imgtype, 'Type of Level 1 data') Loading csst/common/factory.py 0 → 100644 +40 −0 Original line number Diff line number Diff line from astropy.io import fits from .data import INSTRUMENT_LIST from ..msc.mscdata import CsstMscImgData class CsstDataFactory: """ This class is designed to create CsstData and its inherited classes according to different kinds of input data format. """ def __init__(self): pass @staticmethod def createData(fitsfilename): """ create CSST Data instances Parameters ---------- fitsfilename: the file name of fits files Returns ------- """ try: hl = fits.open(fitsfilename) instrument = hl[0].header.get('INSTRUME') # strip or not? detector = hl[0].header.get('DETECTOR') # strip or not? print(instrument, detector) assert instrument in INSTRUMENT_LIST if instrument == 'MSC' and 6 <= int(detector[3:5]) <= 25: # multi-band imaging data = CsstMscImgData(hl[0], hl[1], instrument=instrument, detector=detector) return data except Exception as e: print(e) csst/common/processors.py +6 −5 Original line number Diff line number Diff line from abc import ABCMeta, abstractmethod from enum import Enum class CsstProcStatus(Enum): empty = -1 normal = 0 ioerror = 1 runtimeerror = 2 # self['empty'].info = 'Not run yet.' # self['normal'].info = 'This is a normal run.' # self['ioerror'].info = 'This run is exceptionally stopped due to IO error.' Loading @@ -17,11 +18,11 @@ class CsstProcessor(metaclass=ABCMeta): @abstractmethod def prepare(self, **kwargs): pass @abstractmethod def run(self, data): return self._status @abstractmethod def cleanup(self): pass No newline at end of file csst/msc/__init__.py +0 −1 Original line number Diff line number Diff line __version__ = "0.0.1" No newline at end of file Loading
csst/common/__init__.py +0 −1 Original line number Diff line number Diff line __version__ = "0.0.1" No newline at end of file
csst/common/data.py +18 −46 Original line number Diff line number Diff line Loading @@ -3,46 +3,16 @@ from collections import OrderedDict import astropy.io.fits as fits from astropy.io.fits import HDUList, PrimaryHDU from csst.msc.mscdata import CsstMscImgData from .CsstException import CsstException class CsstDataFactory: """ This class is designed to create CsstData and its inherited classes according to different kinds of input data format. """ INSTRUMENT_LIST = ["MSC", ] def __init__(self): pass def createData(self, fitsfilename): class CsstData: """ Parameters ---------- fitsfilename: the file name of fits files Returns ------- general CSST data class """ try: hl = fits.open(fitsfilename) instrument = hl[0].header.get('INSTRUME') # strip or not? detector = hl[0].header.get('DETECTOR') # strip or not? print(instrument, detector) if instrument == 'MSC' and int(detector[3:5]) >= 6 and int(detector[3:5]) <= 25: # multi-band imaging data = CsstMscImgData(hl[0], hl[1]) except Exception as e: print(e) return data class CsstData: _primary_hdu = [] _l0data = [] # HDUList _l1hdr_global = [] Loading @@ -50,28 +20,30 @@ class CsstData: _l2data = OrderedDict() # _auxdata = OrderedDict() def __init__(self, primaryHDU, imgHDU): def __init__(self, primaryHDU, imgHDU, instrument=None, detector=None): print('create CsstData') self._primary_hdu = primaryHDU self._l0data = imgHDU self.instrument = instrument self.detector = detector def get_l0data(self, *, copy): ''' 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 ''' """ if copy: return self._l0data.data.copy() else: return self._l0data.data def get_l0keyword(self, ext, key): ''' 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 ''' """ if ext == 'pri': try: value = self._primary_hdu.header.get(key) Loading @@ -84,7 +56,6 @@ class CsstData: print(e) else: raise CsstException return value def set_l1keyword(self, key, value): print('check out whether ' + key + " is a valid key and " + value + " is valid value") Loading @@ -94,13 +65,14 @@ class CsstData: def get_auxdata(self, name): print('Parent class returns zero image.') return np.zeros_like(get_l0data()) # return np.zeros_like(self.get_l0data()) return def save_l1data(self, imgtype, filename): ''' """ asve level 1 image and auxilary data to data file imgtype ''' """ print("save L1 image to a fits file with name " + filename) try: self._l1hdr_global.set('TYPE', imgtype, 'Type of Level 1 data') Loading
csst/common/factory.py 0 → 100644 +40 −0 Original line number Diff line number Diff line from astropy.io import fits from .data import INSTRUMENT_LIST from ..msc.mscdata import CsstMscImgData class CsstDataFactory: """ This class is designed to create CsstData and its inherited classes according to different kinds of input data format. """ def __init__(self): pass @staticmethod def createData(fitsfilename): """ create CSST Data instances Parameters ---------- fitsfilename: the file name of fits files Returns ------- """ try: hl = fits.open(fitsfilename) instrument = hl[0].header.get('INSTRUME') # strip or not? detector = hl[0].header.get('DETECTOR') # strip or not? print(instrument, detector) assert instrument in INSTRUMENT_LIST if instrument == 'MSC' and 6 <= int(detector[3:5]) <= 25: # multi-band imaging data = CsstMscImgData(hl[0], hl[1], instrument=instrument, detector=detector) return data except Exception as e: print(e)
csst/common/processors.py +6 −5 Original line number Diff line number Diff line from abc import ABCMeta, abstractmethod from enum import Enum class CsstProcStatus(Enum): empty = -1 normal = 0 ioerror = 1 runtimeerror = 2 # self['empty'].info = 'Not run yet.' # self['normal'].info = 'This is a normal run.' # self['ioerror'].info = 'This run is exceptionally stopped due to IO error.' Loading @@ -17,11 +18,11 @@ class CsstProcessor(metaclass=ABCMeta): @abstractmethod def prepare(self, **kwargs): pass @abstractmethod def run(self, data): return self._status @abstractmethod def cleanup(self): pass No newline at end of file
csst/msc/__init__.py +0 −1 Original line number Diff line number Diff line __version__ = "0.0.1" No newline at end of file