Skip to content

Commit 405a156

Browse files
committed
Test cut_region
1 parent 77aafba commit 405a156

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

yt/data_objects/tests/test_extract_regions.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import numpy as np
2-
from numpy.testing import assert_almost_equal, assert_equal
2+
from numpy.testing import assert_almost_equal, assert_array_less, assert_equal
33

44
from yt.loaders import load
55
from yt.testing import (
@@ -68,6 +68,37 @@ def test_cut_region():
6868
assert_equal(p2["gas", "density"].max() > 0.25, True)
6969

7070

71+
def test_cut_region_simple_syntax():
72+
ds = fake_random_ds(
73+
64,
74+
fields=("density", "temperature", "velocity_x"),
75+
units=("g/cm**3", "K", "cm/s"),
76+
)
77+
ad = ds.all_data()
78+
rho_thresh = ds.quan(0.5, "g/cm**3")
79+
T_thresh = ds.quan(0.5, "K")
80+
low_density = ad.cut_region(ds.fields.gas.density < rho_thresh)
81+
low_density_high_T = ad.cut_region(
82+
[
83+
ds.fields.gas.density < rho_thresh,
84+
ds.fields.gas.temperature > T_thresh,
85+
]
86+
)
87+
reg = ad.cut_region(ds.fields.gas.density / ds.fields.gas.temperature > 1)
88+
89+
# Make sure the low density only contains low density, but should
90+
# also contain low temperature
91+
assert_array_less(low_density["gas", "density"], rho_thresh)
92+
assert low_density["gas", "temperature"].min() < T_thresh
93+
94+
# Make sure the low density, high-T is correctly selected
95+
assert_array_less(low_density_high_T["gas", "density"], rho_thresh)
96+
assert_array_less(T_thresh, low_density_high_T["gas", "temperature"])
97+
98+
# Make sure the ratio of density to temperature is larger than one
99+
assert_array_less(1, reg["gas", "density"] / reg["gas", "temperature"])
100+
101+
71102
def test_region_and_particles():
72103
ds = fake_amr_ds(particles=10000)
73104

0 commit comments

Comments
 (0)