Skip to content

Commit 8a5a431

Browse files
authored
Merge pull request #1129 from rhayes777/feature/fits_aggregator_csv
fix unit tests by restoring .fits files and using MODEL_IMAGe
2 parents 474d583 + cb272ad commit 8a5a431

4 files changed

Lines changed: 38 additions & 15 deletions

File tree

autofit/aggregator/summary/aggregate_fits.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import re
22
from enum import Enum
3-
from typing import List, Union
3+
from typing import Dict, List, Union
44

5+
from astropy.table import Table
56
from astropy.io import fits
67
from pathlib import Path
78

@@ -27,7 +28,7 @@ class FITSFit(Enum):
2728
The HDUs that can be extracted from the fit.fits file.
2829
"""
2930

30-
ModelImage = "MODEL_IMAGE"
31+
ModelData = "MODEL_IMAGE"
3132
ResidualMap = "RESIDUAL_MAP"
3233
NormalizedResidualMap = "NORMALIZED_RESIDUAL_MAP"
3334
ChiSquaredMap = "CHI_SQUARED_MAP"
@@ -100,6 +101,28 @@ def extract_fits(self, hdus: List[Enum]) -> List[fits.HDUList]:
100101

101102
return fits.HDUList(output)
102103

104+
def extract_csv(self, filename : str) -> List[Dict]:
105+
"""
106+
Extract .csv files which store imaging results that are typically on irregular grids and thus don't suit
107+
a .fits file.
108+
109+
Return the result as a list of Dicts corresponding to the fits in the aggregator.
110+
111+
Parameters
112+
----------
113+
filename
114+
The name of the .csv file to extract.
115+
116+
Returns
117+
-------
118+
The extracted HDUs.
119+
"""
120+
output = []
121+
for result in self.aggregator:
122+
output.append(Table.read(result.value(filename), format="fits"))
123+
124+
return output
125+
103126
def output_to_folder(
104127
self,
105128
folder: Path,

autofit/aggregator/summary/aggregate_images.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ class SubplotFit(Enum):
3434
Data = (0, 0)
3535
DataSourceScaled = (1, 0)
3636
SignalToNoiseMap = (2, 0)
37-
ModelImage = (3, 0)
38-
LensLightModelImage = (0, 1)
37+
ModelData = (3, 0)
38+
LensLightModelData = (0, 1)
3939
LensLightSubtractedImage = (1, 1)
40-
SourceModelImage = (2, 1)
40+
SourceModelData = (2, 1)
4141
SourcePlaneZoomed = (3, 1)
4242
NormalizedResidualMap = (0, 2)
4343
NormalizedResidualMapOneSigma = (1, 2)

test_autofit/aggregator/summary_files/test_aggregate_fits.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def make_summary(aggregator):
1212
def test_aggregate(summary):
1313
result = summary.extract_fits(
1414
[
15-
af.FITSFit.ModelImage,
15+
af.FITSFit.ModelData,
1616
af.FITSFit.ResidualMap,
1717
],
1818
)
@@ -25,7 +25,7 @@ def test_output_to_file(summary, output_directory):
2525
folder,
2626
name="id",
2727
hdus=[
28-
af.FITSFit.ModelImage,
28+
af.FITSFit.ModelData,
2929
af.FITSFit.ResidualMap,
3030
],
3131
)
@@ -37,7 +37,7 @@ def test_list_of_names(summary, output_directory):
3737
output_directory,
3838
["one", "two"],
3939
[
40-
af.FITSFit.ModelImage,
40+
af.FITSFit.ModelData,
4141
af.FITSFit.ResidualMap,
4242
],
4343
)

test_autofit/aggregator/summary_files/test_aggregate_images.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def test_longer(aggregate):
4949
[
5050
SubplotFit.NormalizedResidualMap,
5151
SubplotFit.SourcePlaneNoZoom,
52-
SubplotFit.SourceModelImage,
52+
SubplotFit.SourceModelData,
5353
],
5454
)
5555

@@ -61,7 +61,7 @@ def test_subplot_width(aggregate):
6161
[
6262
SubplotFit.NormalizedResidualMap,
6363
SubplotFit.SourcePlaneNoZoom,
64-
SubplotFit.SourceModelImage,
64+
SubplotFit.SourceModelData,
6565
],
6666
subplot_width=2,
6767
)
@@ -76,7 +76,7 @@ def test_output_to_folder(aggregate, output_directory):
7676
[
7777
SubplotFit.Data,
7878
SubplotFit.SourcePlaneZoomed,
79-
SubplotFit.SourceModelImage,
79+
SubplotFit.SourceModelData,
8080
],
8181
)
8282
assert list(Path(output_directory).glob("*.png"))
@@ -89,7 +89,7 @@ def test_list_of_names(aggregate, output_directory):
8989
[
9090
SubplotFit.Data,
9191
SubplotFit.SourcePlaneZoomed,
92-
SubplotFit.SourceModelImage,
92+
SubplotFit.SourceModelData,
9393
],
9494
)
9595
assert set([path.name for path in Path(output_directory).glob("*.png")]) == set([
@@ -109,7 +109,7 @@ def test_output_to_folder_name(
109109
[
110110
SubplotFit.Data,
111111
SubplotFit.SourcePlaneZoomed,
112-
SubplotFit.SourceModelImage,
112+
SubplotFit.SourceModelData,
113113
],
114114
)
115115

@@ -128,7 +128,7 @@ def test_custom_images(
128128
[
129129
SubplotFit.Data,
130130
SubplotFit.SourcePlaneZoomed,
131-
SubplotFit.SourceModelImage,
131+
SubplotFit.SourceModelData,
132132
images,
133133
]
134134
)
@@ -144,7 +144,7 @@ def make_image(output):
144144
[
145145
SubplotFit.Data,
146146
SubplotFit.SourcePlaneZoomed,
147-
SubplotFit.SourceModelImage,
147+
SubplotFit.SourceModelData,
148148
make_image,
149149
]
150150
)

0 commit comments

Comments
 (0)