1212from datetime import datetime
1313from enum import Enum
1414from pathlib import Path
15- from typing import Iterator , Optional , Union , Literal
16- import pydantic
15+ from typing import Iterator , Literal , Optional , Union
1716
1817import gemmi
1918import numpy as np
19+ import pydantic
2020import workflows .recipe
21- from pydantic import BaseModel , ValidationError , Field , PrivateAttr
21+ from pydantic import BaseModel , Field , PrivateAttr , ValidationError
2222from rich .logging import RichHandler
2323from workflows .services .common_service import CommonService
2424
@@ -62,16 +62,19 @@ def check_unit_cell(cls, v):
6262 raise ValueError (f"Invalid unit_cell { orig_v } " )
6363 return v
6464
65+
6566class Material (str , Enum ):
6667 Si = "Si"
6768 CdTe = "CdTe"
6869
70+
6971class DetectorParameters (BaseModel ):
7072 """
7173 Define a set of detector metadata that derived classes
7274 need to provide.
7375 This class is not to be instantiated directly.
7476 """
77+
7578 detector_type : str
7679 thickness : float
7780 material : Material
@@ -86,7 +89,8 @@ def __init_subclass__(cls, **kwargs):
8689 # enforce setting of defaults for all fields in subclasses.
8790 super ().__init_subclass__ (** kwargs )
8891 missing_defaults = [
89- name for name , field in cls .__fields__ .items ()
92+ name
93+ for name , field in cls .__fields__ .items ()
9094 if field .default is None and field .default_factory is None
9195 ]
9296 if missing_defaults :
@@ -96,25 +100,28 @@ def __init_subclass__(cls, **kwargs):
96100
97101 def calculate_mu (self , wavelength : float ) -> float :
98102 if wavelength not in self ._mu_cache :
99- self ._mu_cache [wavelength ] = ffs .index .calculate_mu_for_material_at_wavelength (
100- self .material , wavelength
103+ self ._mu_cache [wavelength ] = (
104+ ffs .index .calculate_mu_for_material_at_wavelength (
105+ self .material , wavelength
106+ )
101107 )
102108 return self ._mu_cache [wavelength ]
103109
104110
105111class Eiger16M (DetectorParameters ):
106112 detector_type : Literal ["Eiger16M" ]
107113 thickness : float = 0.45
108- material : Material = Material .Si
114+ material : Material = Material .Si
109115 pixel_size_x : float = 0.075
110116 pixel_size_y : float = 0.075
111117 image_size_x : int = 4148
112118 image_size_y : int = 4362
113119
120+
114121class Eiger4M (DetectorParameters ):
115122 detector_type : Literal ["Eiger4M" ]
116123 thickness : float = 0.45
117- material : Material = Material .Si
124+ material : Material = Material .Si
118125 pixel_size_x : float = 0.075
119126 pixel_size_y : float = 0.075
120127 image_size_x : int = 2068
@@ -124,7 +131,7 @@ class Eiger4M(DetectorParameters):
124131class Eiger9MCdTe (DetectorParameters ):
125132 detector_type : Literal ["Eiger9MCdTe" ]
126133 thickness : float = 0.75
127- material : Material = Material .CdTe
134+ material : Material = Material .CdTe
128135 pixel_size_x : float = 0.075
129136 pixel_size_y : float = 0.075
130137 image_size_x : int = 3108
@@ -135,7 +142,9 @@ class DetectorGeometry(BaseModel):
135142 distance : float
136143 beam_center_x : float
137144 beam_center_y : float
138- detector : Union [Eiger9MCdTe , Eiger16M , Eiger4M ] = Field (..., discriminator = "detector_type" )
145+ detector : Union [Eiger9MCdTe , Eiger16M , Eiger4M ] = Field (
146+ ..., discriminator = "detector_type"
147+ )
139148
140149 def to_json (self ):
141150 d = self .dict ()
@@ -298,7 +307,7 @@ def gpu_per_image_analysis(
298307 distance = parameters .detector_distance ,
299308 beam_center_x = parameters .xBeam ,
300309 beam_center_y = parameters .yBeam ,
301- detector = {"detector_type" : parameters .detector },
310+ detector = {"detector_type" : parameters .detector },
302311 )
303312 self .log .debug ("{detector_geometry.to_json()=}" )
304313 except ValidationError as e :
0 commit comments