Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: fix buffer masking in cartesian geometry #3856

Merged
merged 3 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -42,15 +42,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 @@ -152,7 +152,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 @@ -306,7 +306,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 @@ -555,7 +555,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 @@ -125,7 +125,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 @@ -246,7 +246,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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the following?

Suggested change
assert_equal(np.nanmin(p4rho[p4rho > 0.0]) >= 0.5, True)
assert np.nanmin(p4rho[p4rho > 0.0]) >= 0.5

Note that I am absolutely happy about the PR as is and don't want to delay it any further, so feel free to push the merge button!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I’m going to keep it as is to match the local dominant convention, even though this is actually not a unit test-based test, so your suggestion should indeed work.