Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run and fix online tests #143

Merged
merged 6 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
toxdeps: tox-pypi-filter
posargs: -n auto --dist loadgroup
envs: |
- linux: py311-devdeps
- linux: py312-online
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

Expand Down
2 changes: 2 additions & 0 deletions changelog/143.breaking.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Update the hash of the CHIANTI data file retrieved by the data manager used in `sunkit_instruments.goes_xrs.calculate_temperature_em`
so that the latest version of the file is used.
2 changes: 2 additions & 0 deletions changelog/143.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed a bug in `~sunkit-instruments.lyra.remove_lytaf_events_from_timeseries` where units were not being correctly passed
to new timeseries.
7 changes: 4 additions & 3 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ filterwarnings =
error
# Do not fail on pytest config issues (i.e. missing plugins) but do show them
always::pytest.PytestConfigWarning
# 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
# is being ignored
# Zeep relies on deprecated cgi in Python 3.11
# Needs a release of zeep 4.2.2 or higher
# https://github.com/mvantellingen/python-zeep/pull/1364
ignore:'cgi' is deprecated and slated for removal in Python 3.13:DeprecationWarning
2 changes: 1 addition & 1 deletion sunkit_instruments/goes_xrs/goes_chianti_tem.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def calculate_temperature_em(goes_ts, abundance="coronal"):
[
"https://sohoftp.nascom.nasa.gov/solarsoft/gen/idl/synoptic/goes/goes_chianti_response_latest.fits"
],
"4ca9730fb039e8a04407ae0aa4d5e3e2566b93dfe549157aa7c8fc3aa1e3e04d",
"cb00c05850e3dc3bbd856eb07c1a372758d689d0845ee591d6e2531afeab0382",
)
def _chianti_temp_emiss(
goes_ts, satellite_number, secondary=0, abundance="coronal", remove_scaling=False
Expand Down
18 changes: 9 additions & 9 deletions sunkit_instruments/lyra/lyra.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from astropy.time import Time

from sunpy import log
from sunpy.data import cache
from sunpy.time import parse_time
from sunpy.time.time import _variables_for_parse_time_docstring
Expand Down Expand Up @@ -116,7 +117,7 @@
data = pandas.DataFrame(
index=time, data={col: channels[i] for i, col in enumerate(data_columns)}
)
ts_new = TimeSeries(data, ts.meta)
ts_new = TimeSeries(data, ts.meta, ts.units)
if return_artifacts:
return ts_new, artifact_status
else:
Expand Down Expand Up @@ -229,7 +230,7 @@
all_lytaf_event_types = get_lytaf_event_types(print_event_types=False)
for artifact in artifacts:
if artifact not in all_lytaf_event_types:
print(all_lytaf_event_types)
log.info(all_lytaf_event_types)
raise ValueError(f"{artifact} is not a valid artifact type. See above.")
# Define outputs
clean_time = parse_time(time)
Expand Down Expand Up @@ -520,7 +521,7 @@
all_event_types = []
# For each database file extract the event types and print them.
if print_event_types:
print("\nLYTAF Event Types\n-----------------\n")
log.info("\nLYTAF Event Types\n-----------------\n")
for suffix in suffixes:
dbname = f"annotation_{suffix}.db"
# Check database file exists, else download it.
Expand All @@ -533,10 +534,10 @@
event_types = cursor.fetchall()
all_event_types.append(event_types)
if print_event_types:
print(f"----------------\n{suffix} database\n----------------")
log.info(f"----------------\n{suffix} database\n----------------")
for event_type in event_types:
print(str(event_type[0]))
print(" ")
log.info(str(event_type[0]))
log.info(" ")
# Unpack event types in all_event_types into single list
all_event_types = [
event_type[0] for event_types in all_event_types for event_type in event_types
Expand Down Expand Up @@ -591,8 +592,8 @@
disc = tmp_discontinuity[0]

if len(disc) == 0:
print(
"No events found within time series interval. " "Returning original series."
log.info(

Check warning on line 595 in sunkit_instruments/lyra/lyra.py

View check run for this annotation

Codecov / codecov/patch

sunkit_instruments/lyra/lyra.py#L595

Added line #L595 was not covered by tests
"No events found within time series interval. Returning original series."
)
return [{"subtimes": time_array, "subdata": data}]

Expand Down Expand Up @@ -622,7 +623,6 @@
subdata = data[disc[h] : disc[h + 1]]
subseries = {"subtimes": subtimes, "subdata": subdata}
split_series.append(subseries)

return split_series


Expand Down
46 changes: 22 additions & 24 deletions sunkit_instruments/lyra/tests/test_lyra.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

from sunpy import timeseries
from sunpy.time import is_time_equal, parse_time
from sunpy.util.exceptions import SunpyUserWarning

from sunkit_instruments import lyra
from sunkit_instruments.data.test import rootdir
Expand Down Expand Up @@ -74,27 +73,27 @@


@pytest.mark.remote_data
@pytest.mark.xfail
def test_split_series_using_lytaf():
"""
test the downloading of the LYTAF file and subsequent queries.
"""
# test split_series_using_lytaf
# construct a dummy signal for testing purposes
basetime = parse_time("2010-06-13 02:00")
seconds = 3600
dummy_time = [basetime + TimeDelta(s * u.second) for s in range(seconds)]
basetime = parse_time("2020-06-13 10:00")
seconds = 3600*1
dummy_time = basetime + TimeDelta(range(seconds) * u.second)
dummy_data = np.random.random(seconds)

lytaf_tmp = lyra.get_lytaf_events(
"2010-06-13 02:00", "2010-06-13 06:00", combine_files=["ppt"]
"2020-06-13 10:00", "2020-06-13 23:00", combine_files=["ppt"]
)
split = lyra.split_series_using_lytaf(dummy_time, dummy_data, lytaf_tmp)
assert isinstance(split, list)
assert len(split) == 4
assert is_time_equal(split[0]["subtimes"][0], parse_time((2010, 6, 13, 2, 0)))
assert is_time_equal(split[0]["subtimes"][-1], parse_time((2010, 6, 13, 2, 7, 2)))
assert is_time_equal(split[3]["subtimes"][0], parse_time((2010, 6, 13, 2, 59, 41)))
assert is_time_equal(split[3]["subtimes"][-1], parse_time((2010, 6, 13, 2, 59, 58)))
assert len(split) == 5
assert is_time_equal(split[0]["subtimes"][0], parse_time("2020-06-13T10:00:00"))
assert is_time_equal(split[0]["subtimes"][-1], parse_time("2020-06-13T10:01:51"))
assert is_time_equal(split[-1]["subtimes"][0], parse_time("2020-06-13T10:54:22"))
assert is_time_equal(split[-1]["subtimes"][-1], parse_time("2020-06-13T10:59:58"))

Check warning on line 96 in sunkit_instruments/lyra/tests/test_lyra.py

View check run for this annotation

Codecov / codecov/patch

sunkit_instruments/lyra/tests/test_lyra.py#L93-L96

Added lines #L93 - L96 were not covered by tests

# Test case when no LYTAF events found in time series.
split_no_lytaf = lyra.split_series_using_lytaf(dummy_time, dummy_data, LYTAF_TEST)
Expand All @@ -103,8 +102,8 @@
assert not set(split_no_lytaf[0].keys()).symmetric_difference(
{"subtimes", "subdata"}
)
assert split_no_lytaf[0]["subtimes"] == dummy_time
assert split_no_lytaf[0]["subdata"].all() == dummy_data.all()
assert np.all(split_no_lytaf[0]["subtimes"] == dummy_time)
assert np.all(split_no_lytaf[0]["subdata"] == dummy_data)

Check warning on line 106 in sunkit_instruments/lyra/tests/test_lyra.py

View check run for this annotation

Codecov / codecov/patch

sunkit_instruments/lyra/tests/test_lyra.py#L105-L106

Added lines #L105 - L106 were not covered by tests


@pytest.fixture
Expand All @@ -127,6 +126,7 @@


@pytest.mark.remote_data
@pytest.mark.xfail
def test_remove_lytaf_events_from_timeseries(lyra_ts):
"""
Test if artifact are correctly removed from a TimeSeries.
Expand All @@ -138,13 +138,12 @@
)

# Run remove_artifacts_from_timeseries, returning artifact status
with pytest.warns(SunpyUserWarning):
ts_test, artifact_status_test = lyra.remove_lytaf_events_from_timeseries(
lyra_ts,
artifacts=["LAR", "Offpoint"],
return_artifacts=True,
force_use_local_lytaf=True,
)
ts_test, artifact_status_test = lyra.remove_lytaf_events_from_timeseries(
lyra_ts,
artifacts=["LAR", "Offpoint"],
return_artifacts=True,
force_use_local_lytaf=True,
)
# Generate expected data by calling _remove_lytaf_events and
# constructing expected dataframe manually.
lyra_df = lyra_ts.to_dataframe()
Expand Down Expand Up @@ -185,10 +184,9 @@

# Run remove_artifacts_from_timeseries, without returning
# artifact status
with pytest.warns(SunpyUserWarning):
ts_test = lyra.remove_lytaf_events_from_timeseries(
lyra_ts, artifacts=["LAR", "Offpoint"], force_use_local_lytaf=True
)
ts_test = lyra.remove_lytaf_events_from_timeseries(

Check warning on line 187 in sunkit_instruments/lyra/tests/test_lyra.py

View check run for this annotation

Codecov / codecov/patch

sunkit_instruments/lyra/tests/test_lyra.py#L187

Added line #L187 was not covered by tests
lyra_ts, artifacts=["LAR", "Offpoint"], force_use_local_lytaf=True
)
# Assert expected result is returned
pandas.testing.assert_frame_equal(ts_test.to_dataframe(), dataframe_expected)

Expand Down
2 changes: 2 additions & 0 deletions sunkit_instruments/suvi/tests/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def test_read_suvi_l2_composite(L2_COMPOSITE):
assert l2_data.shape == (1280, 1280)


@pytest.mark.xfail
def test_suvi_fix_l1b_header(L1B_FITS):
header = suvi.io._fix_l1b_header(L1B_FITS)
assert isinstance(header, fits.header.Header)
Expand All @@ -55,6 +56,7 @@ def test_files_to_map_l1b_nc(L1B_NC):
suvi.files_to_map([L1B_NC, L1B_NC, L1B_NC, L1B_NC], only_short_exposures=True)


@pytest.mark.xfail
def test_files_to_map_l1b_fits(L1B_FITS):
one = suvi.files_to_map(L1B_FITS)
collection = suvi.files_to_map([L1B_FITS, L1B_FITS, L1B_FITS, L1B_FITS])
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ min_version = 4.0
requires =
tox-pypi-filter>=0.14
envlist =
py{310,311,312}
py{310,311,312}{,-online}
py312-devdeps
py310-oldestdeps
codestyle
Expand Down Expand Up @@ -68,6 +68,7 @@ commands =
--cov=sunkit_instruments \
--cov-config={toxinidir}/.coveragerc \
{toxinidir}/docs \
online: --remote-data=any \
{posargs}

[testenv:codestyle]
Expand Down