Skip to content

Commit

Permalink
Merge pull request #508 from OpenCOMPES/src_layout
Browse files Browse the repository at this point in the history
Src layout
  • Loading branch information
rettigl authored Nov 12, 2024
2 parents d26654b + 0d1b805 commit 1b7b926
Show file tree
Hide file tree
Showing 74 changed files with 68 additions and 66 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches: [ main ]
tags: [ v* ]
paths:
- sed/**/*
- src/sed/**/*
- tutorial/**
- .github/workflows/documentation.yml
# Allows you to run this workflow manually from the Actions tab
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
- name: copy tutorial files to docs
run: |
cp -r $GITHUB_WORKSPACE/tutorial $GITHUB_WORKSPACE/docs/
cp -r $GITHUB_WORKSPACE/sed/config $GITHUB_WORKSPACE/docs/sed
cp -r $GITHUB_WORKSPACE/config $GITHUB_WORKSPACE/docs/
- name: download RAW data
# if: steps.cache-primes.outputs.cache-hit != 'true'
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ jobs:
# Linting steps, execute all linters even if one fails
- name: ruff
run:
poetry run ruff sed tests
poetry run ruff src/sed tests
- name: ruff formatting
if: ${{ always() }}
run:
poetry run ruff format --check sed tests
poetry run ruff format --check src/sed tests
- name: mypy
if: ${{ always() }}
run:
poetry run mypy sed tests
poetry run mypy src/sed tests
- name: spellcheck
if: ${{ always() }}
uses: streetsidesoftware/cspell-action@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
tags:
- v[0-9]+.[0-9]+.[0-9]+
paths:
- sed/**/*
- src/sed/**/*
- .github/workflows/release.yml
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down
20 changes: 10 additions & 10 deletions benchmarks/benchmark_sed.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
test_data_dir = os.path.join(package_dir, "..", "tests", "data")
runs = {"generic": None, "mpes": ["30", "50"], "flash": ["43878"], "sxp": ["0016"]}

targets = load_config(package_dir + "/../benchmarks/benchmark_targets.yaml")
targets = load_config(package_dir + "/../../benchmarks/benchmark_targets.yaml")


def test_binning_1d() -> None:
Expand All @@ -59,7 +59,7 @@ def test_binning_1d() -> None:
if np.mean(result) < 0.8 * targets["binning_1d"]:
print(f"Updating targets for 'binning_1d' to {float(np.mean(result))}")
targets["binning_1d"] = float(np.mean(result))
save_config(targets, package_dir + "/../benchmarks/benchmark_targets.yaml")
save_config(targets, package_dir + "/../../benchmarks/benchmark_targets.yaml")


def test_binning_4d() -> None:
Expand All @@ -83,14 +83,14 @@ def test_binning_4d() -> None:
if np.mean(result) < 0.8 * targets["binning_4d"]:
print(f"Updating targets for 'binning_4d' to {float(np.mean(result))}")
targets["binning_4d"] = float(np.mean(result))
save_config(targets, package_dir + "/../benchmarks/benchmark_targets.yaml")
save_config(targets, package_dir + "/../../benchmarks/benchmark_targets.yaml")


def test_splinewarp() -> None:
"""Run a benchmark for the generation of the inverse dfield correction"""
processor = SedProcessor(
dataframe=dataframe.copy(),
config=package_dir + "/config/mpes_example_config.yaml",
config=package_dir + "/../../config/mpes_example_config.yaml",
folder_config={},
user_config={},
system_config={},
Expand All @@ -109,14 +109,14 @@ def test_splinewarp() -> None:
if np.mean(result) < 0.8 * targets["inv_dfield"]:
print(f"Updating targets for 'inv_dfield' to {float(np.mean(result))}")
targets["inv_dfield"] = float(np.mean(result))
save_config(targets, package_dir + "/../benchmarks/benchmark_targets.yaml")
save_config(targets, package_dir + "/../../benchmarks/benchmark_targets.yaml")


def test_workflow_1d() -> None:
"""Run a benchmark for 1d binning of converted data"""
processor = SedProcessor(
dataframe=dataframe.copy(),
config=package_dir + "/config/mpes_example_config.yaml",
config=package_dir + "/../../config/mpes_example_config.yaml",
folder_config={},
user_config={},
system_config={},
Expand Down Expand Up @@ -145,14 +145,14 @@ def test_workflow_1d() -> None:
if np.mean(result) < 0.8 * targets["workflow_1d"]:
print(f"Updating targets for 'workflow_1d' to {float(np.mean(result))}")
targets["workflow_1d"] = float(np.mean(result))
save_config(targets, package_dir + "/../benchmarks/benchmark_targets.yaml")
save_config(targets, package_dir + "/../../benchmarks/benchmark_targets.yaml")


def test_workflow_4d() -> None:
"""Run a benchmark for 4d binning of converted data"""
processor = SedProcessor(
dataframe=dataframe.copy(),
config=package_dir + "/config/mpes_example_config.yaml",
config=package_dir + "/../../config/mpes_example_config.yaml",
folder_config={},
user_config={},
system_config={},
Expand Down Expand Up @@ -181,7 +181,7 @@ def test_workflow_4d() -> None:
if np.mean(result) < 0.8 * targets["workflow_4d"]:
print(f"Updating targets for 'workflow_4d' to {float(np.mean(result))}")
targets["workflow_4d"] = float(np.mean(result))
save_config(targets, package_dir + "/../benchmarks/benchmark_targets.yaml")
save_config(targets, package_dir + "/../../benchmarks/benchmark_targets.yaml")


@pytest.mark.parametrize("loader", get_all_loaders())
Expand Down Expand Up @@ -210,4 +210,4 @@ def test_loader_compute(loader: BaseLoader) -> None:
f"to {float(np.mean(result))}",
)
targets[f"loader_compute_{loader_name}"] = float(np.mean(result))
save_config(targets, package_dir + "/../benchmarks/benchmark_targets.yaml")
save_config(targets, package_dir + "/../../benchmarks/benchmark_targets.yaml")
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,4 @@ nexus:
definition: "NXmpes"
# List containing additional input files to be handed to the pynxtools converter tool,
# e.g. containing a configuration file, and additional metadata.
input_files: ["../sed/config/NXmpes_config.json"]
input_files: ["../config/NXmpes_config.json"]
File renamed without changes.
8 changes: 5 additions & 3 deletions docs/scripts/build_flash_parquets.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from pathlib import Path
import os
from importlib.util import find_spec

import sed
from sed import SedProcessor
from sed.dataset import dataset

config_file = Path(sed.__file__).parent / "config/flash_example_config.yaml"
package_dir = os.path.dirname(find_spec("sed").origin)

config_file = package_dir + "/../../config/flash_example_config.yaml"

dataset.get("Gd_W110", root_dir="./tutorial")
data_path = dataset.dir
Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[tool.poetry]
name = "sed-processor"
packages = [
{include = "sed"}
]
packages = [{include = "sed", from = "src"}]
include = ["config"]
version = "1.0.0a0"
description = "Single Event Data Frame Processor: Backend to handle photoelectron resolved datastreams"
authors = ["OpenCOMPES team <[email protected]>"]
Expand Down Expand Up @@ -84,7 +83,7 @@ omit = [
]

[tool.ruff]
include = ["sed/*.py", "tests/*.py"]
include = ["src/*.py", "tests/*.py"]
lint.select = [
"E", # pycodestyle
"W", # pycodestyle
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions sed/core/config.py → src/sed/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import yaml
from platformdirs import user_config_path

from sed.config.config_model import ConfigModel
from sed.core.config_model import ConfigModel
from sed.core.logging import setup_logging

package_dir = os.path.dirname(find_spec("sed").origin)
Expand All @@ -28,7 +28,7 @@ def parse_config(
folder_config: dict | str = None,
user_config: dict | str = None,
system_config: dict | str = None,
default_config: (dict | str) = f"{package_dir}/config/default.yaml",
default_config: (dict | str) = f"{package_dir}/../../config/default.yaml",
verbose: bool = True,
verify_config: bool = True,
) -> dict:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion sed/dataset/dataset.py → src/sed/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class DatasetsManager:
FILENAME = NAME + ".json"
json_path = {}
json_path["user"] = os.path.join(USER_CONFIG_PATH, FILENAME)
json_path["module"] = os.path.join(os.path.dirname(__file__), FILENAME)
json_path["module"] = os.path.join(os.path.dirname(__file__), "../../../config", FILENAME)
json_path["folder"] = "./" + FILENAME

@staticmethod
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/calibrator/test_delay.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from sed.loader.loader_interface import get_loader

package_dir = os.path.dirname(find_spec("sed").origin)
file = package_dir + "/../tests/data/loader/mpes/Scan0030_2.h5"
file = package_dir + "/../../tests/data/loader/mpes/Scan0030_2.h5"


def test_delay_parameters_from_file() -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/calibrator/test_energy.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from sed.loader.loader_interface import get_loader

package_dir = os.path.dirname(find_spec("sed").origin)
df_folder = package_dir + "/../tests/data/loader/mpes/"
folder = package_dir + "/../tests/data/calibrator/"
df_folder = package_dir + "/../../tests/data/loader/mpes/"
folder = package_dir + "/../../tests/data/calibrator/"
files = glob.glob(df_folder + "*.h5")

traces_list = []
Expand Down
4 changes: 2 additions & 2 deletions tests/calibrator/test_momentum.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

# pylint: disable=duplicate-code
package_dir = os.path.dirname(find_spec("sed").origin)
df_folder = package_dir + "/../tests/data/loader/mpes/"
folder = package_dir + "/../tests/data/calibrator/"
df_folder = package_dir + "/../../tests/data/loader/mpes/"
folder = package_dir + "/../../tests/data/calibrator/"
files = glob.glob(df_folder + "*.h5")

momentum_map_list = []
Expand Down
11 changes: 6 additions & 5 deletions tests/loader/flash/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from sed.core.config import parse_config

package_dir = os.path.dirname(find_spec("sed").origin)
config_path = os.path.join(package_dir, "../tests/data/loader/flash/config.yaml")
config_path = os.path.join(package_dir, "../../tests/data/loader/flash/config.yaml")
H5_PATH = "FLASH1_USER3_stream_2_run43878_file1_20230130T153807.1.h5"
H5_PATHS = [H5_PATH, "FLASH1_USER3_stream_2_run43879_file1_20230130T153807.1.h5"]

Expand Down Expand Up @@ -45,7 +45,7 @@ def fixture_h5_file() -> h5py.File:
Returns:
h5py.File: The open h5 file.
"""
return h5py.File(os.path.join(package_dir, f"../tests/data/loader/flash/{H5_PATH}"), "r")
return h5py.File(os.path.join(package_dir, f"../../tests/data/loader/flash/{H5_PATH}"), "r")


@pytest.fixture(name="h5_file_copy")
Expand All @@ -56,7 +56,7 @@ def fixture_h5_file_copy(tmp_path: Path) -> h5py.File:
h5py.File: The open h5 file copy.
"""
# Create a copy of the h5 file in a temporary directory
original_file_path = os.path.join(package_dir, f"../tests/data/loader/flash/{H5_PATH}")
original_file_path = os.path.join(package_dir, f"../../tests/data/loader/flash/{H5_PATH}")
copy_file_path = tmp_path / "copy.h5"
shutil.copyfile(original_file_path, copy_file_path)

Expand All @@ -72,7 +72,7 @@ def fixture_h5_file2_copy(tmp_path: Path) -> h5py.File:
h5py.File: The open h5 file copy.
"""
# Create a copy of the h5 file in a temporary directory
original_file_path = os.path.join(package_dir, f"../tests/data/loader/flash/{H5_PATHS[1]}")
original_file_path = os.path.join(package_dir, f"../../tests/data/loader/flash/{H5_PATHS[1]}")
copy_file_path = tmp_path / "copy2.h5"
shutil.copyfile(original_file_path, copy_file_path)

Expand All @@ -88,5 +88,6 @@ def fixture_h5_paths() -> list[Path]:
list: A list of h5 file paths.
"""
return [
Path(os.path.join(package_dir, f"../tests/data/loader/flash/{path}")) for path in H5_PATHS
Path(os.path.join(package_dir, f"../../tests/data/loader/flash/{path}"))
for path in H5_PATHS
]
2 changes: 1 addition & 1 deletion tests/loader/mpes/test_mpes_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

package_dir = os.path.dirname(find_spec("sed").origin)

test_data_dir = os.path.join(package_dir, "..", "tests", "data", "loader", "mpes")
test_data_dir = os.path.join(package_dir, "../../tests/data/loader/mpes")

config = parse_config(
os.path.join(test_data_dir, "config.yaml"),
Expand Down
2 changes: 1 addition & 1 deletion tests/loader/sxp/test_sxp_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from sed.loader.sxp.loader import SXPLoader

package_dir = os.path.dirname(find_spec("sed").origin)
config_path = os.path.join(package_dir, "../tests/data/loader/sxp/config.yaml")
config_path = os.path.join(package_dir, "../../tests/data/loader/sxp/config.yaml")
H5_PATH = "RAW-R0016-DA03-S00000.h5"


Expand Down
2 changes: 1 addition & 1 deletion tests/loader/test_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

package_dir = os.path.dirname(find_spec("sed").origin)

test_data_dir = os.path.join(package_dir, "..", "tests", "data")
test_data_dir = os.path.join(package_dir, "../../tests/data")

read_types = ["one_file", "files", "one_folder", "folders", "one_run", "runs"]
runs = {"generic": None, "mpes": ["30", "50"], "flash": ["43878", "43878"], "sxp": ["0016", "0016"]}
Expand Down
6 changes: 3 additions & 3 deletions tests/loader/test_mirrorutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@


package_dir = os.path.dirname(find_spec("sed").origin)
source_folder = package_dir + "/../"
folder = package_dir + "/../tests/data/loader/mpes"
file = package_dir + "/../tests/data/loader/mpes/Scan0030_2.h5"
source_folder = package_dir + "/../../"
folder = package_dir + "/../../tests/data/loader/mpes"
file = package_dir + "/../../tests/data/loader/mpes/Scan0030_2.h5"


def test_copy_tool_folder() -> None:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,18 @@ def test_load_does_not_modify() -> None:
def test_load_config() -> None:
"""Test if the config loader can handle json and yaml files."""
config_json = load_config(
f"{package_dir}/../tests/data/config/config.json",
f"{package_dir}/../../tests/data/config/config.json",
)
config_yaml = load_config(
f"{package_dir}/../tests/data/config/config.yaml",
f"{package_dir}/../../tests/data/config/config.yaml",
)
assert config_json == config_yaml


def test_load_config_raise() -> None:
"""Test if the config loader raises an error for a wrong file type."""
with pytest.raises(TypeError):
load_config(f"{package_dir}/../README.md")
load_config(f"{package_dir}/../../README.md")


def test_complete_dictionary() -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from sed.dataset import DatasetsManager as dm

package_dir = os.path.dirname(find_spec("sed").origin)
json_path = os.path.join(package_dir, "datasets.json")
json_path = os.path.join(package_dir, "../../config/datasets.json")


@pytest.fixture
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_rearrange_data(zip_file): # noqa: ARG001
ds._rearrange_data()
assert os.path.exists("test/datasets/Test/test_file.txt")
assert os.path.exists("test/datasets/Test/test_subdir.txt")
assert ~os.path.exists("test/datasets/Test/subdir")
assert not os.path.exists("test/datasets/Test/subdir")

with pytest.raises(FileNotFoundError):
ds._subdirs = ["non_existing_subdir"]
Expand Down
6 changes: 3 additions & 3 deletions tests/test_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

# pylint: disable=duplicate-code
package_dir = os.path.dirname(find_spec("sed").origin)
df_folder = package_dir + "/../tests/data/loader/mpes/"
folder = package_dir + "/../tests/data/calibrator/"
df_folder = package_dir + "/../../tests/data/loader/mpes/"
folder = package_dir + "/../../tests/data/calibrator/"
files = glob.glob(df_folder + "*.h5")
config = parse_config(
package_dir + "/../tests/data/loader/mpes/config.yaml",
package_dir + "/../../tests/data/loader/mpes/config.yaml",
folder_config={},
user_config={},
system_config={},
Expand Down
Loading

0 comments on commit 1b7b926

Please sign in to comment.