Commit 7a6611cb authored by BO ZHANG's avatar BO ZHANG 🏀
Browse files

added dm.query_rc()

parent 8017aa6f
...@@ -9,16 +9,19 @@ Modified-History: ...@@ -9,16 +9,19 @@ Modified-History:
2022-09-13, Bo Zhang, added CsstMbiDataManager 2022-09-13, Bo Zhang, added CsstMbiDataManager
2022-09-29, Bo Zhang, favor CsstMsDataManager instead of CsstMbiDataManager 2022-09-29, Bo Zhang, favor CsstMsDataManager instead of CsstMbiDataManager
2022-10-26, Bo Zhang, reconstruct CsstMsDataManager, deprecate CsstMbiDataManager 2022-10-26, Bo Zhang, reconstruct CsstMsDataManager, deprecate CsstMbiDataManager
2022-10-28, Bo Zhang, added CsstMsDataManager.query_rc(), dm.dfs_mode, dm.node
""" """
import os
import glob import glob
import os
import re import re
from typing import Union
from astropy.io import fits from astropy.io import fits
from astropy.table import Table from astropy.table import Table
from typing import Union, Tuple
from .dfs import gaia_query_from_dfs
from .params import CSST_PARAMS as CP from .params import CSST_PARAMS as CP
from .params import DFS_CONF
class CsstMsDataManager: class CsstMsDataManager:
...@@ -66,6 +69,9 @@ class CsstMsDataManager: ...@@ -66,6 +69,9 @@ class CsstMsDataManager:
The aux data directory (bias, flat, dark). The aux data directory (bias, flat, dark).
dfs_mode : bool dfs_mode : bool
DFS mode. If True, ``CsstMsDataManager`` will use DFS. DFS mode. If True, ``CsstMsDataManager`` will use DFS.
node : str
The environment in which the pipeline will run.
Use "pml" for Purple Mountain Lab cluster and "local" for others.
_exp_id : int _exp_id : int
The exposure ID. The exposure ID.
_exp_start : int _exp_start : int
...@@ -113,6 +119,7 @@ class CsstMsDataManager: ...@@ -113,6 +119,7 @@ class CsstMsDataManager:
dir_l1: str = ".", dir_l1: str = ".",
path_aux: str = "", # bias dark flat path_aux: str = "", # bias dark flat
dfs_mode: bool = False, dfs_mode: bool = False,
node: str = "local",
_exp_id: int = 100000100, _exp_id: int = 100000100,
_exp_start: int = 20270810081950, _exp_start: int = 20270810081950,
_exp_stop: int = 20270810082220, _exp_stop: int = 20270810082220,
...@@ -160,7 +167,14 @@ class CsstMsDataManager: ...@@ -160,7 +167,14 @@ class CsstMsDataManager:
self._survey = _survey self._survey = _survey
self._imagetype = _imagetype self._imagetype = _imagetype
self._l0_post = _l0_post self._l0_post = _l0_post
# for catalog query
self.dfs_mode = dfs_mode self.dfs_mode = dfs_mode
# for DFS configuration, defaults to "local", could be "pml"
assert node in DFS_CONF.keys()
self.node = node
for k, v in DFS_CONF[node]:
os.putenv(k, v)
# data directory # data directory
self.dir_l0 = dir_l0 self.dir_l0 = dir_l0
...@@ -175,7 +189,7 @@ class CsstMsDataManager: ...@@ -175,7 +189,7 @@ class CsstMsDataManager:
raise NotImplementedError("from_dfs is currently not available!") raise NotImplementedError("from_dfs is currently not available!")
@staticmethod @staticmethod
def from_dir(ver_sim="C5.2", datatype="mbi", dir_l0=".", dir_l1=".", dir_pcref="", path_aux="", dfs_mode=False): def from_dir(ver_sim="C5.2", datatype="mbi", dir_l0=".", dir_l1=".", path_aux="", dfs_mode=False, node="local"):
""" initialize the multi-band imaging data manager """ """ initialize the multi-band imaging data manager """
assert ver_sim in ["C5.2", ] assert ver_sim in ["C5.2", ]
...@@ -206,6 +220,7 @@ class CsstMsDataManager: ...@@ -206,6 +220,7 @@ class CsstMsDataManager:
dir_l1=dir_l1, dir_l1=dir_l1,
path_aux=path_aux, # bias dark flat path_aux=path_aux, # bias dark flat
dfs_mode=dfs_mode, dfs_mode=dfs_mode,
node=node,
_exp_id=_exp_id, _exp_id=_exp_id,
_exp_start=_exp_start, _exp_start=_exp_start,
_exp_stop=_exp_stop, _exp_stop=_exp_stop,
...@@ -362,23 +377,23 @@ class CsstMsDataManager: ...@@ -362,23 +377,23 @@ class CsstMsDataManager:
def get_sls_info(self): def get_sls_info(self):
""" Get the target SLS image header info and return. """ """ Get the target SLS image header info and return. """
if self.dfs_mode: # if self.dfs_mode:
raise NotImplementedError() # raise NotImplementedError()
else: # else:
assert len(self.target_detectors) == 1 assert len(self.target_detectors) == 1
header = fits.getheader(self.l0_detector(self.target_detectors[0]), ext=1) header = fits.getheader(self.l0_detector(self.target_detectors[0]), ext=1)
return header return header
def get_mbi_info(self): def get_mbi_info(self):
""" Get all MBI image header info and return as a table. """ """ Get all MBI image header info and return as a table. """
if self.dfs_mode: # if self.dfs_mode:
raise NotImplementedError() # raise NotImplementedError()
else: # else:
info = Table.read("/nfsdata/share/csst_simulation_data/Cycle-5-SimuData/slitlessSpectroscopy/t_mbi_l1.fits") info = Table.read("/nfsdata/share/csst_simulation_data/Cycle-5-SimuData/slitlessSpectroscopy/t_mbi_l1.fits")
return info return info
@staticmethod @staticmethod
def quickstart(ver_sim="C5.2", datatype="mbi", dir_l1=".", exposure_id=100, dfs_mode=False): def quickstart(ver_sim="C5.2", datatype="mbi", dir_l1=".", exposure_id=100, dfs_mode=False, node="local"):
"""Quick dataset generator for tests on dandelion or PMO """Quick dataset generator for tests on dandelion or PMO
Parameters Parameters
...@@ -393,6 +408,8 @@ class CsstMsDataManager: ...@@ -393,6 +408,8 @@ class CsstMsDataManager:
The serial number of the exposure. 20-154 for C5.2. The serial number of the exposure. 20-154 for C5.2.
dfs_mode : bool dfs_mode : bool
If True, use DFS. If True, use DFS.
node : str
The node in which this program runs. Defaults to "local", could be "pml".
Returns Returns
------- -------
...@@ -428,7 +445,18 @@ class CsstMsDataManager: ...@@ -428,7 +445,18 @@ class CsstMsDataManager:
raise ValueError("@DM: invalid hostname {} or datatype {}!".format(hostname, datatype)) raise ValueError("@DM: invalid hostname {} or datatype {}!".format(hostname, datatype))
return CsstMsDataManager.from_dir( return CsstMsDataManager.from_dir(
ver_sim=ver_sim, datatype=datatype, dir_l0=dir_l0, dir_l1=dir_l1, path_aux=path_aux, dfs_mode=dfs_mode) ver_sim=ver_sim, datatype=datatype, dir_l0=dir_l0, dir_l1=dir_l1, path_aux=path_aux,
dfs_mode=dfs_mode, node=node)
def query_rc(self, ra=180, dec=0, radius=2, min_mag=0, max_mag=20, obstime=-1, limit=-1):
""" Query Reference Catalog (RC) from DFS """
try:
tbl = gaia_query_from_dfs(
ra=ra, dec=dec, radius=radius, min_mag=min_mag, max_mag=max_mag, obstime=obstime, limit=limit)
assert len(tbl) > 0
return tbl
except Exception as e:
return None
class CsstMbiDataManager: class CsstMbiDataManager:
......
...@@ -17,5 +17,3 @@ with open(PACKAGE_PATH + "/data/csst_params.yml") as f: ...@@ -17,5 +17,3 @@ with open(PACKAGE_PATH + "/data/csst_params.yml") as f:
with open(PACKAGE_PATH + "/data/dfs_conf.yml") as f: with open(PACKAGE_PATH + "/data/dfs_conf.yml") as f:
DFS_CONF = yaml.safe_load(f) DFS_CONF = yaml.safe_load(f)
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