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

Update HDF5 to avoid scipp.DataArray.attrs deprecation warnings #25

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions src/esssans/data.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2023 Scipp contributors (https://github.com/scipp)
_version = '1'
_version = '2'

__all__ = ['get_path']

Expand All @@ -15,9 +15,9 @@ def _make_pooch():
version=_version,
registry={
'DIRECT_SANS2D_REAR_34327_4m_8mm_16Feb16.hdf5': 'md5:43f4188301d709aa49df0631d03a67cb', # noqa: E501
'SANS2D00063091.hdf5': 'md5:c212f1c8c68db69eae88eca90a19e7e6',
'SANS2D00063114.hdf5': 'md5:806a5780ff02676afcea1c3d8777ee21',
'SANS2D00063159.hdf5': 'md5:7be098bcc1f4ca73394584076a99146d',
'SANS2D00063091.hdf5': 'md5:1fdbe36a496e914336f2f9b5cad9f00e',
'SANS2D00063114.hdf5': 'md5:536303077b9f55286af5ef6ec5124e1c',
'SANS2D00063159.hdf5': 'md5:e2f2aea3ed9251e579210718de568203',
},
)

Expand Down
38 changes: 28 additions & 10 deletions src/esssans/sans2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,26 @@
def pooch_load(filename: Filename[RunType]) -> RawData[RunType]:
from .data import get_path

da = sc.io.load_hdf5(filename=get_path(filename))
if 'gravity' not in da.coords:
da.coords["gravity"] = gravity_vector()
return RawData[RunType](da)
dg = sc.io.load_hdf5(filename=get_path(filename))
data = dg['data']
if 'gravity' not in data.coords:
data.coords["gravity"] = gravity_vector()
data.coords['pixel_width'] = sc.scalar(0.002033984375, unit='m')
data.coords['pixel_height'] = sc.scalar(0.0035, unit='m')

# Some fixes specific for these Sans2d runs
sample_pos_z_offset = 0.053 * sc.units.m
# There is some uncertainty here
monitor4_pos_z_offset = -6.719 * sc.units.m

data.coords['sample_position'].fields.z += sample_pos_z_offset
# Results are actually slightly better at high-Q if we do not apply a bench offset
# bench_pos_y_offset = 0.001 * sc.units.m
# data.coords['position'].fields.y += bench_pos_y_offset
dg['monitors']['monitor4']['data'].coords[
'position'
].fields.z += monitor4_pos_z_offset
return RawData[RunType](dg)


def pooch_load_direct_beam(filename: DirectBeamFilename) -> DirectBeam:
Expand All @@ -41,21 +57,23 @@ def pooch_load_direct_beam(filename: DirectBeamFilename) -> DirectBeam:


def get_monitor(
da: RawData[RunType], nexus_name: NeXusMonitorName[MonitorType]
dg: RawData[RunType], nexus_name: NeXusMonitorName[MonitorType]
) -> RawMonitor[RunType, MonitorType]:
# See https://github.com/scipp/sciline/issues/52 why copy needed
mon = da.attrs[nexus_name].value.copy()
mon = dg['monitors'][nexus_name]['data'].copy()
return RawMonitor[RunType, MonitorType](mon)


def detector_edge_mask(sample: RawData[SampleRun]) -> DetectorEdgeMask:
def detector_edge_mask(raw: RawData[SampleRun]) -> DetectorEdgeMask:
sample = raw['data']
mask_edges = (
sc.abs(sample.coords['position'].fields.x) > sc.scalar(0.48, unit='m')
) | (sc.abs(sample.coords['position'].fields.y) > sc.scalar(0.45, unit='m'))
return DetectorEdgeMask(mask_edges)


def sample_holder_mask(sample: RawData[SampleRun]) -> SampleHolderMask:
def sample_holder_mask(raw: RawData[SampleRun]) -> SampleHolderMask:
sample = raw['data']
summed = sample.sum('tof')
holder_mask = (
(summed.data < sc.scalar(100, unit='counts'))
Expand All @@ -68,7 +86,7 @@ def sample_holder_mask(sample: RawData[SampleRun]) -> SampleHolderMask:


def mask_detectors(
da: RawData[RunType],
dg: RawData[RunType],
edge_mask: Optional[DetectorEdgeMask],
holder_mask: Optional[SampleHolderMask],
) -> MaskedData[RunType]:
Expand All @@ -83,7 +101,7 @@ def mask_detectors(
holder_mask:
Mask for sample holder.
"""
da = da.copy(deep=False)
da = dg['data'].copy(deep=False)
if edge_mask is not None:
da.masks['edges'] = edge_mask
if holder_mask is not None:
Expand Down