-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pin zarr and add check unique ping time duplicates and tests
- Loading branch information
Showing
4 changed files
with
103 additions
and
5 deletions.
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,44 @@ | ||
import logging | ||
|
||
import xarray as xr | ||
|
||
|
||
def check_unique_ping_time_duplicates(ds_data: xr.Dataset, logger: logging.Logger) -> None: | ||
""" | ||
Raises a warning if the data stored in duplicate pings is not unique. | ||
Parameters | ||
---------- | ||
ds_data : xr.Dataset | ||
Single freq beam dataset being processed in the `SetGroupsEK80.set_beams` class function. | ||
logger : logging.Logger | ||
Warning logger initialized in `SetGroupsEK80` file. | ||
""" | ||
# Group the dataset by the "ping_time" coordinate | ||
groups = ds_data.groupby("ping_time") | ||
|
||
# Loop through each ping_time group | ||
for ping_time_val, group in groups: | ||
# Extract all data variable names to check | ||
data_vars = list(group.data_vars) | ||
|
||
# Use the first duplicate ping time index as a reference | ||
ref_duplicate_ping_time_index = 0 | ||
|
||
# Iterate over each data variable in the group | ||
for var in data_vars: | ||
# Extract data array corresponding to the iterated variable | ||
data_array = group[var] | ||
|
||
# Use the slice corresponding to the reference index as the reference slice | ||
ref_slice = data_array.isel({"ping_time": ref_duplicate_ping_time_index}) | ||
|
||
# Iterate over the remaining entries | ||
for i in range(1, data_array.sizes["ping_time"]): | ||
if not ref_slice.equals(data_array.isel({"ping_time": i})): | ||
logger.warning( | ||
f"Duplicate slices in variable '{var}' corresponding to " | ||
f"ping_time {ping_time_val} differ in data. Data will be lost since we " | ||
"will be dropping all duplicate ping times." | ||
) | ||
break |
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ pytz | |
scipy | ||
xarray | ||
pandas | ||
zarr | ||
zarr>=2,<3 | ||
fsspec | ||
s3fs | ||
requests | ||
|