1111import time
1212from datetime import datetime
1313from pathlib import Path
14- from typing import Iterator , Literal , Optional , Union
14+ from typing import Iterator , Optional , Union , Literal
15+ import pydantic
1516
1617import gemmi
1718import numpy as np
18- import pydantic
1919import workflows .recipe
20- from pydantic import BaseModel , Field , ValidationError
20+ from pydantic import BaseModel , ValidationError , Field
2121from rich .logging import RichHandler
2222from workflows .services .common_service import CommonService
2323
@@ -73,43 +73,50 @@ class DetectorParameters(BaseModel):
7373 _mu_cache : dict = {}
7474
7575 class Config :
76- extra = "forbid" # Don't allow instantiation of this base class
76+ extra = "forbid" # Don't allow instantiation of this base class
7777
7878 def calculate_mu (self , wavelength : float ) -> float :
7979 if wavelength not in self ._mu_cache :
80- self ._mu_cache [wavelength ] = calculate_mu_from_parameters (
81- self .thickness , self . material , wavelength
80+ self ._mu_cache [wavelength ] = ffs . index . calculate_mu_for_material_at_wavelength (
81+ self .material , wavelength
8282 )
8383 return self ._mu_cache [wavelength ]
8484
8585
8686class Eiger16M (DetectorParameters ):
8787 type : Literal ["Eiger16M" ]
8888 thickness : float = 0.45
89- material : str = "Si" # atomic no 14
90- pixel_size_x : float = 0.075 # Default value for Eiger
91- pixel_size_y : float = 0.075 # Default value for Eiger
92- image_size_x : int = 2068 # Default value for Eiger
93- image_size_y : int = 2162 # Default value for Eiger
94- mu : float = 3.9220781 # Default value for Eiger (Silicon) #FIXME replace with mu calculation
95-
89+ material : str = "Si"
90+ pixel_size_x : float = 0.075
91+ pixel_size_y : float = 0.075
92+ image_size_x : int = 4148
93+ image_size_y : int = 4362
9694
97- class Eiger9M (DetectorParameters ):
98- type : Literal ["Eiger9M " ]
95+ class Eiger4M (DetectorParameters ):
96+ type : Literal ["Eiger4M " ]
9997 thickness : float = 0.45
10098 material : str = "Si"
101- pixel_size_x : float = 0.075 # Default value for Eiger
102- pixel_size_y : float = 0.075 # Default value for Eiger
103- image_size_x : int = 1000 # Default value for Eiger9M #FIXME
104- image_size_y : int = 1000 # Default value for Eiger9M #FIXME
105- mu : float = 3.9220781 # Default value for Eiger (Silicon) #FIXME replace with mu calculation
99+ pixel_size_x : float = 0.075
100+ pixel_size_y : float = 0.075
101+ image_size_x : int = 2068
102+ image_size_y : int = 2162
103+
104+
105+ class Eiger9MCdTe (DetectorParameters ):
106+ type : Literal ["Eiger9MCdTe" ]
107+ thickness : float = 0.75
108+ material : str = "CdTe"
109+ pixel_size_x : float = 0.075
110+ pixel_size_y : float = 0.075
111+ image_size_x : int = 3108
112+ image_size_y : int = 3262
106113
107114
108115class DetectorGeometry (BaseModel ):
109116 distance : float
110117 beam_center_x : float
111118 beam_center_y : float
112- detector : Union [Eiger9M , Eiger16M ] = Field (..., discriminator = "type" )
119+ detector : Union [Eiger9MCdTe , Eiger16M , Eiger4M ] = Field (..., discriminator = "type" )
113120
114121 def to_json (self ):
115122 d = self .dict ()
@@ -272,7 +279,7 @@ def gpu_per_image_analysis(
272279 distance = parameters .detector_distance ,
273280 beam_center_x = parameters .xBeam ,
274281 beam_center_y = parameters .yBeam ,
275- detector = {"type" : parameters .detector },
282+ detector = {"type" : parameters .detector },
276283 )
277284 self .log .debug ("{detector_geometry.to_json()=}" )
278285 except ValidationError as e :
@@ -289,6 +296,7 @@ def gpu_per_image_analysis(
289296 ## convert beam centre to correct units (given in mm, want in px).
290297 px_size_x = detector_geometry .detector .pixel_size_x
291298 px_size_y = detector_geometry .detector .pixel_size_y
299+ mu = detector_geometry .detector .calculate_mu (parameters .wavelength )
292300 self .indexer .panel = ffs .index .make_panel (
293301 detector_geometry .distance ,
294302 detector_geometry .beam_center_x / px_size_x ,
@@ -298,7 +306,7 @@ def gpu_per_image_analysis(
298306 detector_geometry .detector .image_size_x ,
299307 detector_geometry .detector .image_size_y ,
300308 detector_geometry .detector .thickness ,
301- detector_geometry . detector . mu ,
309+ mu ,
302310 )
303311 self .indexer .wavelength = parameters .wavelength
304312 self .output_for_index = (
0 commit comments