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

Observation mode added as a new metadata. #140

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
11 changes: 11 additions & 0 deletions sunpy_soar/attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class SOOP(SimpleAttr):
"""


class ObservationMode(SimpleAttr):
"""
The mode of observation to search for.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have a fixed set of values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, for all instruments except SPICE, there aren't many observation modes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know what they are or if we can with that out?

Copy link
Contributor Author

@NucleonGodX NucleonGodX Aug 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can make a list, As Eric suggested for SPICE there are around 80-90. And for others there aren't a lot.

"""


walker = AttrWalker()


Expand Down Expand Up @@ -141,3 +147,8 @@ def _(wlk, attr, params): # NOQA: ARG001
wavemin = attr.min.value
wavemax = attr.max.value
params.append(f"Wavemin='{wavemin}'+AND+Wavemax='{wavemax}'")


@walker.add_applier(ObservationMode)
def _(wlk, attr, params): # NOQA: ARG001
params.append(f"Observation_mode='{attr.value}'")
15 changes: 11 additions & 4 deletions sunpy_soar/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from sunpy.net.base_client import BaseClient, QueryResponseTable
from sunpy.time import parse_time

from sunpy_soar.attrs import SOOP, Product, walker
from sunpy_soar.attrs import SOOP, ObservationMode, Product, walker

__all__ = ["SOARClient"]

Expand Down Expand Up @@ -71,7 +71,13 @@ def add_join_to_query(query: list[str], data_table: str, instrument_table: str):
parameter = f"Wavelength='{wavemin_match.group(1)}'"
elif wavemin_match and wavemax_match:
parameter = f"Wavemin='{wavemin_match.group(1)}'+AND+h2.Wavemax='{wavemax_match.group(1)}'"
prefix = "h1." if not parameter.startswith("Detector") and not parameter.startswith("Wave") else "h2."
prefix = (
"h1."
if not parameter.startswith("Detector")
and not parameter.startswith("Wave")
and not parameter.startswith("Observation")
else "h2."
)
if parameter.startswith("begin_time"):
time_list = parameter.split("+AND+")
final_query += f"h1.{time_list[0]}+AND+h1.{time_list[1]}+AND+"
Expand All @@ -90,7 +96,7 @@ def add_join_to_query(query: list[str], data_table: str, instrument_table: str):
)
if instrument_table:
from_part += f" JOIN {instrument_table} AS h2 USING (data_item_oid)"
select_part += ", h2.detector, h2.wavelength, h2.dimension_index"
select_part += ", h2.detector, h2.wavelength, h2.dimension_index, h2.observation_mode"
return where_part, from_part, select_part

@staticmethod
Expand Down Expand Up @@ -204,6 +210,7 @@ def _do_search(query):
)
if "detector" in info:
result_table["Detector"] = info["detector"]
result_table["Observation mode"] = info["observation_mode"]
if "wavelength" in info:
result_table["Wavelength"] = info["wavelength"]
result_table.sort("Start time")
Expand Down Expand Up @@ -253,7 +260,7 @@ def _can_handle_query(cls, *query):
True if this client can handle the given query.
"""
required = {a.Time}
optional = {a.Instrument, a.Detector, a.Wavelength, a.Level, a.Provider, Product, SOOP}
optional = {a.Instrument, a.Detector, a.Wavelength, a.Level, a.Provider, Product, SOOP, ObservationMode}
if not cls.check_attr_types_in_query(query, required, optional):
return False
# check to make sure the instrument attr passed is one provided by the SOAR.
Expand Down
20 changes: 16 additions & 4 deletions sunpy_soar/tests/test_sunpy_soar.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,18 @@ def test_wavelength_range():
assert all(table["Wavelength"] == 174)


def test_search_observation_mode():
instrument = a.Instrument("METIS")
time = a.Time("2022-03-01", "2022-03-02")
level = a.Level(2)
product = a.soar.Product("metis-vl-pol-angle")
observation = a.soar.ObservationMode("METIS_GENERIC")
res = Fido.search(instrument & time & level & product & observation)
assert len(res[0]) == 32
for table in res:
assert all(table["Observation mode"] == "METIS_GENERIC")


def test_join_science_query():
result = SOARClient._construct_payload( # NOQA: SLF001
[
Expand All @@ -246,8 +258,8 @@ def test_join_science_query():

assert result["QUERY"] == (
"SELECT+h1.instrument, h1.descriptor, h1.level, h1.begin_time, h1.end_time, "
"h1.data_item_id, h1.filesize, h1.filename, h1.soop_name, h2.detector, h2.wavelength, "
"h2.dimension_index+FROM+v_sc_data_item AS h1 JOIN v_eui_sc_fits AS h2 USING (data_item_oid)"
"h1.data_item_id, h1.filesize, h1.filename, h1.soop_name, h2.detector, h2.wavelength, h2.dimension_index, "
"h2.observation_mode+FROM+v_sc_data_item AS h1 JOIN v_eui_sc_fits AS h2 USING (data_item_oid)"
"+WHERE+h1.instrument='EUI'+AND+h1.begin_time>='2021-02-01+00:00:00'+AND+h1.begin_time<='2021-02-02+00:00:00'"
"+AND+h2.dimension_index='1'+AND+h1.level='L1'+AND+h1.descriptor='eui-fsi174-image'"
)
Expand All @@ -265,8 +277,8 @@ def test_join_low_latency_query():

assert result["QUERY"] == (
"SELECT+h1.instrument, h1.descriptor, h1.level, h1.begin_time, h1.end_time, "
"h1.data_item_id, h1.filesize, h1.filename, h1.soop_name, h2.detector, h2.wavelength, "
"h2.dimension_index+FROM+v_ll_data_item AS h1 JOIN v_eui_ll_fits AS h2 USING (data_item_oid)"
"h1.data_item_id, h1.filesize, h1.filename, h1.soop_name, h2.detector, h2.wavelength, h2.dimension_index, "
"h2.observation_mode+FROM+v_ll_data_item AS h1 JOIN v_eui_ll_fits AS h2 USING (data_item_oid)"
"+WHERE+h1.instrument='EUI'+AND+h1.begin_time>='2021-02-01+00:00:00'+AND+h1.begin_time<='2021-02-02+00:00:00'"
"+AND+h2.dimension_index='1'+AND+h1.level='LL01'+AND+h1.descriptor='eui-fsi174-image'"
)
Expand Down