Files
Jungfraujoch/python-client/jfjoch_client/models/detector_settings.py
2024-10-23 19:03:09 +02:00

121 lines
7.3 KiB
Python

# coding: utf-8
"""
Jungfraujoch
API to control Jungfraujoch developed by the Paul Scherrer Institute (Switzerland). Jungfraujoch is a data acquisition and analysis system for pixel array detectors, primarly PSI JUNGFRAU. Jungfraujoch uses FPGA boards to acquire data at high data rates.
The version of the OpenAPI document: 1.0.0-rc.23
Contact: filip.leonarski@psi.ch
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
from __future__ import annotations
import pprint
import re # noqa: F401
import json
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing_extensions import Annotated
from jfjoch_client.models.detector_timing import DetectorTiming
from typing import Optional, Set
from typing_extensions import Self
class DetectorSettings(BaseModel):
"""
DetectorSettings
""" # noqa: E501
frame_time_us: Annotated[int, Field(strict=True, ge=450)] = Field(description="Interval between consecutive frames.")
count_time_us: Optional[StrictInt] = Field(default=None, description="Integration time of the detector. If not provided count time will be set to maximum value for a given frame time.")
internal_frame_generator: Optional[StrictBool] = Field(default=False, description="Use internal frame generator in FPGA instead of getting data from a real detector")
internal_frame_generator_images: Optional[Annotated[int, Field(le=128, strict=True, ge=1)]] = 1
detector_trigger_delay_ns: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=0, description="Delay between TTL trigger and acquisition start [ns]")
timing: Optional[DetectorTiming] = DetectorTiming.TRIGGER
eiger_threshold_ke_v: Optional[Union[Annotated[float, Field(le=100.0, strict=True, ge=1.0)], Annotated[int, Field(le=100, strict=True, ge=1)]]] = Field(default=None, alias="eiger_threshold_keV")
jungfrau_pedestal_g0_frames: Optional[Annotated[int, Field(strict=True, ge=0)]] = 2000
jungfrau_pedestal_g1_frames: Optional[Annotated[int, Field(strict=True, ge=0)]] = 300
jungfrau_pedestal_g2_frames: Optional[Annotated[int, Field(strict=True, ge=0)]] = 300
jungfrau_pedestal_g0_rms_limit: Optional[Annotated[int, Field(strict=True, ge=0)]] = Field(default=100, description="Pixels with pedestal G0 RMS above the threshold are marked as masked pixels")
jungfrau_pedestal_min_image_count: Optional[Annotated[int, Field(strict=True, ge=32)]] = Field(default=128, description="Minimum number of collected images for pedestal to consider it viable")
jungfrau_storage_cell_count: Optional[Annotated[int, Field(le=16, strict=True, ge=1)]] = 1
jungfrau_storage_cell_delay_ns: Optional[Annotated[int, Field(strict=True, ge=2100)]] = Field(default=5000, description="Delay between two storage cells [ns]")
jungfrau_fixed_gain_g1: Optional[StrictBool] = Field(default=False, description="Fix gain to G1 (can be useful for storage cells)")
jungfrau_use_gain_hg0: Optional[StrictBool] = Field(default=False, description="Use high G0 (for low energy applications)")
__properties: ClassVar[List[str]] = ["frame_time_us", "count_time_us", "internal_frame_generator", "internal_frame_generator_images", "detector_trigger_delay_ns", "timing", "eiger_threshold_keV", "jungfrau_pedestal_g0_frames", "jungfrau_pedestal_g1_frames", "jungfrau_pedestal_g2_frames", "jungfrau_pedestal_g0_rms_limit", "jungfrau_pedestal_min_image_count", "jungfrau_storage_cell_count", "jungfrau_storage_cell_delay_ns", "jungfrau_fixed_gain_g1", "jungfrau_use_gain_hg0"]
model_config = ConfigDict(
populate_by_name=True,
validate_assignment=True,
protected_namespaces=(),
)
def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> Optional[Self]:
"""Create an instance of DetectorSettings from a JSON string"""
return cls.from_dict(json.loads(json_str))
def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.
This has the following differences from calling pydantic's
`self.model_dump(by_alias=True)`:
* `None` is only added to the output dict for nullable fields that
were set at model initialization. Other fields with value `None`
are ignored.
"""
excluded_fields: Set[str] = set([
])
_dict = self.model_dump(
by_alias=True,
exclude=excluded_fields,
exclude_none=True,
)
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of DetectorSettings from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return cls.model_validate(obj)
_obj = cls.model_validate({
"frame_time_us": obj.get("frame_time_us"),
"count_time_us": obj.get("count_time_us"),
"internal_frame_generator": obj.get("internal_frame_generator") if obj.get("internal_frame_generator") is not None else False,
"internal_frame_generator_images": obj.get("internal_frame_generator_images") if obj.get("internal_frame_generator_images") is not None else 1,
"detector_trigger_delay_ns": obj.get("detector_trigger_delay_ns") if obj.get("detector_trigger_delay_ns") is not None else 0,
"timing": obj.get("timing") if obj.get("timing") is not None else DetectorTiming.TRIGGER,
"eiger_threshold_keV": obj.get("eiger_threshold_keV"),
"jungfrau_pedestal_g0_frames": obj.get("jungfrau_pedestal_g0_frames") if obj.get("jungfrau_pedestal_g0_frames") is not None else 2000,
"jungfrau_pedestal_g1_frames": obj.get("jungfrau_pedestal_g1_frames") if obj.get("jungfrau_pedestal_g1_frames") is not None else 300,
"jungfrau_pedestal_g2_frames": obj.get("jungfrau_pedestal_g2_frames") if obj.get("jungfrau_pedestal_g2_frames") is not None else 300,
"jungfrau_pedestal_g0_rms_limit": obj.get("jungfrau_pedestal_g0_rms_limit") if obj.get("jungfrau_pedestal_g0_rms_limit") is not None else 100,
"jungfrau_pedestal_min_image_count": obj.get("jungfrau_pedestal_min_image_count") if obj.get("jungfrau_pedestal_min_image_count") is not None else 128,
"jungfrau_storage_cell_count": obj.get("jungfrau_storage_cell_count") if obj.get("jungfrau_storage_cell_count") is not None else 1,
"jungfrau_storage_cell_delay_ns": obj.get("jungfrau_storage_cell_delay_ns") if obj.get("jungfrau_storage_cell_delay_ns") is not None else 5000,
"jungfrau_fixed_gain_g1": obj.get("jungfrau_fixed_gain_g1") if obj.get("jungfrau_fixed_gain_g1") is not None else False,
"jungfrau_use_gain_hg0": obj.get("jungfrau_use_gain_hg0") if obj.get("jungfrau_use_gain_hg0") is not None else False
})
return _obj