Skip to content

Commit

Permalink
Merge pull request #654 from toastisme/beam-probe-types
Browse files Browse the repository at this point in the history
Add probe to phil params and make probe in .expt human readable
  • Loading branch information
dagewa authored Aug 3, 2023
2 parents 1625cfa + 4312daf commit 35a312c
Show file tree
Hide file tree
Showing 28 changed files with 1,267 additions and 100 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
project(dxtbx LANGUAGES C CXX)

# Add the included modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")

# General cmake environment configuration
include(SetDefaultBuildRelWithDebInfo) # Default builds to release with debug info
Expand Down
1 change: 1 addition & 0 deletions newsfragments/299.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Panel geometry definitions in PHIL are merged by panel id before constructing panels
1 change: 1 addition & 0 deletions newsfragments/439.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
``flumpy``: Fix case where incorrect ``flex.vec2``, ``flex.vec3`` could be generated.
1 change: 1 addition & 0 deletions newsfragments/621.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add new Beam class "PolychromaticBeam" for polychromatic/multi-wavelength/wide bandpass experiments.
1 change: 1 addition & 0 deletions newsfragments/626.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update Format handling to reflect move of Eiger detector from PETRA P14 to P13.
1 change: 1 addition & 0 deletions newsfragments/633.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Slicing of imageset objects is now consistently 0-based, including for the sliced data accessor. Previously, the data accessor had to be accessed with the original index offsets.
1 change: 1 addition & 0 deletions newsfragments/645.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add partial support for the Rigaku Oxford Diffraction file format.
1 change: 1 addition & 0 deletions newsfragments/647.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The ``Beam`` model now has a ``probe`` value to keep track of the type of radiation.
1 change: 1 addition & 0 deletions newsfragments/650.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Format classes are now tested against invalid binary data with dials-data, for when dials-regression is not present.
7 changes: 7 additions & 0 deletions src/dxtbx/boost_python/flumpy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,13 @@ py::object vec_from_numpy(py::array np_array) {

static_assert(VecType<int>::fixed_size == 2 || VecType<int>::fixed_size == 3,
"Only vec2/vec3 supported");

// Only accept arrays that have a dimension higher than 1 - we want
// numpy.array([1,2,3]) to fail but numpy.array([[1,2,3]]) to work
if (np_array.ndim() == 1) {
throw std::invalid_argument("Array for conversion to vec must be multidimensional");
}

// Only accept arrays whose last dimension is the size of this object
if (np_array.shape(np_array.ndim() - 1) != VecType<int>::fixed_size) {
throw std::invalid_argument("Input array last dimension is not size "
Expand Down
33 changes: 33 additions & 0 deletions src/dxtbx/dxtbx_model_ext.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ from scitbx.array_family import shared as flex_shared
# Attempt to use the stub typing for flex-inheritance
from scitbx.array_family.flex import FlexPlain

from dxtbx_model_ext import Probe # type: ignore

# TypeVar for the set of Experiment models that can be joint-accepted
# - profile, imageset and scalingmodel are handled as 'object'
TExperimentModel = TypeVar(
Expand Down Expand Up @@ -113,6 +115,37 @@ class Beam(BeamBase):
@staticmethod
def from_dict(data: Dict) -> Beam: ...
def to_dict(self) -> Dict: ...
@staticmethod
def get_probe_from_name(name: str) -> Probe: ...

class PolychromaticBeam(Beam):
@overload
def __init__(self, beam: PolychromaticBeam) -> None: ...
@overload
def __init__(self, direction: Vec3Float) -> None: ...
@overload
def __init__(
self,
direction: Vec3Float,
divergence: float,
sigma_divergence: float,
deg: bool = ...,
) -> None: ...
@overload
def __init__(
self,
direction: Vec3Float,
divergence: float,
sigma_divergence: float,
polarization_normal: Vec3Float,
polarization_fraction: float,
flux: float,
transmission: float,
deg: bool = ...,
) -> None: ...
@staticmethod
def from_dict(data: Dict) -> PolychromaticBeam: ...
def to_dict(self) -> Dict: ...

class CrystalBase:
@property
Expand Down
15 changes: 15 additions & 0 deletions src/dxtbx/format/FormatCBFMini.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from __future__ import annotations

import binascii
import datetime
import os
import pathlib
import sys
Expand Down Expand Up @@ -73,6 +74,20 @@ def __init__(self, image_file, **kwargs):
self._raw_data = None
super().__init__(image_file, **kwargs)

@staticmethod
def _get_timestamp_from_raw_header(
header: str | list[str],
) -> datetime.datetime | None:
"""Given a raw header, or lines from, attempt to extract the timestamp field"""
if isinstance(header, str):
header = header.splitlines()
timestamp = None
for record in header:
if len(record[1:].split()) <= 2 and record.count(":") == 2:
timestamp = datetime.datetime.fromisoformat(record[1:].strip())
break
return timestamp

def _start(self):
"""Open the image file, read the image header, copy it into a
dictionary for future reference."""
Expand Down
13 changes: 12 additions & 1 deletion src/dxtbx/format/FormatCBFMiniEigerPetraP14.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from __future__ import annotations

import datetime
import sys

from dxtbx.format.FormatCBFMiniEiger import FormatCBFMiniEiger
Expand All @@ -19,11 +20,21 @@ def understand(image_file):

header = FormatCBFMiniEiger.get_cbf_header(image_file)

# Valid from 22nd May 2021
expected_serial = "E-32-0129"
if timestamp := FormatCBFMiniEiger._get_timestamp_from_raw_header(header):
# We have a timestamp. Let's see what detector we should expect

# Before 22nd May 2021
if timestamp < datetime.datetime(2021, 5, 22):
expected_serial = "E-32-0107"

# Find the line recording detector serial, and check
for record in header.split("\n"):
if (
"# detector" in record.lower()
and "eiger" in record.lower()
and "E-32-0107" in record
and expected_serial in record
):
return True

Expand Down
2 changes: 2 additions & 0 deletions src/dxtbx/format/FormatGatanDM4.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
)
from dxtbx.format.Format import Format
from dxtbx.format.FormatMultiImage import FormatMultiImage
from dxtbx.model.beam import Probe


def read_tag(f, byteorder):
Expand Down Expand Up @@ -358,6 +359,7 @@ def _beam(self):
wavelength=wavelength,
polarization=(0, 1, 0),
polarization_fraction=0.5,
probe=Probe.electron,
)

def _scan(self):
Expand Down
2 changes: 2 additions & 0 deletions src/dxtbx/format/FormatMRC.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from dxtbx.format.Format import Format
from dxtbx.format.FormatMultiImage import FormatMultiImage
from dxtbx.model import ScanFactory
from dxtbx.model.beam import Probe

logger = logging.getLogger("dials")

Expand Down Expand Up @@ -226,6 +227,7 @@ def _beam(self):
wavelength=wavelength,
polarization=(0, 1, 0),
polarization_fraction=0.5,
probe=Probe.electron,
)


Expand Down
Loading

0 comments on commit 35a312c

Please sign in to comment.