|
1 | 1 | 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 |
3 | 3 |
|
4 | 4 | from yt.loaders import load
|
5 | 5 | from yt.testing import (
|
@@ -68,6 +68,37 @@ def test_cut_region():
|
68 | 68 | assert_equal(p2["gas", "density"].max() > 0.25, True)
|
69 | 69 |
|
70 | 70 |
|
| 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 | + |
71 | 102 | def test_region_and_particles():
|
72 | 103 | ds = fake_amr_ds(particles=10000)
|
73 | 104 |
|
|
0 commit comments