Skip to content

Commit

Permalink
edit creation of scan2d object to remove datapoints where attenuators…
Browse files Browse the repository at this point in the history
… are moving
  • Loading branch information
P-Mousley authored Dec 6, 2024
1 parent bb5db46 commit b5d1e6f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
8 changes: 4 additions & 4 deletions src/islatu/background.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
from scipy.stats import norm
from scipy.optimize import curve_fit

from .region import Region
from .image import Image
from islatu.region import Region
from islatu.image import Image


@dataclass
Expand Down Expand Up @@ -70,8 +70,8 @@ def roi_subtraction(image, list_of_regions: List[Region]):
# the intensity measured in all the background regions so far.
sum_of_bkg_areas += np.sum(
image.array_original[
int(region.x_start):int(region.x_end),
int(region.y_start):int(region.y_end)
int(region.y_start):int(region.y_end),
int(region.x_start):int(region.x_end)
]
)
# Add the number of pixels in this background ROI to the total number of
Expand Down
2 changes: 1 addition & 1 deletion src/islatu/cropping.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ def crop_to_region(array: np.ndarray, region: Region):
region:
The instance of Region to crop to.
"""
return array[region.x_start:region.x_end, region.y_start:region.y_end]
return array[region.y_start:region.y_end,region.x_start:region.x_end]
27 changes: 14 additions & 13 deletions src/islatu/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class and its children.
import h5py


from .scan import Scan2D
from .image import Image
from .data import Data
from .region import Region
from .debug import debug
from .metadata import Metadata
from islatu.scan import Scan2D
from islatu.image import Image
from islatu.data import Data
from islatu.region import Region
from islatu.debug import debug
from islatu.metadata import Metadata


class NexusBase(Metadata):
Expand Down Expand Up @@ -70,7 +70,7 @@ def detector(self):
Raises:
ValueError if more than one NXdetector is found.
"""
det, = self.instrument.NXdetector
det, = self.instrument.NXdetector[0]
return det

@property
Expand Down Expand Up @@ -560,7 +560,7 @@ def load_images_from_h5(h5_file_path,datanxfilepath,transpose=False):
return images


def i07_nxs_parser(file_path: str):
def i07_nxs_parser(file_path: str,remove_indices=None):
"""
Parses a .nxs file acquired from the I07 beamline at diamond, returning an
instance of Scan2D. This process involves loading the images contained in
Expand All @@ -577,15 +577,17 @@ def i07_nxs_parser(file_path: str):
"""
# Use the magical parser class that does everything for us.
i07_nxs = I07Nexus(file_path)

detname=list(i07_nxs.entry.instrument.keys())[0]
if 'attenuation_filters_moving' in i07_nxs.entry[f'{detname}'].keys():
remove_indices=np.where(np.array(i07_nxs.entry[f'{detname}/attenuation_filters_moving']))[0]
# Load the images, taking a transpose if necessary (because which axis is
# x and which is why is determined by fast vs slow detector axes in memory).
if i07_nxs.detector_name in [
I07Nexus.excalibur_detector_2021,
I07Nexus.excalibur_04_2022,
I07Nexus.pilatus_02_2024,
I07Nexus.excalibur_08_2024]:
images = load_images_from_h5(i07_nxs.local_data_path,i07_nxs._src_data_path[1], transpose=True)
images = load_images_from_h5(i07_nxs.local_data_path,i07_nxs._src_data_path[1], transpose=False)

# The dependent variable.
rough_intensity = i07_nxs.default_signal
Expand All @@ -602,14 +604,13 @@ def i07_nxs_parser(file_path: str):
data = Data(rough_intensity, rough_intensity_e, i07_nxs.probe_energy,
theta=axis)
elif i07_nxs.default_axis_type == 'tth':
data = Data(rough_intensity, rough_intensity_e, i07_nxs.probe_energy,
theta=axis/2)
data = Data(rough_intensity, rough_intensity_e, i07_nxs.probe_energy, theta=axis/2)
else:
raise NotImplementedError(
f"{i07_nxs.default_axis_type} is not a supported axis type.")

# Returns the Scan2D object
return Scan2D(data, i07_nxs, images)
return Scan2D(data, i07_nxs, images, remove_indices)


def _try_to_find_files(filenames: List[str],
Expand Down
10 changes: 5 additions & 5 deletions src/islatu/refl_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

from typing import List

from .scan import Scan
from .stitching import concatenate, rebin
from .data import Data
from islatu.scan import Scan
from islatu.stitching import concatenate, rebin
from islatu.data import Data


class Profile(Data):
Expand Down Expand Up @@ -136,9 +136,9 @@ def transmission_normalisation(self,overwrite_transmissions=None):
"""
for i,scan in enumerate(self.scans):
if overwrite_transmissions is not None:
overwrite_transmission=overwrite_transmissions[i]
overwrite_transmission = overwrite_transmissions[i]
else:
overwrite_transmission=None
overwrite_transmission = None
scan.transmission_normalisation(overwrite_transmission)

self.concatenate()
Expand Down
4 changes: 3 additions & 1 deletion src/islatu/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,13 @@ def i07reduce(run_numbers, yaml_file, directory='/dls/{}/data/{}/{}/',

if q_subsample_dicts is not None:
log_processing_stage(
"Doctoring data.\nSorry, I mean: Bounding q-vectors.")
"Bounding q-vectors.")
# We'll need to subsample a subset of our scans.
for q_subsample_dict in q_subsample_dicts:
refl.subsample_q(**q_subsample_dict)
debug.log("Limited q-range on specified scans.")



# Rebin the data, if the user requested this.
if the_boss.data.rebin:
Expand Down
8 changes: 5 additions & 3 deletions src/islatu/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def subsample_q(self, q_min=0, q_max=float('inf')):
# be used like this, and they encourage np.asarray(condition).nonzero()

# Now remove all data points at these qs.
self.remove_data_points(illegal_q_indices)
self.remove_data_points(illegal_q_indices)

def transmission_normalisation(self,overwrite_transmission):
"""
Expand Down Expand Up @@ -107,11 +107,13 @@ class Scan2D(Scan):
The detector images in the given scan.
"""

def __init__(self, data: Data, metadata: Metadata, images: List[Image]) \
def __init__(self, data: Data, metadata: Metadata, images: List[Image],remove_indices=None) \
-> None:
super().__init__(data, metadata)
self.images = images

if remove_indices is not None:
self.remove_data_points(remove_indices)

def crop(self, crop_function, **kwargs):
"""
Crop every image in images according to crop_function.
Expand Down

0 comments on commit b5d1e6f

Please sign in to comment.