Skip to content

Commit

Permalink
Merge branch 'main' of github.com:sunpy/radiospectra into pr/61
Browse files Browse the repository at this point in the history
  • Loading branch information
nabobalis committed Nov 17, 2023
2 parents 6e93300 + 4e2a9db commit ab0d29a
Show file tree
Hide file tree
Showing 5 changed files with 281 additions and 6 deletions.
9 changes: 5 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
repos:
- repo: https://github.com/PyCQA/autoflake
rev: v1.7.7
rev: v2.2.1
hooks:
- id: autoflake
args: ['--in-place', '--remove-all-unused-imports', '--remove-unused-variable']
exclude: ".*(.fits|.fts|.fit|.txt|tca.*|extern.*|.rst|.md|__init__.py|docs/conf.py)$"
- repo: https://github.com/psf/black
rev: 22.10.0
rev: 23.11.0
hooks:
- id: black
exclude: ".*(.fits|.fts|.fit|.txt|.csv)$"
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
exclude: ".*(.fits|.fts|.fit|.txt|.csv)$"
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.5.0
hooks:
- id: check-ast
- id: check-case-conflict
Expand All @@ -31,3 +31,4 @@ repos:

ci:
autofix_prs: false
autoupdate_schedule: "quarterly"
1 change: 1 addition & 0 deletions changelog/84.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug where incorrectly formatted dates were not handled by the `radiospectra.spectrogram.Spectrogram`.
244 changes: 244 additions & 0 deletions radiospectra/spectrogram/sources/tests/test_callisto.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pathlib import Path
from datetime import datetime
from unittest import mock
from unittest.mock import MagicMock

import numpy as np

Expand Down Expand Up @@ -247,3 +248,246 @@ def test_callisto(parse_path_moc):
assert spec.wavelength.min.to(u.MHz) == 20 * u.MHz
assert spec.wavelength.max.to(u.MHz).round(1) == 91.8 * u.MHz
assert str(spec.observatory_location) == "(3801942.21260148, 528924.60367802, 5077174.56861812) m"


@mock.patch("sunpy.util.io.is_file")
@mock.patch("radiospectra.spectrogram.spectrogram_factory.fits.open")
def test_callisto_hour_rollover(hdul_moc, is_file_mock):
is_file_mock.return_value = True
freqs = [
91.81300354003906,
91.25,
91.06300354003906,
90.625,
90.43800354003906,
89.75,
89.68800354003906,
89.0,
88.625,
88.25,
88.06300354003906,
87.56300354003906,
87.43800354003906,
87.06300354003906,
86.5,
86.06300354003906,
85.875,
85.56300354003906,
84.875,
84.68800354003906,
84.31300354003906,
83.875,
83.68800354003906,
83.0,
82.75,
82.43800354003906,
81.875,
81.75,
81.18800354003906,
80.75,
80.625,
80.25,
79.68800354003906,
79.25,
79.125,
78.68800354003906,
78.43800354003906,
78.06300354003906,
77.43800354003906,
77.0,
76.625,
76.56300354003906,
76.0,
75.56300354003906,
75.125,
75.0,
74.68800354003906,
74.31300354003906,
73.68800354003906,
73.31300354003906,
72.875,
72.625,
72.125,
71.75,
71.56300354003906,
71.0,
70.93800354003906,
70.25,
70.18800354003906,
69.68800354003906,
69.43800354003906,
69.06300354003906,
68.43800354003906,
68.06300354003906,
67.93800354003906,
67.31300354003906,
66.93800354003906,
66.81300354003906,
66.125,
66.06300354003906,
65.43800354003906,
65.0,
64.875,
64.25,
64.06300354003906,
63.8129997253418,
63.3129997253418,
62.75,
62.5,
62.0,
61.9379997253418,
61.5629997253418,
60.875,
60.75,
60.3129997253418,
59.9379997253418,
59.6879997253418,
59.0,
58.625,
58.25,
58.1879997253418,
57.5,
57.125,
56.9379997253418,
56.5,
56.3129997253418,
55.9379997253418,
55.4379997253418,
54.9379997253418,
54.8129997253418,
54.4379997253418,
53.9379997253418,
53.4379997253418,
53.125,
52.9379997253418,
52.5629997253418,
51.875,
51.5629997253418,
51.1879997253418,
50.8129997253418,
50.5629997253418,
50.0629997253418,
49.6879997253418,
49.3129997253418,
48.9379997253418,
48.8129997253418,
48.125,
48.0629997253418,
47.4379997253418,
47.25,
46.9379997253418,
46.25,
45.875,
45.8129997253418,
45.3129997253418,
45.0629997253418,
44.375,
44.1879997253418,
43.8129997253418,
43.3129997253418,
43.1879997253418,
42.5,
42.125,
42.0629997253418,
41.5629997253418,
41.1879997253418,
40.6879997253418,
40.4379997253418,
39.875,
39.8129997253418,
39.4379997253418,
38.75,
38.375,
38.0629997253418,
37.6879997253418,
37.5629997253418,
36.875,
36.8129997253418,
36.25,
36.0629997253418,
35.6879997253418,
35.0629997253418,
34.875,
34.5,
34.125,
33.8129997253418,
33.125,
33.0,
32.5629997253418,
32.0629997253418,
31.937999725341797,
31.25,
30.875,
30.562999725341797,
30.125,
30.062999725341797,
29.375,
29.312999725341797,
28.875,
28.25,
28.187999725341797,
27.562999725341797,
27.125,
26.75,
26.687999725341797,
26.125,
25.75,
25.375,
25.0,
24.812999725341797,
24.125,
23.812999725341797,
23.437999725341797,
23.125,
22.812999725341797,
22.437999725341797,
21.875,
21.812999725341797,
21.125,
20.75,
20.375,
20.0,
20.0,
20.0,
20.0,
20.0,
20.0,
20.0,
20.0,
20.0,
]

header = {
"CONTENT": "e-CALLISTO",
"DATE-OBS": "2011/06/07",
"TIME-OBS": "23:46:06",
"DATE-END": "2011/06/07",
"TIME-END": "24:01:06",
"INSTRUME": "Bir",
"OBS_LAC": "N",
"OBS_LAT": 53.0941390991211,
"OBS_LOC": "E",
"OBS_LON": 7.92012977600098,
"OBS_ALT": 416.5,
}
array = np.zeros((200, 3600))
hdu0 = MagicMock()
hdu1 = MagicMock()
hdu0.header = header
hdu0.data = array
hdu1.data = {
"TIME": np.arange(3600) * 0.25,
"FREQUENCY": np.array(freqs),
}
hdul_moc.return_value = [hdu0, hdu1]
file = Path("fake.fit.gz")
spec = Spectrogram(file)
assert isinstance(spec, CALISTOSpectrogram)
assert spec.observatory == "BIR"
assert spec.instrument == "E-CALLISTO"
assert spec.detector == "E-CALLISTO"
assert spec.start_time.datetime == datetime(2011, 6, 7, 23, 46, 6, 0)
assert spec.end_time.datetime == datetime(2011, 6, 8, 0, 1, 6, 0)
assert spec.wavelength.min.to(u.MHz) == 20 * u.MHz
assert spec.wavelength.max.to(u.MHz).round(1) == 91.8 * u.MHz
assert str(spec.observatory_location) == "(3801942.21260148, 528924.60367802, 5077174.56861812) m"
30 changes: 29 additions & 1 deletion radiospectra/spectrogram/spectrogram_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,35 @@ def _read_cdf(file):
@staticmethod
def _read_fits(file):
hd_pairs = fits.open(file)
if hd_pairs[0].header.get("TELESCOP", "") == "EOVSA":
if "e-CALLISTO" in hd_pairs[0].header.get("CONTENT", ""):
data = hd_pairs[0].data
times = hd_pairs[1].data["TIME"].flatten() * u.s
freqs = hd_pairs[1].data["FREQUENCY"].flatten() * u.MHz
start_time = parse_time(hd_pairs[0].header["DATE-OBS"] + " " + hd_pairs[0].header["TIME-OBS"])
try:
end_time = parse_time(hd_pairs[0].header["DATE-END"] + " " + hd_pairs[0].header["TIME-END"])
except ValueError:
# See https://github.com/sunpy/radiospectra/issues/74
time_comps = hd_pairs[0].header["TIME-END"].split(":")
time_comps[0] = "00"
fixed_time = ":".join(time_comps)
date_offset = parse_time(hd_pairs[0].header["DATE-END"] + " " + fixed_time)
end_time = date_offset + 1 * u.day

times = start_time + times
meta = {
"fits_meta": hd_pairs[0].header,
"detector": "e-CALLISTO",
"instrument": "e-CALLISTO",
"observatory": hd_pairs[0].header["INSTRUME"],
"start_time": start_time,
"end_time": end_time,
"wavelength": a.Wavelength(freqs.min(), freqs.max()),
"times": times,
"freqs": freqs,
}
return data, meta
elif hd_pairs[0].header.get("TELESCOP", "") == "EOVSA":
times = Time(hd_pairs[2].data["mjd"] + hd_pairs[2].data["time"] / 1000.0 / 86400.0, format="mjd")
freqs = hd_pairs[1].data["sfreq"] * u.GHz
data = hd_pairs[0].data
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ remote_data_strict = True
junit_family=xunit1
filterwarnings =
error
error::sunpy.util.exceptions.SunpyDeprecationWarning
#
# A list of warnings to ignore follows. If you add to this list, you MUST
# add a comment or ideally a link to an issue that explains why the warning
Expand All @@ -87,6 +86,8 @@ filterwarnings =
ignore:numpy.ndarray size changed:RuntimeWarning
# Zeep
ignore:'cgi' is deprecated:DeprecationWarning
# https://github.com/pytest-dev/pytest-cov/issues/557
ignore:The --rsyncdir command line argument and rsyncdirs config variable are deprecated.:DeprecationWarning

[pycodestyle]
max_line_length = 100
Expand Down

0 comments on commit ab0d29a

Please sign in to comment.