-
Notifications
You must be signed in to change notification settings - Fork 44
Fix GNSS data retrieval and downloading functions #794
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
Open
sssangha
wants to merge
3
commits into
dev
Choose a base branch
from
unr_archive_migration
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+58
−18
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,19 +69,35 @@ def get_station_list( | |
|
|
||
| def get_stats_by_llh(llhBox=None, baseURL=_UNR_URL): | ||
| """ | ||
| Function to pull lat, lon, height, beginning date, end date, and number of solutions for stations inside the bounding box llhBox. | ||
| llhBox should be a tuple in SNWE format. | ||
| Pull lat, lon, height for stations inside the bounding box from | ||
| both legacy and IGS20 UNR holdings. Prioritizes IGS20 coordinates. | ||
| """ | ||
| if llhBox is None: | ||
| llhBox = [-90, 90, -180, 180] | ||
| S, N, W, E = llhBox | ||
|
|
||
| stationHoldings = f'{baseURL}NGLStationPages/llh.out' | ||
| # it's a file like object and works just like a file | ||
| url_legacy = f'{baseURL}NGLStationPages/llh.out' | ||
| url_igs20 = f'{baseURL}gps_timeseries/IGS20/llh/llh.out' | ||
| col_names = ['ID', 'Lat', 'Lon', 'Hgt_m'] | ||
|
|
||
| # Read legacy list | ||
| try: | ||
| stat_leg = pd.read_csv(url_legacy, sep=r'\s+', names=col_names) | ||
| except Exception as e: | ||
| logger.warning("Failed to fetch legacy llh.out: %s", e) | ||
| stat_leg = pd.DataFrame(columns=col_names) | ||
|
|
||
| # Read IGS20 list | ||
| try: | ||
| stat_igs = pd.read_csv(url_igs20, sep=r'\s+', names=col_names) | ||
| except Exception as e: | ||
| logger.warning("Failed to fetch IGS20 llh.out: %s", e) | ||
| stat_igs = pd.DataFrame(columns=col_names) | ||
|
|
||
| stations = pd.read_csv(stationHoldings, sep=r'\s+', names=['ID', 'Lat', 'Lon', 'Hgt_m']) | ||
| # Combine prioritizing IGS20 (placing it first and keeping 'first') | ||
| stations = pd.concat([stat_igs, stat_leg], ignore_index=True) | ||
| stations.drop_duplicates(subset=['ID'], keep='first', inplace=True) | ||
|
|
||
| # convert lons from [-360, 0] to [-180, 180] | ||
| # Convert lons from [-360, 0] to [-180, 180] | ||
| stations['Lon'] = ((stations['Lon'].values + 180) % 360) - 180 | ||
|
|
||
| stations = filterToBBox(stations, llhBox) | ||
|
|
@@ -142,7 +158,7 @@ def download_tropo_delays( | |
| def download_UNR(statID, year, writeDir=".", download=False, baseURL=_UNR_URL): | ||
| """ | ||
| Download a zip file containing tropospheric delays for a given | ||
| station and year. | ||
| station and year, with a fallback to the legacy archive. | ||
|
|
||
| The URL format is: | ||
| http://geodesy.unr.edu/gps_timeseries/IGS20/trop/<ssss>/ | ||
|
|
@@ -173,22 +189,45 @@ def download_UNR(statID, year, writeDir=".", download=False, baseURL=_UNR_URL): | |
| f"Data repository {baseURL} has not yet been implemented" | ||
| ) | ||
|
|
||
| URL = ( | ||
| stat_upper = statID.upper() | ||
|
|
||
| # First attempt: IGS20 framework | ||
| url_igs20 = ( | ||
| f"{baseURL}gps_timeseries/IGS20/trop/" | ||
| f"{statID.upper()}/{statID.upper()}.{year}.trop.zip" | ||
| f"{stat_upper}/{stat_upper}.{year}.trop.zip" | ||
| ) | ||
|
|
||
| # Fallback: Legacy operational framework | ||
| url_legacy = ( | ||
| f"{baseURL}gps_timeseries/trop/" | ||
| f"{stat_upper}/{stat_upper}.{year}.trop.zip" | ||
| ) | ||
|
|
||
| logger.debug("Currently checking station %s in %s", statID, year) | ||
| logger.debug("Checking station %s in %s", statID, year) | ||
|
|
||
| if download: | ||
| saveLoc = os.path.abspath( | ||
| os.path.join(writeDir, f"{statID.upper()}.{year}.trop.zip") | ||
| ) | ||
| filepath = download_url(URL, saveLoc) | ||
| if filepath == "": | ||
| raise ValueError("Year or station ID does not exist") | ||
| filename = f"{stat_upper}.{year}.trop.zip" | ||
| save_loc = os.path.abspath(os.path.join(writeDir, filename)) | ||
|
|
||
| # Try IGS20 first | ||
| filepath = download_url(url_igs20, save_loc) | ||
|
|
||
| # If IGS20 is missing, try legacy | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this work if a subset of stations is available but others are not? |
||
| if not filepath: | ||
| logger.debug( | ||
| "IGS20 not found for %s in %s. Trying legacy.", | ||
| statID, year | ||
| ) | ||
| filepath = download_url(url_legacy, save_loc) | ||
|
|
||
| if not filepath: | ||
| raise ValueError( | ||
| "Year or station ID does not exist in either archive" | ||
| ) | ||
| else: | ||
| filepath = check_url(URL) | ||
| filepath = check_url(url_igs20) | ||
| if not filepath: | ||
| filepath = check_url(url_legacy) | ||
|
|
||
| return {"ID": statID, "year": year, "path": filepath} | ||
|
|
||
|
|
||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sssangha would it make more sense to wrap all of the legacy calls within a single try/except that checks for stations for which IGS20 was successful for all stations and then pulls legacy data only for the subset of stations that are not available? That way the IGS20 is still the default and all the work needed if legacy stations are required is skipped unless they are actually needed.