Skip to content

Commit

Permalink
Merge pull request #74 from dschwoerer/devel
Browse files Browse the repository at this point in the history
Version 0.2.4
  • Loading branch information
dschwoerer authored Apr 21, 2023
2 parents 83e85ff + 0155eca commit 88346de
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 110 deletions.
30 changes: 0 additions & 30 deletions .github/workflows/coverage.yml

This file was deleted.

5 changes: 4 additions & 1 deletion .github/workflows/test-python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ jobs:
timeout-minutes: 15
strategy:
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
extra-install: ["", "numba"]
exclude:
- python-version: '3.11'
extra-install: 'numba'
fail-fast: false

steps:
Expand Down
22 changes: 14 additions & 8 deletions xemc3/core/dataset.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import warnings
from typing import Any, Mapping, Union
from typing import Any, Mapping, Union, Optional
import sys

if sys.version_info >= (3, 8):
Expand Down Expand Up @@ -236,7 +236,10 @@ def iter_plates(self, *, symmetry=False, segments=1):
for key in var_list:
ds[key] = var_list[key][i]
if len(phid.shape) == 1:
assert phid.shape == xd.shape
assert phid.shape == xd.shape, (
f"Expected phi.shape = {phid.shape} == x.shape = {xd.shape} to match."
+ utils.raise_issue
)
for j in range(ds.dims["plate_ind"]):
yield ds.isel(
plate_ind=j, **{k: slice(None, v[j]) for k, v in crop.items()}
Expand Down Expand Up @@ -395,7 +398,6 @@ def plot(self, key, *args, **kw):
from . import plot_3d

if "plate_ind" in self.data.dims:
# assert args == []
return plot_3d.divertor(self.data, key, *args, **kw)

init = {}
Expand Down Expand Up @@ -437,7 +439,7 @@ def mean_time(self) -> xr.Dataset:

def isel(
self,
indexers: Mapping[str, Any] = None,
indexers: Optional[Mapping[str, Any]] = None,
drop: bool = False,
missing_dims: Union[
Literal["raise"], Literal["warn"], Literal["ignore"]
Expand Down Expand Up @@ -478,7 +480,7 @@ def isel(

def sel(
self,
indexers: Mapping[str, Any] = None,
indexers: Optional[Mapping[str, Any]] = None,
drop: bool = False,
missing_dims: str = "raise",
**indexers_kwargs: Any,
Expand All @@ -489,7 +491,9 @@ def sel(
for k in indexers.keys():
val = indexers[k]
if "delta_" + k in ds.dims and k + "_bounds" in ds:
assert k in ds.dims
assert (
k in ds.dims
), f"Expected {k} in {ds.dims} - maybe you already selected in {k} dim?"
assert (
len(ds[k + "_bounds"].dims) == 2
), "Only 1D bounds are currently supported. Maybe try isel."
Expand All @@ -513,7 +517,9 @@ def sel(
else:
forisel[k] = val
ds = ds.emc3.isel(forisel)
assert isinstance(ds, xr.Dataset)
assert isinstance(
ds, xr.Dataset
), f"Expected to have an xr.Dataset, but instead got {type(ds)}"
return ds

def evaluate_at_xyz(self, x, y, z, *args, **kwargs):
Expand All @@ -533,7 +539,7 @@ def evaluate_at_rpz(
key=None,
periodicity: int = 5,
updownsym: bool = True,
delta_phi: float = None,
delta_phi: Optional[float] = None,
fill_value=None,
lazy=False,
progress=False,
Expand Down
44 changes: 28 additions & 16 deletions xemc3/core/depo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
import typing

from .utils import rrange
from .utils import rrange, raise_issue


if 0:
Expand Down Expand Up @@ -86,7 +86,10 @@ def read_depo_raw(ds: xr.Dataset, fn: str) -> typing.List[xr.DataArray]:

with open(fn) as f:
line = f.readline().split()
assert len(line) == 2
assert len(line) == 2, (
f"Unexpected: `{line}` at start of `{fn}` - expected 2 elements"
+ raise_issue
)
blockasize = int(line[0])
# Lines look like this:
# Index
Expand All @@ -110,21 +113,28 @@ def read_depo_raw(ds: xr.Dataset, fn: str) -> typing.List[xr.DataArray]:
line = bad.sub(r"\1E\2", f.readline()).split()
ints = [int(x) for x in line[:7]]
floats = [float(x) for x in line[7:]]
assert (
ints[0] == i + 1
), f"Expected first index to be contigous, thus expected {i+1} but got {ints[0]}"
assert ints[1] == 3, f"Expected 3 but got {ints[1]}"
assert ints[0] == i + 1, (
f"Expected first index to be contigous, thus expected {i+1} but got {ints[0]} while reading {fn}"
+ raise_issue
)
assert ints[1] == 3, (
f"Expected 3 but got {ints[1]} while reading `{fn}`." + raise_issue
)
# print(ints[3:])
if haszone:
slc = tuple(ints[3:])
else:
assert ints[3] == 0, f"Expected zoneid=0 but got {ints[3]}"
assert ints[3] == 0, (
f"Expected zoneid=0 but got {ints[3]}" + raise_issue
)
slc = tuple(ints[4:])

for name, val in zip(varnames, (ints[2] == 1, floats[0])):
out[name][slc] = val
if last:
assert not out["surftype"][last]
assert not out["surftype"][last], (
f"Unexpected input in `{fn}`." + raise_issue
)
if ints[2] != 1:
last = slc
# print("a", out["surftype"][slc], ints[2] == 1)
Expand All @@ -148,11 +158,11 @@ def read_depo_raw(ds: xr.Dataset, fn: str) -> typing.List[xr.DataArray]:
break
ints = [int(x) for x in line[:7]]
floats = [float(x) for x in line[7:]]
assert ints[1] == 3, f"Expected 3 but got {ints[1]}"
assert ints[1] == 3, f"Expected 3 but got {ints[1]}" + raise_issue
if haszone:
slc = tuple(ints[3:])
else:
assert ints[3] == 0
assert ints[3] == 0, f"Unexpected input in {fn} `line`." + raise_issue
slc = tuple(ints[4:])
for name, val in zip(varnames, (ints[2] == 1, floats[0])):
out2[name][slc] = val
Expand All @@ -164,11 +174,11 @@ def read_depo_raw(ds: xr.Dataset, fn: str) -> typing.List[xr.DataArray]:
out2["other"][j][slc] = floats[j + 1]

if sparse:
assert any([d.nnz for d in out["other"]]) == hasother
assert any([d.nnz for d in out2["other"]]) == hasother2
assert any([d.nnz for d in out["other"]]) == hasother, raise_issue
assert any([d.nnz for d in out2["other"]]) == hasother2, raise_issue
# if not hasother:
# out["other"] = []
assert not hasother2
assert not hasother2, raise_issue
out2["other"] = []

ret = [
Expand All @@ -178,8 +188,8 @@ def read_depo_raw(ds: xr.Dataset, fn: str) -> typing.List[xr.DataArray]:
xr.DataArray(data=tocoo(d), dims=dims)
for d in [out2["surftype"], out2["flux"], *out2["other"]]
]
assert len(ret[0]) == 6, f"{len(ret[0])}"
assert len(ret[1]) == 2
assert len(ret[0]) == 6, f"Expected 6 items but got {len(ret[0])}." + raise_issue
assert len(ret[1]) == 2, raise_issue
return ret[0] + ret[1]


Expand Down Expand Up @@ -208,7 +218,9 @@ def write_depo_raw_part(datas, f, i):


def write_depo_raw(datas, fn):
assert len(datas) == 8, f"Expected 8 data entries, but got { len(datas) }"
assert len(datas) == 8, (
f"Expected 8 data entries, but got { len(datas) }" + raise_issue
)
datas = datas[:6], datas[6:]
i = 0
with open(fn, "w") as f:
Expand Down
1 change: 0 additions & 1 deletion xemc3/core/evaluate_at.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@


def _evaluate_get_keys(ds, r, phi, z, periodicity, updownsym, delta_phi, progress):

with warnings.catch_warnings():
warnings.filterwarnings("ignore", "invalid value encountered in remainder")
phi = phi % (np.pi * 2 / periodicity)
Expand Down
Loading

0 comments on commit 88346de

Please sign in to comment.