Skip to content

Commit

Permalink
rename path templates and introduce optional config section
Browse files Browse the repository at this point in the history
  • Loading branch information
hgloeckner committed Aug 19, 2024
1 parent cf18ed8 commit df08fbb
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 22 deletions.
11 changes: 3 additions & 8 deletions halodrops.cfg
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
[MANDATORY]
data_directory = ./example_data

[helper.paths.Flight.__init__]
path_structure = {platform}/Level_0/{flight}

[helper.paths.Platform.__init__]
path_structure = {platform}/Level_0

[processor.Sonde.add_path_structure]
path_structure = {platform}/Level_0/{flight}
[OPTIONAL]
path_to_flight_ids = {platform}/Level_0
path_to_l0_files = {platform}/Level_0/{flight_id}
4 changes: 2 additions & 2 deletions src/halodrops/helper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@
)


platform_path_template = "{platform}/Level_0"
flight_path_template = "{platform}/Level_0/{flight_id}"
path_to_flight_ids = "{platform}/Level_0"
path_to_l0_files = "{platform}/Level_0/{flight_id}"

l2_flight_attributes_map = {
"True Air Speed (m/s)": "true_air_speed_(ms-1)",
Expand Down
8 changes: 4 additions & 4 deletions src/halodrops/helper/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from halodrops.helper import rawreader as rr
from halodrops.processor import Sonde
from halodrops.helper import platform_path_template, flight_path_template
from halodrops.helper import path_to_flight_ids, path_to_l0_files

# create logger
module_logger = logging.getLogger("halodrops.helper.paths")
Expand All @@ -25,7 +25,7 @@ def __init__(
data_directory,
platform_id,
platform_directory_name=None,
path_structure=platform_path_template,
path_structure=path_to_flight_ids,
) -> None:
self.platform_id = platform_id
self.platform_directory_name = platform_directory_name
Expand Down Expand Up @@ -64,7 +64,7 @@ def __init__(
data_directory,
flight_id,
platform_id,
path_structure=flight_path_template,
path_structure=path_to_l0_files,
):
"""Creates an instance of Paths object for a given flight
Expand Down Expand Up @@ -101,7 +101,7 @@ def __init__(
flight_dir = os.path.join(
self.data_directory,
self.path_structure.format(
platform=self.platform_id, flight=self.flight_id
platform=self.platform_id, flight_id=self.flight_id
),
)
self.flight_idpath = flight_dir
Expand Down
14 changes: 7 additions & 7 deletions src/halodrops/pipeline.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .helper.paths import Platform, Flight
from .helper.__init__ import platform_path_template, flight_path_template
from .helper.__init__ import path_to_flight_ids, path_to_l0_files
from .processor import Sonde
import configparser
import inspect
Expand Down Expand Up @@ -162,16 +162,16 @@ def get_platforms(config):
"""
data_directory = config.get("MANDATORY", "data_directory")
path_structure = config.get(
"MANDATORY", "platform_path_structure", fallback=platform_path_template
"OPTIONAL", "path_to_flight_ids", fallback=path_to_flight_ids
)
if config.has_option("MANDATORY", "platforms"):
if not config.has_option("MANDATORY", "platform_directory_names"):
if config.has_option("OPTIONAL", "platforms"):
if not config.has_option("OPTIONAL", "platform_directory_names"):
raise ValueError(
"platform_directory_names must be provided in the config file when platforms is specified"
)
platforms = config.get("MANDATORY", "platforms").split(",")
platforms = config.get("OPTIONAL", "platforms").split(",")
platform_directory_names = config.get(
"MANDATORY", "platform_directory_names"
"OPTIONAL", "platform_directory_names"
).split(",")
platforms = dict(zip(platforms, platform_directory_names))
for directory_name in platform_directory_names:
Expand Down Expand Up @@ -223,7 +223,7 @@ def create_and_populate_flight_object(

platform_objects = get_platforms(config)
path_structure = config.get(
"MANDATORY", "flight_path_structure", fallback=flight_path_template
"OPTIONAL", "path_to_l0_files", fallback=path_to_l0_files
)
output["platforms"] = platform_objects
output["sondes"] = {}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
main_data_directory = "./example_data"
platform_id = "HALO"
flightdate = "20200119"
path_structure = "{platform}/Level_0/{flight}"
path_structure = "{platform}/Level_0/{flight_id}"
platform_path_structure = "{platform}/Level_0"

l1_path = os.path.join(main_data_directory, platform_id, "Level_1", flightdate)
Expand Down

0 comments on commit df08fbb

Please sign in to comment.