Commit b4bd79b5 authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

major update: use triggers instead of rules

parent 618219c3
[csst-hstdm-l1]
obsid = [
"501", #
"502", #
"503", #
"504" #
]
chipid = [
"01", "02"
]
projid=[
"501"# not yet determined
]
[csst-msc-l1-mbi]
obsid = [
"101", #
"102", #
"103", #
"104", #
"105", #
"106", #
# "107", #
# "108", #
# "109", #
"110", #
"111", #
"112", #
# "113", #
# "114", #
# "115", #
# "116", #
# "117", #
# "118", #
# "119", #
# "120", #
# "121", #
# "122", #
# "123", #
# "124", #
# "125", #
# "126", #
# "127", #
# "128", #
# "129", #
# "130", #
# "131", #
# "132", #
]
chipid = [
"06", "07", "08", "09",
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
"22", "23", "24", "25"
]
[csst-msc-l1-ast]
obsid = [
"101", #
"102", #
"103", #
"104", #
"105", #
"106", #
# "107", #
# "108", #
# "109", #
"110", #
"111", #
"112", #
# "113", #
# "114", #
# "115", #
# "116", #
# "117", #
# "118", #
# "119", #
# "120", #
# "121", #
# "122", #
# "123", #
# "124", #
# "125", #
# "126", #
# "127", #
# "128", #
# "129", #
# "130", #
# "131", #
# "132", #
]
chipid = [
"06", "07", "08", "09",
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
"22", "23", "24", "25"
]
[csst-msc-l1-sls]
obsid = [
"101", #
"102", #
"103", #
"104", #
"105", #
"106", #
# "107", #
# "108", #
# "109", #
"110", #
"111", #
"112", #
# "113", #
# "114", #
# "115", #
# "116", #
# "117", #
# "118", #
# "119", #
# "120", #
# "121", #
# "122", #
# "123", #
# "124", #
# "125", #
# "126", #
# "127", #
# "128", #
# "129", #
# "130", #
# "131", #
# "132", #
]
chipid = [ "01", "02", "03", "04", "05", "10", "21", "26", "27", "28", "29", "30"]
["csst-msc-l1-qc0"]
obsid = [
# "101", #
# "102", #
# "103", #
# "104", #
# "105", #
# "106", #
# "107", #
# "108", #
# "109", #
# "110", #
# "111", #
# "112", #
# "113", #
# "114", #
# "115", #
# "116", #
# "117", #
# "118", #
# "119", #
"120", #
"121", #
"122", #
"123", #
"124", #
"125", #
"126", #
"127", #
"128", #
"129", #
# "130", #
# "131", #
# "132", #
]
chipid = [
"01", "02", "03", "04", "05", "06", "07", "08", "09", "10",
"11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
"21", "22", "23", "24", "25", "26", "27", "28", "29", "30",
]
......@@ -2,24 +2,41 @@ import redis
import toml
import os
redis_config_path = os.path.join(os.path.dirname(__file__), "redis_config.toml")
REDIS_CONFIG = toml.load(redis_config_path)
CONFIG = toml.load(os.path.join(os.path.dirname(__file__), "config", "config.toml"))
class DFS:
def __init__(self, location="naoc"):
if location not in CONFIG.keys():
print("Available DFS locations: ", list(CONFIG.keys()))
raise ValueError(f"Unknown dfs location: {location}")
self.location = location
self.config = CONFIG[location]
print("Setting DFS config:")
for k, v in self.config["dfs"].items():
if k not in os.environ.keys():
os.environ.setdefault(k, str(v))
print(f" - Set {k}: {v}")
else:
print(f" - {k}: {os.environ[k]}")
self.redis = Redis(location)
class Redis(redis.Redis):
def __init__(self, location="naoc"):
if location not in REDIS_CONFIG.keys():
print("Available redis locations: ", list(REDIS_CONFIG.keys()))
if location not in CONFIG.keys():
print("Available redis locations: ", list(CONFIG.keys()))
raise ValueError(f"Unknown redis location: {location}")
super().__init__(
host=REDIS_CONFIG[location]["host"],
port=REDIS_CONFIG[location]["port"],
db=REDIS_CONFIG[location]["db"],
password=REDIS_CONFIG[location]["password"],
host=CONFIG[location]["redis"]["host"],
port=CONFIG[location]["redis"]["port"],
db=CONFIG[location]["redis"]["db"],
password=CONFIG[location]["redis"]["password"],
)
self.qname = password = REDIS_CONFIG[location]["qname"]
self.config = REDIS_CONFIG[location]
self.qname = password = CONFIG[location]["redis"]["qname"]
self.config = CONFIG[location]["redis"]
print("Setting redis config:")
for k, v in self.config.items():
......
from astropy import time
import numpy as np
import string
def gen_dag_run_id(digits=6):
"""
Generate a unique run_id for a dag.
"""
now = time.Time.now()
dag_run_id = now.strftime("%Y%m%d-%H%M%S-")
n = len(string.ascii_lowercase)
for i in range(digits):
dag_run_id += string.ascii_lowercase[np.random.randint(low=0, high=n)]
return dag_run_id
from csst_dag.constants import MSC_MBI_CHIPID
from csst_dfs_client import plan, level0
# python -m csst_dag.trigger.csst-msc-l1-mbi
result = plan.write_file("csst-msc-c9-50sqdeg-v3-plan/pointing_50_all.json")
print(result)
obs_type = "WIDE"
project_id = "None"
print(__file__)
[build-system]
requires = ["setuptools>=68.0", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "csst_dag"
version = "0.0.1"
authors = [
{name = "Bo Zhang", email = "bozhang@nao.cas.cn"}
]
description = "CSST DAG"
readme = { file = "README.md", content-type = "text/markdown" }
requires-python = ">=3.11"
license = {text = "MIT"}
keywords = ["astronomy", "scientific", "physics"]
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering :: Physics",
"Topic :: Scientific/Engineering :: Astronomy"
]
dependencies = [
# 需手动将requirements.txt中的依赖按以下格式转换:
"astropy",
"numpy",
"redis",
"toml",
"csst-dfs-client@git+https://csst-tb.bao.ac.cn/code/csst-dfs/csst-dfs-client.git",
]
[project.urls]
homepage = "https://csst-tb.bao.ac.cn/code/csst-cicd/csst-dag"
[tool.setuptools]
# 自动发现 Python 包
packages = {find = {where = ["."]}}
include-package-data = true
[tool.setuptools.package-data]
csst_dag = [
"constants/*",
"dag/*",
"config/*"
]
\ No newline at end of file
from csst_dag.dag import CSST_DAG_LIST
dag = CSST_DAG_LIST[0]
print(dag)
dag.pprint()
dag.match(obsid="11009101682009", chipid="01")
dag.match(obsid="10109101682009", chipid="12")
assert CSST_DAG_LIST.match(obsid="11009101682009", chipid="01") == ["csst-msc-l1-sls"]
assert CSST_DAG_LIST.match(obsid="11009101682009", chipid="12") == [
"csst-msc-l1-mbi",
"csst-msc-l1-ast",
]
assert CSST_DAG_LIST.match(obsid="12009101682009", chipid="09") == ["csst-msc-l1-qc0"]
assert CSST_DAG_LIST.match(obsid="12009101682009", chipid="00") == []
assert CSST_DAG_LIST.match(a=1) == []
dags = CSST_DAG_LIST.match_dag(obsid="11009101682009", chipid="01")
dag = dags[0]
dag.gen_message(obsid="11009101682009", chipid="01")
import pytest
from csst_dag import gen_level1_dag_message
def test_gen_level1_dag_message_msc_sls():
msg = gen_level1_dag_message(obsid="11009101682009", chipid="01", return_dict=True)
assert msg["dag_id"] == "csst-msc-l1-sls"
def test_gen_level1_dag_message_msc_mbi():
msg = gen_level1_dag_message(obsid="11009101682009", chipid="09", return_dict=True)
assert msg["dag_id"] == "csst-msc-l1-mbi"
def test_gen_level1_dag_message_msc_invalid_chipid():
with pytest.raises(ValueError):
msg = gen_level1_dag_message(
obsid="11009101682009", chipid="00", return_dict=True
)
def test_gen_level1_dag_message_msc_none():
msg = gen_level1_dag_message(obsid="12009101682009", chipid="00", return_dict=True)
assert msg is None
from csst_dag.dfs import DFS
def test_dfs_naoc():
dfs = DFS(location="naoc")
print(dfs.config)
assert len(dfs.redis.get_all()) == 0
from csst_dag.redis import Redis
def test_redis_naoc():
r = Redis(location="naoc")
print(r)
assert len(r.get_all()) == 0
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