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

API(fields): support for generating biased tracer fields #138

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 5 additions & 0 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
version: 2

build:
os: ubuntu-22.04
tools:
python: "3.11"

python:
install:
- method: pip
Expand Down
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
Loading