Skip to content

Commit

Permalink
Add flake8-commas rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiggi committed Apr 2, 2024
1 parent a7f252e commit 7c997eb
Show file tree
Hide file tree
Showing 32 changed files with 407 additions and 105 deletions.
11 changes: 9 additions & 2 deletions disdrodb/api/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,11 @@ def check_station_has_data(product, data_source, campaign_name, station_name, ba
def check_metadata_dir(product, data_source, campaign_name, base_dir=None):
"""Check existence of the metadata directory. If does not exists, raise an error."""
metadata_dir = define_metadata_dir(
product=product, base_dir=base_dir, data_source=data_source, campaign_name=campaign_name, check_exists=False
product=product,
base_dir=base_dir,
data_source=data_source,
campaign_name=campaign_name,
check_exists=False,
)
if not os.path.exists(metadata_dir) and os.path.isdir(metadata_dir):
msg = f"The metadata directory does not exist at {metadata_dir}."
Expand Down Expand Up @@ -253,7 +257,10 @@ def check_metadata_file(product, data_source, campaign_name, station_name, base_
def check_issue_dir(data_source, campaign_name, base_dir=None):
"""Check existence of the issue directory. If does not exists, raise an error."""
issue_dir = define_issue_dir(
base_dir=base_dir, data_source=data_source, campaign_name=campaign_name, check_exists=False
base_dir=base_dir,
data_source=data_source,
campaign_name=campaign_name,
check_exists=False,
)
if not os.path.exists(issue_dir) and os.path.isdir(issue_dir):
msg = "The issue directory does not exist at {issue_dir}."
Expand Down
30 changes: 24 additions & 6 deletions disdrodb/api/create_directories.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ def _check_campaign_name_consistency(raw_dir: str, processed_dir: str) -> str:


def _copy_station_metadata(
data_source: str, campaign_name: str, station_name: str, base_dir: str = None, check_validity: bool = False
data_source: str,
campaign_name: str,
station_name: str,
base_dir: str = None,
check_validity: bool = False,
) -> None:
"""Copy the station YAML file from the ``raw_dir/metadata`` into ``processed_dir/metadata``.
Expand Down Expand Up @@ -159,7 +163,12 @@ def _copy_station_metadata(


def _check_pre_existing_station_data(
data_source: str, campaign_name: str, station_name: str, product: str, base_dir=None, force=False
data_source: str,
campaign_name: str,
station_name: str,
product: str,
base_dir=None,
force=False,
):
"""Check for pre-existing station data.
Expand Down Expand Up @@ -328,7 +337,10 @@ def _create_station_directories(
station_name=station_name,
)
_ = create_metadata_directory(
base_dir=base_dir, product=product, data_source=data_source, campaign_name=campaign_name
base_dir=base_dir,
product=product,
data_source=data_source,
campaign_name=campaign_name,
)

if product.upper() == "RAW":
Expand Down Expand Up @@ -400,7 +412,7 @@ def create_initial_station_structure(
raise ValueError(
f"A metadata file already exists at {metadata_filepath}. "
"The station is already part of the DISDRODB Archive or "
"or you already initialized the directory structure for the station !"
"or you already initialized the directory structure for the station !",
)

# Create directory structure (/metadata, /issue and /data/<station_name>)
Expand Down Expand Up @@ -429,7 +441,10 @@ def create_initial_station_structure(

# Report location of the campaign directory
campaign_dir = define_campaign_dir(
base_dir=base_dir, data_source=data_source, campaign_name=campaign_name, product="RAW"
base_dir=base_dir,
data_source=data_source,
campaign_name=campaign_name,
product="RAW",
)
print(f"Initial station directory structure created at: {campaign_dir}")

Expand Down Expand Up @@ -479,7 +494,10 @@ def create_test_archive(test_base_dir, data_source, campaign_name, station_name,
base_dir=base_dir,
)
dst_issue_fpath = define_issue_filepath(
data_source=data_source, campaign_name=campaign_name, station_name=station_name, base_dir=test_base_dir
data_source=data_source,
campaign_name=campaign_name,
station_name=station_name,
base_dir=test_base_dir,
)
copy_file(src_issue_fpath, dst_issue_fpath)
copy_file(src_metadata_fpath, dst_metadata_fpath)
Expand Down
2 changes: 1 addition & 1 deletion disdrodb/data_transfer/download_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def _download_file_from_url(url: str, dst_dir: str, force: bool = False) -> str:
else:
raise ValueError(
f"There are already raw files within {dst_dir}. Download is suspended. "
"Use force=True to force the download and overwrite existing raw files."
"Use force=True to force the download and overwrite existing raw files.",
)

os.makedirs(dst_dir, exist_ok=True)
Expand Down
6 changes: 4 additions & 2 deletions disdrodb/data_transfer/zenodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def _define_zenodo_metadata(metadata):
"upload_type": "dataset",
"description": description,
"creators": _define_creators_list(metadata),
}
},
}
return zenodo_metadata

Expand Down Expand Up @@ -235,7 +235,9 @@ def upload_station_to_zenodo(metadata_filepath: str, sandbox: bool = True) -> st
print(" - Uploading station data")
try:
disdrodb_data_url = _upload_file_to_zenodo(
filepath=station_zip_filepath, metadata_filepath=metadata_filepath, sandbox=sandbox
filepath=station_zip_filepath,
metadata_filepath=metadata_filepath,
sandbox=sandbox,
)
os.remove(station_zip_filepath)
except Exception as e:
Expand Down
10 changes: 8 additions & 2 deletions disdrodb/l0/check_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,16 @@ def _check_bin_consistency(sensor_name: str) -> None:
if all(arr.size > 1 for arr in [velocity_bin_center, velocity_bin_lower, velocity_bin_upper, velocity_bin_width]):
np.testing.assert_allclose(velocity_bin_upper - velocity_bin_lower, velocity_bin_width, atol=1e-3, rtol=1e-4)
np.testing.assert_allclose(
velocity_bin_lower + velocity_bin_width / 2, velocity_bin_center, atol=1e-3, rtol=1e-4
velocity_bin_lower + velocity_bin_width / 2,
velocity_bin_center,
atol=1e-3,
rtol=1e-4,
)
np.testing.assert_allclose(
velocity_bin_upper - velocity_bin_width / 2, velocity_bin_center, atol=1e-3, rtol=1e-4
velocity_bin_upper - velocity_bin_width / 2,
velocity_bin_center,
atol=1e-3,
rtol=1e-4,
)


Expand Down
6 changes: 3 additions & 3 deletions disdrodb/l0/l0_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def run_l0a(
force=force,
verbose=verbose,
parallel=parallel,
)
),
)
if parallel:
list_logs = dask.compute(*list_tasks)
Expand Down Expand Up @@ -611,7 +611,7 @@ def run_l0b(
verbose=verbose,
debugging_mode=debugging_mode,
parallel=parallel,
)
),
)
else:
bag = db.from_sequence(filepaths, npartitions=len(filepaths))
Expand Down Expand Up @@ -770,7 +770,7 @@ def run_l0b_from_nc(
force=force,
verbose=verbose,
parallel=parallel,
)
),
)
else:
bag = db.from_sequence(filepaths, npartitions=len(filepaths))
Expand Down
4 changes: 2 additions & 2 deletions disdrodb/l0/l0_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def _check_metadata_reader(metadata):
if "/" not in reader_reference:
raise ValueError(
f"The reader '{reader_reference}' reported in the metadata is not valid. Must have"
" '<DATA_SOURCE>/<READER_NAME>' pattern."
" '<DATA_SOURCE>/<READER_NAME>' pattern.",
)
# - Get the reader_reference component list
reader_components = reader_reference.split("/")
Expand Down Expand Up @@ -335,7 +335,7 @@ def get_station_reader_function(data_source, campaign_name, station_name, base_d
if "reader" not in metadata:
raise ValueError(
"The `reader` key is not available in the metadata of the"
f" {data_source} {campaign_name} {station_name} station."
f" {data_source} {campaign_name} {station_name} station.",
)

# ------------------------------------------------------------------------.
Expand Down
2 changes: 1 addition & 1 deletion disdrodb/l0/standards.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ def _check_contiguous_chunksize_agrees(encoding_dict, var):
contiguous = encoding_dict[var].get("contiguous", False)
if isinstance(chunksizes, list) and len(chunksizes) >= 1 and contiguous:
raise ValueError(
f"Invalid encodings for variable {var}. 'chunksizes' are specified but 'contiguous' is set to True !"
f"Invalid encodings for variable {var}. 'chunksizes' are specified but 'contiguous' is set to True !",
)


Expand Down
2 changes: 1 addition & 1 deletion disdrodb/l0/template_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def infer_column_names(df: pd.DataFrame, sensor_name: str, row_idx: int = 1):
if not _has_constant_characters(arr):
print(
f"ATTENTION: Column {i} values have non-unique number of characters. "
f"Selecting row {row_idx} to infer possible columns."
f"Selecting row {row_idx} to infer possible columns.",
)

# Subset a single string
Expand Down
55 changes: 44 additions & 11 deletions disdrodb/metadata/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def _check_metadata_campaign_name(metadata, expected_name):
raise ValueError("The 'campaign_name' key in the metadata is empty.")
if campaign_name != expected_name:
raise ValueError(
f"The campaign_name in the metadata is '{campaign_name}' but the campaign directory is '{expected_name}'"
f"The campaign_name in the metadata is '{campaign_name}' but the campaign directory is '{expected_name}'",
)
return None

Expand All @@ -104,7 +104,7 @@ def _check_metadata_data_source(metadata, expected_name):
raise ValueError("The 'data_source' key in the metadata is empty.")
if data_source != expected_name:
raise ValueError(
f"The data_source in the metadata is '{data_source}' but the data_source directory is '{expected_name}'"
f"The data_source in the metadata is '{data_source}' but the data_source directory is '{expected_name}'",
)
return None

Expand All @@ -123,7 +123,8 @@ def _check_metadata_station_name(metadata, expected_name):
raise ValueError("The 'station_name' key in the metadata is empty.")
if station_name != expected_name:
raise ValueError(
f"The station_name in the metadata is '{station_name}' but the metadata file is named '{expected_name}.yml'"
f"The station_name in the metadata is '{station_name}' but the metadata file is named"
f" '{expected_name}.yml'",
)
return None

Expand Down Expand Up @@ -265,7 +266,11 @@ def check_archive_metadata_keys(base_dir: str = None) -> bool:
is_valid = True
base_dir = get_base_dir(base_dir)
list_metadata_paths = get_list_metadata(
base_dir=base_dir, data_sources=None, campaign_names=None, station_names=None, with_stations_data=False
base_dir=base_dir,
data_sources=None,
campaign_names=None,
station_names=None,
with_stations_data=False,
)
for filepath in list_metadata_paths:
data_source = infer_data_source_from_path(filepath)
Expand Down Expand Up @@ -306,7 +311,11 @@ def check_archive_metadata_campaign_name(base_dir: str = None) -> bool:
is_valid = True
base_dir = get_base_dir(base_dir)
list_metadata_paths = get_list_metadata(
base_dir=base_dir, data_sources=None, campaign_names=None, station_names=None, with_stations_data=False
base_dir=base_dir,
data_sources=None,
campaign_names=None,
station_names=None,
with_stations_data=False,
)
for filepath in list_metadata_paths:
data_source = infer_data_source_from_path(filepath)
Expand Down Expand Up @@ -346,7 +355,11 @@ def check_archive_metadata_data_source(base_dir: str = None) -> bool:
is_valid = True
base_dir = get_base_dir(base_dir)
list_metadata_paths = get_list_metadata(
base_dir=base_dir, data_sources=None, campaign_names=None, station_names=None, with_stations_data=False
base_dir=base_dir,
data_sources=None,
campaign_names=None,
station_names=None,
with_stations_data=False,
)
for filepath in list_metadata_paths:
data_source = infer_data_source_from_path(filepath)
Expand Down Expand Up @@ -386,7 +399,11 @@ def check_archive_metadata_sensor_name(base_dir: str = None) -> bool:
is_valid = True
base_dir = get_base_dir(base_dir)
list_metadata_paths = get_list_metadata(
base_dir=base_dir, data_sources=None, campaign_names=None, station_names=None, with_stations_data=False
base_dir=base_dir,
data_sources=None,
campaign_names=None,
station_names=None,
with_stations_data=False,
)
for filepath in list_metadata_paths:
data_source = infer_data_source_from_path(filepath)
Expand Down Expand Up @@ -426,7 +443,11 @@ def check_archive_metadata_station_name(base_dir: str = None) -> bool:
is_valid = True
base_dir = get_base_dir(base_dir)
list_metadata_paths = get_list_metadata(
base_dir=base_dir, data_sources=None, campaign_names=None, station_names=None, with_stations_data=False
base_dir=base_dir,
data_sources=None,
campaign_names=None,
station_names=None,
with_stations_data=False,
)
for filepath in list_metadata_paths:
data_source = infer_data_source_from_path(filepath)
Expand Down Expand Up @@ -468,7 +489,11 @@ def check_archive_metadata_reader(base_dir: str = None) -> bool:
is_valid = True
base_dir = get_base_dir(base_dir)
list_metadata_paths = get_list_metadata(
base_dir=base_dir, data_sources=None, campaign_names=None, station_names=None, with_stations_data=False
base_dir=base_dir,
data_sources=None,
campaign_names=None,
station_names=None,
with_stations_data=False,
)
for filepath in list_metadata_paths:
data_source = infer_data_source_from_path(filepath)
Expand Down Expand Up @@ -511,7 +536,11 @@ def check_archive_metadata_compliance(base_dir: str = None, raise_error=False):
is_valid = True
base_dir = get_base_dir(base_dir)
list_metadata_paths = get_list_metadata(
base_dir=base_dir, data_sources=None, campaign_names=None, station_names=None, with_stations_data=False
base_dir=base_dir,
data_sources=None,
campaign_names=None,
station_names=None,
with_stations_data=False,
)
for filepath in list_metadata_paths:
data_source = infer_data_source_from_path(filepath)
Expand Down Expand Up @@ -554,7 +583,11 @@ def check_archive_metadata_geolocation(base_dir: str = None):
is_valid = True
base_dir = get_base_dir(base_dir)
list_metadata_paths = get_list_metadata(
base_dir=base_dir, data_sources=None, campaign_names=None, station_names=None, with_stations_data=False
base_dir=base_dir,
data_sources=None,
campaign_names=None,
station_names=None,
with_stations_data=False,
)
for filepath in list_metadata_paths:
data_source = infer_data_source_from_path(filepath)
Expand Down
6 changes: 5 additions & 1 deletion disdrodb/metadata/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ def get_archive_metadata_key_value(key: str, return_tuple: bool = True, base_dir
"""
base_dir = get_base_dir(base_dir)
list_metadata_paths = get_list_metadata(
base_dir=base_dir, data_sources=None, campaign_names=None, station_names=None, with_stations_data=False
base_dir=base_dir,
data_sources=None,
campaign_names=None,
station_names=None,
with_stations_data=False,
)
list_info = []
for filepath in list_metadata_paths:
Expand Down
6 changes: 5 additions & 1 deletion disdrodb/metadata/scripts/disdrodb_check_metadata_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
@click.command()
@click_base_dir_option
@click.option(
"--raise_error", type=bool, show_default=True, default=True, help="Whether to raise error of finish the check"
"--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.checks import check_archive_metadata_compliance
Expand Down
11 changes: 9 additions & 2 deletions disdrodb/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ def create_fake_metadata_directory(base_dir, product, data_source="DATA_SOURCE",
from disdrodb.api.create_directories import create_metadata_directory

return create_metadata_directory(
base_dir=base_dir, product=product, data_source=data_source, campaign_name=campaign_name
base_dir=base_dir,
product=product,
data_source=data_source,
campaign_name=campaign_name,
)


def create_fake_station_dir(
base_dir, product, data_source="DATA_SOURCE", campaign_name="CAMPAIGN_NAME", station_name="station_name"
base_dir,
product,
data_source="DATA_SOURCE",
campaign_name="CAMPAIGN_NAME",
station_name="station_name",
):
from disdrodb.api.create_directories import create_station_directory

Expand Down
Loading

0 comments on commit 7c997eb

Please sign in to comment.