Commit 7098156a authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

updated docstring

parent 762f84f7
...@@ -3,7 +3,7 @@ from collections import OrderedDict ...@@ -3,7 +3,7 @@ from collections import OrderedDict
import astropy.io.fits as fits import astropy.io.fits as fits
from astropy.io.fits import HDUList, PrimaryHDU from astropy.io.fits import HDUList, PrimaryHDU
from csst.common.CsstException import CsstException from csst.common.exception import CsstException
__all__ = ["CsstData", "INSTRUMENT_LIST"] __all__ = ["CsstData", "INSTRUMENT_LIST"]
...@@ -12,9 +12,7 @@ INSTRUMENT_LIST = ["MSC", ] ...@@ -12,9 +12,7 @@ INSTRUMENT_LIST = ["MSC", ]
class CsstData: class CsstData:
""" """ General CSST data class """
general CSST data class
"""
_primary_hdu = [] _primary_hdu = []
_l0data = [] # HDUList _l0data = [] # HDUList
_l1hdr_global = [] _l1hdr_global = []
...@@ -30,10 +28,12 @@ class CsstData: ...@@ -30,10 +28,12 @@ class CsstData:
self.detector = detector self.detector = detector
def get_l0data(self, copy=True): def get_l0data(self, copy=True):
""" """ get level 0 data from CsstData class
obtain level 0 data from CsstData class
copy: True: if the user want to copy the memory of the data to the new class; Parameters
False: only reference of the data memory is written to the new class ----------
copy : bool
if True, return a copy.
""" """
if copy: if copy:
return self._l0data.data.copy() return self._l0data.data.copy()
...@@ -41,10 +41,14 @@ class CsstData: ...@@ -41,10 +41,14 @@ class CsstData:
return self._l0data.data return self._l0data.data
def get_l0keyword(self, ext="pri", key="INSTRUME"): def get_l0keyword(self, ext="pri", key="INSTRUME"):
""" """ get a specific keyword from fits header of level 0 image data
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 Parameters
key: the name of the key ----------
ext: {"pri"| "img"}
the HDU extension
key:
the key
""" """
if ext == 'pri': if ext == 'pri':
try: try:
...@@ -60,20 +64,30 @@ class CsstData: ...@@ -60,20 +64,30 @@ class CsstData:
raise CsstException raise CsstException
def set_l1keyword(self, key, value): 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') print('save image data to l2data')
raise NotImplementedError
def get_auxdata(self, name): def get_auxdata(self, name):
""" get aux data
Parameters
----------
"""
print('Parent class returns zero image.') print('Parent class returns zero image.')
# return np.zeros_like(self.get_l0data()) # return np.zeros_like(self.get_l0data())
return raise NotImplementedError
def save_l1data(self, imgtype, filename): def save_l1data(self, imgtype, filename):
""" """ save L1 image and auxilary data to file
asve level 1 image and auxilary data to data file
imgtype Parameters
----------
imgtype: {}
image type
""" """
print("save L1 image to a fits file with name " + filename) print("save L1 image to a fits file with name " + filename)
try: try:
......
#import BaseException
class CsstException(BaseException): class CsstException(BaseException):
def __init__(self): def __init__(self):
print('Exceoption raised.') print('Exceoption raised.')
...@@ -11,28 +11,28 @@ __all__ = ["CsstMscData", "CsstMscImgData"] ...@@ -11,28 +11,28 @@ __all__ = ["CsstMscData", "CsstMscImgData"]
class CsstMscData(CsstData): class CsstMscData(CsstData):
_l1img_types = {'sci': True, 'weight': True, 'flag': True} _l1img_types = {'sci': True, 'weight': True, 'flag': True}
def __init__(self, primaryHDU, imgHDU, **kwargs): def __init__(self, priHDU, imgHDU, **kwargs):
print('create CsstMscData') super(CsstData, self).__init__(priHDU, imgHDU, **kwargs)
super(CsstData, self).__init__(primaryHDU, imgHDU, **kwargs) self._l1hdr_global = priHDU.header.copy()
self._l1hdr_global = primaryHDU.header.copy()
# self._l1hdr_global['SIMPLE'] = 'T' #/ conforms to FITS standard # self._l1hdr_global['SIMPLE'] = 'T' #/ conforms to FITS standard
# self._l1hdr_global['NAXIS'] = 0kkjk # self._l1hdr_global['NAXIS'] = 0kkjk
self._l1data['sci'] = ImageHDU() self._l1data['sci'] = ImageHDU()
self._l1data['weight'] = ImageHDU() self._l1data['weight'] = ImageHDU()
self._l1data['flag'] = ImageHDU() self._l1data['flag'] = ImageHDU()
def set_flat(self, flatimg): def set_flat(self, flat):
""" """ set flat
Parameters Parameters
---------- ----------
flatimg flat:
flat image
Returns Returns
------- -------
""" """
self._auxdata['flat'] = flatimg self._auxdata['flat'] = flat
def set_bias(self, biasimg): def set_bias(self, biasimg):
self._auxdata['bias'] = biasimg self._auxdata['bias'] = biasimg
...@@ -80,32 +80,33 @@ class CsstMscData(CsstData): ...@@ -80,32 +80,33 @@ class CsstMscData(CsstData):
class CsstMscImgData(CsstMscData): class CsstMscImgData(CsstMscData):
def __init__(self, primaryHDU, imgHDU, **kwargs): def __init__(self, priHDU, imgHDU, **kwargs):
# print('create CsstMscImgData') # print('create CsstMscImgData')
super(CsstMscData, self).__init__(primaryHDU, imgHDU, **kwargs) super(CsstMscData, self).__init__(priHDU, imgHDU, **kwargs)
def __repr__(self): def __repr__(self):
return "<CsstMscImgData: {} {}>".format(self.instrument, self.detector) return "<CsstMscImgData: {} {}>".format(self.instrument, self.detector)
@staticmethod @staticmethod
def read(fitsfilename): def read(fp):
""" create CSST Data instances """ read from fits file
Parameters Parameters
---------- ----------
fitsfilename: fp:
the file name of fits files the file path of fits file
Returns Returns
------- -------
CsstMscImgData
""" """
try: try:
hl = fits.open(fitsfilename) hl = fits.open(fp)
instrument = hl[0].header.get('INSTRUME') # strip or not? instrument = hl[0].header.get('INSTRUME') # strip or not?
detector = hl[0].header.get('DETECTOR') # 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 assert instrument in INSTRUMENT_LIST
if instrument == 'MSC' and 6 <= int(detector[3:5]) <= 25: if instrument == 'MSC' and 6 <= int(detector[3:5]) <= 25:
# multi-band imaging # multi-band imaging
...@@ -113,10 +114,3 @@ class CsstMscImgData(CsstMscData): ...@@ -113,10 +114,3 @@ class CsstMscImgData(CsstMscData):
return data return data
except Exception as e: except Exception as e:
print(e) print(e)
# def test():
# fp = MSC_MS_210527171000_100000279_16_raw.fits
#
#
# if __name__=="__main__":
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment