Skip to content

Commit 602128b

Browse files
committed
Everything else
1 parent 8efa2af commit 602128b

14 files changed

+53
-40
lines changed

Diff for: aiapy/calibrate/tests/test_prep.py

-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ def test_degradation_4500_missing() -> None:
230230
degradation(4500 * u.angstrom, obstime, correction_table=get_correction_table(10))
231231

232232

233-
@pytest.mark.xfail(reason="JSOC is down")
234233
@pytest.mark.remote_data
235234
def test_degradation_4500_jsoc() -> None:
236235
# 4500 has a max version of 3, so by default it will error

Diff for: aiapy/calibrate/tests/test_util.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ def test_obstime_out_of_range() -> None:
9494

9595

9696
@pytest.mark.remote_data
97-
@pytest.mark.xfail(reason="JSOC is down")
9897
def test_pointing_table() -> None:
9998
expected_columns = ["T_START", "T_STOP"]
10099
for c in ["094", "171", "193", "211", "304", "335", "1600", "1700", "4500"]:
@@ -118,11 +117,10 @@ def test_pointing_table() -> None:
118117

119118

120119
@pytest.mark.remote_data
121-
@pytest.mark.xfail(reason="JSOC is down")
122120
def test_pointing_table_unavailable() -> None:
123121
# Check that missing pointing data raises a nice error
124122
t = astropy.time.Time("1990-01-01")
125-
with pytest.raises(RuntimeError, match="Could not find any pointing information"):
123+
with pytest.raises(RuntimeError, match="No data found for this query"):
126124
get_pointing_table("jsoc", start=t - 3 * u.h, end=t + 3 * u.h)
127125

128126

Diff for: aiapy/calibrate/util.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def get_correction_table(source):
198198

199199
@u.quantity_input
200200
@validate_channel("channel")
201-
def _select_epoch_from_correction_table(channel: u.angstrom, obstime, table):
201+
def _select_epoch_from_correction_table(channel: u.angstrom, obstime, correction_table):
202202
"""
203203
Return correction table with only the first epoch and the epoch in which
204204
``obstime`` falls and for only one given calibration version.
@@ -207,14 +207,14 @@ def _select_epoch_from_correction_table(channel: u.angstrom, obstime, table):
207207
----------
208208
channel : `~astropy.units.Quantity`
209209
obstime : `~astropy.time.Time`
210-
table : `~astropy.table.QTable`
210+
correction_table : `~astropy.table.QTable`
211211
"""
212212
# Select only this channel
213213
# NOTE: The WAVE_STR prime keys for the aia.response JSOC series for the
214214
# non-EUV channels do not have a thick/thin designation
215215
thin = "_THIN" if channel not in (1600, 1700, 4500) * u.angstrom else ""
216216
wave = channel.to(u.angstrom).value
217-
table = table[table["WAVE_STR"] == f"{wave:.0f}{thin}"]
217+
table = correction_table[correction_table["WAVE_STR"] == f"{wave:.0f}{thin}"]
218218
table.sort("DATE") # Newest entries will be last
219219
if len(table) == 0:
220220
extra_msg = " Max version is 3." if channel == 4500 * u.AA else ""
@@ -289,7 +289,9 @@ def get_pointing_table(source, *, start=None, end=None):
289289
if start is None or end is None:
290290
msg = "start and end must be provided if source is 'jsoc'"
291291
raise ValueError(msg)
292-
table = get_data_from_jsoc(query=f"aia.master_pointing3h[{start.isot}Z-{end.isot}Z]", key="**ALL**")
292+
table = QTable.from_pandas(
293+
get_data_from_jsoc(query=f"aia.master_pointing3h[{start.isot}Z-{end.isot}Z]", key="**ALL**")
294+
)
293295
elif source.lower() == "lmsal":
294296
table = QTable(astropy_ascii.read(fetch_pointing_table()))
295297
else:

Diff for: aiapy/response/channel.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from aiapy import _SSW_MIRRORS
1717
from aiapy.calibrate import degradation
18-
from aiapy.calibrate.util import _select_epoch_from_correction_table, get_correction_table
18+
from aiapy.calibrate.util import _select_epoch_from_correction_table
1919
from aiapy.data._manager import manager
2020
from aiapy.util import telescope_number
2121
from aiapy.util.decorators import validate_channel
@@ -282,7 +282,7 @@ def crosstalk(
282282
return u.Quantity(np.zeros(self.wavelength.shape), u.cm**2)
283283

284284
@u.quantity_input
285-
def eve_correction(self, obstime, source) -> u.dimensionless_unscaled:
285+
def eve_correction(self, obstime, correction_table) -> u.dimensionless_unscaled:
286286
r"""
287287
Correct effective area to give good agreement with full-disk EVE data.
288288
@@ -306,8 +306,9 @@ def eve_correction(self, obstime, source) -> u.dimensionless_unscaled:
306306
----------
307307
obstime : `~astropy.time.Time`
308308
The time of the observation.
309-
source : `pathlib.Path` or `str` or `int`, optional
310-
TODO: UPDATE
309+
correction_table : `astropy.table.QTable`
310+
Table of correction parameters.
311+
See `aiapy.calibrate.util.get_correction_table` for more information.
311312
312313
Returns
313314
-------
@@ -320,7 +321,7 @@ def eve_correction(self, obstime, source) -> u.dimensionless_unscaled:
320321
table = _select_epoch_from_correction_table(
321322
self.channel,
322323
obstime,
323-
get_correction_table(source=source),
324+
correction_table=correction_table,
324325
)
325326
effective_area_interp = np.interp(table["EFF_WVLN"][-1], self.wavelength, self.effective_area)
326327
return table["EFF_AREA"][0] / effective_area_interp
@@ -360,7 +361,7 @@ def wavelength_response(
360361
obstime=None,
361362
include_eve_correction=False,
362363
include_crosstalk=True,
363-
**kwargs,
364+
correction_table,
364365
) -> u.DN / u.ph * u.cm**2:
365366
r"""
366367
The wavelength response function is the product of the gain and the
@@ -393,9 +394,8 @@ def wavelength_response(
393394
The time-dependent correction is also included.
394395
include_crosstalk : `bool`, optional
395396
If true, include the effect of crosstalk between channels that share a telescope
396-
correction_table : `~astropy.table.Table` or `str`, optional
397-
Table of correction parameters or path to correction table file.
398-
If not specified, it will be queried from JSOC.
397+
correction_table : `~astropy.table.Table`
398+
Table of correction parameters.
399399
See `aiapy.calibrate.util.get_correction_table` for more information.
400400
401401
Returns
@@ -412,8 +412,8 @@ def wavelength_response(
412412
"""
413413
eve_correction, time_correction = 1, 1
414414
if obstime is not None:
415-
time_correction = degradation(self.channel, obstime, **kwargs)
415+
time_correction = degradation(self.channel, obstime, correction_table=correction_table)
416416
if include_eve_correction:
417-
eve_correction = self.eve_correction(obstime, **kwargs)
417+
eve_correction = self.eve_correction(obstime, correction_table=correction_table)
418418
crosstalk = self.crosstalk if include_crosstalk else 0 * u.cm**2
419419
return (self.effective_area + crosstalk) * self.gain * time_correction * eve_correction

Diff for: aiapy/util/net.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,11 @@ def get_data_from_jsoc(query, *, key, seg=None):
3636
If the query fails for any reason.
3737
"""
3838
try:
39-
return drms.Client().query(query, key=key, seg=seg)
40-
except KeyError as e:
41-
# This probably should not be here but yolo.
42-
# If there's no pointing information available between these times,
43-
# JSOC will raise a cryptic KeyError
44-
# (see https://github.com/LM-SAL/aiapy/issues/71)
45-
msg = "Could not find any pointing information"
46-
raise RuntimeError(msg) from e
39+
jsoc_result = drms.Client().query(query, key=key, seg=seg)
4740
except Exception as e:
4841
msg = f"Unable to query the JSOC.\n Error message: {e}"
4942
raise OSError(msg) from e
43+
if len(jsoc_result) == 0:
44+
msg = f"No data found for this query: {query}, key: {key}, seg: {seg}"
45+
raise RuntimeError(msg)
46+
return jsoc_result

Diff for: aiapy/util/tests/test_net.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55

66
@pytest.mark.remote_data
7-
@pytest.mark.xfail(reason="JSOC is currently down")
87
def test_get_data_from_jsoc():
9-
assert get_data_from_jsoc("aia.lev1[2001-01-01]", key="T_OBS") is not None
8+
assert get_data_from_jsoc("aia.master_pointing3h[2010-05-13T00:00:00Z]", key="**ALL**") is not None
109

1110

1211
def test_get_data_from_jsoc_error():

Diff for: aiapy/util/tests/test_util.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,8 @@ def test_sdo_location(aia_171_map) -> None:
1616
@pytest.mark.remote_data
1717
def test_sdo_location_raises_error() -> None:
1818
# Confirm that an error is raised for a time without records
19-
with pytest.raises(ValueError, match="No JSOC records near this time: 2001-01-01T00:00:00.000"):
19+
with pytest.raises(
20+
RuntimeError,
21+
match="No data found for this query: aia.lev1[2000-12-31T23:59:57.000/6s], key: T_OBS, HAEX_OBS, HAEY_OBS, HAEZ_OBS, seg: None",
22+
):
2023
aiapy.util.sdo_location("2001-01-01")

Diff for: examples/calculate_response_function.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import astropy.time
1515
import astropy.units as u
1616

17+
from aiapy.calibrate.util import get_correction_table
1718
from aiapy.response import Channel
1819

1920
###############################################################################
@@ -94,7 +95,8 @@
9495
# Additionally, `aiapy.response.Channel` provides a method for calculating
9596
# the wavelength response function using the equation above,
9697

97-
wavelength_response_335 = aia_335_channel.wavelength_response()
98+
correction_table = get_correction_table("jsoc")
99+
wavelength_response_335 = aia_335_channel.wavelength_response(correction_table=correction_table)
98100
print(wavelength_response_335)
99101

100102
###############################################################################
@@ -118,7 +120,9 @@
118120
# by default in the wavelength response calculation. To exclude this
119121
# effect,
120122

121-
wavelength_response_335_no_cross = aia_335_channel.wavelength_response(include_crosstalk=False)
123+
wavelength_response_335_no_cross = aia_335_channel.wavelength_response(
124+
include_crosstalk=False, correction_table=correction_table
125+
)
122126

123127
###############################################################################
124128
# If we look at the response around 131 Å (the channel with which 335 Å shares
@@ -145,8 +149,10 @@
145149
# of 1 January 2019,
146150

147151
obstime = astropy.time.Time("2019-01-01T00:00:00")
148-
wavelength_response_335_time = aia_335_channel.wavelength_response(obstime=obstime)
149-
wavelength_response_335_eve = aia_335_channel.wavelength_response(obstime=obstime, include_eve_correction=True)
152+
wavelength_response_335_time = aia_335_channel.wavelength_response(obstime=obstime, correction_table=correction_table)
153+
wavelength_response_335_eve = aia_335_channel.wavelength_response(
154+
obstime=obstime, include_eve_correction=True, correction_table=correction_table
155+
)
150156

151157
###############################################################################
152158
# We can then compare the two corrected response

Diff for: examples/skip_correct_degradation.py renamed to examples/correct_degradation.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from sunpy.net import attrs as a
1717

1818
from aiapy.calibrate import degradation
19+
from aiapy.calibrate.util import get_correction_table
1920

2021
# This lets you pass `astropy.time.Time` objects directly to matplotlib
2122
time_support(format="jyear")
@@ -51,7 +52,7 @@
5152
# For more details on how the correction factor is calculated, see the documentation for the
5253
# `aiapy.calibrate.degradation` function.
5354

54-
correction_factor = degradation(335 * u.angstrom, table["DATE_OBS"])
55+
correction_factor = degradation(335 * u.angstrom, table["DATE_OBS"], correction_table=get_correction_table("jsoc"))
5556
table["DATAMEAN_DEG"] = table["DATAMEAN"] / correction_factor
5657

5758
###############################################################################

Diff for: examples/prepping_level_1_data.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212

1313
import matplotlib.pyplot as plt
1414

15+
import astropy.units as u
16+
1517
import sunpy.map
1618

1719
import aiapy.data.sample as sample_data
1820
from aiapy.calibrate import register, update_pointing
21+
from aiapy.calibrate.util import get_pointing_table
1922

2023
###############################################################################
2124
# Performing multi-wavelength analysis on level 1 data can be problematic as
@@ -42,10 +45,12 @@
4245
###############################################################################
4346
# The first step in this process is to update the metadata of the map to the
4447
# most recent pointing using the `aiapy.calibrate.update_pointing` function.
45-
# This function queries the JSOC for the most recent pointing information,
46-
# updates the metadata, and returns a `sunpy.map.Map` with updated metadata.
48+
# One needs to get the pointing information from the JSOC using the
49+
# `aiapy.calibrate.util.get_pointing_table` function.
4750

48-
aia_map_updated_pointing = update_pointing(aia_map)
51+
# Make range wide enough to get closest 3-hour pointing
52+
pointing_table = get_pointing_table("JSOC", aia_map.date - 12 * u.h, aia_map.date + 12 * u.h)
53+
aia_map_updated_pointing = update_pointing(aia_map, pointing_table=pointing_table)
4954

5055
###############################################################################
5156
# If we take a look at the plate scale and rotation matrix of the map, we
File renamed without changes.

Diff for: examples/skip_download_specific_data.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
level_1_maps = sunpy.map.Map(files)
5959
# We get the pointing table outside of the loop for the relevant time range.
6060
# Otherwise you're making a call to the JSOC every single time.
61-
pointing_table = get_pointing_table(level_1_maps[0].date - 3 * u.h, level_1_maps[-1].date + 3 * u.h)
61+
pointing_table = get_pointing_table("jsoc", start=level_1_maps[0].date - 3 * u.h, end=level_1_maps[-1].date + 3 * u.h)
6262
# The same applies for the correction table.
63-
correction_table = get_correction_table(source=10)
63+
correction_table = get_correction_table(source="jsoc")
6464

6565
level_15_maps = []
6666
for a_map in level_1_maps:

Diff for: pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ docs = [
6969
"sunpy-sphinx-theme",
7070
"sunpy-sphinx-theme",
7171
]
72+
dev = ["aiapy[all,tests,docs]"]
7273

7374
[project.urls]
7475
Homepage = "https://aia.lmsal.com/"

Diff for: tox.ini

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ envlist =
66
py{310,311,312,313}
77
py313-devdeps
88
py310-oldestdeps
9+
cupy
910
codestyle
1011
build_docs{,-gallery}
1112

@@ -31,6 +32,7 @@ set_env =
3132
MPLBACKEND = agg
3233
devdeps: PIP_EXTRA_INDEX_URL = https://pypi.anaconda.org/astropy/simple https://pypi.anaconda.org/scientific-python-nightly-wheels/simple
3334
deps =
35+
cupy: cupy-cuda12x
3436
# For packages which publish nightly wheels this will pull the latest nightly
3537
devdeps: astropy>=0.0.dev0
3638
devdeps: sunpy>=0.0.dev0

0 commit comments

Comments
 (0)