Skip to content

Commit 99a0b61

Browse files
committed
preperation for merge and release
1 parent aa50fdb commit 99a0b61

19 files changed

Lines changed: 236 additions & 216 deletions

File tree

docs/code_ref/io.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ to certain directories.
66

77
.. automodapi:: stixcore.io
88

9-
.. automodapi:: stixcore.io.fits
10-
.. automodapi:: stixcore.io.fits.processors
9+
.. automodapi:: stixcore.io.product_processors.fits.processors
10+
.. automodapi:: stixcore.io.product_processors.plots.processors
1111

1212
.. automodapi:: stixcore.io.soc
1313
.. automodapi:: stixcore.io.soc.manager

processed.sqlite

-24 KB
Binary file not shown.

stixcore/io/FlareListManager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ def read_flarelist(self):
9595
"""
9696
if self.update or not self.file.exists():
9797
last_date = datetime(2020, 1, 1, 0, 0, 0)
98-
last_date = datetime(2025, 4, 12, 0, 0, 0)
99-
# only run flare detection for time oldet than 7 days
98+
# only run flare detection for time older than 7 days
10099
today = datetime.now() - timedelta(days=7)
101100
flare_df_lists = []
102101
if self.file.exists():
@@ -141,6 +140,7 @@ def read_flarelist(self):
141140
f"with {len(ql_lc_files)} lightcurve files and "
142141
f"{len(ql_bg_files)} background files"
143142
)
143+
# TODO re-enable flare-list creation
144144
# flares = stixpy.detect_flares(start, end,
145145
# ql_lc_files=ql_lc_files,
146146
# ql_bg_files=ql_bg_files)
File renamed without changes.

stixcore/io/fits/processors.py renamed to stixcore/io/product_processors/fits/processors.py

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
"""Module for the different processing levels."""
22

3-
from pathlib import Path
43
from datetime import datetime
54

65
import numpy as np
7-
from matplotlib import pyplot as plt
86

97
import astropy.units as u
108
from astropy.io import fits
@@ -27,7 +25,6 @@
2725
"FitsL0Processor",
2826
"FitsL1Processor",
2927
"FitsL2Processor",
30-
"PlotProcessor",
3128
]
3229

3330

@@ -1084,106 +1081,6 @@ def write_fits(self, prod, *, version=0):
10841081
return [filetowrite]
10851082

10861083

1087-
class PlotProcessor(FitsL2Processor):
1088-
"""A file product processor for plot images"""
1089-
1090-
def __init__(self, archive_path):
1091-
"""Creates a new PlotProcessor object.
1092-
1093-
Parameters
1094-
----------
1095-
archive_path : Path
1096-
the output root path where the files should be created
1097-
"""
1098-
super().__init__(archive_path)
1099-
1100-
def generate_filename(self, product, *, version=0, suffix=".svg"):
1101-
"""Generates a SOAR conform filename based on product characteristics.
1102-
1103-
Parameters
1104-
----------
1105-
product : Product
1106-
The data product the file name should be generated for
1107-
version : int, optional
1108-
The file version, by default 0 = detect from codebase
1109-
suffix : str, optional
1110-
file name suffix like svg, png, ..., by default '.svg'
1111-
1112-
Returns
1113-
-------
1114-
Path
1115-
a Path object with full name and path
1116-
"""
1117-
p = Path(super().generate_filename(product=product, version=version, header=True, status="C"))
1118-
return p.with_suffix(suffix).name
1119-
1120-
def generate_primary_header(self, filename, product, *, version=0):
1121-
"""Transforms the fits header into a more generic header dict
1122-
that might be used in other output file formats
1123-
1124-
Parameters
1125-
----------
1126-
filename : Path
1127-
The envisoned file name and path for the product
1128-
product : Product
1129-
The products holding the data
1130-
version : int, optional
1131-
the processing version, by default 0 = detect from codebase
1132-
1133-
Returns
1134-
-------
1135-
dict
1136-
a dict of header keywords and values
1137-
"""
1138-
l1, l2 = super().generate_primary_header(filename, product, version=version)
1139-
header = dict()
1140-
for k, v in l1:
1141-
header[k] = v
1142-
for kv in l2:
1143-
header[kv[0]] = kv[1]
1144-
return header
1145-
1146-
def write_plot(self, product, *, version=0):
1147-
"""
1148-
Write products into a plot image file.
1149-
1150-
Parameters
1151-
----------
1152-
product : `stixcore.product.level2`
1153-
1154-
version : `int`
1155-
the version modifier for the filename
1156-
default 0 = detect from codebase.
1157-
1158-
Returns
1159-
-------
1160-
list
1161-
of created file as `pathlib.Path`
1162-
1163-
"""
1164-
if version == 0:
1165-
version = product.get_processing_version()
1166-
1167-
filename = self.generate_filename(product=product, version=version)
1168-
1169-
# headers = self.generate_primary_header(filename, product, version=version)
1170-
# headers['parent'] = get_complete_file_name(product.parent_file_path.name)
1171-
1172-
parts = [product.level, product.utc_timerange.center.strftime("%Y/%m/%d"), product.type.upper()]
1173-
# for science data use start date
1174-
if product.type in ["sci", "flarelist"]:
1175-
parts[1] = product.utc_timerange.start.strftime("%Y/%m/%d")
1176-
path = self.archive_path.joinpath(*[str(x) for x in parts])
1177-
path.mkdir(parents=True, exist_ok=True)
1178-
1179-
plot_path = path / filename
1180-
1181-
fig = product.get_plot()
1182-
fig.savefig(plot_path, format="svg")
1183-
plt.close(fig)
1184-
return plot_path
1185-
1186-
11871084
class FitsL3Processor(FitsL2Processor):
11881085
def __init__(self, archive_path):
11891086
super().__init__(archive_path)
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
"""Module for the different processing levels."""
2+
3+
from pathlib import Path
4+
5+
from matplotlib import pyplot as plt
6+
7+
from stixcore.io.product_processors.fits.processors import FitsL2Processor
8+
from stixcore.util.logging import get_logger
9+
10+
__all__ = [
11+
"PlotProcessor",
12+
]
13+
14+
15+
logger = get_logger(__name__)
16+
17+
18+
class PlotProcessor(FitsL2Processor):
19+
"""A file product processor for plot images"""
20+
21+
def __init__(self, archive_path):
22+
"""Creates a new PlotProcessor object.
23+
24+
Parameters
25+
----------
26+
archive_path : Path
27+
the output root path where the files should be created
28+
"""
29+
super().__init__(archive_path)
30+
31+
def generate_filename(self, product, *, version=0, suffix=".svg"):
32+
"""Generates a SOAR conform filename based on product characteristics.
33+
34+
Parameters
35+
----------
36+
product : Product
37+
The data product the file name should be generated for
38+
version : int, optional
39+
The file version, by default 0 = detect from codebase
40+
suffix : str, optional
41+
file name suffix like svg, png, ..., by default '.svg'
42+
43+
Returns
44+
-------
45+
Path
46+
a Path object with full name and path
47+
"""
48+
p = Path(super().generate_filename(product=product, version=version, header=True, status="C"))
49+
return p.with_suffix(suffix).name
50+
51+
def generate_primary_header(self, filename, product, *, version=0):
52+
"""Transforms the fits header into a more generic header dict
53+
that might be used in other output file formats
54+
55+
Parameters
56+
----------
57+
filename : Path
58+
The envisoned file name and path for the product
59+
product : Product
60+
The products holding the data
61+
version : int, optional
62+
the processing version, by default 0 = detect from codebase
63+
64+
Returns
65+
-------
66+
dict
67+
a dict of header keywords and values
68+
"""
69+
l1, l2 = super().generate_primary_header(filename, product, version=version)
70+
header = dict()
71+
for k, v in l1:
72+
header[k] = v
73+
for kv in l2:
74+
header[kv[0]] = kv[1]
75+
return header
76+
77+
def write_plot(self, product, *, version=0):
78+
"""
79+
Write products into a plot image file.
80+
81+
Parameters
82+
----------
83+
product : `stixcore.product.level2`
84+
85+
version : `int`
86+
the version modifier for the filename
87+
default 0 = detect from codebase.
88+
89+
Returns
90+
-------
91+
list
92+
of created file as `pathlib.Path`
93+
94+
"""
95+
if version == 0:
96+
version = product.get_processing_version()
97+
98+
filename = self.generate_filename(product=product, version=version)
99+
100+
# headers = self.generate_primary_header(filename, product, version=version)
101+
# headers['parent'] = get_complete_file_name(product.parent_file_path.name)
102+
103+
parts = [product.level, product.utc_timerange.center.strftime("%Y/%m/%d"), product.type.upper()]
104+
# for science data use start date
105+
if product.type in ["sci", "flarelist"]:
106+
parts[1] = product.utc_timerange.start.strftime("%Y/%m/%d")
107+
path = self.archive_path.joinpath(*[str(x) for x in parts])
108+
path.mkdir(parents=True, exist_ok=True)
109+
110+
plot_path = path / filename
111+
112+
fig = product.get_plot()
113+
fig.savefig(plot_path, format="svg")
114+
plt.close(fig)
115+
return plot_path
File renamed without changes.

stixcore/io/fits/tests/test_processors.py renamed to stixcore/io/product_processors/tests/test_processors.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
from astropy.table import QTable
77

88
from stixcore.data.test import test_data
9-
from stixcore.io.fits.processors import FitsL0Processor, FitsL1Processor, FitsLBProcessor
9+
from stixcore.io.product_processors.fits.processors import (
10+
FitsL0Processor,
11+
FitsL1Processor,
12+
FitsLBProcessor,
13+
)
14+
from stixcore.io.product_processors.plots.processors import PlotProcessor
1015
from stixcore.products.product import Product
1116
from stixcore.soop.manager import SOOPManager
1217
from stixcore.time import SCETime, SCETimeRange
@@ -51,7 +56,7 @@ def test_levelb_processor_generate_filename_without_rid():
5156

5257

5358
@patch("stixcore.products.level0.quicklookL0.QLProduct")
54-
@patch("stixcore.io.fits.processors.datetime")
59+
@patch("stixcore.io.product_processors.fits.processors.datetime")
5560
def test_levelb_processor_generate_primary_header(datetime, product):
5661
processor = FitsLBProcessor("some/path")
5762
datetime.now().isoformat.return_value = "1234-05-07T01:02:03.346"
@@ -136,7 +141,7 @@ def test_level0_processor_generate_filename():
136141

137142

138143
@patch("stixcore.products.level0.quicklookL0.QLProduct")
139-
@patch("stixcore.io.fits.processors.datetime")
144+
@patch("stixcore.io.product_processors.fits.processors.datetime")
140145
def test_level0_processor_generate_primary_header(datetime, product):
141146
processor = FitsL0Processor("some/path")
142147
datetime.now().isoformat.return_value = "1234-05-07T01:02:03.346"
@@ -290,3 +295,15 @@ def test_level1_processor_generate_primary_header(product, soop_manager):
290295
assert np.allclose(test_data[name], value)
291296
else:
292297
assert value == test_data[name]
298+
299+
300+
@patch("stixcore.products.lowlatency.quicklookLL.LightCurveL3")
301+
def test_plot_processor_generate_filename(product):
302+
processor = PlotProcessor("some/path")
303+
product.type = "ql"
304+
product.scet_timerange = SCETimeRange(start=SCETime(0, 0), end=SCETime(coarse=0, fine=2**16 - 1))
305+
product.utc_timerange = product.scet_timerange.to_timerange()
306+
product.level = "LL03"
307+
product.name = "lightcurve"
308+
filename = processor.generate_filename(product, version=1)
309+
assert filename == "solo_LL03_stix-ql-lightcurve_20000101_V01C.svg"

stixcore/processing/L0toL1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from stixcore.config.config import CONFIG
1010
from stixcore.ephemeris.manager import Spice, SpiceKernelManager
11-
from stixcore.io.fits.processors import FitsL1Processor
11+
from stixcore.io.product_processors.fits.processors import FitsL1Processor
1212
from stixcore.products import Product
1313
from stixcore.products.level0.scienceL0 import NotCombineException
1414
from stixcore.soop.manager import SOOPManager

stixcore/processing/L1toL2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from stixcore.config.config import CONFIG
1010
from stixcore.ephemeris.manager import Spice
11-
from stixcore.io.fits.processors import FitsL2Processor
11+
from stixcore.io.product_processors.fits.processors import FitsL2Processor
1212
from stixcore.processing.sswidl import SSWIDLProcessor
1313
from stixcore.products import Product
1414
from stixcore.products.level0.scienceL0 import NotCombineException

0 commit comments

Comments
 (0)