Commit 6665b215 authored by Wei Shoulin's avatar Wei Shoulin
Browse files

get header

parent 9a909bd2
......@@ -255,8 +255,8 @@ create table msc_level1_ref (
create table msc_level1_header
(
id int(20) not null,
ra float,
"dec" float,
ra_obj float,
dec_obj float,
create_time datetime,
primary key (id)
);
......@@ -270,8 +270,8 @@ create table msc_cal2level0
create table msc_cal_header
(
id int(20) not null,
ra float,
"dec" float,
ra_obj float,
dec_obj float,
create_time datetime,
primary key (id)
);
......@@ -319,8 +319,8 @@ create table msc_level2_data (
create table msc_level2_header (
id BIGINT not null,
ra float8 null,
"dec" float8 null,
ra_obj float8 null,
dec_obj float8 null,
constraint PK_MSC_LEVEL2_HEADER primary key (id)
);
/*===========================ifs===================================*/
......@@ -346,8 +346,8 @@ create table ifs_level0_data
create table ifs_level0_header
(
id int(20) not null,
ra float,
"dec" float,
ra_obj float,
dec_obj float,
object_name varchar(64) not null,
version varchar(64) not null,
primary key (id)
......@@ -374,8 +374,8 @@ create table ifs_cal2level0
create table ifs_cal_header
(
id int(20) not null,
ra float,
"dec" float,
ra_obj float,
dec_obj float,
create_time datetime,
primary key (id)
);
......@@ -424,8 +424,8 @@ create table ifs_level1_ref (
create table ifs_level1_header
(
id int(20) not null,
ra float,
"dec" float,
ra_obj float,
dec_obj float,
create_time datetime,
primary key (id)
);
......@@ -463,8 +463,8 @@ create table mci_level0_data
create table mci_level0_header
(
id int(20) not null,
ra float,
"dec" float,
ra_obj float,
dec_obj float,
object_name varchar(64) not null,
version varchar(64) not null,
primary key (id)
......@@ -491,8 +491,8 @@ create table mci_cal2level0
create table mci_cal_header
(
id int(20) not null,
ra float,
"dec" float,
ra_obj float,
dec_obj float,
create_time datetime,
primary key (id)
);
......@@ -541,8 +541,8 @@ create table mci_level1_ref (
create table mci_level1_header
(
id int(20) not null,
ra float,
"dec" float,
ra_obj float,
dec_obj float,
create_time datetime,
primary key (id)
);
......@@ -580,8 +580,8 @@ create table sls_level0_data
create table sls_level0_header
(
id int(20) not null,
ra float,
"dec" float,
ra_obj float,
dec_obj float,
create_time datetime,
primary key (id)
);
......@@ -607,8 +607,8 @@ create table sls_cal2level0
create table sls_cal_header
(
id int(20) not null,
ra float,
"dec" float,
ra_obj float,
dec_obj float,
create_time datetime,
primary key (id)
);
......@@ -656,8 +656,8 @@ create table sls_level1_ref (
create table sls_level1_header
(
id int(20) not null,
ra float,
"dec" float,
ra_obj float,
dec_obj float,
create_time datetime,
primary key (id)
);
......@@ -692,8 +692,8 @@ create table sls_level2_spectra
create table sls_level2_spectra_header
(
id int(20) not null,
ra float,
"dec" float,
ra_obj float,
dec_obj float,
create_time datetime,
primary key (id)
);
......@@ -720,8 +720,8 @@ create table cpic_level0_data
create table cpic_level0_header
(
id int(20) not null,
ra float,
"dec" float,
ra_obj float,
dec_obj float,
create_time datetime,
primary key (id)
);
......@@ -747,8 +747,8 @@ create table cpic_cal2level0
create table cpic_cal_header
(
id int(20) not null,
ra float,
"dec" float,
ra_obj float,
dec_obj float,
create_time datetime,
primary key (id)
);
......@@ -796,8 +796,8 @@ create table cpic_level1_ref (
create table cpic_level1_header
(
id int(20) not null,
ra float,
"dec" float,
ra_obj float,
dec_obj float,
create_time datetime,
primary key (id)
);
......
......@@ -97,7 +97,7 @@ def ingesst_one(file_path, db, copyfiles):
dec_obj = header["DEC_OBJ"]
db.execute("delete from cpic_level0_header where id=?",(level0_id_id,))
db.execute("insert into cpic_level0_header \
(id, ra, `dec`, create_time) \
(id, ra_obj, dec_obj, create_time) \
values (?,?,?,?)",
(level0_id_id, ra_obj, dec_obj, create_time))
......
......@@ -108,7 +108,7 @@ def ingest_one(file_path, db, copyfiles):
dec_obj = header["OBJ_DEC"]
db.execute("delete from ifs_level0_header where id=?",(level0_id_id,))
db.execute("insert into ifs_level0_header \
(id, ra, `dec`, object_name, version) \
(id, ra_obj, dec_obj, object_name, version) \
values (?,?,?,?,?)",
(level0_id_id, ra_obj, dec_obj, object_name, version))
......
......@@ -46,8 +46,8 @@ class Level0DataApi(object):
prc_status = get_parameter(kwargs, "prc_status")
file_name = get_parameter(kwargs, "file_name")
limit = get_parameter(kwargs, "limit", 0)
ra = get_parameter(kwargs, "ra", None)
dec = get_parameter(kwargs, "dec", None)
ra_obj = get_parameter(kwargs, "ra_obj", None)
dec_obj = get_parameter(kwargs, "dec_obj", None)
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'
......@@ -72,10 +72,10 @@ class Level0DataApi(object):
sql_condition = f"{sql_condition} and h.object_name='{object_name}'"
if version:
sql_condition = f"{sql_condition} and h.version='{version}'"
if ra:
sql_condition = f"{sql_condition} and (h.ra <= {ra+radius} and h.ra >={ra-radius})"
if dec:
sql_condition = f"{sql_condition} and (h.dec <= {dec+radius} and h.ra >={dec-radius})"
if ra_obj:
sql_condition = f"{sql_condition} and (h.ra <= {ra_obj + 2*radius} and h.ra >={ra_obj - 2*radius})"
if dec_obj:
sql_condition = f"{sql_condition} and (h.dec <= {dec_obj + 2*radius} and h.ra >={dec_obj - 2*radius})"
if file_name:
sql_condition = f" and d.filename='{file_name}'"
......@@ -119,7 +119,9 @@ class Level0DataApi(object):
r = self.db.select_one(
"select * from ifs_level0_data where id=?", (id,))
if r:
return Result.ok_data(data=Level0Record().from_dict(r))
data = Level0Record().from_dict(r)
data.header = self.db.select_one("select * from ifs_level0_header where id=?", (id,))
return Result.ok_data(data = data)
else:
return Result.error(message=f"id:{id} not found")
except Exception as e:
......@@ -131,7 +133,9 @@ class Level0DataApi(object):
r = self.db.select_one(
"select * from ifs_level0_data where level0_id=?", (level0_id,))
if r:
return Result.ok_data(data=Level0Record().from_dict(r))
data = Level0Record().from_dict(r)
data.header = self.db.select_one("select * from msc_level0_header where id=?", (data.id,))
return Result.ok_data(data = data)
else:
return Result.error(message=f"level0_id:{level0_id} not found")
except Exception as e:
......
......@@ -107,7 +107,7 @@ def ingest_one(file_path, db, copyfiles):
dec_obj = header["OBJ_DEC"]
db.execute("delete from mci_level0_header where id=?",(level0_id_id,))
db.execute("insert into mci_level0_header \
(id, ra, `dec`, object_name, version) \
(id, ra_obj, dec_obj, object_name, version) \
values (?,?,?,?,?)",
(level0_id_id, ra_obj, dec_obj, object_name, version))
......
......@@ -31,8 +31,8 @@ class Level0DataApi(object):
prc_status : [int],
file_name: [str],
version: [str],
ra: [float],
dec: [float],
ra_obj: [float],
dec_obj: [float],
radius: [float],
limit: limits returns the number of records,default 0:no-limit
......@@ -42,31 +42,45 @@ class Level0DataApi(object):
obs_id = get_parameter(kwargs, "obs_id")
detector_no = get_parameter(kwargs, "detector_no")
obs_type = get_parameter(kwargs, "obs_type")
object_name = get_parameter(kwargs, "object_name")
version = get_parameter(kwargs, "version")
exp_time_start = get_parameter(kwargs, "obs_time", [None, None])[0]
exp_time_end = get_parameter(kwargs, "obs_time", [None, None])[1]
qc0_status = get_parameter(kwargs, "qc0_status")
prc_status = get_parameter(kwargs, "prc_status")
file_name = get_parameter(kwargs, "file_name")
ra_obj = get_parameter(kwargs, "ra_obj", None)
dec_obj = get_parameter(kwargs, "dec_obj", None)
radius = get_parameter(kwargs, "radius", 0)
limit = get_parameter(kwargs, "limit", 0)
sql_count = "select count(*) as c from mci_level0_data where 1=1"
sql_data = f"select * from mci_level0_data where 1=1"
sql_count = 'select count(*) as c from mci_level0_data d left join mci_level0_header h on d.id=h.id where 1=1'
sql_data = 'select d.* from mci_level0_data d left join mci_level0_header h on d.id=h.id where 1=1'
sql_condition = ""
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:
sql_condition = f"{sql_condition} and detector_no='{detector_no}'"
sql_condition = f"{sql_condition} and d.detector_no='{detector_no}'"
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:
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:
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:
sql_condition = f"{sql_condition} and qc0_status={qc0_status}"
sql_condition = f"{sql_condition} and d.qc0_status={qc0_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 object_name:
sql_condition = f"{sql_condition} and h.object_name='{object_name}'"
if version:
sql_condition = f"{sql_condition} and h.version='{version}'"
if ra_obj:
sql_condition = f"{sql_condition} and (h.ra <= {ra_obj + 2*radius} and h.ra >={ra_obj - 2*radius})"
if dec_obj:
sql_condition = f"{sql_condition} and (h.dec <= {dec_obj + 2*radius} and h.ra >={dec_obj - 2*radius})"
if file_name:
sql_condition = f" and filename='{file_name}'"
......@@ -109,7 +123,9 @@ class Level0DataApi(object):
r = self.db.select_one(
"select * from mci_level0_data where id=?", (id,))
if r:
return Result.ok_data(data=Level0Record().from_dict(r))
data = Level0Record().from_dict(r)
data.header = self.db.select_one("select * from msc_level0_header where id=?", (data.id,))
return Result.ok_data(data = data)
else:
return Result.error(message=f"id:{id} not found")
except Exception as e:
......@@ -121,7 +137,9 @@ class Level0DataApi(object):
r = self.db.select_one(
"select * from mci_level0_data where level0_id=?", (level0_id,))
if r:
return Result.ok_data(data=Level0Record().from_dict(r))
data = Level0Record().from_dict(r)
data.header = self.db.select_one("select * from msc_level0_header where id=?", (data.id,))
return Result.ok_data(data = data)
else:
return Result.error(message=f"level0_id:{level0_id} not found")
except Exception as e:
......
......@@ -65,7 +65,9 @@ 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))
db.end()
#level0
detector = fits_header["DETECTOR"]
detector = get_header_value("DETECTOR", fits_header, "")
if len(detector) > 2:
detector = detector[-2:]
filename = get_header_value("FILENAME", fits_header, os.path.basename(file_path))
existed = db.exists(
......@@ -95,25 +97,27 @@ def ingest_one(file_path, db, copyfiles):
(level0_id, obs_id, detector, obs_type, exp_start_time, exp_time, detector_status_id, filename, file_full_path, qc0_status, prc_status,create_time))
db.end()
level0_id_id = db.last_row_id()
#level0-header
ra_obj = fits_header["RA_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"]
ra_obj = get_header_value("RA_OBJ", fits_header, 0)
dec_obj = get_header_value("DEC_OBJ", fits_header, 0)
crpix1 = get_header_value("CRPIX1", img_header, 0)
crpix2 = get_header_value("CRPIX2", img_header, 0)
crval1 = get_header_value("CRVAL1", img_header, 0)
crval2 = get_header_value("CRVAL2", img_header, 0)
ctype1 = get_header_value("CTYPE1", img_header, "")
ctype2 = get_header_value("CTYPE2", img_header, "")
cd1_1 = get_header_value("CD1_1", img_header, 0)
cd1_2 = get_header_value("CD1_2", img_header, 0)
cd2_1 = get_header_value("CD2_1", img_header, 0)
cd2_2 = get_header_value("CD2_2", img_header, 0)
db.execute("delete from msc_level0_header where id=?",(level0_id_id,))
db.execute("insert into msc_level0_header \
(id, ra_obj, dec_obj, crpix1, crpix2, crval1, crval1, \
(id, ra_obj, dec_obj, crpix1, crpix2, crval1, crval2, \
ctype1, ctype2, cd1_1, cd1_2, cd2_1, cd2_2, 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))
(level0_id_id, ra_obj, dec_obj, crpix1, crpix2, crval1, crval2, ctype1, ctype2, cd1_1, cd1_2, cd2_1, cd2_2, create_time))
if copyfiles:
#copy files
......
......@@ -27,21 +27,11 @@ class Level0DataApi(object):
obs_time : (start, end),
qc0_status : [int],
prc_status : [int],
file_name: [str]
limit: limits returns the number of records,default 0:no-limit
file_name: [str],
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],
limit: limits returns the number of records,default 0:no-limit
return: csst_dfs_common.models.Result
'''
......@@ -57,19 +47,8 @@ class Level0DataApi(object):
limit = get_parameter(kwargs, "limit", 0)
ra_obj = get_parameter(kwargs, "ra_obj", None)
dec_obj = get_parameter(kwargs, "dec_obj", None)
crpix1 = get_parameter(kwargs, "crpix1", None)
crpix2 = get_parameter(kwargs, "crpix2", None)
crval1 = get_parameter(kwargs, "crval1", None)
crval2 = get_parameter(kwargs, "crval2", 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"
......@@ -89,29 +68,9 @@ class Level0DataApi(object):
if 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}'"
sql_condition = f"{sql_condition} and (h.ra_obj <={ra_obj + 2*radius} and h.ra_obj >={ra_obj - 2*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}'"
sql_condition = f"{sql_condition} and (h.dec_obj <={dec_obj+2*radius} and h.dec_obj >={dec_obj- 2*radius}"
if file_name:
sql_condition = f" and filename='{file_name}'"
......@@ -155,9 +114,11 @@ class Level0DataApi(object):
r = self.db.select_one(
"select * from msc_level0_data where id=?", (id,))
if r:
return Result.ok_data(data=Level0Record().from_dict(r))
data = Level0Record().from_dict(r)
data.header = self.db.select_one("select * from msc_level0_header where id=?", (id,))
return Result.ok_data(data = data)
else:
return Result.error(message=f"id:{id} not found")
return Result.error(message=f"id:{id} not found")
except Exception as e:
log.error(e)
return Result.error(message=str(e))
......@@ -167,7 +128,9 @@ class Level0DataApi(object):
r = self.db.select_one(
"select * from msc_level0_data where level0_id=?", (level0_id,))
if r:
return Result.ok_data(data=Level0Record().from_dict(r))
data = Level0Record().from_dict(r)
data.header = self.db.select_one("select * from msc_level0_header where id=?", (data.id,))
return Result.ok_data(data = data)
else:
return Result.error(message=f"level0_id:{level0_id} not found")
except Exception as e:
......
......@@ -93,7 +93,7 @@ def ingesst_one(file_path, db, copyfiles):
dec_obj = header["DEC_OBJ"]
db.execute("delete from sls_level0_header where id=?",(level0_id_id,))
db.execute("insert into sls_level0_header \
(id, ra, `dec`, create_time) \
(id, ra_obj, dec_obj, create_time) \
values (?,?,?,?)",
(level0_id_id, ra_obj, dec_obj, create_time))
......
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