Skip to content

Commit

Permalink
functions to generate biased fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ntessore committed Oct 20, 2023
1 parent 29938e2 commit 45ecef3
Show file tree
Hide file tree
Showing 3 changed files with 270 additions and 75 deletions.
6 changes: 6 additions & 0 deletions glass/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@
GLASS modules.
'''

__all__ = (
"update_metadata",
)

from .array import update_metadata
13 changes: 13 additions & 0 deletions glass/core/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,16 @@ def cumtrapz(f, x, dtype=None, out=None):
np.cumsum((f[..., 1:] + f[..., :-1])/2*np.diff(x), axis=-1, out=out[..., 1:])
out[..., 0] = 0
return out


def update_metadata(array, **metadata):
"""update dtype.metadata of an array"""
array = np.asanyarray(array)
updated = {}
if array.dtype.metadata is not None:
updated.update(array.dtype.metadata)
updated.update(metadata)
dtype = np.dtype(array.dtype.fields or array.dtype.str, metadata=updated)
if not np.can_cast(dtype, array.dtype, casting="no"):
raise ValueError("array does not support updating metadata")
array.dtype = dtype
Loading

0 comments on commit 45ecef3

Please sign in to comment.