Source code for swxsoc.net.attr

"""
Search attribute classes and walker for the SWXSOC FIDO client.

This module defines custom search attributes used by the SWXSOCClient
to query SWXSOC data archives on AWS S3.
"""

import sunpy.net.attrs as a
from sunpy.net.attr import AttrAnd, AttrOr, AttrWalker, SimpleAttr

__all__ = [
    "SearchTime",
    "Level",
    "Instrument",
    "Descriptor",
    "DevelopmentBucket",
    "walker",
]

# Initialize the attribute walker
walker = AttrWalker()


# Map sunpy attributes to SWXSOC attributes for easy access
[docs] class SearchTime(a.Time): """ Attribute for specifying the time range for the search. Attributes ---------- start : `str` The start time in ISO format. end : `str` The end time in ISO format. """
[docs] class Level(a.Level): """ Attribute for specifying the data level for the search. Attributes ---------- value : str The data level value. """
[docs] class Instrument(a.Instrument): """ Attribute for specifying the instrument for the search. Attributes ---------- value : str The instrument value. """
[docs] class Descriptor(a.Detector): """ Attribute to specify the data type for the search. Attributes ---------- value : str The data type """
[docs] class DevelopmentBucket(SimpleAttr): """ Attribute for specifying whether to search in the DevelopmentBucket for testing purposes. Attributes ---------- value : bool Whether to use the DevelopmentBucket. Defaults to False. """
@walker.add_creator(AttrOr) def create_or(wlk, tree): """ Creates an 'AttrOr' object from the provided tree of attributes. Parameters ---------- wlk : AttrWalker The AttrWalker instance used for creating the attributes. tree : AttrOr The 'AttrOr' tree structure. Returns ------- list A list of created attributes. """ results = [] for sub in tree.attrs: results.append(wlk.create(sub)) return results @walker.add_creator(AttrAnd) def create_and(wlk, tree): """ Creates an 'AttrAnd' object from the provided tree of attributes. Parameters ---------- wlk : AttrWalker The AttrWalker instance used for creating the attributes. tree : AttrAnd The 'AttrAnd' tree structure. Returns ------- list A list containing a single dictionary of attributes. """ result = {} for sub in tree.attrs: wlk.apply(sub, result) return [result] @walker.add_applier(SearchTime) def apply_time(wlk, attr, params): """ Applies 'a.Time' attribute to the parameters. Parameters ---------- wlk : AttrWalker The AttrWalker instance used for applying the attributes. attr : a.Time The 'a.Time' attribute to be applied. params : dict The parameters dictionary to be updated. """ params.update({"startTime": attr.start.isot, "endTime": attr.end.isot}) @walker.add_applier(Level) def apply_level(wlk, attr, params): """ Applies 'a.Level' attribute to the parameters. Parameters ---------- wlk : AttrWalker The AttrWalker instance used for applying the attributes. attr : a.Level The 'a.Level' attribute to be applied. params : dict The parameters dictionary to be updated. """ params.update({"level": attr.value.lower()}) @walker.add_applier(Instrument) def apply_instrument(wlk, attr, params): """ Applies 'a.Instrument' attribute to the parameters. Parameters ---------- wlk : AttrWalker The AttrWalker instance used for applying the attributes. attr : a.Instrument The 'a.Instrument' attribute to be applied. params : dict The parameters dictionary to be updated. """ params.update({"instrument": attr.value.upper()}) @walker.add_applier(DevelopmentBucket) def apply_development_bucket(wlk, attr, params): """ Applies 'DevelopmentBucket' attribute to the parameters. Parameters ---------- wlk : AttrWalker The AttrWalker instance used for applying the attributes. attr : DevelopmentBucket The 'DevelopmentBucket' attribute to be applied. params : dict The parameters dictionary to be updated. """ params.update({"use_development_bucket": attr.value}) @walker.add_applier(Descriptor) def apply_descriptor(wlk, attr, params): """ Applies 'Descriptor' attribute to the parameters. Parameters ---------- wlk : AttrWalker The AttrWalker instance used for applying the attributes. attr : Descriptor The 'Descriptor' attribute to be applied. params : dict The parameters dictionary to be updated. """ params.update({"descriptor": attr.value})