Skip to content

Commit

Permalink
Update lyra code
Browse files Browse the repository at this point in the history
  • Loading branch information
nabobalis committed Oct 28, 2024
1 parent d075d05 commit a80a645
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
16 changes: 8 additions & 8 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 @@ -229,7 +230,7 @@ def _remove_lytaf_events(
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 @@ def get_lytaf_event_types(print_event_types=True):
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 @@ def get_lytaf_event_types(print_event_types=True):
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 @@ def split_series_using_lytaf(timearray, data, lytaf):
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 @@ def split_series_using_lytaf(timearray, data, lytaf):
subdata = data[disc[h] : disc[h + 1]]
subseries = {"subtimes": subtimes, "subdata": subdata}
split_series.append(subseries)

return split_series


Expand Down
23 changes: 11 additions & 12 deletions sunkit_instruments/lyra/tests/test_lyra.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,20 @@ def test_split_series_using_lytaf():
"""
# 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 95 in sunkit_instruments/lyra/tests/test_lyra.py

View check run for this annotation

Codecov / codecov/patch

sunkit_instruments/lyra/tests/test_lyra.py#L92-L95

Added lines #L92 - L95 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 @@ -102,8 +101,8 @@ def test_split_series_using_lytaf():
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 105 in sunkit_instruments/lyra/tests/test_lyra.py

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L104 - L105 were not covered by tests


@pytest.fixture
Expand Down

0 comments on commit a80a645

Please sign in to comment.