Skip to content

Commit

Permalink
Backport PR yt-project#3856: BUG: fix buffer masking in cartesian geo…
Browse files Browse the repository at this point in the history
…metry
  • Loading branch information
neutrinoceros authored and meeseeksmachine committed Mar 31, 2022
1 parent da27553 commit 4740566
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 9 deletions.
11 changes: 11 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path

import matplotlib
import numpy
import pytest
import yaml
from packaging.version import Version
Expand All @@ -20,6 +21,7 @@
)

MPL_VERSION = Version(matplotlib.__version__)
NUMPY_VERSION = Version(numpy.__version__)


def pytest_addoption(parser):
Expand Down Expand Up @@ -122,6 +124,15 @@ def pytest_configure(config):
),
)

if NUMPY_VERSION < Version("1.19") and MPL_VERSION < Version("3.3"):
# This warning is triggered from matplotlib in exactly one test at the time of writing
# and exclusively on the minimal test env. Upgrading numpy or matplotlib resolves
# the issue, so we can afford to ignore it.
config.addinivalue_line(
"filterwarnings",
"ignore:invalid value encountered in less_equal:RuntimeWarning",
)

if find_spec("astropy") is not None:
# at the time of writing, astropy's wheels are behind numpy's latest
# version but this doesn't cause actual problems in our test suite
Expand Down
6 changes: 3 additions & 3 deletions tests/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ answer_tests:
- yt/frontends/chombo/tests/test_outputs.py:test_zp
- yt/frontends/chombo/tests/test_outputs.py:test_kho

local_enzo_008: # PR 2926
local_enzo_009: # PR 3856
- yt/frontends/enzo/tests/test_outputs.py:test_moving7
- yt/frontends/enzo/tests/test_outputs.py:test_galaxy0030
- yt/frontends/enzo/tests/test_outputs.py:test_toro1d
- yt/frontends/enzo/tests/test_outputs.py:test_kh2d
- yt/frontends/enzo/tests/test_outputs.py:test_ecp
- yt/frontends/enzo/tests/test_outputs.py:test_nuclei_density_fields

local_enzo_e_001: # PR 3273
local_enzo_e_002: # PR 3856
- yt/frontends/enzo_e/tests/test_outputs.py:test_hello_world
- yt/frontends/enzo_e/tests/test_outputs.py:test_particle_fields

Expand Down Expand Up @@ -151,7 +151,7 @@ answer_tests:
- yt/frontends/boxlib/tests/test_outputs.py:test_NyxDataset
- yt/frontends/boxlib/tests/test_outputs.py:test_WarpXDataset

local_ramses_004:
local_ramses_005: # PR 3856
- yt/frontends/ramses/tests/test_outputs.py:test_output_00080

local_ytdata_008:
Expand Down
4 changes: 2 additions & 2 deletions yt/geometry/coordinates/cartesian_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ def _ortho_pixelize(
if hasattr(period, "in_units"):
period = period.in_units("code_length").d

buff = np.zeros((size[1], size[0]), dtype="f8")
buff = np.full((size[1], size[0]), np.nan, dtype="float64")
particle_datasets = (ParticleDataset, StreamParticlesDataset)
is_sph_field = finfo.is_sph_field

Expand Down Expand Up @@ -550,7 +550,7 @@ def _oblique_pixelize(self, data_source, field, bounds, size, antialias):
from yt.frontends.ytdata.data_structures import YTSpatialPlotDataset

indices = np.argsort(data_source["pdx"])[::-1].astype(np.int_)
buff = np.zeros((size[1], size[0]), dtype="f8")
buff = np.full((size[1], size[0]), np.nan, dtype="float64")
ftype = "index"
if isinstance(data_source.ds, YTSpatialPlotDataset):
ftype = "gas"
Expand Down
2 changes: 1 addition & 1 deletion yt/geometry/coordinates/cylindrical_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def _ortho_pixelize(
period[1] = self.period[self.y_axis[dim]]
if hasattr(period, "in_units"):
period = period.in_units("code_length").d
buff = np.zeros(size, dtype="f8")
buff = np.full(size, np.nan, dtype="float64")
pixelize_cartesian(
buff,
data_source["px"],
Expand Down
2 changes: 1 addition & 1 deletion yt/geometry/coordinates/geographic_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def _ortho_pixelize(
pdx = data_source["pdx"]
py = data_source["py"]
pdy = data_source["pdy"]
buff = np.zeros((size[1], size[0]), dtype="f8")
buff = np.full((size[1], size[0]), np.nan, dtype="float64")
pixelize_cartesian(
buff,
px,
Expand Down
4 changes: 4 additions & 0 deletions yt/utilities/lib/pixelization_routines.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ def pixelize_cartesian(np.float64_t[:,:] buff,
# This will reduce artifacts if we ever move to
# compositing instead of replacing bitmaps.
if overlap1 * overlap2 < 1.e-6: continue
# make sure pixel value is not a NaN before incrementing it
if buff[i,j] != buff[i,j]: buff[i,j] = 0.0
buff[i,j] += (dsp * overlap1) * overlap2
else:
buff[i,j] = dsp
Expand Down Expand Up @@ -506,6 +508,8 @@ def pixelize_off_axis_cartesian(
fabs(zsp - cz) * 0.99 > dzsp:
continue
mask[i, j] += 1
# make sure pixel value is not a NaN before incrementing it
if buff[i,j] != buff[i,j]: buff[i,j] = 0.0
buff[i, j] += dsp
for i in range(buff.shape[0]):
for j in range(buff.shape[1]):
Expand Down
5 changes: 3 additions & 2 deletions yt/visualization/tests/test_offaxisprojection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import tempfile
import unittest

import numpy as np

from yt.testing import (
assert_equal,
assert_fname,
Expand Down Expand Up @@ -98,5 +100,4 @@ def test_field_cut_off_axis_octree():
(p3.frb[("gas", "density")] == p4.frb[("gas", "density")]).all(), False
)
p4rho = p4.frb[("gas", "density")]
assert_equal(p4rho.min() == 0.0, True) # Lots of zeros
assert_equal(p4rho[p4rho > 0.0].min() >= 0.5, True)
assert_equal(np.nanmin(p4rho[p4rho > 0.0]) >= 0.5, True)

0 comments on commit 4740566

Please sign in to comment.