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

adapt for input pmapname

parent 4a969a95
Pipeline #8873 passed with stage
...@@ -16,16 +16,21 @@ from .slsconf import convert_slsconf ...@@ -16,16 +16,21 @@ from .slsconf import convert_slsconf
class CCDS: class CCDS:
def __init__(self, ccds_root="/ccds_root", ccds_cache="/pipeline/ccds_cache"): def __init__(
print("Setting CCDS root path ... ", end="") self,
ccds_root="/ccds_root",
ccds_cache="/pipeline/ccds_cache",
pmapname=None,
):
print("[CCDS] Setting CCDS root path ... ", end="")
self.ccds_root = ccds_root self.ccds_root = ccds_root
print(self.ccds_root) print(self.ccds_root)
print("Setting CCDS cache path ... ", end="") print("[CCDS] Setting CCDS cache path ... ", end="")
self.ccds_cache = ccds_cache self.ccds_cache = ccds_cache
print(self.ccds_cache) print(self.ccds_cache)
print("Setting CCDS environment variables ... ", end="") print("[CCDS] Setting CCDS environment variables ... ", end="")
os.environ["CCDS_MODE"] = "remote" os.environ["CCDS_MODE"] = "remote"
os.environ["CCDS_PATH"] = ccds_cache os.environ["CCDS_PATH"] = ccds_cache
os.environ["CCDS_OBSERVATORY"] = "csst" os.environ["CCDS_OBSERVATORY"] = "csst"
...@@ -36,24 +41,26 @@ class CCDS: ...@@ -36,24 +41,26 @@ class CCDS:
print(self.observatory) print(self.observatory)
assert ( assert (
self.observatory == "csst" self.observatory == "csst"
), f"observatory [{self.observatory}] is not csst!" ), f"observatory [{self.observatory}] is not `csst`!"
print("Query for operational_context ... ", end="") self.operational_context = client.get_default_context(self.observatory)
print(f"[CCDS] Query for operational_context = {self.operational_context}... ")
self.pmapname = pmapname if pmapname is not None else self.operational_context
print(f"[CCDS] Setting pmapname = {self.pmapname}... ")
try: try:
self.operational_context = client.get_default_context(self.observatory)
# dump mappings # dump mappings
client.dump_mappings(self.operational_context) client.dump_mappings(self.pmapname)
self.is_available = True self.is_available = True
except BaseException as e: except BaseException as e:
print("CCDS access failed! ", e.args) print(f"[CCDS] Failed to get pmapname={self.pmapname}:", e.args)
self.operational_context = ""
self.is_available = False self.is_available = False
print(self.operational_context)
# assert self.operational_context != "", f"operational_context [{self.operational_context}] is empty!" print(f"[CCDS] operational_context = {self.operational_context}")
print(f"[CCDS] pmapname = {self.pmapname}")
def __repr__(self): def __repr__(self):
return ( return (
f"< CCDS url='{os.getenv('CCDS_SERVER_URL', default='')}' >\n" f"[CCDS] url='{os.getenv('CCDS_SERVER_URL', default='')}' >\n"
f" - is_available={self.is_available}\n" f" - is_available={self.is_available}\n"
f" - observatory='{self.observatory}'\n" f" - observatory='{self.observatory}'\n"
f" - operational_context='{self.operational_context}'\n" f" - operational_context='{self.operational_context}'\n"
...@@ -67,7 +74,7 @@ class CCDS: ...@@ -67,7 +74,7 @@ class CCDS:
): ):
# print("get min header") # print("get min header")
hdrs = client.api.get_minimum_header( hdrs = client.api.get_minimum_header(
self.operational_context, file_path, ignore_cache=False self.pmapname, file_path, ignore_cache=False
) )
# {'CAMERA': 'MS', # {'CAMERA': 'MS',
# 'CHIPID': '10', # 'CHIPID': '10',
...@@ -76,7 +83,7 @@ class CCDS: ...@@ -76,7 +83,7 @@ class CCDS:
# 'INSTRUME': 'MSC', # 'INSTRUME': 'MSC',
# 'REFTYPE': 'UNDEFINED'} # 'REFTYPE': 'UNDEFINED'}
# print("get best ref") # print("get best ref")
refs = client.api.get_best_references(self.operational_context, hdrs) refs = client.api.get_best_references(self.pmapname, hdrs)
# {'bias': 'csst_msc_ms_bias_10_000001.fits', # {'bias': 'csst_msc_ms_bias_10_000001.fits',
# 'dark': 'csst_msc_ms_dark_10_000001.fits', # 'dark': 'csst_msc_ms_dark_10_000001.fits',
# 'ledflat': 'csst_msc_ms_ledflat_10_000001.fits', # 'ledflat': 'csst_msc_ms_ledflat_10_000001.fits',
...@@ -86,7 +93,7 @@ class CCDS: ...@@ -86,7 +93,7 @@ class CCDS:
# print("get file info") # print("get file info")
refs_fp = dict() refs_fp = dict()
for ref_type in refs.keys(): for ref_type in refs.keys():
d = client.api.get_file_info(self.operational_context, refs[ref_type]) d = client.api.get_file_info(self.pmapname, refs[ref_type])
if d: if d:
fp = os.path.join(self.ccds_root, d["file_path"]) fp = os.path.join(self.ccds_root, d["file_path"])
assert os.path.exists(fp), f"File path [{fp}] does not exist!" assert os.path.exists(fp), f"File path [{fp}] does not exist!"
......
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