From e20bba7d0bf421b09d60e758e6228391292517e9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 20:11:22 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- disdrodb/issue/writer.py | 6 +- disdrodb/l0/routines.py | 106 +++++++++--------- disdrodb/tests/test_l0/test_l0a_processing.py | 12 +- .../tests/test_l0/test_l0b_nc_processing.py | 86 ++++++++------ disdrodb/tests/test_l0/test_l0b_processing.py | 44 ++++---- disdrodb/tests/test_l0/test_template_tools.py | 24 ++-- 6 files changed, 155 insertions(+), 123 deletions(-) diff --git a/disdrodb/issue/writer.py b/disdrodb/issue/writer.py index 111e36c7..5ce22ea6 100644 --- a/disdrodb/issue/writer.py +++ b/disdrodb/issue/writer.py @@ -30,7 +30,8 @@ def _write_issue_docs(f): """Provide template for issue.yml""" - f.write("""# This file is used to store timesteps/time periods with wrong/corrupted observation. + f.write( + """# This file is used to store timesteps/time periods with wrong/corrupted observation. # The specified timesteps are dropped during the L0 processing. # The time format used is the isoformat : YYYY-mm-dd HH:MM:SS. # The 'timesteps' key enable to specify the list of timesteps to be discarded. @@ -46,7 +47,8 @@ def _write_issue_docs(f): # - ['2018-08-01 12:00:00', '2018-08-01 14:00:00'] # - ['2018-08-01 15:44:30', '2018-08-01 15:59:31'] # - ['2018-08-02 12:44:30', '2018-08-02 12:59:31'] \n -""") +""" + ) return None diff --git a/disdrodb/l0/routines.py b/disdrodb/l0/routines.py index fb2e4023..fb748c2b 100644 --- a/disdrodb/l0/routines.py +++ b/disdrodb/l0/routines.py @@ -201,24 +201,26 @@ def run_disdrodb_l0a_station( ): """Run the L0A processing of a station calling the disdrodb_l0a_station in the terminal.""" # Define command - cmd = " ".join([ - "disdrodb_run_l0a_station", - # Station arguments - data_source, - campaign_name, - station_name, - # Processing options - "--force", - str(force), - "--verbose", - str(verbose), - "--debugging_mode", - str(debugging_mode), - "--parallel", - str(parallel), - "--base_dir", - str(base_dir), - ]) + cmd = " ".join( + [ + "disdrodb_run_l0a_station", + # Station arguments + data_source, + campaign_name, + station_name, + # Processing options + "--force", + str(force), + "--verbose", + str(verbose), + "--debugging_mode", + str(debugging_mode), + "--parallel", + str(parallel), + "--base_dir", + str(base_dir), + ] + ) # Execute command _execute_cmd(cmd) return None @@ -239,26 +241,28 @@ def run_disdrodb_l0b_station( ): """Run the L0B processing of a station calling disdrodb_run_l0b_station in the terminal.""" # Define command - cmd = " ".join([ - "disdrodb_run_l0b_station", - # Station arguments - data_source, - campaign_name, - station_name, - # Processing options - "--force", - str(force), - "--verbose", - str(verbose), - "--debugging_mode", - str(debugging_mode), - "--parallel", - str(parallel), - "--remove_l0a", - str(remove_l0a), - "--base_dir", - str(base_dir), - ]) + cmd = " ".join( + [ + "disdrodb_run_l0b_station", + # Station arguments + data_source, + campaign_name, + station_name, + # Processing options + "--force", + str(force), + "--verbose", + str(verbose), + "--debugging_mode", + str(debugging_mode), + "--parallel", + str(parallel), + "--remove_l0a", + str(remove_l0a), + "--base_dir", + str(base_dir), + ] + ) # Execute command _execute_cmd(cmd) return None @@ -276,18 +280,20 @@ def run_disdrodb_l0b_concat_station( This function runs the ``disdrodb_run_l0b_concat_station`` script in the terminal. """ - cmd = " ".join([ - "disdrodb_run_l0b_concat_station", - data_source, - campaign_name, - station_name, - "--remove_l0b", - str(remove_l0b), - "--verbose", - str(verbose), - "--base_dir", - str(base_dir), - ]) + cmd = " ".join( + [ + "disdrodb_run_l0b_concat_station", + data_source, + campaign_name, + station_name, + "--remove_l0b", + str(remove_l0b), + "--verbose", + str(verbose), + "--base_dir", + str(base_dir), + ] + ) _execute_cmd(cmd) diff --git a/disdrodb/tests/test_l0/test_l0a_processing.py b/disdrodb/tests/test_l0/test_l0a_processing.py index 25080bbe..f323251b 100644 --- a/disdrodb/tests/test_l0/test_l0a_processing.py +++ b/disdrodb/tests/test_l0/test_l0a_processing.py @@ -336,11 +336,13 @@ def test_is_not_corrupted(): def test_cast_column_dtypes(): # Create a test dataframe with object columns - df = pd.DataFrame({ - "time": ["2022-01-01 00:00:00", "2022-01-01 00:05:00", "2022-01-01 00:10:00"], - "station_number": "station_number", - "altitude": "8849", - }) + df = pd.DataFrame( + { + "time": ["2022-01-01 00:00:00", "2022-01-01 00:05:00", "2022-01-01 00:10:00"], + "station_number": "station_number", + "altitude": "8849", + } + ) # Call the function sensor_name = "OTT_Parsivel" df_out = cast_column_dtypes(df, sensor_name, verbose=False) diff --git a/disdrodb/tests/test_l0/test_l0b_nc_processing.py b/disdrodb/tests/test_l0/test_l0b_nc_processing.py index 6116aeca..6ea0deb6 100644 --- a/disdrodb/tests/test_l0/test_l0b_nc_processing.py +++ b/disdrodb/tests/test_l0/test_l0b_nc_processing.py @@ -85,13 +85,15 @@ def test_replace_nan_flags(create_test_config_files): Function that creates and removes the dummy config file. """ # Mock xarray Dataset - ds = xr.Dataset({ - "key_1": xr.DataArray([0, 1, 2, 3, 4]), - "key_2": xr.DataArray([1, -9999, 2, 3, 89]), - "key_3": xr.DataArray([1.0, -9999.0, 2.0, 3.0, 89.0]), - "key_4": xr.DataArray([1, -9999, -8888, 2, 3]), - "key_not_in_dict": xr.DataArray([10, 20, 30, 40, 50]), - }) + ds = xr.Dataset( + { + "key_1": xr.DataArray([0, 1, 2, 3, 4]), + "key_2": xr.DataArray([1, -9999, 2, 3, 89]), + "key_3": xr.DataArray([1.0, -9999.0, 2.0, 3.0, 89.0]), + "key_4": xr.DataArray([1, -9999, -8888, 2, 3]), + "key_not_in_dict": xr.DataArray([10, 20, 30, 40, 50]), + } + ) # Call the replace_nan_flags function result_ds = replace_nan_flags(ds, sensor_name=TEST_SENSOR_NAME, verbose=True) @@ -108,13 +110,15 @@ def test_replace_nan_flags(create_test_config_files): @pytest.mark.parametrize("create_test_config_files", [config_dict], indirect=True) def test_set_nan_outside_data_range(create_test_config_files): - ds = xr.Dataset({ - "key_1": xr.DataArray([0, 1, 2, 3, 4]), - "key_2": xr.DataArray([9, 10, 50, 51, 30]), - "key_3": xr.DataArray([-11, -10, 0, 10, 11]), - "key_4": xr.DataArray([99, 100, 150, 200, 201]), - "key_not_in_dict": xr.DataArray([0, 1, 2, 3, 4]), - }) + ds = xr.Dataset( + { + "key_1": xr.DataArray([0, 1, 2, 3, 4]), + "key_2": xr.DataArray([9, 10, 50, 51, 30]), + "key_3": xr.DataArray([-11, -10, 0, 10, 11]), + "key_4": xr.DataArray([99, 100, 150, 200, 201]), + "key_not_in_dict": xr.DataArray([0, 1, 2, 3, 4]), + } + ) result_ds = set_nan_outside_data_range(ds, TEST_SENSOR_NAME, verbose=True) @@ -131,13 +135,15 @@ def test_set_nan_outside_data_range(create_test_config_files): @pytest.mark.parametrize("create_test_config_files", [config_dict], indirect=True) def test_set_nan_invalid_values(create_test_config_files): - ds = xr.Dataset({ - "key_1": xr.DataArray([0, 1, 2, 3, 4]), - "key_2": xr.DataArray([9, 10, 20, 30, 40]), - "key_3": xr.DataArray([0, 0.1, 0.2, 0.3, 1.0]), - "key_4": xr.DataArray([0, 0, 0, 1, 1]), - "key_not_in_dict": xr.DataArray([0, 1, 2, 3, 4]), - }) + ds = xr.Dataset( + { + "key_1": xr.DataArray([0, 1, 2, 3, 4]), + "key_2": xr.DataArray([9, 10, 20, 30, 40]), + "key_3": xr.DataArray([0, 0.1, 0.2, 0.3, 1.0]), + "key_4": xr.DataArray([0, 0, 0, 1, 1]), + "key_not_in_dict": xr.DataArray([0, 1, 2, 3, 4]), + } + ) result_ds = set_nan_invalid_values(ds, TEST_SENSOR_NAME, verbose=True) @@ -159,12 +165,14 @@ def test_replace_custom_nan_flags(): dict_nan_flags = {"key_1": [-999], "key_2": [-9999, -8888], "key_3": [0]} # Mock xarray Dataset - ds = xr.Dataset({ - "key_1": xr.DataArray([1, -999, 2, 3, 4]), - "key_2": xr.DataArray([1, -9999, -8888, 2, 3]), - "key_3": xr.DataArray([0, 1, 0, 2, 3]), - "key_not_in_flags": xr.DataArray([10, 20, 30, 40, 50]), - }) + ds = xr.Dataset( + { + "key_1": xr.DataArray([1, -999, 2, 3, 4]), + "key_2": xr.DataArray([1, -9999, -8888, 2, 3]), + "key_3": xr.DataArray([0, 1, 0, 2, 3]), + "key_not_in_flags": xr.DataArray([10, 20, 30, 40, 50]), + } + ) # Call the replace_custom_nan_flags function result_ds = replace_custom_nan_flags(ds, dict_nan_flags=dict_nan_flags) @@ -253,12 +261,14 @@ def test_rename_dataset(): @pytest.mark.parametrize("create_test_config_files", [config_dict], indirect=True) def test_subset_dataset(create_test_config_files): # Define xarray Dataset with extra variables (assumed to be renamed) - ds = xr.Dataset({ - "var1": xr.DataArray([1, 2, 3]), - "var2": xr.DataArray([4, 5, 6]), - "var3": xr.DataArray([7, 8, 9]), - "var_not_needed": xr.DataArray([10, 11, 12]), - }) + ds = xr.Dataset( + { + "var1": xr.DataArray([1, 2, 3]), + "var2": xr.DataArray([4, 5, 6]), + "var3": xr.DataArray([7, 8, 9]), + "var_not_needed": xr.DataArray([10, 11, 12]), + } + ) # Define dict_names mapping # - Key are used to rename (the values are used for subsetting) @@ -277,10 +287,12 @@ def test_subset_dataset(create_test_config_files): @pytest.mark.parametrize("create_test_config_files", [config_dict], indirect=True) def test_get_missing_variables(create_test_config_files): # Define xarray Dataset with some variables (assumed to be renamed and subsetted) - ds = xr.Dataset({ - "var1": xr.DataArray([1, 2, 3]), - "var2": xr.DataArray([4, 5, 6]), - }) + ds = xr.Dataset( + { + "var1": xr.DataArray([1, 2, 3]), + "var2": xr.DataArray([4, 5, 6]), + } + ) # Define dict_names mapping # - Key are used to rename (the values are used for subsetting) diff --git a/disdrodb/tests/test_l0/test_l0b_processing.py b/disdrodb/tests/test_l0/test_l0b_processing.py index 509ec658..72cbf83e 100644 --- a/disdrodb/tests/test_l0/test_l0b_processing.py +++ b/disdrodb/tests/test_l0/test_l0b_processing.py @@ -96,15 +96,17 @@ def define_test_dummy_configs(): @pytest.mark.parametrize("create_test_config_files", [define_test_dummy_configs()], indirect=True) def test_create_l0b_from_l0a(create_test_config_files): # Create a sample DataFrame - df = pd.DataFrame({ - "time": pd.date_range("2022-01-01", periods=10, freq="H"), - "raw_drop_concentration": np.random.rand(10), - "raw_drop_average_velocity": np.random.rand(10), - "raw_drop_number": np.random.rand(10), - "latitude": np.random.rand(10), - "longitude": np.random.rand(10), - "altitude": np.random.rand(10), - }) + df = pd.DataFrame( + { + "time": pd.date_range("2022-01-01", periods=10, freq="H"), + "raw_drop_concentration": np.random.rand(10), + "raw_drop_average_velocity": np.random.rand(10), + "raw_drop_number": np.random.rand(10), + "latitude": np.random.rand(10), + "longitude": np.random.rand(10), + "altitude": np.random.rand(10), + } + ) # Create a sample attrs dictionary attrs = { "sensor_name": "test", @@ -152,11 +154,13 @@ def test_create_l0b_from_l0a(create_test_config_files): def test_add_dataset_crs_coords(): # Create example dataset - ds = xr.Dataset({ - "var1": xr.DataArray([1, 2, 3], dims="time"), - "lat": xr.DataArray([0, 1, 2], dims="time"), - "lon": xr.DataArray([0, 1, 2], dims="time"), - }) + ds = xr.Dataset( + { + "var1": xr.DataArray([1, 2, 3], dims="time"), + "lat": xr.DataArray([0, 1, 2], dims="time"), + "lon": xr.DataArray([0, 1, 2], dims="time"), + } + ) # Call the function and check the output ds_out = add_dataset_crs_coords(ds) @@ -182,11 +186,13 @@ def test_set_attrs_dict(): def test__set_coordinate_attributes(): # Create example dataset - ds = xr.Dataset({ - "var1": xr.DataArray([1, 2, 3], dims="time"), - "lat": xr.DataArray([0, 1, 2], dims="time"), - "lon": xr.DataArray([0, 1, 2], dims="time"), - }) + ds = xr.Dataset( + { + "var1": xr.DataArray([1, 2, 3], dims="time"), + "lat": xr.DataArray([0, 1, 2], dims="time"), + "lon": xr.DataArray([0, 1, 2], dims="time"), + } + ) ds.lat.attrs["units"] = "degrees_north" ds.lon.attrs["units"] = "degrees_east" diff --git a/disdrodb/tests/test_l0/test_template_tools.py b/disdrodb/tests/test_l0/test_template_tools.py index 1a9a6b56..6811355f 100644 --- a/disdrodb/tests/test_l0/test_template_tools.py +++ b/disdrodb/tests/test_l0/test_template_tools.py @@ -244,12 +244,14 @@ class Test_Print_Df_With_Any_Nan_Rows: """Test test_print_df_with_any_nan_rows.""" def test_df_with_nan_and_none_values(self, capfd): - df = pd.DataFrame({ - "A": [1, 2, None, 4], - "B": ["a", "b", None, "d"], - "C": [1, 2, np.nan, 4], - "D": [1, 2, 3, 4], - }) + df = pd.DataFrame( + { + "A": [1, 2, None, 4], + "B": ["a", "b", None, "d"], + "C": [1, 2, np.nan, 4], + "D": [1, 2, 3, 4], + } + ) print_df_with_any_nan_rows(df) out, _ = capfd.readouterr() assert "Column 0 ( A ):\n [nan]" in out @@ -330,10 +332,12 @@ def test_numeric_array(self): def test_infer_column_names(capfd): sensor_name = "OTT_Parsivel" - df = pd.DataFrame({ - "0": [123.345, 123.345], # same number of character - "1": [12.3456, 1.345], # not same number characters - }) + df = pd.DataFrame( + { + "0": [123.345, 123.345], # same number of character + "1": [12.3456, 1.345], # not same number characters + } + ) dict_possible_columns = infer_column_names(df=df, sensor_name=sensor_name, row_idx=0) assert dict_possible_columns[0] == ["rainfall_amount_absolute_32bit"] out, _ = capfd.readouterr()