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

Subdomain extraction #86

Merged
merged 33 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
41c1bae
added matmul
Adnan-Ali-Ahmad Feb 18, 2022
bf66a73
spatial PR commit
Adnan-Ali-Ahmad Feb 18, 2022
7fe084a
array minor change
Adnan-Ali-Ahmad Mar 15, 2022
2a8618d
minor stuff
Adnan-Ali-Ahmad Mar 28, 2022
86c9e21
temp stash
Adnan-Ali-Ahmad Apr 25, 2022
5a5acb0
beginning merge
Adnan-Ali-Ahmad May 31, 2022
f959133
Merge remote-tracking branch 'upstream/main' into dev_spatial
Adnan-Ali-Ahmad May 31, 2022
28dff7f
subdomain extraction & coord transforms
Adnan-Ali-Ahmad Jun 2, 2022
fe892fc
spatial package added
Adnan-Ali-Ahmad Jun 2, 2022
e179dcf
merged with dev
Adnan-Ali-Ahmad Jun 2, 2022
9711bea
minor yapf
Adnan-Ali-Ahmad Jun 2, 2022
7ca0cbc
forgot import of subdomain
Adnan-Ali-Ahmad Jun 2, 2022
a0071b3
small changes
Adnan-Ali-Ahmad Jun 7, 2022
8a26e2b
cylindrical transforms
Adnan-Ali-Ahmad Jun 7, 2022
205adf4
Merge branch 'main' into spatial2
Adnan-Ali-Ahmad Jun 13, 2022
a4800cb
slicing PR. This is subdomain extraction
Adnan-Ali-Ahmad Jun 13, 2022
509713c
Merge branch 'spatial2' of https://github.com/Adnan-Ali-Ahmad/osyris …
Adnan-Ali-Ahmad Jun 13, 2022
e2018f0
add new line
Adnan-Ali-Ahmad Jun 13, 2022
3af9990
revert name assignement change
Adnan-Ali-Ahmad Jun 13, 2022
015d006
revert spherical component computations for now
Adnan-Ali-Ahmad Jun 13, 2022
8faa3ff
newline
Adnan-Ali-Ahmad Jun 13, 2022
81ef3e5
Update src/osyris/spatial/__init__.py
Adnan-Ali-Ahmad Jun 14, 2022
4be4096
Update src/osyris/spatial/spatial.py
Adnan-Ali-Ahmad Jun 14, 2022
a88c647
Update src/osyris/spatial/spatial.py
Adnan-Ali-Ahmad Jun 14, 2022
2d6b805
renaming spatial.py to subdomain.py
Adnan-Ali-Ahmad Jun 14, 2022
b5c3d6e
reverted name setter in .to method
Adnan-Ali-Ahmad Jun 14, 2022
668789a
removing parent and meta attribution
Adnan-Ali-Ahmad Jun 15, 2022
cd909e7
removing loader from subdomain
Adnan-Ali-Ahmad Jun 24, 2022
6fd8903
implemented shape check
Adnan-Ali-Ahmad Jun 27, 2022
98b8702
import dataset
Adnan-Ali-Ahmad Jun 27, 2022
16e522a
warning message added
Adnan-Ali-Ahmad Jun 30, 2022
7896bc5
merging with usptream
Adnan-Ali-Ahmad Jun 30, 2022
398962c
flake8
Adnan-Ali-Ahmad Jun 30, 2022
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
4 changes: 3 additions & 1 deletion src/osyris/core/vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ def __invert__(self):
return np.logical_not(self)

def to(self, unit):
return self.__class__(**{c: xyz.to(unit) for c, xyz in self._xyz.items()})
return self.__class__(**{c: xyz.to(unit)
for c, xyz in self._xyz.items()},
name=self.name)
nvaytet marked this conversation as resolved.
Show resolved Hide resolved
Adnan-Ali-Ahmad marked this conversation as resolved.
Show resolved Hide resolved

def _wrap_numpy(self, func, *args, **kwargs):
if isinstance(args[0], (tuple, list)):
Expand Down
6 changes: 6 additions & 0 deletions src/osyris/spatial/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2022 Osyris contributors (https://github.com/nvaytet/osyris)
Adnan-Ali-Ahmad marked this conversation as resolved.
Show resolved Hide resolved

# flake8: noqa

from .spatial import *
Adnan-Ali-Ahmad marked this conversation as resolved.
Show resolved Hide resolved
43 changes: 43 additions & 0 deletions src/osyris/spatial/spatial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2022 Osyris contributors (https://github.com/nvaytet/osyris)
Adnan-Ali-Ahmad marked this conversation as resolved.
Show resolved Hide resolved

import numpy as np


def extract_sphere(dataset, radius, origin):
Adnan-Ali-Ahmad marked this conversation as resolved.
Show resolved Hide resolved
"""
Extract a spherical subdomain around an origin point.
"""
subdomain = dataset.__class__(nout=dataset.meta["nout"], path=dataset.meta["path"])
Adnan-Ali-Ahmad marked this conversation as resolved.
Show resolved Hide resolved
subdomain.meta = dataset.meta
Adnan-Ali-Ahmad marked this conversation as resolved.
Show resolved Hide resolved
subdomain._parent = dataset
Adnan-Ali-Ahmad marked this conversation as resolved.
Show resolved Hide resolved

for name, group in dataset.items():
pos = group.get("position", group.parent["amr"]["position"])
Adnan-Ali-Ahmad marked this conversation as resolved.
Show resolved Hide resolved
r = (pos - origin).norm
c = (r < radius).values
if np.any(c):
subdomain[name] = dataset[name][c]

return subdomain


def extract_cube(dataset, dx, dy, dz, origin):
Adnan-Ali-Ahmad marked this conversation as resolved.
Show resolved Hide resolved
"""
Extract a cubic domain of size dx, dy & dz around an origin point
"""
subdomain = dataset.__class__(nout=dataset.meta["nout"], path=dataset.meta["path"])
subdomain.meta = dataset.meta
subdomain._parent = dataset

for name, group in dataset.items():
pos = group.get("position", group.parent["amr"]["position"])
centered_pos = pos - origin
cx = (centered_pos.x <= dx * .5) & (centered_pos.x >= -dx * .5)
cy = (centered_pos.y <= dy * .5) & (centered_pos.y >= -dy * .5)
cz = (centered_pos.z <= dz * .5) & (centered_pos.z >= -dz * .5)
c = (cx & cy & cz).values
if np.any(c):
subdomain[name] = dataset[name][c]

return subdomain