Skip to content

Commit

Permalink
Add pycodestyle rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiggi committed Apr 2, 2024
1 parent 65f67e9 commit f7393ff
Show file tree
Hide file tree
Showing 119 changed files with 287 additions and 116 deletions.
4 changes: 2 additions & 2 deletions disdrodb/api/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def check_sensor_name(sensor_name: str, product: str = "L0A") -> None:


def check_campaign_name(campaign_name):
"""Check the campaign name is upper case !"""
"""Check the campaign name is upper case !."""
upper_campaign_name = campaign_name.upper()
if campaign_name != upper_campaign_name:
msg = f"The campaign directory name {campaign_name} must be defined uppercase: {upper_campaign_name}"
Expand All @@ -138,7 +138,7 @@ def check_campaign_name(campaign_name):


def check_data_source(data_source):
"""Check the data_source name is upper case !"""
"""Check the data_source name is upper case !."""
upper_data_source = data_source.upper()
if data_source != upper_data_source:
msg = f"The data source directory name {data_source} must be defined uppercase: {upper_data_source}"
Expand Down
1 change: 1 addition & 0 deletions disdrodb/api/create_directories.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ def create_station_directory(base_dir, product, data_source, campaign_name, stat


def create_issue_directory(base_dir, data_source, campaign_name):
"""Create issue directory."""
issue_dir = define_issue_dir(
base_dir=base_dir,
data_source=data_source,
Expand Down
14 changes: 7 additions & 7 deletions disdrodb/api/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,45 +91,45 @@ def _get_version_from_filepath(filepath):


def get_version_from_filepaths(filepaths):
"""Return the DISDROB product version of the specified files"""
"""Return the DISDROB product version of the specified files."""
if isinstance(filepaths, str):
filepaths = [filepaths]
list_version = [_get_version_from_filepath(filepath) for filepath in filepaths]
return list_version


def get_campaign_name_from_filepaths(filepaths):
"""Return the DISDROB campaign name of the specified files"""
"""Return the DISDROB campaign name of the specified files."""
list_id = get_key_from_filepaths(filepaths, key="campaign_name")
return list_id


def get_station_name_from_filepaths(filepaths):
"""Return the DISDROB station name of the specified files"""
"""Return the DISDROB station name of the specified files."""
list_id = get_key_from_filepaths(filepaths, key="station_name")
return list_id


def get_product_from_filepaths(filepaths):
"""Return the DISDROB product name of the specified files"""
"""Return the DISDROB product name of the specified files."""
list_id = get_key_from_filepaths(filepaths, key="product")
return list_id


def get_start_time_from_filepaths(filepaths):
"""Return the start time of the specified files"""
"""Return the start time of the specified files."""
list_start_time = get_key_from_filepaths(filepaths, key="start_time")
return list_start_time


def get_end_time_from_filepaths(filepaths):
"""Return the end time of the specified files"""
"""Return the end time of the specified files."""
list_end_time = get_key_from_filepaths(filepaths, key="end_time")
return list_end_time


def get_start_end_time_from_filepaths(filepaths):
"""Return the start and end time of the specified files"""
"""Return the start and end time of the specified files."""
list_start_time = get_key_from_filepaths(filepaths, key="start_time")
list_end_time = get_key_from_filepaths(filepaths, key="end_time")
return np.array(list_start_time), np.array(list_end_time)
Expand Down
12 changes: 5 additions & 7 deletions disdrodb/api/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def available_stations(
):
"""Return stations for which data are available on disk."""
base_dir = get_base_dir(base_dir)
# Checks
# Checks arguments
product = check_product(product)
data_sources = _check_data_sources(
base_dir=base_dir,
Expand All @@ -293,11 +293,6 @@ def available_stations(
product=product,
campaign_names=campaign_names,
)
# Format arguments to list
if isinstance(data_sources, str):
data_sources = [data_sources]
if isinstance(campaign_names, str):
campaign_names = [campaign_names]

# If data_source is None, first retrieve all stations
if data_sources is None:
Expand All @@ -309,14 +304,17 @@ def available_stations(
data_sources=data_sources,
product=product,
)

# Then, if campaign_name is not None, subset by campaign_name
if campaign_names is not None:
list_info = [info for info in list_info if info[1] in campaign_names]

if return_tuple:
return list_info

# TODO:
# - Filter by station names !
# - Add check_station_names

# TODO: ENSURE THAT NO DUPLICATED STATION NAMES ?
list_stations = [info[2] for info in list_info]
return list_stations
3 changes: 2 additions & 1 deletion disdrodb/api/scripts/disdrodb_initialize_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------.
"""Script to initialize the DISDRODB station directory structure."""
import sys
from typing import Optional

Expand All @@ -38,7 +39,7 @@ def disdrodb_initialize_station(
# Processing options
base_dir: Optional[str] = None,
):
"""Initialize the DISDRODB directory structure for a station.
r"""Initialize the DISDRODB directory structure for a station.
It adds the relevant directories and the default issue and metadata YAML files..
Expand Down
2 changes: 1 addition & 1 deletion disdrodb/configs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""
Created on Thu Nov 2 15:39:01 2023
Created on Thu Nov 2 15:39:01 2023.
@author: ghiggi
"""
Expand Down
4 changes: 1 addition & 3 deletions disdrodb/data_transfer/download_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def click_download_options(function: object):
function : object
Function.
"""

function = click.option(
"-f",
"--force",
Expand All @@ -103,8 +102,7 @@ def download_archive(
force: bool = False,
base_dir: Optional[str] = None,
):
"""Get all YAML files that contain the ``disdrodb_data_url`` key
and download the data locally.
"""Download DISDRODB stations with the ``disdrodb_data_url`` in the metadata.
Parameters
----------
Expand Down
23 changes: 23 additions & 0 deletions disdrodb/data_transfer/scripts/disdrodb_download_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,29 @@ def disdrodb_download_archive(
base_dir: Optional[str] = None,
force: bool = False,
):
"""Download DISDRODB stations with the ``disdrodb_data_url`` in the metadata.
Parameters
----------
data_sources : str or list of str, optional
Data source name (eg : EPFL).
If not provided (``None``), all data sources will be downloaded.
The default is ``data_source=None``.
campaign_names : str or list of str, optional
Campaign name (eg : EPFL_ROOF_2012).
If not provided (``None``), all campaigns will be downloaded.
The default is ``campaign_name=None``.
station_names : str or list of str, optional
Station name.
If not provided (``None``), all stations will be downloaded.
The default is ``station_name=None``.
force : bool, optional
If ``True``, overwrite the already existing raw data file.
The default is ``False``.
base_dir : str (optional)
Base directory of DISDRODB. Format: ``<...>/DISDRODB``.
If ``None`` (the default), the disdrodb config variable ``base_dir`` is used.
"""
from disdrodb.data_transfer.download_data import download_archive

base_dir = parse_base_dir(base_dir)
Expand Down
23 changes: 23 additions & 0 deletions disdrodb/data_transfer/scripts/disdrodb_download_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@ def disdrodb_download_station(
base_dir: Optional[str] = None,
force: bool = False,
):
"""
Download data of a single DISDRODB station from the DISDRODB remote repository.
Parameters
----------
data_source : str
The name of the institution (for campaigns spanning multiple countries) or
the name of the country (for campaigns or sensor networks within a single country).
Must be provided in UPPER CASE.
campaign_name : str
The name of the campaign. Must be provided in UPPER CASE.
station_name : str
The name of the station.
base_dir : str, optional
The base directory of DISDRODB, expected in the format ``<...>/DISDRODB``.
If not specified, the path specified in the DISDRODB active configuration will be used.
force: bool, optional
If ``True``, overwrite the already existing raw data file.
The default is ``False``.
base_dir : str (optional)
Base directory of DISDRODB. Format: ``<...>/DISDRODB``.
If ``None`` (the default), the disdrodb config variable ``base_dir`` is used.
"""
from disdrodb.data_transfer.download_data import download_station

base_dir = parse_base_dir(base_dir)
Expand Down
30 changes: 30 additions & 0 deletions disdrodb/data_transfer/scripts/disdrodb_upload_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,36 @@ def disdrodb_upload_archive(
platform: Optional[str] = None,
force: bool = False,
):
"""Find all stations containing local data and upload them to a remote repository.
Parameters
----------
platform: str, optional
Name of the remote platform.
The default platform is ``"sandbox.zenodo"`` (for testing purposes).
Switch to ``"zenodo"`` for final data dissemination.
force: bool, optional
If ``True``, upload even if data already exists on another remote location.
The default is ``force=False``.
base_dir : str (optional)
Base directory of DISDRODB. Format: ``<...>/DISDRODB``.
If ``None`` (the default), the ``base_dir`` path specified in the DISDRODB active configuration will be used.
Other Parameters
----------------
data_sources: str or list of str, optional
Data source name (eg: EPFL).
If not provided (``None``), all data sources will be uploaded.
The default is ``data_source=None``.
campaign_names: str or list of str, optional
Campaign name (eg: EPFL_ROOF_2012).
If not provided (``None``), all campaigns will be uploaded.
The default is ``campaign_name=None``.
station_names: str or list of str, optional
Station name.
If not provided (``None``), all stations will be uploaded.
The default is ``station_name=None``.
"""
from disdrodb.data_transfer.upload_data import upload_archive

base_dir = parse_base_dir(base_dir)
Expand Down
27 changes: 27 additions & 0 deletions disdrodb/data_transfer/scripts/disdrodb_upload_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,33 @@ def disdrodb_upload_station(
base_dir: Optional[str] = None,
force: bool = False,
):
"""
Upload data from a single DISDRODB station on a remote repository.
This function also automatically update the disdrodb_data url in the metadata file.
Parameters
----------
data_source : str
The name of the institution (for campaigns spanning multiple countries) or
the name of the country (for campaigns or sensor networks within a single country).
Must be provided in UPPER CASE.
campaign_name : str
The name of the campaign. Must be provided in UPPER CASE.
station_name : str
The name of the station.
base_dir : str, optional
The base directory of DISDRODB, expected in the format ``<...>/DISDRODB``.
If ``None`` (the default), the ``base_dir`` path specified in the DISDRODB active configuration will be used.
platform: str, optional
Name of the remote data storage platform.
The default platform is ``"sandbox.zenodo"`` (for testing purposes).
Switch to ``"zenodo"`` for final data dissemination.
force: bool, optional
If ``True``, upload the data and overwrite the ``disdrodb_data_url``.
The default is ``force=False``.
"""
from disdrodb.data_transfer.upload_data import upload_station

base_dir = parse_base_dir(base_dir)
Expand Down
2 changes: 1 addition & 1 deletion disdrodb/data_transfer/upload_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@


def click_upload_options(function: object):
"""Click command arguments for DISDRODB data upload."""
function = click.option(
"--platform",
type=click.Choice(["zenodo", "sandbox.zenodo"], case_sensitive=False),
Expand Down Expand Up @@ -199,7 +200,6 @@ def upload_archive(
Other Parameters
----------------
data_sources: str or list of str, optional
Data source name (eg: EPFL).
If not provided (``None``), all data sources will be uploaded.
Expand Down
2 changes: 0 additions & 2 deletions disdrodb/data_transfer/zenodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def _check_http_response(
task_description: str,
) -> None:
"""Check the Zenodo HTTP request response status code and raise an error if not the expected one."""

if response.status_code == expected_status_code:
return

Expand Down Expand Up @@ -95,7 +94,6 @@ def _define_disdrodb_data_url(zenodo_host, deposit_id, filename):

def _upload_file_to_zenodo(filepath: str, metadata_filepath: str, sandbox: bool) -> None:
"""Upload a file to a Zenodo bucket."""

# Read metadata
metadata = read_yaml(metadata_filepath)
data_source = metadata["data_source"]
Expand Down
2 changes: 1 addition & 1 deletion disdrodb/issue/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""
Created on Sat Nov 11 01:12:40 2023
Created on Sat Nov 11 01:12:40 2023.
@author: ghiggi
"""
Expand Down
2 changes: 0 additions & 2 deletions disdrodb/issue/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def _is_numpy_array_string(arr):
arr : numpy array
Numpy array to check.
"""

dtype = arr.dtype.type
return dtype in (np.str_, np.unicode_)

Expand Down Expand Up @@ -148,7 +147,6 @@ def check_timesteps(timesteps):

def _check_time_period_nested_list_format(time_periods):
"""Check that the time_periods is a list of list of length 2."""

if not isinstance(time_periods, list):
msg = "'time_periods' must be a list'"
log_error(logger, msg=msg, verbose=False)
Expand Down
4 changes: 3 additions & 1 deletion disdrodb/issue/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@


class NoDatesSafeLoader(yaml.SafeLoader):
"""A YAML loader that does not parse dates."""

@classmethod
def remove_implicit_resolver(cls, tag_to_remove):
"""
Expand All @@ -47,7 +49,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."
"""Read a YAML file without converting automatically date string to datetime."""
NoDatesSafeLoader.remove_implicit_resolver("tag:yaml.org,2002:timestamp")
with open(filepath) as f:
dictionary = yaml.load(f, Loader=NoDatesSafeLoader)
Expand Down
2 changes: 1 addition & 1 deletion disdrodb/issue/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@


def _write_issue_docs(f):
"""Provide template for issue.yml"""
"""Provide template for issue.yml."""
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.
Expand Down
Loading

0 comments on commit f7393ff

Please sign in to comment.