Skip to content

Commit

Permalink
Refactor checks of raw directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiggi committed Nov 8, 2023
1 parent 4f558ea commit 77de56e
Show file tree
Hide file tree
Showing 10 changed files with 365 additions and 169 deletions.
486 changes: 335 additions & 151 deletions disdrodb/l0/io.py

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion disdrodb/l0/l0_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,6 @@ def run_l0b_concat(processed_dir, station_name, remove=False, verbose=False):
if n_files == 1:
msg = f"Only a single file is available for concatenation in {l0b_dir_path}."
log_warning(logger=logger, msg=msg, verbose=verbose)
raise ValueError(msg)

# -------------------------------------------------------------------------.
# Concatenate the files
Expand Down
4 changes: 2 additions & 2 deletions disdrodb/l0/routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ def run_disdrodb_l0(
):
"""Run the L0 processing of DISDRODB stations.
This function enable to launch the processing of many DISDRODB stations with a single command.
This function allows to launch the processing of many DISDRODB stations with a single command.
From the list of all available DISDRODB stations, it runs the processing of the
stations matching the provided data_sources, campaign_names and station_names.
Expand Down Expand Up @@ -618,7 +618,7 @@ def run_disdrodb_l0a(
):
"""Run the L0A processing of DISDRODB stations.
This function enable to launch the processing of many DISDRODB stations with a single command.
This function allows to launch the processing of many DISDRODB stations with a single command.
From the list of all available DISDRODB stations, it runs the processing of the
stations matching the provided data_sources, campaign_names and station_names.
Expand Down
2 changes: 1 addition & 1 deletion disdrodb/l0/scripts/disdrodb_run_l0.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def disdrodb_run_l0(
"""
Run the L0 processing of DISDRODB stations.
This function enable to launch the processing of many DISDRODB stations with a single command.
This function allows to launch the processing of many DISDRODB stations with a single command.
From the list of all available DISDRODB stations, it runs the processing of the
stations matching the provided data_sources, campaign_names and station_names.
Expand Down
2 changes: 1 addition & 1 deletion disdrodb/l0/scripts/disdrodb_run_l0a.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def disdrodb_run_l0a(
"""
Run the L0A processing of DISDRODB stations.
This function enable to launch the processing of many DISDRODB stations with a single command.
This function allows to launch the processing of many DISDRODB stations with a single command.
From the list of all available DISDRODB stations, it runs the processing
of the stations matching the provided data_sources, campaign_names and station_names.
Expand Down
2 changes: 1 addition & 1 deletion disdrodb/l0/scripts/disdrodb_run_l0b.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def disdrodb_run_l0b(
"""
Run the L0B processing of DISDRODB stations.
This function enable to launch the processing of many DISDRODB stations with a single command.
This function allows to launch the processing of many DISDRODB stations with a single command.
From the list of all available DISDRODB stations, it runs the processing of the
stations matching the provided data_sources, campaign_names and station_names.
Expand Down
3 changes: 1 addition & 2 deletions disdrodb/l0/scripts/disdrodb_run_l0b_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def disdrodb_run_l0b_concat(
):
"""Run the L0B concatenation of available DISDRODB stations.
This function enable to launch the processing of many DISDRODB stations with a single command.
This function allow to launch the processing of many DISDRODB stations with a single command.
From the list of all available DISDRODB stations, it runs the processing of the
stations matching the provided data_sources, campaign_names and station_names.
Expand Down Expand Up @@ -84,4 +84,3 @@ def disdrodb_run_l0b_concat(
remove_l0b=remove_l0b,
verbose=verbose,
)

4 changes: 3 additions & 1 deletion disdrodb/metadata/scripts/disdrodb_check_metadata_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@

@click.command()
@click.option("--base_dir", type=str, show_default=True, default=None, help="DISDRODB base directory")
@click.option("--raise_error", type=bool, show_default=True, default=True, help="Whether to raise error of finish the check")
@click.option(
"--raise_error", type=bool, show_default=True, default=True, help="Whether to raise error of finish the check"
)
def disdrodb_check_metadata_archive(base_dir=None, raise_error=True):
from disdrodb.metadata.check_metadata import check_archive_metadata_compliance

Expand Down
10 changes: 5 additions & 5 deletions disdrodb/tests/test_l0/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_create_directory_structure(tmp_path, mocker):
assert os.path.exists(l0a_folder_path)


def test_check_raw_dir_input(tmp_path):
def test_check_raw_dir_is_a_directory(tmp_path):
base_dir = tmp_path / "DISDRODB"
station_name = "station_1"
data_source = "data_source"
Expand All @@ -139,7 +139,7 @@ def test_check_raw_dir_input(tmp_path):
campaign_name=campaign_name,
station_name=station_name,
)
io._check_raw_dir_input(str(base_dir))
io._check_raw_dir_is_a_directory(str(base_dir))


def test_check_directory_exist():
Expand Down Expand Up @@ -358,12 +358,12 @@ def test_get_l0b_fpath():
####--------------------------------------------------------------------------.


def test_check_glob_pattern():
def test__check_glob_pattern():
with pytest.raises(TypeError, match="Expect pattern as a string."):
io.check_glob_pattern(1)
io._check_glob_pattern(1)

with pytest.raises(ValueError, match="glob_pattern should not start with /"):
io.check_glob_pattern("/1")
io._check_glob_pattern("/1")


def test_get_raw_file_list():
Expand Down
20 changes: 16 additions & 4 deletions disdrodb/tests/test_l0/test_l0b_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import numpy as np
import pandas as pd
import pytest
import xarray as xr

from disdrodb.l0.l0_processing import run_l0b_concat
Expand Down Expand Up @@ -70,10 +71,6 @@ def create_dummy_l0b_file(filepath: str, time):


def test_xr_concat_datasets(tmp_path):
# from pathlib import Path
# tmp_path = Path("/tmp/test8")
# tmp_path.mkdir()

# Write L0B files
filepath_1 = os.path.join(tmp_path, "test_1.nc")
filepath_2 = os.path.join(tmp_path, "test_2.nc")
Expand Down Expand Up @@ -224,6 +221,10 @@ def mock_write_l0b(ds: xr.Dataset, fpath: str, force=False) -> None:


def test_run_disdrodb_l0b_concat(tmp_path):
# from pathlib import Path
# tmp_path = Path("/tmp/test10")
# tmp_path.mkdir()

# Define stations info
base_dir = os.path.join(tmp_path, "DISDRODB")
data_source = "data_source"
Expand Down Expand Up @@ -270,3 +271,14 @@ def test_run_disdrodb_l0b_concat(tmp_path):
# Assert the presence of 2 concatenated netcdf files (one for each station)
list_files = glob.glob(os.path.join(base_dir, "Processed", data_source, campaign_name, "L0B", "*.nc"))
assert len(list_files) == 2

# Check that if L0B files are removed, raise error if no stations available
with pytest.raises(ValueError):
run_disdrodb_l0b_concat(
base_dir=base_dir,
data_sources=data_source,
campaign_names=campaign_name,
station_names=[station_name1, station_name2],
remove_l0b=True,
verbose=False,
)

0 comments on commit 77de56e

Please sign in to comment.