Skip to content

Commit

Permalink
Fix disdrodb_initialize_station and base_dir defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiggi committed Dec 4, 2023
1 parent 30b9496 commit 65ee24d
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 22 deletions.
7 changes: 4 additions & 3 deletions disdrodb/api/scripts/disdrodb_initialize_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import click

from disdrodb.utils.scripts import click_base_dir_option, click_station_arguments
from disdrodb.utils.scripts import click_base_dir_option, click_station_arguments, parse_base_dir

sys.tracebacklimit = 0 # avoid full traceback error if occur

Expand Down Expand Up @@ -56,8 +56,9 @@ def disdrodb_initialize_station(
Format: <...>/DISDRODB \n
If not specified, uses path specified in the DISDRODB active configuration. \n
"""
from disdrodb.l0.routines import create_initial_station_structure

from disdrodb.api.create_directories import create_initial_station_structure
base_dir = parse_base_dir(base_dir)

create_initial_station_structure(
base_dir=base_dir,
data_source=data_source,
Expand Down
5 changes: 2 additions & 3 deletions disdrodb/data_transfer/scripts/disdrodb_download_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import click

from disdrodb.data_transfer.download_data import click_download_archive_options, click_download_options
from disdrodb.utils.scripts import click_base_dir_option
from disdrodb.utils.scripts import click_base_dir_option, parse_base_dir, parse_arg_to_list

sys.tracebacklimit = 0 # avoid full traceback error if occur

Expand All @@ -38,8 +38,7 @@ def disdrodb_download_archive(
force: bool = False,
):
from disdrodb.data_transfer.download_data import download_archive
from disdrodb.utils.scripts import parse_arg_to_list

base_dir = parse_base_dir(base_dir)
data_sources = parse_arg_to_list(data_sources)
campaign_names = parse_arg_to_list(campaign_names)
station_names = parse_arg_to_list(station_names)
Expand Down
4 changes: 2 additions & 2 deletions disdrodb/data_transfer/scripts/disdrodb_download_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import click

from disdrodb.data_transfer.download_data import click_download_options
from disdrodb.utils.scripts import click_base_dir_option, click_station_arguments
from disdrodb.utils.scripts import click_base_dir_option, click_station_arguments, parse_base_dir

sys.tracebacklimit = 0 # avoid full traceback error if occur

Expand All @@ -40,7 +40,7 @@ def disdrodb_download_station(
force: bool = False,
):
from disdrodb.data_transfer.download_data import download_station

base_dir = parse_base_dir(base_dir)
download_station(
base_dir=base_dir,
data_source=data_source,
Expand Down
4 changes: 2 additions & 2 deletions disdrodb/data_transfer/scripts/disdrodb_upload_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import click

from disdrodb.data_transfer.upload_data import click_upload_archive_options, click_upload_options
from disdrodb.utils.scripts import click_base_dir_option
from disdrodb.utils.scripts import click_base_dir_option, parse_arg_to_list, parse_base_dir

sys.tracebacklimit = 0 # avoid full traceback error if occur

Expand All @@ -41,8 +41,8 @@ def disdrodb_upload_archive(
force: bool = False,
):
from disdrodb.data_transfer.upload_data import upload_archive
from disdrodb.utils.scripts import parse_arg_to_list

base_dir = parse_base_dir(base_dir)
data_sources = parse_arg_to_list(data_sources)
campaign_names = parse_arg_to_list(campaign_names)
station_names = parse_arg_to_list(station_names)
Expand Down
5 changes: 3 additions & 2 deletions disdrodb/data_transfer/scripts/disdrodb_upload_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import click

from disdrodb.data_transfer.upload_data import click_upload_options
from disdrodb.utils.scripts import click_base_dir_option, click_station_arguments
from disdrodb.utils.scripts import click_base_dir_option, click_station_arguments, parse_base_dir

sys.tracebacklimit = 0 # avoid full traceback error if occur

Expand All @@ -41,7 +41,8 @@ def disdrodb_upload_station(
force: bool = False,
):
from disdrodb.data_transfer.upload_data import upload_station


base_dir = parse_base_dir(base_dir)
upload_station(
base_dir=base_dir,
data_source=data_source,
Expand Down
5 changes: 3 additions & 2 deletions disdrodb/metadata/scripts/disdrodb_check_metadata_archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import click

from disdrodb.utils.scripts import click_base_dir_option
from disdrodb.utils.scripts import click_base_dir_option, parse_base_dir

sys.tracebacklimit = 0 # avoid full traceback error if occur

Expand All @@ -31,5 +31,6 @@
)
def disdrodb_check_metadata_archive(base_dir=None, raise_error=True):
from disdrodb.metadata.checks import check_archive_metadata_compliance


base_dir = parse_base_dir(base_dir)
check_archive_metadata_compliance(base_dir=base_dir, raise_error=raise_error)
34 changes: 34 additions & 0 deletions disdrodb/tests/test_api/test_api_create_directories.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import os

import pytest
from click.testing import CliRunner

from disdrodb.api.scripts.disdrodb_initialize_station import disdrodb_initialize_station
from disdrodb.api.create_directories import (
_check_campaign_name_consistency,
_check_data_source_consistency,
Expand Down Expand Up @@ -322,6 +324,38 @@ def test_create_initial_station_structure(tmp_path):
)


def test_create_initial_station_structure_cmd(tmp_path):
"""Check creation of station initial files and directories."""
base_dir = tmp_path / "DISDRODB"
campaign_name = "CAMPAIGN_NAME"
data_source = "DATA_SOURCE"
station_name = "station_name"

# Invoke command in the terminal
runner = CliRunner()
runner.invoke(
disdrodb_initialize_station,
[data_source, campaign_name, station_name, "--base_dir", str(base_dir)],
)

# Check metadata and issue files have been created
metadata_filepath = define_metadata_filepath(
base_dir=base_dir,
data_source=data_source,
campaign_name=campaign_name,
station_name=station_name,
product="RAW",
)
issue_filepath = define_issue_filepath(
base_dir=base_dir,
data_source=data_source,
campaign_name=campaign_name,
station_name=station_name,
)
assert os.path.exists(metadata_filepath)
assert os.path.exists(issue_filepath)


def test_create_test_archive(tmp_path):
"""Check creation of test archive."""
base_dir = tmp_path / "base" / "DISDRODB"
Expand Down
17 changes: 9 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,14 @@ packages = ["disdrodb"]

[project.scripts]
# Initialization
disdrodb_initialize_station="disdrodb.api.create_directories.scripts.disdrodb_initialize_station:disdrodb_initialize_station"
disdrodb_initialize_station="disdrodb.api.scripts.disdrodb_initialize_station:disdrodb_initialize_station"
# Metadata archive
disdrodb_check_metadata_archive="disdrodb.metadata.scripts.disdrodb_check_metadata_archive:disdrodb_check_metadata_archive"
# Data transfer
disdrodb_download_archive="disdrodb.data_transfer.scripts.disdrodb_download_archive:disdrodb_download_archive"
disdrodb_download_station="disdrodb.data_transfer.scripts.disdrodb_download_station:disdrodb_download_station"
disdrodb_upload_archive="disdrodb.data_transfer.scripts.disdrodb_upload_archive:disdrodb_upload_archive"
disdrodb_upload_station="disdrodb.data_transfer.scripts.disdrodb_upload_station:disdrodb_upload_station"
# L0A
disdrodb_run_l0a_station="disdrodb.l0.scripts.disdrodb_run_l0a_station:disdrodb_run_l0a_station"
disdrodb_run_l0a="disdrodb.l0.scripts.disdrodb_run_l0a:disdrodb_run_l0a"
Expand All @@ -80,13 +87,7 @@ disdrodb_run_l0b_concat="disdrodb.l0.scripts.disdrodb_run_l0b_concat:disdrodb_ru
# L0
disdrodb_run_l0b="disdrodb.l0.scripts.disdrodb_run_l0b:disdrodb_run_l0b"
disdrodb_run_l0="disdrodb.l0.scripts.disdrodb_run_l0:disdrodb_run_l0"
# Data transfer
disdrodb_download_archive="disdrodb.data_transfer.scripts.disdrodb_download_archive:disdrodb_download_archive"
disdrodb_download_station="disdrodb.data_transfer.scripts.disdrodb_download_station:disdrodb_download_station"
disdrodb_upload_archive="disdrodb.data_transfer.scripts.disdrodb_upload_archive:disdrodb_upload_archive"
disdrodb_upload_station="disdrodb.data_transfer.scripts.disdrodb_upload_station:disdrodb_upload_station"
# Metadata archive
disdrodb_check_metadata_archive="disdrodb.metadata.scripts.disdrodb_check_metadata_archive:disdrodb_check_metadata_archive"


[tool.pytest.ini_options]
addopts = "--cov --cov-report term-missing --cov-report xml --cov-report lcov:lcov.info"
Expand Down

0 comments on commit 65ee24d

Please sign in to comment.