|
1 | 1 | """Module for the different processing levels.""" |
2 | 2 |
|
3 | | -from pathlib import Path |
4 | 3 | from datetime import datetime |
5 | 4 |
|
6 | 5 | import numpy as np |
7 | | -from matplotlib import pyplot as plt |
8 | 6 |
|
9 | 7 | import astropy.units as u |
10 | 8 | from astropy.io import fits |
|
27 | 25 | "FitsL0Processor", |
28 | 26 | "FitsL1Processor", |
29 | 27 | "FitsL2Processor", |
30 | | - "PlotProcessor", |
31 | 28 | ] |
32 | 29 |
|
33 | 30 |
|
@@ -1084,106 +1081,6 @@ def write_fits(self, prod, *, version=0): |
1084 | 1081 | return [filetowrite] |
1085 | 1082 |
|
1086 | 1083 |
|
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 | | - |
1187 | 1084 | class FitsL3Processor(FitsL2Processor): |
1188 | 1085 | def __init__(self, archive_path): |
1189 | 1086 | super().__init__(archive_path) |
|
0 commit comments