Commit 20e9490a authored by Wei Shoulin's avatar Wei Shoulin
Browse files

level2

parent 0cee9195
...@@ -18,3 +18,6 @@ def format_time_ms(float_time): ...@@ -18,3 +18,6 @@ def format_time_ms(float_time):
data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time) data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time)
data_secs = (float_time - int(float_time)) * 1000 data_secs = (float_time - int(float_time)) * 1000
return "%s.%03d" % (data_head, data_secs) return "%s.%03d" % (data_head, data_secs)
def str_to_datetime(str_time):
return datetime.strptime(str_time.split('.')[0], '%Y-%m-%d %H:%M:%S')
\ No newline at end of file
...@@ -2,6 +2,20 @@ import dataclasses ...@@ -2,6 +2,20 @@ import dataclasses
from typing import List,Dict from typing import List,Dict
from .common import BaseModel, default_field from .common import BaseModel, default_field
@dataclasses.dataclass
class UserRecord(BaseModel):
id: int = 0
user_name: str=""
true_name: str=""
email: str=""
passwd: str=""
organization: str=""
create_time: str=""
status: int = 0
last_login_ip: str=""
last_login_time: str=""
role: str=""
@dataclasses.dataclass @dataclasses.dataclass
class Observation(BaseModel): class Observation(BaseModel):
id: int = 0 id: int = 0
......
import dataclasses
from .common import BaseModel
@dataclasses.dataclass
class Level2Record(BaseModel):
id: int = 0
level0_id: str = ''
level1_id: int = 0
brick_id: int = 0
module_id: str = ''
object_name : str=""
data_type: str=""
filename : str=""
file_path: str=""
qc2_status: int = 0
qc2_time: str=""
prc_status: int = 0
prc_time: str=""
create_time: str=""
update_time: str=""
pipeline_id: str=""
import_status: int = 0
@dataclasses.dataclass
class Level2TypeRecord(BaseModel):
data_type: str=""
module_id: str = ''
key_column : str=""
hdu_index: int=0
demo_filename : str=""
demo_file_path: str=""
ra_column: str=""
dec_column: str=""
update_time: str=""
create_time: str=""
import_status: int = 0
def filter_table_name(data_type):
return '_'.join(data_type.split('-'))
...@@ -6,6 +6,7 @@ from astropy.io import fits ...@@ -6,6 +6,7 @@ from astropy.io import fits
from astropy import wcs from astropy import wcs
import numpy as np import numpy as np
import healpy as hp import healpy as hp
from csst_dfs_commons.models.constants import PI, DEFAULT_NSIDE
def get_header_value(key: str, headers, default_value = None): def get_header_value(key: str, headers, default_value = None):
try: try:
...@@ -74,3 +75,34 @@ def hdul_of_healpix_ids(hdulist, nside=256): ...@@ -74,3 +75,34 @@ def hdul_of_healpix_ids(hdulist, nside=256):
healpixids = hp.query_polygon(nside, xyzpoly.T) healpixids = hp.query_polygon(nside, xyzpoly.T)
return healpixids return healpixids
def heapix_sql_condition(ra, dec, radius, ra_col = 'ra', dec_col = 'dec', nside = DEFAULT_NSIDE):
arcDec = (PI / 180) * dec
whereSql = f"abs((180./{PI}) * ACOS(SIN({PI} * {dec_col}/180) * SIN({arcDec}) + COS({PI} * {dec_col}/180) * COS({arcDec}) * COS(({PI}/180) * ({ra_col} - {ra})))) < {radius}"
heapix_ids = get_healpix_ids(ra, dec, radius, nside)
nside_column = "NS%dHIdx" % (nside,)
whereZoneSql = "%s in (%s)" % \
(nside_column, ','.join([str(i) for i in heapix_ids]))
return whereZoneSql, whereSql
def level2_heapix_sql_condition(ra, dec, radius, ra_col = 'ra', dec_col = 'dec', nside = DEFAULT_NSIDE):
x2 = f"cos({dec_col})*cos({ra_col})"
y2 = f"cos({dec_col})*sin({ra_col})"
z2 = f"sin({dec_col})"
x1 = f"cos({dec})*cos({ra})"
y1 = f"cos({dec})*sin({ra})"
z1 = f"sin({dec})"
distance = f"pow(({x2}-{x1}),2)+pow(({y2}-{y1}),2)+pow(({z2}-{z1}),2)"
heapix_ids = get_healpix_ids(ra, dec, radius, nside)
nside_column = "brick_id"
whereZoneSql = "%s in (%s)" % \
(nside_column, ','.join([str(i) for i in heapix_ids]))
whereSql = f"{distance} <= 4*pow({radius}/2, 2) and {whereZoneSql}"
return whereSql
\ No newline at end of file
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