-
Notifications
You must be signed in to change notification settings - Fork 9
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
NPI-3669 Migrate SP3 transform and trim, introduce minimal SP3 creation utility script #63
Merged
ronaldmaj
merged 9 commits into
main
from
NPI-3669-utility-func-for-minimal-sp3-generation
Jan 8, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9a6f05e
NPI-3669 add sp3 transformation and trimming functionality (from othe…
treefern 7a8ae97
NPI-3669 update filter_by_svs() to make all filtering args properly o…
treefern 8dd48a2
NPI-3669 more unit tests for sp3 processing, filter_by_svs(), trim_df…
treefern 48c3701
NPI-3669 break out trim_to_first_n_epochs() as a utility function, up…
treefern 8f45be9
NPI-3669 add notes on important unit tests which remain to be added t…
treefern d5b7ea4
Merge branch 'main' into NPI-3669-utility-func-for-minimal-sp3-genera…
treefern 7241486
NPI-3669 added docstrings based on PR comments, added more notes for …
treefern a15cd42
NPI-3669 cleanup of redundent comment
treefern 0945e26
NPI-3669 update docstrings in sp3.py for consistency, in response to …
treefern 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 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 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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from datetime import timedelta | ||
from typing import Optional | ||
from gnssanalysis.filenames import convert_nominal_span, determine_properties_from_filename | ||
from gnssanalysis.gn_io.sp3 import filter_by_svs, read_sp3, trim_to_first_n_epochs, write_sp3, remove_offline_sats | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
#### Configuration #### | ||
|
||
src_path = "IGS0DEMULT_20243181800_02D_05M_ORB.SP3" | ||
dest_path = "IGS0DEMULT_20243181800_02D_05M_ORB.SP3-trimmed" | ||
|
||
# Constrain to x SVs, specific SV names, both, or neither | ||
trim_to_sv_names: Optional[list[str]] = ["G02", "G03", "G19"] | ||
trim_to_sv_count: Optional[int] = None # 1 | ||
trim_to_sat_letter: Optional[str] = None # "E" | ||
|
||
# How many epochs to include in the trimmed file (offset from start) | ||
trim_to_num_epochs: int = 3 | ||
|
||
drop_offline_sats: bool = False | ||
|
||
#### End configuration #### | ||
|
||
|
||
filename = src_path.rsplit("/")[-1] | ||
print(f"Filename is: {filename}") | ||
|
||
# Raw data would be: determine_sp3_name_props() - that retrieves in seconds. But we want to be more generally applicable, so not just SP3 here ideally. | ||
sample_rate: timedelta = convert_nominal_span(determine_properties_from_filename(filename)["sampling_rate"]) | ||
print(f"sample_rate is: {sample_rate}") | ||
|
||
# Load | ||
print("Loading SP3 into DataFrame...") | ||
sp3_df = read_sp3(src_path) | ||
|
||
# Trim to first x epochs | ||
print(f"Trimming to first {trim_to_num_epochs} epochs") | ||
sp3_df = trim_to_first_n_epochs(sp3_df=sp3_df, epoch_count=trim_to_num_epochs, sp3_filename=filename) | ||
|
||
# Filter to chosen SVs or number of SVs... | ||
print( | ||
f"Applying SV filters (max count: {trim_to_sv_count}, limit to names: {trim_to_sv_names}, limit to constellation: {trim_to_sat_letter})..." | ||
) | ||
sp3_df = filter_by_svs( | ||
sp3_df, filter_by_count=trim_to_sv_count, filter_by_name=trim_to_sv_names, filter_to_sat_letter=trim_to_sat_letter | ||
) | ||
|
||
# Drop offline sats if requested | ||
if drop_offline_sats: | ||
print(f"Dropping offline sats...") | ||
sp3_df = remove_offline_sats(sp3_df) | ||
|
||
# Write out | ||
print( | ||
"Writing out new SP3 file... " | ||
'CAUTION: at the time of writing the header is based on stale metadata in .attrs["HEADER"], not the contents ' | ||
"of the dataframe. It will need to be manually updated." | ||
) | ||
write_sp3(sp3_df, dest_path) | ||
|
||
# Test if we can successfully read that file... | ||
print("Testing re-read of the output file...") | ||
re_read = read_sp3(dest_path) |
Oops, something went wrong.
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.
Very useful function and I've tested it now on a sample SP3 file - works great!