Commit a64fbab9 authored by Wei Shoulin's avatar Wei Shoulin
Browse files

C9

parent f579d41e
......@@ -41,7 +41,7 @@ class Result(dict):
self[k] = v
return self
class Request(object):
class Request(dict):
def __init__(self, **kvargs):
super(Request, self).__init__()
for k, v in kvargs.items():
......@@ -54,12 +54,21 @@ class Request(object):
r.append(k, v)
return r
@staticmethod
def from_tuple(data: tuple, columns: tuple):
return Request.from_dict(dict(zip(columns, data)))
@staticmethod
def from_list(data: list, columns: tuple):
return [Request.from_tuple(rec, columns) for rec in data]
def append(self, k: str, v):
self.__setattr__(k, v)
self[k] = v
return self
def __getattr__(self, attr):
try:
return object.__getattribute__(self, attr)
except:
if attr in self.keys():
return self[attr]
return ''
Record = Request
\ No newline at end of file
......@@ -2,20 +2,6 @@ import dataclasses
from typing import List,Dict
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
class Observation(BaseModel):
id: int = 0
......@@ -42,6 +28,23 @@ class Detector(BaseModel):
create_time: str=""
update_time: str=""
@dataclasses.dataclass
class Pipeline(BaseModel):
pipeline_id: str = ""
pipeline_name: str = ""
module_id: str=""
level: int = 0
create_time: str=""
update_time: str=""
@dataclasses.dataclass
class FileType(BaseModel):
file_type_id: str = ""
file_type: str = ""
module_id: str=""
level: int = 0
create_time: str=""
update_time: str=""
@dataclasses.dataclass
class DetectorStatus(BaseModel):
......@@ -112,8 +115,7 @@ class Level0Record(BaseModel):
obs_id: str = ""
detector_no: str = ""
module_id: str = ""
filter: str=""
obs_type: str = ""
file_type: str = ""
obs_time: str=""
exp_time: float = 0
detector_status_id: int = 0
......@@ -129,19 +131,19 @@ class Level0Record(BaseModel):
@dataclasses.dataclass
class Level0PrcRecord(BaseModel):
id: int = 0
level0_id: str = ""
level0_id: int = ""
run_id: str = ""
pipeline_id: str = ""
prc_module: str = ""
params_file_path: str=""
prc_status: int = 0
prc_time: str=""
result_file_path: str=""
message: str=""
@dataclasses.dataclass
class Level1Record(BaseModel):
id: int = 0
level0_id : str = ""
data_type: str=""
file_type: str=""
cor_sci_id: int = 0
module_id: str = ""
prc_params: str=""
......@@ -164,12 +166,12 @@ class Level1Record(BaseModel):
class Level1PrcRecord(BaseModel):
id: int = 0
level1_id: int = 0
run_id: str = ""
pipeline_id: str = ""
prc_module: str = ""
params_file_path: str=""
prc_status: int = 0
prc_time: str=""
result_file_path: str=""
message: str=""
@dataclasses.dataclass
class OtherDataRecord(BaseModel):
......
import dataclasses
from typing import Optional
from .common import BaseModel
from datetime import datetime
@dataclasses.dataclass
class SysMenu(BaseModel):
menu_id: int = 0
menu_name: str = ''
title: str = ''
icon: str = ''
path: str = ''
paths: str = ''
menu_type: str = ''
action: str = ''
permission: str = ''
parent_id: int = 0
no_cache: bool = False
breadcrumb: str = ''
component: str = ''
sort: int = 0
visible: str = ''
is_frame: str = ''
create_by: int = 0
update_by: int = 0
created_at: str = ''
updated_at: str = ''
children: list = dataclasses.field(default_factory=list)
@dataclasses.dataclass
class SysRole(BaseModel):
role_id: int = 0
role_name: str = ''
status: str = ''
role_key: str = ''
role_sort: int = 0
flag: str = ''
remark: str = ''
admin: bool = False
data_scope: str = ''
create_by: int = 0
update_by: int = 0
created_at: str = ''
updated_at: str = ''
menuIds: list[int] = dataclasses.field(default_factory=list)
menus: list[SysMenu] = dataclasses.field(default_factory=list)
@dataclasses.dataclass
class SysUser(BaseModel):
user_id: int = 0
username: str = ''
truename: str = ''
password: str = ''
mobile: str = ''
role_id: int = 0
salt: str = ''
instrument: str = ''
avatar: str = ''
gender: str = ''
email: str = ''
remark: str = ''
status: str = ''
last_login_ip: str = ''
last_login_time: str = ''
create_by: int = 0
update_by: int = 0
created_at: str = ''
updated_at: str = ''
role: SysRole = None
@dataclasses.dataclass
class SysConfig(BaseModel):
config_id: int = 0
config_name: str = ''
config_key: str = ''
config_value: str = ''
config_type: str = ''
is_frontend: str = ''
remark: str = ''
create_by: int = 0
update_by: int = 0
created_at: str = ''
updated_at: str = ''
@dataclasses.dataclass
class SysDictData(BaseModel):
dict_code: int = 0
dict_sort: int = 0
dict_label: str = ''
dict_value: str = ''
dict_type: str = ''
css_class: str = ''
list_class: str = ''
is_default: str = ''
status: int = 0
remark: str = ''
create_by: int = 0
update_by: int = 0
created_at: str = ''
updated_at: str = ''
@dataclasses.dataclass
class SysDictType(BaseModel):
dict_id: int = 0
dict_name: str = ''
dict_type: str = ''
status: int = 0
remark: str = ''
create_by: int = 0
update_by: int = 0
created_at: str = ''
updated_at: str = ''
@dataclasses.dataclass
class ProcessMessage(BaseModel):
msg_id: str = ''
pipeline_id: str = ''
msg_body: str = ''
\ No newline at end of file
from astropy_healpix import HEALPix
from astropy.coordinates import ICRS
from astropy import units as u
from astropy.coordinates import SkyCoord, spherical_to_cartesian
from astropy.coordinates import SkyCoord
from astropy.io import fits
from astropy import wcs
import numpy as np
import healpy as hp
from csst_dfs_commons.models.constants import PI, DEFAULT_NSIDE
def get_header_value(key: str, headers, default_value = None):
......@@ -49,33 +47,6 @@ def get_raw_header(filepath, **keys):
union[key]= value
return union
def fits_of_healpix_ids(filepath, nside=256):
""" Get healpix ids for the fits file
:param filepath: the file path of fits
:param nside: default 128, approximate resolution at NSIDE 1024 is 0.057 deg, 12582912 bricks
:return: a numpy.ndarray (n,)
"""
with fits.open(filepath) as hdulist:
return hdul_of_healpix_ids(hdulist, nside)
def hdul_of_healpix_ids(hdulist, nside=256):
nx = get_header_value('NAXIS1', hdulist, 0)
ny = get_header_value('NAXIS2', hdulist, 0)
fits_wcs = wcs.WCS(hdulist[1])
ra0, dec0 = fits_wcs.all_pix2world(0, 0, 1)
ra0, dec1 = fits_wcs.all_pix2world(0, ny, 1)
ra1, dec0 = fits_wcs.all_pix2world(nx, 0, 1)
ra1, dec1 = fits_wcs.all_pix2world(nx, ny, 1)
ra_poly, dec_poly = np.array([[ra0, ra0, ra1, ra1], [dec0, dec1, dec0, dec1]])
xyzpoly = spherical_to_cartesian(np.deg2rad(ra_poly), np.deg2rad(dec_poly), 1)
xyzpoly = tuple(map(tuple, xyzpoly))
xyzpoly = np.array(xyzpoly).reshape(-1, 3)
healpixids = hp.query_polygon(nside, xyzpoly.T)
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}"
......@@ -87,6 +58,25 @@ def heapix_sql_condition(ra, dec, radius, ra_col = 'ra', dec_col = 'dec', nside
return whereZoneSql, whereSql
def catalog_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 = "NS%dHIdx" % (nside,)
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
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})"
......
......@@ -2,6 +2,5 @@
astropy==5.3.4
pandas==2.0.3
numpy==1.26.1
healpy==1.16.6
# specific
astropy_healpix==1.0.1
\ 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