-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into ewm7922-defect-pixel-masks
- Loading branch information
Showing
92 changed files
with
3,026 additions
and
1,542 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
[submodule "tests/data/snapred-data"] | ||
path = tests/data/snapred-data | ||
url = https://code.ornl.gov/sns-hfir-scse/infrastructure/test-data/snapred-data.git | ||
branch = main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,51 @@ | ||
from typing import Any, Optional | ||
|
||
from numpy import integer | ||
from pydantic import BaseModel, computed_field, field_serializer | ||
from pydantic import BaseModel, ConfigDict, field_validator | ||
|
||
from snapred.meta.Config import Config | ||
from snapred.meta.Enum import StrEnum | ||
|
||
VERSION_START = Config["version.start"] | ||
VERSION_NONE_NAME = Config["version.friendlyName.error"] | ||
VERSION_DEFAULT_NAME = Config["version.friendlyName.default"] | ||
|
||
# VERSION_DEFAULT is a SNAPRed-internal "magic" integer: | ||
# * it is implicitely set during `Config` initialization. | ||
VERSION_DEFAULT = Config["version.default"] | ||
|
||
class VersionState(StrEnum): | ||
DEFAULT = Config["version.friendlyName.default"] | ||
LATEST = "latest" | ||
NEXT = "next" | ||
|
||
|
||
# I'm not sure why ci is failing without this, it doesn't seem to be used anywhere | ||
VERSION_DEFAULT = VersionState.DEFAULT | ||
|
||
Version = int | VersionState | ||
|
||
|
||
class VersionedObject(BaseModel): | ||
# Base class for all versioned DAO | ||
|
||
# In pydantic, a leading double underscore activates | ||
# the `__pydantic_private__` feature, which limits the visibility | ||
# of the attribute to the interior scope of its own class. | ||
__version: Optional[int] = None | ||
|
||
@classmethod | ||
def parseVersion(cls, version, *, exclude_none: bool = False, exclude_default: bool = False) -> int | None: | ||
v: int | None | ||
# handle two special cases | ||
if (not exclude_none) and (version is None or version == VERSION_NONE_NAME): | ||
v = None | ||
elif (not exclude_default) and (version == VERSION_DEFAULT_NAME or version == VERSION_DEFAULT): | ||
v = VERSION_DEFAULT | ||
# parse integers | ||
elif isinstance(version, int | integer): | ||
if int(version) >= VERSION_START: | ||
v = int(version) | ||
else: | ||
raise ValueError(f"Given version {version} is smaller than start version {VERSION_START}") | ||
# otherwise this is an error | ||
else: | ||
raise ValueError(f"Cannot initialize version as {version}") | ||
return v | ||
|
||
@classmethod | ||
def writeVersion(cls, version) -> int | str: | ||
v: int | str | ||
if version is None: | ||
v = VERSION_NONE_NAME | ||
elif version == VERSION_DEFAULT: | ||
v = VERSION_DEFAULT_NAME | ||
elif isinstance(version, int | integer): | ||
v = int(version) | ||
else: | ||
raise ValueError("Version is not valid") | ||
return v | ||
|
||
def __init__(self, **kwargs): | ||
version = kwargs.pop("version", None) | ||
super().__init__(**kwargs) | ||
self.__version = self.parseVersion(version) | ||
|
||
@field_serializer("version", check_fields=False, when_used="json") | ||
def write_user_defaults(self, value: Any): # noqa ARG002 | ||
return self.writeVersion(self.__version) | ||
|
||
# NOTE some serialization still using the dict() method | ||
def dict(self, **kwargs): | ||
res = super().dict(**kwargs) | ||
res["version"] = self.writeVersion(res["version"]) | ||
return res | ||
|
||
@computed_field | ||
@property | ||
def version(self) -> int: | ||
return self.__version | ||
|
||
@version.setter | ||
def version(self, v): | ||
self.__version = self.parseVersion(v, exclude_none=True) | ||
version: Version | ||
|
||
@field_validator("version", mode="before") | ||
def validate_version(cls, value: Version) -> Version: | ||
if value in VersionState.values(): | ||
return value | ||
|
||
if isinstance(value, str): | ||
raise ValueError(f"Version must be an int or {VersionState.values()}") | ||
|
||
if value is None: | ||
raise ValueError("Version must be specified") | ||
|
||
if value < VERSION_START: | ||
raise ValueError(f"Version must be greater than {VERSION_START}") | ||
|
||
return value | ||
|
||
# NOTE: This approach was taken because 'field_serializer' was checking against the | ||
# INITIAL value of version for some reason. This is a workaround. | ||
# | ||
def model_dump_json(self, *args, **kwargs): # noqa ARG002 | ||
if self.version in VersionState.values(): | ||
raise ValueError(f"Version {self.version} must be flattened to an int before writing to JSON") | ||
return super().model_dump_json(*args, **kwargs) | ||
|
||
model_config = ConfigDict(use_enum_values=True, validate_assignment=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/snapred/backend/dao/ingredients/RebinFocussedGroupDataIngredients.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from pydantic import BaseModel | ||
|
||
from snapred.backend.dao.state.PixelGroup import PixelGroup | ||
|
||
|
||
class RebinFocussedGroupDataIngredients(BaseModel): | ||
pixelGroup: PixelGroup | ||
preserveEvents: bool = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/snapred/backend/dao/request/LoadCalibrationRecordRequest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from pydantic import BaseModel | ||
|
||
from snapred.backend.dao import RunConfig | ||
from snapred.backend.dao.indexing.Versioning import Version | ||
|
||
|
||
class LoadCalibrationRecordRequest(BaseModel): | ||
runConfig: RunConfig | ||
version: Version |
Oops, something went wrong.