Commit 0fe65969 authored by Wei Shoulin's avatar Wei Shoulin
Browse files

as

parent d521aa51
...@@ -212,14 +212,19 @@ class RefFitsApi(object): ...@@ -212,14 +212,19 @@ class RefFitsApi(object):
def associate_raw(self, **kwargs): def associate_raw(self, **kwargs):
''' associate raw fits to reference file
parameter kwargs:
raw_fits_ids = [list]
ref_fits_id = [int]
'''
raw_fits_ids = get_parameter(kwargs, "raw_fits_ids") raw_fits_ids = get_parameter(kwargs, "raw_fits_ids")
ref_fits_id = get_parameter(kwargs, "ref_fits_id") ref_fits_id = get_parameter(kwargs, "ref_fits_id")
if raw_fits_ids is None or ref_fits_id is None: if raw_fits_ids is None or ref_fits_id is None:
raise Exception("raw_fits_ids or ref_fits_id is None") raise Exception("raw_fits_ids or ref_fits_id is None")
sql = ['INSERT INTO ifs_raw_ref (fit_id, ref_id, create_time) values '] sql = 'INSERT INTO ifs_raw_ref (fit_id, ref_id, create_time) values '
values = ["(%s,%s,%s)"%(i,ref_fits_id,format_time_ms(time.time())) for i in raw_fits_ids] values = ["(%s,%s,'%s')"%(i,ref_fits_id,format_time_ms(time.time())) for i in raw_fits_ids]
self.db.execute(sql + ",".join(values)) self.db.execute(sql + ",".join(values))
......
...@@ -9,35 +9,40 @@ class IFSFitsTestCase(unittest.TestCase): ...@@ -9,35 +9,40 @@ class IFSFitsTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.api = RefFitsApi() self.api = RefFitsApi()
def test_find(self): # def test_find(self):
recs = self.api.find(exp_time=('2021-03-19 13:42:22', '2021-03-19 15:28:00'), ref_type=RefFitsApi.REF_FITS_FLAT) # recs = self.api.find(exp_time=('2021-03-19 13:42:22', '2021-03-19 15:28:00'), ref_type=RefFitsApi.REF_FITS_FLAT)
print('find:', recs) # print('find:', recs)
assert len(recs) > 1 # assert len(recs) > 1
recs = self.api.find() # recs = self.api.find()
print('=' * 80) # print('=' * 80)
print('find:', recs) # print('find:', recs)
assert len(recs) > 1 # assert len(recs) > 1
def test_read(self): # def test_read(self):
recs = self.api.find(file_name='CCD2_Flat_img.fits') # recs = self.api.find(file_name='CCD2_Flat_img.fits')
print("The full path: ", os.path.join(self.api.root_dir, recs[0]['file_path'])) # print("The full path: ", os.path.join(self.api.root_dir, recs[0]['file_path']))
file_segments = self.api.read(file_path=recs[0]['file_path']) # file_segments = self.api.read(file_path=recs[0]['file_path'])
file_bytes = b''.join(file_segments) # file_bytes = b''.join(file_segments)
hdul = fits.HDUList.fromstring(file_bytes) # hdul = fits.HDUList.fromstring(file_bytes)
print(hdul.info()) # print(hdul.info())
hdr = hdul[0].header # hdr = hdul[0].header
print(repr(hdr)) # print(repr(hdr))
def test_update_status(self): # def test_update_status(self):
recs = self.api.find(file_name='CCD2_Flat_img.fits') # recs = self.api.find(file_name='CCD2_Flat_img.fits')
self.api.update_status(fits_id=recs[0]['id'],status=1) # self.api.update_status(fits_id=recs[0]['id'],status=1)
rec = self.api.get(fits_id=recs[0]['id']) # rec = self.api.get(fits_id=recs[0]['id'])
assert rec['status'] == 1 # assert rec['status'] == 1
def test_write(self): # def test_write(self):
recs = self.api.write(file_path='/opt/temp/csst_ifs/CCD3_Flat_img.fits') # recs = self.api.write(file_path='/opt/temp/csst_ifs/CCD3_Flat_img.fits')
recs = self.api.find(file_name='CCD3_Flat_img.fits') # recs = self.api.find(file_name='CCD3_Flat_img.fits')
rec = self.api.get(fits_id=recs[0]['id']) # rec = self.api.get(fits_id=recs[0]['id'])
print(rec) # print(rec)
def test_associate_raw(self):
raw_fits_ids = [3,4,5]
ref_fits_id = 2
self.api.associate_raw(raw_fits_ids = raw_fits_ids, ref_fits_id = ref_fits_id)
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