-
Notifications
You must be signed in to change notification settings - Fork 4
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
Optimise depends_on chain resolution by using h5py #253
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,6 +81,31 @@ def _as_datetime(obj: Any): | |
return None | ||
|
||
|
||
_scipp_dtype = { | ||
np.dtype('int8'): sc.DType.int32, | ||
np.dtype('int16'): sc.DType.int32, | ||
np.dtype('uint8'): sc.DType.int32, | ||
np.dtype('uint16'): sc.DType.int32, | ||
np.dtype('uint32'): sc.DType.int32, | ||
np.dtype('uint64'): sc.DType.int64, | ||
np.dtype('int32'): sc.DType.int32, | ||
np.dtype('int64'): sc.DType.int64, | ||
np.dtype('float32'): sc.DType.float32, | ||
np.dtype('float64'): sc.DType.float64, | ||
np.dtype('bool'): sc.DType.bool, | ||
} | ||
|
||
|
||
def _dtype_fromdataset(dataset: H5Dataset) -> sc.DType: | ||
return _scipp_dtype.get(dataset.dtype, sc.DType.string) | ||
|
||
|
||
def _squeezed_field_sizes(dataset: H5Dataset) -> dict[str, int]: | ||
if (shape := dataset.shape) == (1,): | ||
return {} | ||
return {f'dim_{i}': size for i, size in enumerate(shape)} | ||
|
||
|
||
@dataclass | ||
class Field: | ||
"""NeXus field. | ||
|
@@ -93,6 +118,12 @@ class Field: | |
dtype: sc.DType | None = None | ||
errors: H5Dataset | None = None | ||
|
||
def __post_init__(self) -> None: | ||
if self.sizes is None: | ||
self.sizes = _squeezed_field_sizes(self.dataset) | ||
if self.dtype is None: | ||
self.dtype = _dtype_fromdataset(self.dataset) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please check that this is sound! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feared that there might be some code that relies on |
||
@cached_property | ||
def attrs(self) -> dict[str, Any]: | ||
"""The attributes of the dataset. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring is outdated now, at least in parts?