Skip to content

Commit

Permalink
FIX: Make sure configurations are synced between packages (IMAP-Scien…
Browse files Browse the repository at this point in the history
…ce-Operations-Center#336)

This moves all the data configuration handling to the imap_data_access
package.
  • Loading branch information
greglucas authored Feb 13, 2024
1 parent a29978f commit 96be9a0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 57 deletions.
13 changes: 0 additions & 13 deletions imap_processing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,8 @@
# packet definitions directory path.
#
# This directory is used by the imap_processing package to find the packet definitions.
import os
from pathlib import Path

# NOTE: Use a config dictionary, so it is a mutable global object,
# otherwise updating previous imports from other modules
# wouldn't have been updated globally (for example if referencing a string).
config = {"DATA_DIR": Path(os.getenv("IMAP_DATA_DIR") or Path.cwd() / "imap-data")}
"""imap_processing configuration dictionary.
DATA_DIR : This is where the file data is stored and organized by instrument and level.
The default location is in the current working directory, but can be
set on the command line using the --data-dir option, or through
the environment variable IMAP_DATA_DIR.
"""

# Eg. imap_module_directory = /usr/local/lib/python3.11/site-packages/imap_processing
imap_module_directory = Path(__file__).parent

Expand Down
7 changes: 3 additions & 4 deletions imap_processing/cdf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
from pathlib import Path
from typing import Optional

import imap_data_access
import numpy as np
import xarray as xr
from cdflib.xarray import xarray_to_cdf

import imap_processing


def calc_start_time(shcoarse_time: int):
"""Calculate the datetime64 from the CCSDS secondary header information.
Expand Down Expand Up @@ -62,7 +61,7 @@ def write_cdf(
orbit, before the SPICE field. No underscores allowed.
directory : pathlib.Path, optional
The directory to write the file to. The default is obtained
from the global imap_processing.config["DATA_DIR"].
from the global imap_data_access.config["DATA_DIR"].
Returns
-------
Expand Down Expand Up @@ -104,7 +103,7 @@ def write_cdf(
# mission/instrument/data_level/year/month/filename
# /<directory | DATA_DIR>/<instrument>/<data_level>/<year>/<month>
_, instrument, data_level = data.attrs["Logical_source"].split("_")
directory = imap_processing.config["DATA_DIR"] / instrument / data_level
directory = imap_data_access.config["DATA_DIR"] / instrument / data_level
directory /= date_string[:4]
directory /= date_string[4:6]
filename_and_path = Path(directory)
Expand Down
2 changes: 1 addition & 1 deletion imap_processing/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _validate_args(args):
if not data_path.exists():
raise ValueError(f"Data directory {args.data_dir} does not exist")
# Set the data directory to the user-supplied value
imap_processing.config["DATA_DIR"] = data_path
imap_data_access.config["DATA_DIR"] = data_path


class ProcessInstrument(ABC):
Expand Down
13 changes: 6 additions & 7 deletions imap_processing/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""Global pytest configuration for the package."""
import imap_data_access
import pytest

import imap_processing


@pytest.fixture(autouse=True)
def _set_global_data_dir(tmp_path):
def _set_global_config(monkeypatch, tmp_path):
"""Set the global data directory to a temporary directory."""
_original_data_dir = imap_processing.config["DATA_DIR"]
imap_processing.config["DATA_DIR"] = tmp_path
yield
imap_processing.config["DATA_DIR"] = _original_data_dir
monkeypatch.setitem(imap_data_access.config, "DATA_DIR", tmp_path)
monkeypatch.setitem(
imap_data_access.config, "DATA_ACCESS_URL", "https://api.test.com"
)
32 changes: 0 additions & 32 deletions imap_processing/tests/test_data_access.py

This file was deleted.

0 comments on commit 96be9a0

Please sign in to comment.