Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Change snapshot_directory property to allow GDA to optionally specify…
Browse files Browse the repository at this point in the history
… it (#1422)
  • Loading branch information
rtuck99 authored Jun 3, 2024
1 parent c1bf9cf commit 0dd461b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/hyperion/parameters/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
TriggerMode,
)
from numpy.typing import NDArray
from pydantic import BaseModel, Extra, Field, validator
from pydantic import BaseModel, Extra, Field, root_validator, validator
from scanspec.core import AxesPoints
from semver import Version

Expand Down Expand Up @@ -161,17 +161,24 @@ class DiffractionExperiment(HyperionParameters):
selected_aperture: AperturePositionGDANames | None = Field(default=None)
ispyb_experiment_type: IspybExperimentType
storage_directory: str
snapshot_directory: Path

@root_validator(pre=True)
def validate_snapshot_directory(cls, values):
snapshot_dir = values.get(
"snapshot_directory", Path(values["storage_directory"], "snapshots")
)
values["snapshot_directory"] = (
snapshot_dir if isinstance(snapshot_dir, Path) else Path(snapshot_dir)
)
return values

@property
def visit_directory(self) -> Path:
return (
Path(CONST.I03.BASE_DATA_DIR) / str(datetime.date.today().year) / self.visit
)

@property
def snapshot_directory(self) -> Path:
return Path(self.storage_directory) / "snapshots"

@property
def num_images(self) -> int:
return 0
Expand Down
16 changes: 16 additions & 0 deletions tests/unit_tests/parameters/test_parameter_model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from pathlib import Path

import pytest
from pydantic import ValidationError
Expand Down Expand Up @@ -82,3 +83,18 @@ def test_robot_load_then_centre_params():
test_params = RobotLoadThenCentre(**params)
assert test_params.visit_directory
assert test_params.detector_params


def test_default_snapshot_path(minimal_3d_gridscan_params):
gridscan_params = ThreeDGridScan(**minimal_3d_gridscan_params)
assert gridscan_params.snapshot_directory == Path(
"/tmp/dls/i03/data/2024/cm31105-4/xraycentring/123456/snapshots"
)

params_with_snapshot_path = dict(minimal_3d_gridscan_params)
params_with_snapshot_path["snapshot_directory"] = "/tmp/my_snapshots"

gridscan_params_with_snapshot_path = ThreeDGridScan(**params_with_snapshot_path)
assert gridscan_params_with_snapshot_path.snapshot_directory == Path(
"/tmp/my_snapshots"
)

0 comments on commit 0dd461b

Please sign in to comment.