Commit 7137724f authored by Xie Zhou's avatar Xie Zhou
Browse files

为msc_level0_header添加更多字段

parent dd5a3c0d
...@@ -203,8 +203,18 @@ create table msc_level0_data ...@@ -203,8 +203,18 @@ create table msc_level0_data
create table msc_level0_header create table msc_level0_header
( (
id int(20) not null, id int(20) not null,
ra float, ra_obj float,
"dec" float, dec_obj float,
crpix1 float,
crpix2 float,
crval1 float,
crval2 float,
ctype1 varchar(10),
ctype2 varchar(10),
cd1_1 float,
cd1_2 float,
cd2_1 float,
cd2_2 float,
create_time datetime, create_time datetime,
primary key (id) primary key (id)
); );
......
...@@ -46,9 +46,9 @@ class Level0DataApi(object): ...@@ -46,9 +46,9 @@ class Level0DataApi(object):
prc_status = get_parameter(kwargs, "prc_status") prc_status = get_parameter(kwargs, "prc_status")
file_name = get_parameter(kwargs, "file_name") file_name = get_parameter(kwargs, "file_name")
limit = get_parameter(kwargs, "limit", 0) limit = get_parameter(kwargs, "limit", 0)
ra = get_parameter(kwargs, "ra", None) ra = get_parameter(kwargs, "ra", None)
dec = get_parameter(kwargs, "limit", None) dec = get_parameter(kwargs, "dec", None)
radius = get_parameter(kwargs, "limit", 0) radius = get_parameter(kwargs, "radius", 0)
sql_count = 'select count(*) as c from ifs_level0_data d left join ifs_level0_header h on d.id=h.id where 1=1' sql_count = 'select count(*) as c from ifs_level0_data d left join ifs_level0_header h on d.id=h.id where 1=1'
sql_data = 'select d.* from ifs_level0_data d left join ifs_level0_header h on d.id=h.id where 1=1' sql_data = 'select d.* from ifs_level0_data d left join ifs_level0_header h on d.id=h.id where 1=1'
......
...@@ -40,14 +40,15 @@ def ingest_one(file_path, db, copyfiles): ...@@ -40,14 +40,15 @@ def ingest_one(file_path, db, copyfiles):
dest_root_dir = os.getenv("CSST_LOCAL_FILE_ROOT", "/opt/temp/csst") dest_root_dir = os.getenv("CSST_LOCAL_FILE_ROOT", "/opt/temp/csst")
hdul = fits.open(file_path) hdul = fits.open(file_path)
header = hdul[0].header fits_header = hdul[0].header
img_header = hdul[1].header
obs_id = header["OBSID"] obs_id = fits_header["OBSID"]
exp_start_time = f"{header['DATE-OBS']} {header['TIME-OBS']}" exp_start_time = f"{fits_header['DATE-OBS']} {fits_header['TIME-OBS']}"
exp_time = header['EXPTIME'] exp_time = fits_header['EXPTIME']
module_id = header["INSTRUME"] module_id = fits_header["INSTRUME"]
obs_type = header["FILETYPE"] obs_type = fits_header["FILETYPE"]
qc0_status = -1 qc0_status = -1
prc_status = -1 prc_status = -1
time_now = datetime.datetime.now() time_now = datetime.datetime.now()
...@@ -64,8 +65,8 @@ def ingest_one(file_path, db, copyfiles): ...@@ -64,8 +65,8 @@ def ingest_one(file_path, db, copyfiles):
(obs_id,exp_start_time,exp_time,module_id,obs_type,facility_status_id,module_status_id,qc0_status, prc_status,create_time)) (obs_id,exp_start_time,exp_time,module_id,obs_type,facility_status_id,module_status_id,qc0_status, prc_status,create_time))
db.end() db.end()
#level0 #level0
detector = header["DETECTOR"] detector = fits_header["DETECTOR"]
filename = get_header_value("FILENAME", header, os.path.basename(file_path)) filename = get_header_value("FILENAME", fits_header, os.path.basename(file_path))
existed = db.exists( existed = db.exists(
"select * from msc_level0_data where filename=?", "select * from msc_level0_data where filename=?",
...@@ -81,7 +82,7 @@ def ingest_one(file_path, db, copyfiles): ...@@ -81,7 +82,7 @@ def ingest_one(file_path, db, copyfiles):
file_full_path = file_path file_full_path = file_path
if copyfiles: if copyfiles:
file_dir = f"{dest_root_dir}/{module_id}/{obs_type.upper()}/{header['EXPSTART']}/{obs_id}/MS" file_dir = f"{dest_root_dir}/{module_id}/{obs_type.upper()}/{fits_header['EXPSTART']}/{obs_id}/MS"
if not os.path.exists(file_dir): if not os.path.exists(file_dir):
os.makedirs(file_dir) os.makedirs(file_dir)
file_full_path = f"{file_dir}/{filename}.fits" file_full_path = f"{file_dir}/{filename}.fits"
...@@ -95,13 +96,24 @@ def ingest_one(file_path, db, copyfiles): ...@@ -95,13 +96,24 @@ def ingest_one(file_path, db, copyfiles):
db.end() db.end()
level0_id_id = db.last_row_id() level0_id_id = db.last_row_id()
#level0-header #level0-header
ra_obj = header["RA_OBJ"] ra_obj = fits_header["RA_OBJ"]
dec_obj = header["DEC_OBJ"] dec_obj = fits_header["DEC_OBJ"]
crpix1 = img_header["CRPIX1"]
crpix2 = img_header["CRPIX2"]
crval1 = img_header["CRVAL1"]
crval1 = img_header["CRVAL2"]
ctype1 = img_header["CTYPE1"]
ctype2 = img_header["CTYPE2"]
cd1_1 = img_header["CD1_1"]
cd1_2 = img_header["CD1_2"]
cd2_1 = img_header["CD2_1"]
cd2_2 = img_header["CD2_2"]
db.execute("delete from msc_level0_header where id=?",(level0_id_id,)) db.execute("delete from msc_level0_header where id=?",(level0_id_id,))
db.execute("insert into msc_level0_header \ db.execute("insert into msc_level0_header \
(id, ra, `dec`, create_time) \ (id, ra_obj, dec_obj, crpix1, crpix2, crval1, crval1, \
values (?,?,?,?)", ctype1, ctype2, cd1_1, cd1_2, cd2_1, cd2_2, create_time) \
(level0_id_id, ra_obj, dec_obj, create_time)) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
(level0_id_id, ra_obj, dec_obj, crpix1, crpix2, crval1, crval1, ctype1, ctype2, cd1_1, cd1_2, cd2_1, cd2_2, create_time))
if copyfiles: if copyfiles:
#copy files #copy files
......
...@@ -29,7 +29,20 @@ class Level0DataApi(object): ...@@ -29,7 +29,20 @@ class Level0DataApi(object):
prc_status : [int], prc_status : [int],
file_name: [str] file_name: [str]
limit: limits returns the number of records,default 0:no-limit limit: limits returns the number of records,default 0:no-limit
ra_obj: [float],
dec_obj: [float],
crpix1: [float],
crpix2: [float],
crval1: [float],
crval1: [float],
ctype1: [float],
ctype2: [float],
cd1_1: [float],
cd1_2: [float],
cd2_1: [float],
cd2_2: [float],
radius: [float],
return: csst_dfs_common.models.Result return: csst_dfs_common.models.Result
''' '''
try: try:
...@@ -42,25 +55,64 @@ class Level0DataApi(object): ...@@ -42,25 +55,64 @@ class Level0DataApi(object):
prc_status = get_parameter(kwargs, "prc_status") prc_status = get_parameter(kwargs, "prc_status")
file_name = get_parameter(kwargs, "file_name") file_name = get_parameter(kwargs, "file_name")
limit = get_parameter(kwargs, "limit", 0) limit = get_parameter(kwargs, "limit", 0)
ra_obj = get_parameter(kwargs, "ra_obj", None)
sql_count = "select count(*) as c from msc_level0_data where 1=1" dec_obj = get_parameter(kwargs, "dec_obj", None)
sql_data = f"select * from msc_level0_data where 1=1" crpix1 = get_parameter(kwargs, "crpix1", None)
crpix2 = get_parameter(kwargs, "crpix2", None)
crval1 = get_parameter(kwargs, "crval1", None)
crval1 = get_parameter(kwargs, "crval1", None)
ctype1 = get_parameter(kwargs, "ctype1", None)
ctype2 = get_parameter(kwargs, "ctype2", None)
cd1_1 = get_parameter(kwargs, "cd1_1", None)
cd1_2 = get_parameter(kwargs, "cd1_2", None)
cd2_1 = get_parameter(kwargs, "cd2_1", None)
cd2_2 = get_parameter(kwargs, "cd2_2", None)
radius = get_parameter(kwargs, "radius", 0)
sql_count = "select count(*) as c from msc_level0_data d left join msc_level0_header h on d.id=h.id where 1=1"
sql_data = f"select * from msc_level0_data d left join msc_level0_header h on d.id=h.id where 1=1"
sql_condition = "" sql_condition = ""
if obs_id: if obs_id:
sql_condition = f"{sql_condition} and obs_id='{obs_id}'" sql_condition = f"{sql_condition} and d.obs_id='{obs_id}'"
if detector_no: if detector_no:
sql_condition = f"{sql_condition} and detector_no='{detector_no}'" sql_condition = f"{sql_condition} and d.detector_no='{detector_no}'"
if obs_type: if obs_type:
sql_condition = f"{sql_condition} and obs_type='{obs_type}'" sql_condition = f"{sql_condition} and d.obs_type='{obs_type}'"
if exp_time_start: if exp_time_start:
sql_condition = f"{sql_condition} and obs_time >='{exp_time_start}'" sql_condition = f"{sql_condition} and d.obs_time >='{exp_time_start}'"
if exp_time_end: if exp_time_end:
sql_condition = f"{sql_condition} and obs_time <='{exp_time_end}'" sql_condition = f"{sql_condition} and d.obs_time <='{exp_time_end}'"
if qc0_status: if qc0_status:
sql_condition = f"{sql_condition} and qc0_status={qc0_status}" sql_condition = f"{sql_condition} and d.qc0_status={qc0_status}"
if prc_status: if prc_status:
sql_condition = f"{sql_condition} and prc_status={prc_status}" sql_condition = f"{sql_condition} and d.prc_status={prc_status}"
if ra_obj:
sql_condition = f"{sql_condition} and (h.ra_obj <='{ra_obj+radius} and h.ra_obj >={ra_obj-radius}'"
if dec_obj:
sql_condition = f"{sql_condition} and (h.dec_obj <='{dec_obj+radius} and h.dec_obj >={dec_obj-radius}'"
if crpix1:
sql_condition = f"{sql_condition} and h.crpix1 ='{crpix1}'"
if crpix2:
sql_condition = f"{sql_condition} and h.crpix2 ='{crpix2}'"
if crval1:
sql_condition = f"{sql_condition} and h.crval1 ='{crval1}'"
if crval1:
sql_condition = f"{sql_condition} and h.crval1 ='{crval1}'"
if ctype1:
sql_condition = f"{sql_condition} and h.ctype1 ='{ctype1}'"
if ctype2:
sql_condition = f"{sql_condition} and h.ctype2 ='{ctype2}'"
if cd1_1:
sql_condition = f"{sql_condition} and h.cd1_1='{cd1_1}'"
if cd1_2:
sql_condition = f"{sql_condition} and h.cd1_2='{cd1_2}'"
if cd2_1:
sql_condition = f"{sql_condition} and h.cd2_1='{cd2_1}'"
if cd2_2:
sql_condition = f"{sql_condition} and h.cd2_2='{cd2_2}'"
if file_name: if file_name:
sql_condition = f" and filename='{file_name}'" sql_condition = f" and filename='{file_name}'"
......
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