Skip to content

Commit 394f403

Browse files
authored
End2end rid lut manager (#390)
* bump all product versions to 2 * add copy and parent option * fix missing init of singleton
1 parent 9fd6fc7 commit 394f403

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

stixcore/processing/find.py

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import sys
2+
import shutil
23
import logging
34
import argparse
45
from pathlib import Path
56

7+
import astropy.units as u
68
from astropy.io import fits
79

810
from stixcore.config.config import CONFIG
11+
from stixcore.products.product import Product
912
from stixcore.time.datetime import SCETime
1013
from stixcore.util.logging import get_logger
1114

@@ -62,11 +65,24 @@ def find_fits(args):
6265
choices=["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "NOTSET"],
6366
dest='log_level')
6467

68+
parser.add_argument("-c", "--copy",
69+
help="copy the found files into that dir", type=str,
70+
default=None, dest='copy_dest')
71+
72+
parser.add_argument("--parents",
73+
help="return the parents and not the fits itself",
74+
default=False,
75+
action='store_true', dest='get_parents')
76+
6577
args = parser.parse_args(args)
6678

6779
if args.log_level:
6880
logger.setLevel(logging.getLevelName(args.log_level))
6981

82+
if args.copy_dest:
83+
args.copy_dest = Path(args.copy_dest)
84+
args.copy_dest.mkdir(parents=True, exist_ok=True)
85+
7086
fits_dir = Path(args.fits_dir)
7187

7288
include_levels = dict([(level, 1) for level in
@@ -132,22 +148,36 @@ def find_fits(args):
132148
continue
133149

134150
# prod = Product(c)
135-
obt_beg = SCETime.from_string(fits.getval(c, 'OBT_BEG'))
136-
obt_end = SCETime.from_string(fits.getval(c, 'OBT_END'))
137-
138-
# obt filter overlapping
139-
if not ((obt_beg >= args.start_obt and obt_end <= args.end_obt) or
140-
(obt_beg >= args.start_obt and args.end_obt < obt_end) or
141-
(obt_beg < args.start_obt and obt_end > args.start_obt)):
151+
try:
152+
f_beg = SCETime.from_string(fits.getval(c, 'OBT_BEG'))[0]
153+
f_end = SCETime.from_string(fits.getval(c, 'OBT_END'))[0]
154+
except Exception:
155+
f_beg = SCETime.from_float(fits.getval(c, 'OBT_BEG') * u.s)
156+
f_end = SCETime.from_float(fits.getval(c, 'OBT_END') * u.s)
157+
158+
# obt filter included
159+
if not ((f_beg >= args.start_obt and f_end <= args.end_obt)):
160+
# should also overlap?
161+
# or (f_beg > args.start_obt and f_beg < args.end_obt) or
162+
# (f_end > args.start_obt and f_end < args.end_obt)):
142163
continue
164+
if args.get_parents:
165+
p = Product(c)
166+
found.extend(p.find_parent_files(fits_dir))
143167

144-
found.append(c)
168+
else:
169+
found.append(c)
145170

146171
logger.info(f'#candidates: {n_candidates}')
147172
logger.info(f'#found: {len(found)}')
148173

149174
for f in found:
150175
print(str(f))
176+
if args.copy_dest:
177+
fits_parent_path = f.relative_to(fits_dir)
178+
target = args.copy_dest / fits_parent_path
179+
target.parent.mkdir(parents=True, exist_ok=True)
180+
shutil.copy2(f, target)
151181

152182
return found
153183

stixcore/util/scripts/end2end_testing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from stixcore.data.test import test_data
1111
from stixcore.ephemeris.manager import Spice, SpiceKernelManager
1212
from stixcore.idb.manager import IDBManager
13+
from stixcore.io.RidLutManager import RidLutManager
1314
from stixcore.io.soc.manager import SOCManager
1415
from stixcore.processing.L0toL1 import Level1
1516
from stixcore.processing.LBtoL0 import Level0
@@ -145,6 +146,8 @@ def end2end_pipeline(indir, fitsdir):
145146
idbpath = Path(__file__).parent.parent.parent / "data" / "idb"
146147
IDBManager.instance = IDBManager(idbpath) # force_version="2.26.35")
147148

149+
RidLutManager.instance = RidLutManager(Path(CONFIG.get('Publish', 'rid_lut_file')), update=True)
150+
148151
PipelineStatus.log_setup()
149152

150153
soc = SOCManager(indir)

0 commit comments

Comments
 (0)