From 197e0914877e2dec355e3431c0c91525fa6e4bed Mon Sep 17 00:00:00 2001 From: shoulinwei Date: Fri, 8 Dec 2023 23:09:08 +0800 Subject: [PATCH] fix deps and version --- README.md | 2 +- csst_dfs_commons/convert/date_utils.py | 5 ++- csst_dfs_commons/models/facility.py | 14 +++++++ csst_dfs_commons/models/level2.py | 40 ++++++++++++++++++ csst_dfs_commons/utils/fits.py | 32 ++++++++++++++ csst_dfs_commons/version.py | 1 + requirements.txt | 10 +++-- setup.cfg | 26 ++++++------ setup.py | 58 +++++++++++++++++++++++++- 9 files changed, 170 insertions(+), 18 deletions(-) create mode 100644 csst_dfs_commons/models/level2.py create mode 100644 csst_dfs_commons/version.py diff --git a/README.md b/README.md index 5ccdaa2..329b695 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Introduction -This package provides basic common library for CSST. +This package provides common library for DFS of CSST. ## Installation diff --git a/csst_dfs_commons/convert/date_utils.py b/csst_dfs_commons/convert/date_utils.py index 13872df..03a1d71 100644 --- a/csst_dfs_commons/convert/date_utils.py +++ b/csst_dfs_commons/convert/date_utils.py @@ -17,4 +17,7 @@ def format_time_ms(float_time): local_time = time.localtime(float_time) data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time) data_secs = (float_time - int(float_time)) * 1000 - return "%s.%03d" % (data_head, data_secs) \ No newline at end of file + 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 diff --git a/csst_dfs_commons/models/facility.py b/csst_dfs_commons/models/facility.py index a22b20e..b5bbf24 100644 --- a/csst_dfs_commons/models/facility.py +++ b/csst_dfs_commons/models/facility.py @@ -2,6 +2,20 @@ 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 diff --git a/csst_dfs_commons/models/level2.py b/csst_dfs_commons/models/level2.py new file mode 100644 index 0000000..bc2c635 --- /dev/null +++ b/csst_dfs_commons/models/level2.py @@ -0,0 +1,40 @@ +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('-')) + diff --git a/csst_dfs_commons/utils/fits.py b/csst_dfs_commons/utils/fits.py index fe73442..c64eb43 100644 --- a/csst_dfs_commons/utils/fits.py +++ b/csst_dfs_commons/utils/fits.py @@ -6,6 +6,7 @@ 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): try: @@ -74,3 +75,34 @@ def hdul_of_healpix_ids(hdulist, nside=256): 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}" + + 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 diff --git a/csst_dfs_commons/version.py b/csst_dfs_commons/version.py new file mode 100644 index 0000000..d538f87 --- /dev/null +++ b/csst_dfs_commons/version.py @@ -0,0 +1 @@ +__version__ = "1.0.0" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index d29e67e..86c0769 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,7 @@ -astropy -astropy_healpix -healpy \ No newline at end of file +# base +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 diff --git a/setup.cfg b/setup.cfg index 5405d77..f0bfd90 100644 --- a/setup.cfg +++ b/setup.cfg @@ -7,16 +7,18 @@ description = CSST Commons Module. long_description = file: README.md long_description_content_type = text/markdown keywords = astronomy, astrophysics, cosmology, space, CSST -url = https://github.com/astronomical-data-processing/csst-dfs-commons -project_urls = - Bug Tracker = https://github.com/astronomical-data-processing/csst-dfs-commons/issues -classifiers = - Programming Language :: Python :: 3 - License :: OSI Approved :: MIT License - Operating System :: OS Independent +url = https://csst-tb.bao.ac.cn/code/csst-dfs/csst-dfs-commons -[options] -packages = find: -python_requires = >=3.7 -zip_safe = False -setup_requires = setuptools_scm \ No newline at end of file +[bumpver] +current_version = "1.0.0" +version_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]" +commit_message = "Release {new_version}" +commit = True +tag = True +push = True + +[bumpver:file_patterns] +setup.cfg = + current_version = "{version}" +csst_dfs_commons/version.py = + __version__ = "{version}" \ No newline at end of file diff --git a/setup.py b/setup.py index 53f4d29..9204c78 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,61 @@ # coding: utf-8 import os from setuptools import setup +setup_pars = { + "packages" : [ + 'csst_dfs_commons', + 'csst_dfs_commons.convert', + 'csst_dfs_commons.logging', + 'csst_dfs_commons.models', + 'csst_dfs_commons.utils', + ], + "package_dir" : { + 'csst_dfs_commons' : 'csst_dfs_commons', + 'csst_dfs_commons.convert' : 'csst_dfs_commons/convert', + 'csst_dfs_commons.logging' : 'csst_dfs_commons/logging', + 'csst_dfs_commons.models' : 'csst_dfs_commons/models', + 'csst_dfs_commons.utils' : 'csst_dfs_commons/utils', + }, +} + +def requirements(): + with open("requirements.txt", "r") as f: + return [ + req.strip() + for req in f.readlines() + if not req.startswith("#") and req.__contains__("==") + ] + +def version(): + __version = {} + version_path = os.path.join(os.path.dirname(__file__), "csst_dfs_commons", "version.py") + with open(version_path, "r") as file: + exec(file.read(), __version) + return __version["__version__"] + +setup( + name="csst_dfs_commons", + version=version(), + description="common library for CSST Data Flow System (DFS)", + long_description=open('README.md').read(), + license="MIT", + python_requires=">=3.7", + install_requires=requirements(), + zip_safe=False, + classifiers=[ + "Development Status :: 4 - Beta", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3", + "Topic :: Scientific/Engineering :: Physics", + "Topic :: Scientific/Engineering :: Astronomy", + + ], + include_package_data=False, + project_urls={ + 'Source': 'https://csst-tb.bao.ac.cn/code/csst-dfs/csst-dfs-api-local', + }, + **setup_pars +) -setup(use_scm_version={'write_to': os.path.join('csst_dfs_commons', '_version.py')}) -- GitLab