diff --git a/src/calng/base_geometry.py b/src/calng/base_geometry.py index 198d018cdd75e3d48b303dfbc6d61168d05d1ce0..0b0485f55d9da88cc4a6e07c7b2ceed2ec83f095 100644 --- a/src/calng/base_geometry.py +++ b/src/calng/base_geometry.py @@ -160,6 +160,17 @@ class GeometryFileNode(Configurable): assignment=Assignment.OPTIONAL, accessMode=AccessMode.RECONFIGURABLE, ) + fileType = String( + displayedName="File type", + defaultValue="crystfel", + description="What kind of file will be loaded. Corresponds to options within " + "EXtra-geom. Note that the options listed here may not all apply to all " + "geometries. I think 'crystfel' (uses extra_geom.[geometry type]" + ".from_crystfel_geom is the most 'universal', so I left that as default.", + options=["crystfel", "h5", "h5+quadrants"], + assignment=Assignment.OPTIONAL, + accessMode=AccessMode.RECONFIGURABLE, + ) offset = make_x_y_offset_node() updateManualOnLoad = Bool( defaultValue=True, @@ -246,9 +257,20 @@ class ManualGeometryBase(Device): file_path = self.geometryFile.filePath.value self._set_status(f"Loading geometry from {file_path}...") + file_type = self.geometryFile.fileType.value try: - geometry = self.geometry_class.from_crystfel_geom(file_path) + if file_type == "crystfel": + geometry = self.geometry_class.from_crystfel_geom(file_path) + elif file_type == "h5": + geometry = self.geometry_class.from_h5_file(file_path) + elif file_type == "h5+quadrants": + geometry = self.geometry_class.from_h5_file_and_quad_positions( + file_path, + [(Q.x.value, Q.y.value) for Q in self._quadrant_corners], + ) + else: + raise ValueError(f"Invalid file type {file_type}") except FileNotFoundError: self._set_status("Geometry file not found", level=logging.WARN) except RuntimeError as e: