Skip to content

Commit

Permalink
Add Q,W,UP ruff rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiggi committed May 10, 2023
1 parent 109c6b4 commit 1ee0b45
Show file tree
Hide file tree
Showing 86 changed files with 28 additions and 110 deletions.
3 changes: 1 addition & 2 deletions disdrodb/api/info.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
import re
Expand Down Expand Up @@ -72,7 +71,7 @@ def get_key_from_filepaths(fpaths, key):
def _get_version_from_filepath(filepath, integer=False):
version = get_key_from_filepath(filepath, key="version")
if integer:
version = int(re.findall("\d+", version)[0])
version = int(re.findall("\\d+", version)[0])
return version


Expand Down
3 changes: 1 addition & 2 deletions disdrodb/api/io.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
Expand Down Expand Up @@ -201,7 +200,7 @@ def _get_metadata_fpath(disdrodb_dir, product_level, data_source, campaign_name,
def get_metadata_dict(disdrodb_dir, product_level, data_source, campaign_name, station_name):
"""Get metadata of a given station."""
metadata_fpath = _get_metadata_fpath(disdrodb_dir, product_level, data_source, campaign_name, station_name)
with open(metadata_fpath, "r") as f:
with open(metadata_fpath) as f:
metadata_dict = yaml.safe_load(f)
return metadata_dict

Expand Down
5 changes: 2 additions & 3 deletions disdrodb/api/metadata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
Expand Down Expand Up @@ -27,7 +26,7 @@

def _read_yaml_file(fpath):
"""Read a YAML file into dictionary."""
with open(fpath, "r") as f:
with open(fpath) as f:
dictionary = yaml.safe_load(f)
return dictionary

Expand Down Expand Up @@ -57,7 +56,7 @@ def read_station_metadata(disdrodb_dir, product_level, data_source, campaign_nam
raise ValueError(f"The metadata file for {station_name} at {fpath} does not exists.")

# Read the metadata file
with open(fpath, "r") as f:
with open(fpath) as f:
dictionary = yaml.safe_load(f)
return dictionary

Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/check_configs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import glob
import os
from typing import List, Optional, Union
Expand Down
3 changes: 1 addition & 2 deletions disdrodb/l0/check_metadata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
from typing import Union
Expand Down Expand Up @@ -38,7 +37,7 @@ def read_yaml(fpath: str) -> dict:
dict
Attributes read from the YAML file.
"""
with open(fpath, "r") as f:
with open(fpath) as f:
attrs = yaml.safe_load(f)
return attrs

Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/check_standards.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
27 changes: 13 additions & 14 deletions disdrodb/l0/io.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
Expand Down Expand Up @@ -592,11 +591,11 @@ def _parse_fpath(fpath: str) -> str:
if not isinstance(fpath, str):
raise TypeError("'_parse_fpath' expects a directory/filepath string.")
if fpath[-1] == "/":
print("{} should not end with /.".format(fpath))
print(f"{fpath} should not end with /.")
fpath = fpath[:-1]

elif fpath[-1] == "\\":
print("{} should not end with /.".format(fpath))
print(f"{fpath} should not end with /.")
fpath = fpath[:-1]

return fpath
Expand All @@ -610,25 +609,25 @@ def _check_raw_dir_input(raw_dir):
if not isinstance(raw_dir, str):
raise TypeError("Provide 'raw_dir' as a string'.")
if not os.path.exists(raw_dir):
raise ValueError("'raw_dir' {} directory does not exist.".format(raw_dir))
raise ValueError(f"'raw_dir' {raw_dir} directory does not exist.")
if not os.path.isdir(raw_dir):
raise ValueError("'raw_dir' {} is not a directory.".format(raw_dir))
raise ValueError(f"'raw_dir' {raw_dir} is not a directory.")


def _check_raw_dir_data_subfolders(raw_dir):
"""Check `data` directory in raw dir."""
list_subfolders = os.listdir(raw_dir)
if len(list_subfolders) == 0:
raise ValueError("There are not subfolders in {}".format(raw_dir))
raise ValueError(f"There are not subfolders in {raw_dir}")
if "data" not in list_subfolders:
raise ValueError("'raw_dir' {} should have the /data subfolder.".format(raw_dir))
raise ValueError(f"'raw_dir' {raw_dir} should have the /data subfolder.")

# -------------------------------------------------------------------------.
#### Check there are subfolders corresponding to station to process
raw_data_dir = os.path.join(raw_dir, "data")
list_data_station_name = os.listdir(raw_data_dir)
if len(list_data_station_name) == 0:
raise ValueError("No station directories within {}".format(raw_data_dir))
raise ValueError(f"No station directories within {raw_data_dir}")

# -------------------------------------------------------------------------.
#### Check there are data files in each list_data_station_name
Expand All @@ -637,7 +636,7 @@ def _check_raw_dir_data_subfolders(raw_dir):
idx_0_files = np.where(np.array(list_nfiles_per_station) == 0)[0]
if len(idx_0_files) > 0:
empty_station_dir = [list_raw_data_station_dir[idx] for idx in idx_0_files]
raise ValueError("The following data directories are empty: {}".format(empty_station_dir))
raise ValueError(f"The following data directories are empty: {empty_station_dir}")


def _check_raw_dir_metadata(raw_dir, verbose=True):
Expand All @@ -660,7 +659,7 @@ def _check_raw_dir_metadata(raw_dir, verbose=True):
os.path.join(metadata_dir, station_name + ".yml") for station_name in list_data_station_name
]
_ = [write_default_metadata(fpath) for fpath in list_metadata_fpath]
msg = "'raw_dir' {} should have the /metadata subfolder. ".format(raw_dir)
msg = f"'raw_dir' {raw_dir} should have the /metadata subfolder. "
msg1 = "It has been now created with also empty metadata files to be filled for each station."
raise ValueError(msg + msg1)

Expand All @@ -679,14 +678,14 @@ def _check_raw_dir_metadata(raw_dir, verbose=True):
os.path.join(metadata_dir, station_name + ".yml") for station_name in list_missing_station_name
]
_ = [write_default_metadata(fpath) for fpath in list_missing_metadata_fpath]
msg = "The metadata files for the following station_name were missing: {}".format(list_missing_station_name)
msg = f"The metadata files for the following station_name were missing: {list_missing_station_name}"
raise ValueError(msg + " Now have been created to be filled.")

# - Check not excess metadata compared to present stations
idx_excess_metadata_station = np.where(np.isin(list_metadata_station_name, list_data_station_name, invert=True))[0]
if len(idx_excess_metadata_station) > 0:
list_excess_station_name = [list_metadata_station_name[idx] for idx in idx_excess_metadata_station]
print("There are the following metadata files without corresponding data: {}".format(list_excess_station_name))
print(f"There are the following metadata files without corresponding data: {list_excess_station_name}")

# -------------------------------------------------------------------------.
#### Check metadata compliance
Expand Down Expand Up @@ -739,7 +738,7 @@ def _check_raw_dir_issue(raw_dir, verbose=True):
os.path.join(issue_dir, station_name + ".yml") for station_name in list_missing_station_name
]
_ = [write_default_issue(fpath) for fpath in list_missing_issue_fpath]
msg = "The issue files for the following station_name were missing: {}".format(list_missing_station_name)
msg = f"The issue files for the following station_name were missing: {list_missing_station_name}"
log_warning(logger, msg, verbose)

# - Check not excess issue compared to present stations
Expand Down Expand Up @@ -808,7 +807,7 @@ def _check_is_processed_dir(processed_dir):

# Check is the processed_dir
if processed_dir.find("DISDRODB/Processed") == -1 and processed_dir.find("DISDRODB\\Processed") == -1:
msg = "Expecting 'processed_dir' to contain the pattern */DISDRODB/Processed/*. or *\DISDRODB\Processed\*."
msg = "Expecting 'processed_dir' to contain the pattern */DISDRODB/Processed/*. or *\\DISDRODB\\Processed\\*."
logger.error(msg)
raise ValueError(msg)

Expand Down
3 changes: 1 addition & 2 deletions disdrodb/l0/issue.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
Expand Down Expand Up @@ -372,7 +371,7 @@ def remove_implicit_resolver(cls, tag_to_remove):
def load_yaml_without_date_parsing(filepath):
"Read a YAML file without converting automatically date string to datetime."
NoDatesSafeLoader.remove_implicit_resolver("tag:yaml.org,2002:timestamp")
with open(filepath, "r") as f:
with open(filepath) as f:
dictionary = yaml.load(f, Loader=NoDatesSafeLoader)
# Return empty dictionary if nothing to be read in the file
if isinstance(dictionary, type(None)):
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/l0_reader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/l0a_processing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/l0b_concat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/l0b_processing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/metadata.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/ARM/ARM_LD.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/ARM/ARM_LPM.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/AUSTRALIA/MELBOURNE_2007_OTT.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/AUSTRALIA/MELBOURNE_2007_THIES.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/BRAZIL/CHUVA_LPM.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/BRAZIL/CHUVA_OTT.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/BRAZIL/GOAMAZON_LPM.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/BRAZIL/GOAMAZON_OTT.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/CHINA/CHONGQING.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/DENMARK/EROSION_nc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/EPFL/ARCTIC_2021.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/EPFL/COMMON_2011.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/EPFL/DAVOS_2009_2011.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/EPFL/EPFL_2009.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/EPFL/EPFL_ROOF_2008.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/EPFL/EPFL_ROOF_2010.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/EPFL/EPFL_ROOF_2011.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/EPFL/EPFL_ROOF_2012.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/EPFL/GENEPI_2007.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/EPFL/GRAND_ST_BERNARD_2007.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/EPFL/GRAND_ST_BERNARD_2007_2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/EPFL/HPICONET_2010.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/EPFL/HYMEX_LTE_SOP2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/EPFL/HYMEX_LTE_SOP3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/EPFL/HYMEX_LTE_SOP4.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/EPFL/PARADISO_2014.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/EPFL/PARSIVEL_2007.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
1 change: 0 additions & 1 deletion disdrodb/l0/readers/EPFL/PLATO_2019.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------.
# Copyright (c) 2021-2022 DISDRODB developers
#
Expand Down
Loading

0 comments on commit 1ee0b45

Please sign in to comment.