Skip to content

Commit

Permalink
Clean Clutter
Browse files Browse the repository at this point in the history
  • Loading branch information
DiamondLightSource-build-server committed Oct 1, 2023
1 parent 02954eb commit cd03663
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 51 deletions.
68 changes: 39 additions & 29 deletions src/dxtbx/boost_python/ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,35 +195,39 @@ namespace dxtbx { namespace boost_python {
return PyBytes_FromStringAndSize(&*packed.begin(), packed.size());
}

double distance_between_points(scitbx::vec2<int> const& a, scitbx::vec2<int> const& b) {
return std::sqrt((std::pow(double(b[0]-a[0]),2)+std::pow(double(b[1]-a[1]),2)));
double distance_between_points(scitbx::vec2<int> const &a,
scitbx::vec2<int> const &b) {
return std::sqrt(
(std::pow(double(b[0] - a[0]), 2) + std::pow(double(b[1] - a[1]), 2)));
}

void radial_average(scitbx::af::versa<double, scitbx::af::flex_grid<> > & data,
scitbx::af::versa<bool, scitbx::af::flex_grid<> > & mask,
scitbx::vec2<int> const& beam_center,
scitbx::af::shared<double> sums,
scitbx::af::shared<double> sums_sq,
scitbx::af::shared<int> counts,
double pixel_size, double distance,
scitbx::vec2<int> const& upper_left,
scitbx::vec2<int> const& lower_right) {
void radial_average(scitbx::af::versa<double, scitbx::af::flex_grid<> > &data,
scitbx::af::versa<bool, scitbx::af::flex_grid<> > &mask,
scitbx::vec2<int> const &beam_center,
scitbx::af::shared<double> sums,
scitbx::af::shared<double> sums_sq,
scitbx::af::shared<int> counts,
double pixel_size,
double distance,
scitbx::vec2<int> const &upper_left,
scitbx::vec2<int> const &lower_right) {
std::size_t extent = sums.size();
double extent_in_mm = extent * pixel_size;
double extent_two_theta = std::atan(extent_in_mm/distance)*180/scitbx::constants::pi;

for(std::size_t y = upper_left[1]; y < lower_right[1]; y++) {
for(std::size_t x = upper_left[0]; x < lower_right[0]; x++) {
double val = data(x,y);
if(val > 0 && mask(x,y)) {
scitbx::vec2<int> point((int)x,(int)y);
double d_in_mm = distance_between_points(point,beam_center) * pixel_size;
double twotheta = std::atan(d_in_mm/distance)*180/scitbx::constants::pi;
std::size_t bin = (std::size_t)std::floor(twotheta*extent/extent_two_theta);
if (bin >= extent)
continue;
double extent_two_theta =
std::atan(extent_in_mm / distance) * 180 / scitbx::constants::pi;

for (std::size_t y = upper_left[1]; y < lower_right[1]; y++) {
for (std::size_t x = upper_left[0]; x < lower_right[0]; x++) {
double val = data(x, y);
if (val > 0 && mask(x, y)) {
scitbx::vec2<int> point((int)x, (int)y);
double d_in_mm = distance_between_points(point, beam_center) * pixel_size;
double twotheta = std::atan(d_in_mm / distance) * 180 / scitbx::constants::pi;
std::size_t bin =
(std::size_t)std::floor(twotheta * extent / extent_two_theta);
if (bin >= extent) continue;
sums[bin] += val;
sums_sq[bin] += val*val;
sums_sq[bin] += val * val;
counts[bin]++;
}
}
Expand Down Expand Up @@ -261,11 +265,17 @@ namespace dxtbx { namespace boost_python {
def("is_big_endian", is_big_endian);
def("uncompress", &uncompress, (arg_("packed"), arg_("slow"), arg_("fast")));
def("compress", &compress);
def("radial_average", &radial_average,
(arg("data"), arg("beam_center"), arg("sums"), arg("sums_sq"), arg("counts"),
arg("pixel_size"), arg("distance"),
arg("upper_left"), arg("lower_right")))
;
def("radial_average",
&radial_average,
(arg("data"),
arg("beam_center"),
arg("sums"),
arg("sums_sq"),
arg("counts"),
arg("pixel_size"),
arg("distance"),
arg("upper_left"),
arg("lower_right")));
def("uncompress_rod_TY6",
&uncompress_rod_TY6,
(arg_("data"), arg_("offsets"), arg_("slow"), arg_("fast")));
Expand Down
3 changes: 2 additions & 1 deletion src/dxtbx/command_line/detector_superpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import math
import sys

from serialtbx.detector import iterate_detector_at_level

from libtbx.phil import parse
from libtbx.test_utils import approx_equal
from scitbx.array_family import flex
from scitbx.math.superpose import least_squares_fit
from scitbx.matrix import col
from serialtbx.detector import iterate_detector_at_level

import dials.util
from dials.util.options import OptionParser
Expand Down
4 changes: 2 additions & 2 deletions src/dxtbx/command_line/image2pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
import sys

import numpy as np
import serialtbx.detector.cspad
import serialtbx.util

import libtbx.option_parser
from libtbx import easy_pickle
from libtbx.utils import Usage
import serialtbx.util
from scitbx.array_family import flex
import serialtbx.detector.cspad

import dxtbx.util

Expand Down
2 changes: 1 addition & 1 deletion src/dxtbx/command_line/radial_average.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
from libtbx.utils import Sorry, Usage
from scitbx.array_family import flex
from scitbx.matrix import col
from dxtbx.ext import radial_average

import dxtbx
import dxtbx.util
from dxtbx.ext import radial_average
from dxtbx.model.experiment_list import ExperimentListFactory

master_phil = iotbx.phil.parse(
Expand Down
2 changes: 1 addition & 1 deletion src/dxtbx/format/FormatCBFMultiTile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import numpy
import pycbf

from scitbx.array_family import flex
from scitbx import matrix
from scitbx.array_family import flex

from dxtbx.format.FormatCBF import FormatCBF
from dxtbx.format.FormatCBFFull import FormatCBFFull
Expand Down
4 changes: 1 addition & 3 deletions src/dxtbx/format/FormatNexusJungfrauExt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

import h5py
import numpy as np

from scitbx.array_family import flex

from serialtbx.detector.jungfrau import pad_stacked_format

from scitbx.array_family import flex

from dxtbx.format.FormatNexus import FormatNexus
from dxtbx.format.nexus import h5str
Expand Down
4 changes: 2 additions & 2 deletions src/dxtbx/format/FormatPYmultitile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
from calendar import timegm
from time import strptime

from serialtbx.detector.legacy_metrology.cspad_detector import CSPadDetector

from iotbx.detectors.npy import image_dict_to_unicode
from scitbx.matrix import col

from serialtbx.detector.legacy_metrology.cspad_detector import CSPadDetector

from dxtbx.format.FormatPY import FormatPY
from dxtbx.model import Detector

Expand Down
4 changes: 2 additions & 2 deletions src/dxtbx/format/FormatXTC.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import time

import numpy as np
import serialtbx.detector.xtc
import serialtbx.util

from libtbx.phil import parse
from scitbx.array_family import flex
Expand All @@ -15,8 +17,6 @@
from dxtbx.format.FormatStill import FormatStill
from dxtbx.model import Spectrum
from dxtbx.util.rotate_and_average import rotate_and_average
import serialtbx.util
import serialtbx.detector.xtc

try:
import psana
Expand Down
6 changes: 3 additions & 3 deletions src/dxtbx/format/FormatXTCCspad.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import sys

import numpy as np
import serialtbx.detector.cspad
from serialtbx.detector import cspad
from serialtbx.detector.xtc import env_distance

from cctbx.eltbx import attenuation_coefficient
from libtbx.phil import parse
from scitbx.array_family import flex
from scitbx.matrix import col
from serialtbx.detector import cspad
from serialtbx.detector.xtc import env_distance
import serialtbx.detector.cspad

from dxtbx.format.FormatXTC import FormatXTC, locator_str
from dxtbx.model import Detector, ParallaxCorrectedPxMmStrategy
Expand Down
1 change: 0 additions & 1 deletion src/dxtbx/format/FormatXTCEpix.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ def get_detector(self, index=None):

def _detector(self, index=None):
from PSCalib.SegGeometryStore import sgs

from serialtbx.detector.xtc import basis_from_geo

run = self.get_run_from_index(index)
Expand Down
1 change: 0 additions & 1 deletion src/dxtbx/format/FormatXTCJungfrau.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ def get_detector(self, index=None):

def _detector(self, index=None):
from PSCalib.SegGeometryStore import sgs

from serialtbx.detector.xtc import basis_from_geo

run = self.get_run_from_index(index)
Expand Down
4 changes: 2 additions & 2 deletions src/dxtbx/format/FormatXTCRayonix.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
raise
psana = None

from serialtbx.detector import rayonix

from libtbx.phil import parse
from scitbx.array_family import flex

from dxtbx.format.FormatXTC import FormatXTC, locator_str

from serialtbx.detector import rayonix

rayonix_locator_str = """
rayonix {
bin_size = None
Expand Down
4 changes: 2 additions & 2 deletions src/dxtbx/format/cbf_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
import sys

import pycbf
from serialtbx.detector import basis

from dxtbx.format.FormatCBFMultiTile import cbf_wrapper
from scitbx.array_family import flex
from serialtbx.detector import basis

import dxtbx.format.Registry
from dxtbx.format.FormatCBFMultiTile import cbf_wrapper


def add_frame_specific_cbf_tables(
Expand Down
2 changes: 1 addition & 1 deletion src/dxtbx/format/nxmx_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

import h5py
import numpy as np
from serialtbx.detector import basis

from cctbx import factor_ev_angstrom
from libtbx import easy_pickle
from libtbx.phil import parse
from libtbx.utils import Sorry
from scitbx import matrix
from scitbx.array_family import flex
from serialtbx.detector import basis

from dials.util.options import ArgumentParser, flatten_experiments

Expand Down

0 comments on commit cd03663

Please sign in to comment.