Skip to content

Commit 06f9722

Browse files
authored
Merge pull request #39 from chrishavlin/handling_revsered_dims
handling revesred dimension arrays
2 parents 099433e + a6bab63 commit 06f9722

File tree

15 files changed

+193
-51
lines changed

15 files changed

+193
-51
lines changed

.github/workflows/build-test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111
python-version: ['3.8', '3.9', '3.10']
1212

1313
steps:
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v3
1515
- name: Set up Python ${{ matrix.python-version }}
16-
uses: actions/setup-python@v2
16+
uses: actions/setup-python@v4
1717
with:
1818
python-version: ${{ matrix.python-version }}
1919
- name: Install dependencies

.github/workflows/check-build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ jobs:
66
name: twinecheck
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@v2
9+
- uses: actions/checkout@v3
1010
- name: Set up Python
11-
uses: actions/setup-python@v2
11+
uses: actions/setup-python@v4
1212
with:
1313
python-version: 3.9
1414
- name: Install dependencies

.github/workflows/check-manifest.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- name: Checkout Source
10-
uses: actions/checkout@v2
10+
uses: actions/checkout@v3
1111
- name: Setup Python
12-
uses: actions/setup-python@v2
12+
uses: actions/setup-python@v4
1313
with:
1414
python-version: 3.9
1515
- name: install check-manifest

.github/workflows/create-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
steps:
1515
- name: Checkout code
16-
uses: actions/checkout@v2
16+
uses: actions/checkout@v3
1717
- name: Create Release
1818
id: create_release
1919
uses: actions/create-release@v1

.github/workflows/publish-to-pypi.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ jobs:
1111
name: Build and Publish
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@master
14+
- uses: actions/checkout@v3
1515
- name: Set up Python 3.9
16-
uses: actions/setup-python@v1
16+
uses: actions/setup-python@v4
1717
with:
1818
python-version: 3.9
1919
- name: Install dependencies

.github/workflows/style-checks.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ jobs:
66
name: flake8
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/checkout@master
9+
- uses: actions/checkout@v3
1010
- name: Setup Python
11-
uses: actions/setup-python@master
11+
uses: actions/setup-python@v4
1212
with:
13-
python-version: 3.8
13+
python-version: 3.9
1414
- name: install
1515
id: install
1616
run : pip install -r tests/lint_requirements.txt
@@ -25,11 +25,11 @@ jobs:
2525
name: black
2626
runs-on: ubuntu-latest
2727
steps:
28-
- uses: actions/checkout@master
28+
- uses: actions/checkout@v3
2929
- name: Setup Python
30-
uses: actions/setup-python@master
30+
uses: actions/setup-python@v4
3131
with:
32-
python-version: 3.8
32+
python-version: 3.9
3333
- name: install
3434
id: install
3535
run : pip install -r tests/lint_requirements.txt
@@ -44,11 +44,11 @@ jobs:
4444
name: isort
4545
runs-on: ubuntu-latest
4646
steps:
47-
- uses: actions/checkout@master
47+
- uses: actions/checkout@v3
4848
- name: Setup Python
49-
uses: actions/setup-python@master
49+
uses: actions/setup-python@v4
5050
with:
51-
python-version: 3.8
51+
python-version: 3.9
5252
- name: install
5353
id: install
5454
run : pip install -r tests/lint_requirements.txt

HISTORY.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# History
22

3+
## 0.1.2 (2022-02-27)
4+
5+
Bug fix release.
6+
7+
### Fixes:
8+
* fixes handling of xarray variables with dimensions in decreasing
9+
order (e.g., latitude from 90 to -90) without
10+
having to re-index the whole variable (PR [39](https://github.com/data-exp-lab/yt_xarray/pull/39)).
11+
312
## 0.1.1 (2022-02-07)
413

514
This release builds out the loading functions introduced in v0.1.0 and includes

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.1.1
2+
current_version = 0.1.2
33
commit = True
44
tag = True
55

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,6 @@
3737
test_suite="tests",
3838
tests_require=test_requirements,
3939
url="https://github.com/data-exp-lab/yt_xarray",
40-
version="0.1.1",
40+
version="0.1.2",
4141
zip_safe=False,
4242
)

tests/test_xr_to_yt.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,64 @@ def test_add_3rd_axis_name(yt_geom):
479479

480480
with pytest.raises(ValueError, match="Unsupported geometry type"):
481481
_ = xr2yt._add_3rd_axis_name("bad_geometry", expected[:-1])
482+
483+
484+
def _get_pixelized_slice(yt_ds):
485+
slc = yt_ds.slice(
486+
yt_ds.coordinates.axis_id["depth"],
487+
yt_ds.domain_center[yt_ds.coordinates.axis_id["depth"]],
488+
center=yt_ds.domain_center,
489+
)
490+
vals = yt_ds.coordinates.pixelize(
491+
0,
492+
slc,
493+
("stream", "test_field"),
494+
yt_ds.arr([1, 359, -89, 89], "code_length"),
495+
(400, 400),
496+
)
497+
return slc, vals
498+
499+
500+
def _get_ds_for_reverse_tests(stretched, use_callable, chunksizes):
501+
ds = construct_minimal_ds(
502+
min_x=1,
503+
max_x=359,
504+
min_z=50,
505+
max_z=650,
506+
min_y=89,
507+
max_y=-89,
508+
n_x=50,
509+
n_y=100,
510+
n_z=30,
511+
z_stretched=stretched,
512+
npseed=True,
513+
)
514+
yt_ds = ds.yt.load_grid(use_callable=use_callable, chunksizes=chunksizes)
515+
return yt_ds
516+
517+
518+
@pytest.mark.parametrize(
519+
"stretched,use_callable,chunksizes",
520+
[
521+
(True, False, None),
522+
(False, False, None),
523+
(False, True, None),
524+
(False, True, 20),
525+
(False, False, 20),
526+
],
527+
)
528+
def test_reversed_axis(stretched, use_callable, chunksizes):
529+
# tests for when the incoming data is not positive-monotonic
530+
531+
yt_ds = _get_ds_for_reverse_tests(stretched, use_callable, chunksizes)
532+
533+
if stretched:
534+
grid_obj = yt_ds.index.grids[0]
535+
ax_id = yt_ds.coordinates.axis_id["latitude"]
536+
assert np.all(grid_obj.cell_widths[ax_id] > 0)
537+
538+
slc, vals = _get_pixelized_slice(yt_ds)
539+
540+
pdy_lats = slc._generate_container_field("pdy")
541+
assert np.all(pdy_lats > 0)
542+
assert np.all(np.isfinite(vals))

0 commit comments

Comments
 (0)