Update data tools and fixes #65
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the lompe.data_tools download/read helpers (SuperMAG, AMPERE/Iridium, SuperDARN, CHAMP, DMSP) and adds a vendored SuperMAG API client module intended to support more robust SuperMAG downloads.
Changes:
- Refactors SuperMAG downloading to use a SuperMAG API client with retries/parallel station fetch and Lompe-style output formatting.
- Adjusts several data tools for small robustness/behavior tweaks (Iridium variable handling, SuperDARN “file exists” behavior, formatting fixes, clearer CHAMP message).
- Adds a new
supermag_api.pymodule (vendored API client).
Reviewed changes
Copilot reviewed 7 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
lompe/data_tools/supermag.py |
Refactor SuperMAG download flow to use an API client + retries and output conversion. |
lompe/data_tools/supermag_api.py |
Adds a vendored SuperMAG API client implementation. |
lompe/data_tools/superdarn.py |
Minor behavior change when cached SuperDARN file exists. |
lompe/data_tools/get_lompe_data.py |
Updates Swarm import and default paths; minor formatting change. |
lompe/data_tools/dmsp_ssies.py |
Indentation/formatting adjustments in spline prep calls. |
lompe/data_tools/dataloader.py |
Updates Iridium raw-file globbing and supports b_eci vs db_eci. |
lompe/data_tools/champ.py |
Updates the “no data” message to include CHAMP availability range. |
lompe/data_tools/ampere.py |
Adds “file exists” log and minor formatting change. |
Comments suppressed due to low confidence (3)
lompe/data_tools/supermag.py:156
_get_supermag_inventoryignores thestatusreturn value fromSuperMAGGetInventory. On HTTP/API errors the underlying client returnsstatus=0and an error payload, which can be mistaken for a non-empty station list and later cause bogus station downloads. Checkstatusand raise/retry when it is false, and consider validating that station entries look like station codes before returning.
try:
status, stations = SuperMAGGetInventory(userid, start, extent)
if stations is None or len(stations) == 0:
raise ValueError("No stations returned")
return stations
lompe/data_tools/supermag.py:281
_get_supermag_all_stationsreads station metadata from an absolute, user-specific path (/Users/.../supermag_stations_info.csv). This will fail for everyone else (including CI) and breaks the downloader out of the box. Either ship this CSV as package data and load it viaimportlib.resources, query station latitudes from SuperMAG, or make the high-latitude filter optional with a configurable path/threshold.
smag_stations = pd.read_csv(
"/Users/fasilkebede/Documents/LOMPE/substorm/supermag_stations_info.csv"
)
high_lat = smag_stations[smag_stations["GEOLAT"] >= 50]
stations = np.intersect1d(stations, high_lat["IAGA"].values)
lompe/data_tools/supermag.py:33
- Typo in docstring: "geogrpahic" → "geographic".
"""Download SuperMAG geogrpahic magnetic field data for one event day.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+12
to
+18
| try: | ||
| from supermag_api.supermag_api import * | ||
| except ImportError: | ||
| raise ImportError( | ||
| "supermag-api is not installed. Install it with:\n\n" | ||
| "pip install supermag-api" | ||
| ) |
Comment on lines
10
to
+16
| from .champ import download_champ | ||
| from .superdarn import download_sdarn | ||
| from .swarm import download_swarm | ||
| from .swarm import download_swarm_mag | ||
| from .dmsp_ssies import download_dmsp_ssies | ||
|
|
||
|
|
||
| def prepare_event_data(event, data_path="./lompe_data/", sources=None, basepath="./", **kwargs): | ||
| def prepare_event_data(event, data_path="./sample_dataset/", sources=None, basepath="./sample_dataset/", **kwargs): |
Comment on lines
+18
to
+24
| ;supermag_api.py | ||
| ; ================ | ||
| ; Author S. Antunes, based on supermag-api.pro by R.J.Barnes | ||
|
|
||
|
|
||
| ; (c) 2021 The Johns Hopkins University Applied Physics Laboratory | ||
| ;LLC. All Rights Reserved. |
| except Exception as e: | ||
| print(f"No champ data in this period: {e}") | ||
| print( | ||
| f"No champ data: Champ data available (2000-07-19 to 2010-09-17), returning: {e}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scripts to download data in the data_tools folder are fixed and example (data_tools_example.ipynb) on how to use it added in the examples folder.