Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add probe to phil params and make probe in .expt human readable #654

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c981f71
Add a probe enum
dagewa Jul 21, 2023
bae2822
get_probe accessor
dagewa Jul 21, 2023
6eea2fd
probe-->Probe, and export to Python.
dagewa Jul 21, 2023
eb22c37
Export get_probe
dagewa Jul 21, 2023
2b79fd8
Ensure probe_ is initialized. Now we get:
dagewa Jul 21, 2023
6979e25
Add set_probe and export.
dagewa Jul 21, 2023
e5c8839
Ensure probe is initialised by the other constructors too
dagewa Jul 24, 2023
48c096d
Incorporate probe into equality and similarity checks
dagewa Jul 24, 2023
899b166
Add get_probe_name method so that the NeXus probe name can be
dagewa Jul 24, 2023
463391b
Include the probe in to/from dict methods and pickle suite.
dagewa Jul 24, 2023
0b08c5d
Add probe to make_polarized_beam, and fix longstanding bug in that me…
dagewa Jul 24, 2023
f5e5441
Set electron probe for various 3D ED format classes
dagewa Jul 24, 2023
9f2400a
News
dagewa Jul 24, 2023
823b075
Rename newsfragments/xxx.feature to newsfragments/647.feature
DiamondLightSource-build-server Jul 24, 2023
930be09
Easier override of panel geometry (#644)
dagewa Jul 25, 2023
436a1b6
Flumpy: Don't allow converting 1D vectors to vec2/3 (#648)
ndevenish Jul 25, 2023
180fac8
FormatROD (#645)
dagewa Jul 26, 2023
e9b88d2
Check Registry against refl/expt files (#650)
ndevenish Jul 26, 2023
69169ff
Make Imageset slices consistently index from 0
dagewa Jul 26, 2023
0a068b5
MNT: Update CMake modules path relative to script
ndevenish Jul 27, 2023
64bcb32
Fixes for EMBL beamlines at PETRA (#626)
christianbecke Jul 31, 2023
ef5f9ab
Add polychromatic beam (#621)
toastisme Aug 2, 2023
3f1a106
Merge branch 'main' into 575-beam-model-should-state-probe-type
dagewa Aug 2, 2023
d2cf031
Add probe to PolychromaticBeam
dagewa Aug 2, 2023
7f0e289
Fixes for tests
dagewa Aug 2, 2023
1f3c257
Added get_probe_from_name to Beam. Added Probe to beam_phil_scope. Ch…
toastisme Aug 3, 2023
4312daf
Added more typehints for beam.py. Added empty PolychromaticBeam const…
toastisme Aug 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading