Skip to content

Commit 46d2c08

Browse files
committed
Linting
1 parent 88118cc commit 46d2c08

2 files changed

Lines changed: 44 additions & 34 deletions

File tree

seagliderOG1/tools.py

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
# in the sg_cal strings, e.g. calibcomm_oxygen or calibcomm_optode contains 'SBE 43F' or 'Optode 4330F'
2828
# Using this, and the presence of calibration coefficients (e.g., optode_FoilCoefA1), we can make
2929
# a guess as to the sensor type
30-
def gather_sensor_info(ds_other: xr.Dataset, ds_sgcal: xr.Dataset, firstrun: bool = False) -> xr.Dataset:
30+
def gather_sensor_info(
31+
ds_other: xr.Dataset, ds_sgcal: xr.Dataset, firstrun: bool = False
32+
) -> xr.Dataset:
3133
"""
3234
Gathers sensor information from the provided datasets and organizes it into a new dataset.
3335
@@ -81,7 +83,9 @@ def gather_sensor_info(ds_other: xr.Dataset, ds_sgcal: xr.Dataset, firstrun: boo
8183
ds_sensor["aa4330"].attrs["ancillary_variables"] = aanderaa_ancillary
8284

8385

84-
def add_sensor_to_dataset(dsa: xr.Dataset, ds: xr.Dataset, sg_cal: xr.Dataset, firstrun: bool = False) -> xr.Dataset:
86+
def add_sensor_to_dataset(
87+
dsa: xr.Dataset, ds: xr.Dataset, sg_cal: xr.Dataset, firstrun: bool = False
88+
) -> xr.Dataset:
8589
"""
8690
Add sensor information to the dataset based on instrument data and calibration parameters.
8791
@@ -522,12 +526,12 @@ def calc_Z(ds: xr.Dataset) -> xr.Dataset:
522526
def get_sg_attrs(ds: xr.Dataset) -> dict:
523527
"""
524528
Extract seaglider attributes and calibration information into a dictionary.
525-
529+
526530
Parameters
527531
----------
528532
ds
529533
Dataset containing seaglider attributes and calibration data.
530-
534+
531535
Returns
532536
-------
533537
dict
@@ -577,15 +581,15 @@ def split_by_unique_dims(ds: xr.Dataset) -> dict:
577581
def convert_units(ds: xr.Dataset) -> xr.Dataset:
578582
"""
579583
Convert the units of variables in an xarray Dataset to preferred units.
580-
584+
581585
This is useful, for instance, to convert cm/s to m/s based on vocabulary
582586
specifications.
583-
587+
584588
Parameters
585589
----------
586590
ds
587591
The dataset containing variables to convert.
588-
592+
589593
Returns
590594
-------
591595
xarray.Dataset
@@ -620,10 +624,12 @@ def convert_units(ds: xr.Dataset) -> xr.Dataset:
620624
return ds
621625

622626

623-
def reformat_units_var(ds: xr.Dataset, var_name: str, unit_format: dict = vocabularies.unit_str_format) -> str:
627+
def reformat_units_var(
628+
ds: xr.Dataset, var_name: str, unit_format: dict = vocabularies.unit_str_format
629+
) -> str:
624630
"""
625631
Rename units in the dataset based on the provided dictionary for OG1.
626-
632+
627633
Parameters
628634
----------
629635
ds
@@ -632,7 +638,7 @@ def reformat_units_var(ds: xr.Dataset, var_name: str, unit_format: dict = vocabu
632638
The name of the variable whose units should be reformatted.
633639
unit_format, optional
634640
A dictionary mapping old unit strings to new formatted unit strings.
635-
641+
636642
Returns
637643
-------
638644
str
@@ -658,17 +664,19 @@ def reformat_units_var(ds: xr.Dataset, var_name: str, unit_format: dict = vocabu
658664
return new_unit
659665

660666

661-
def reformat_units_str(old_unit: str, unit_format: dict = vocabularies.unit_str_format) -> str:
667+
def reformat_units_str(
668+
old_unit: str, unit_format: dict = vocabularies.unit_str_format
669+
) -> str:
662670
"""
663671
Reformat a unit string based on the provided unit format dictionary.
664-
672+
665673
Parameters
666674
----------
667675
old_unit
668676
The original unit string to reformat.
669677
unit_format, optional
670678
A dictionary mapping old unit strings to new formatted unit strings.
671-
679+
672680
Returns
673681
-------
674682
str
@@ -725,23 +733,23 @@ def convert_units_var(
725733
def convert_qc_flags(dsa: xr.Dataset, qc_name: str) -> xr.Dataset:
726734
"""
727735
Convert QC flag variables to proper integer format and update attributes.
728-
736+
729737
This function converts QC flag variables from string format to int8,
730738
handles NaN values appropriately, removes 'QC_' prefixes from flag meanings,
731739
and adds proper metadata including long_name and standard_name.
732-
740+
733741
Parameters
734742
----------
735743
dsa
736744
The dataset containing QC flag variables.
737745
qc_name
738746
The name of the QC flag variable to process.
739-
747+
740748
Returns
741749
-------
742750
xarray.Dataset
743751
Dataset with converted QC flag variable and updated attributes.
744-
752+
745753
Notes
746754
-----
747755
Must be called after the main variable has been assigned its OG1 long_name.
@@ -780,19 +788,19 @@ def convert_qc_flags(dsa: xr.Dataset, qc_name: str) -> xr.Dataset:
780788
def find_best_dtype(var_name: str, da: xr.DataArray) -> type:
781789
"""
782790
Determine the optimal data type for a variable based on its name and values.
783-
791+
784792
Parameters
785793
----------
786794
var_name
787795
The name of the variable.
788796
da
789797
The data array to analyze.
790-
798+
791799
Returns
792800
-------
793801
type
794802
The recommended numpy data type.
795-
803+
796804
Notes
797805
-----
798806
- Latitude/longitude variables use double precision
@@ -821,12 +829,12 @@ def find_best_dtype(var_name: str, da: xr.DataArray) -> type:
821829
def set_fill_value(new_dtype: type) -> int:
822830
"""
823831
Calculate appropriate fill value for integer data types.
824-
832+
825833
Parameters
826834
----------
827835
new_dtype
828836
The target integer data type.
829-
837+
830838
Returns
831839
-------
832840
int
@@ -839,12 +847,12 @@ def set_fill_value(new_dtype: type) -> int:
839847
def set_best_dtype(ds: xr.Dataset) -> xr.Dataset:
840848
"""
841849
Optimize data types across all variables in the dataset to reduce memory usage.
842-
850+
843851
Parameters
844852
----------
845853
ds
846854
The dataset to optimize.
847-
855+
848856
Returns
849857
-------
850858
xarray.Dataset
@@ -904,17 +912,15 @@ def set_best_dtype_value(value, var_name: str):
904912
return converted_value
905913

906914

907-
908-
909915
def encode_times(ds: xr.Dataset) -> xr.Dataset:
910916
"""
911917
Encode time variables with standard units and remove problematic attributes.
912-
918+
913919
Parameters
914920
----------
915921
ds
916922
Dataset containing time variables to encode.
917-
923+
918924
Returns
919925
-------
920926
xarray.Dataset
@@ -937,12 +943,12 @@ def encode_times(ds: xr.Dataset) -> xr.Dataset:
937943
def encode_times_og1(ds: xr.Dataset) -> xr.Dataset:
938944
"""
939945
Encode time variables according to OG1 format specifications.
940-
946+
941947
Parameters
942948
----------
943949
ds
944950
Dataset containing time variables to encode.
945-
951+
946952
Returns
947953
-------
948954
xarray.Dataset
@@ -963,7 +969,9 @@ def encode_times_og1(ds: xr.Dataset) -> xr.Dataset:
963969
return ds
964970

965971

966-
def merge_parts_of_dataset(ds: xr.Dataset, dim1: str = "sg_data_point", dim2: str = "ctd_data_point") -> xr.Dataset:
972+
def merge_parts_of_dataset(
973+
ds: xr.Dataset, dim1: str = "sg_data_point", dim2: str = "ctd_data_point"
974+
) -> xr.Dataset:
967975
"""
968976
Merges variables from a dataset along two dimensions, ensuring consistency in coordinates.
969977
The function first separates the dataset into two datasets based on the specified dimensions,
@@ -1067,7 +1075,9 @@ def pad_ds(ds, max_size):
10671075
return merged_ds
10681076

10691077

1070-
def combine_two_dim_of_dataset(ds: xr.Dataset, dim1: str = "sg_data_point", dim2: str = "ctd_data_point") -> xr.Dataset:
1078+
def combine_two_dim_of_dataset(
1079+
ds: xr.Dataset, dim1: str = "sg_data_point", dim2: str = "ctd_data_point"
1080+
) -> xr.Dataset:
10711081
"""
10721082
Updates the original dataset by removing variables with dim1 and dim2
10731083
and adding the merged dataset.

seagliderOG1/writers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
def save_dataset(ds, output_file="../test.nc"):
1010
"""
1111
Attempts to save the dataset to a NetCDF file.
12-
13-
If a TypeError occurs due to invalid attribute values, converts the invalid
12+
13+
If a TypeError occurs due to invalid attribute values, converts the invalid
1414
attributes to strings and retries the save operation.
1515
1616
Parameters

0 commit comments

Comments
 (0)