Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
3ba2a4d
worked on pixave sph projections
nastasha-w Feb 19, 2025
81100cb
free all allocated memory at end of pencil beam SPH projection
nastasha-w Feb 19, 2025
7886d87
first go at on-axis pixel-ave SPH projection backend
nastasha-w Feb 19, 2025
3d461e2
edit SPH pix-av proj. backend: 2x2 kernel case
nastasha-w Feb 20, 2025
f09b223
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 20, 2025
190c2ff
first go at connecting the backend to the rest of the code
nastasha-w Feb 21, 2025
6168a16
continued work on integrating backend
nastasha-w Feb 21, 2025
d7ec606
more backend integration, including for tests
nastasha-w Feb 21, 2025
7f06360
debug until compiles (macOS)
nastasha-w Feb 24, 2025
9a0b360
fix docstring typo
nastasha-w Feb 24, 2025
dc8153b
more docstring typos
nastasha-w Feb 24, 2025
df809a7
more docstring typos
nastasha-w Feb 24, 2025
0ae4e73
fix type annotations?
nastasha-w Feb 24, 2025
ce5fa63
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 24, 2025
3868858
first go on-axes pixelave proj test setup
nastasha-w Feb 24, 2025
593b0ed
function annotation fixes?
nastasha-w Feb 25, 2025
f8f52df
raise error if invalid pixelmeaning arg
nastasha-w Feb 25, 2025
cc2510a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 25, 2025
9bd50ce
bugfix: pass on pixelmeaning value, not string "pixelmeaning"
nastasha-w Feb 25, 2025
3e9d5bc
remove wrongfully added pixelmeaning arg
nastasha-w Feb 25, 2025
adfc60f
first try: test for both pixelmeaning opts.
nastasha-w Feb 25, 2025
cc39df4
add pixelmeaning arg to avoid errors in pixelize calls
nastasha-w Feb 25, 2025
fc62668
add pixelmeaning arg to to_frb to avoid errors
nastasha-w Feb 25, 2025
6308cf4
add pixelmeaning arg. for ParticleImageBuffer to avoid errors
nastasha-w Feb 25, 2025
4833b91
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 25, 2025
30b8f11
fix function annotation error
nastasha-w Feb 25, 2025
42bf766
cython function wants bounds to be an array
nastasha-w Feb 25, 2025
2a3e0e1
pytest parametrize used -> ignore with nose
nastasha-w Feb 25, 2025
df40e05
just be less strict on pixelave bounds input type
nastasha-w Feb 25, 2025
1050181
free shared kern2by2 *after* parallel section
nastasha-w Feb 26, 2025
1642c3a
debugged until test runs to assert
nastasha-w Feb 26, 2025
429874a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 26, 2025
01371d1
fix errors in pencilbeam tests (types in testing funcs)
nastasha-w Feb 28, 2025
ad6f377
add debugging print lines
nastasha-w Feb 28, 2025
b0201fa
shorter func name
nastasha-w Feb 28, 2025
ba9e707
use pixel-meaning-dependent projection function
nastasha-w Feb 28, 2025
f1ed43c
lots of debug msgs, some actually debugging
nastasha-w Feb 28, 2025
ff0aa45
attempt to fix indexing in output nd kern2by2
nastasha-w Feb 28, 2025
57a8476
matched due to indexing error?
nastasha-w Feb 28, 2025
63708bd
print statement edits
nastasha-w Feb 28, 2025
cc0adef
a bit more test debugging
nastasha-w Feb 28, 2025
467c509
style edit
nastasha-w Feb 28, 2025
9635ae1
output grid axis order is (y, x)
nastasha-w Feb 28, 2025
80c5bc6
fix domain-edge error non-periodic test
nastasha-w Feb 28, 2025
2f3f613
fix bug in test
nastasha-w Feb 28, 2025
6c46316
pixelave projection gets segfaults even if I free nothing
nastasha-w Feb 28, 2025
76a7e69
more index revision
nastasha-w Feb 28, 2025
85ade08
tests fail but at least the segfaults are gone
nastasha-w Feb 28, 2025
d375ae8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 28, 2025
ed57977
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Feb 28, 2025
529ad6b
transposed later in coordinate handler -> normal x, y axis order in b…
nastasha-w Mar 5, 2025
f23b7e2
update test: match projection plot (y, x) axis order
nastasha-w Mar 5, 2025
4d53439
fixed *some* problems in 2x2 kernel stamps (indexing)
nastasha-w Mar 5, 2025
d7d0c55
bugfix: for 2x2 stamps, was adjusting prefector_j in each periodicity…
nastasha-w Mar 5, 2025
a3725fc
fewer test cases for faster iteration
nastasha-w Mar 5, 2025
0502ba4
try higher kernel sampling for baseline?
nastasha-w Mar 5, 2025
dfbe1ac
more mucking around with tests
nastasha-w Mar 24, 2025
c51a4b2
speed up tests, on-axis test pass with lowered precision reqs.
nastasha-w Mar 28, 2025
6d7eda4
fix div. by 0 error test failure?
nastasha-w Mar 28, 2025
dd0d9f5
remove function not used in updated test
nastasha-w Apr 1, 2025
2007da4
added function to reduce image res by averaging
nastasha-w Apr 1, 2025
a8f5a92
added off-axis projection test for pixave; passes
nastasha-w Apr 1, 2025
395527d
moved resreduce to testing.py, renamed
nastasha-w Apr 1, 2025
d73e07e
add test for pixave mass conservation
nastasha-w Apr 1, 2025
b5360a0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 1, 2025
7ac336f
fix tuple annotation?
nastasha-w Apr 7, 2025
e4c908b
update docstring
nastasha-w Apr 7, 2025
3befdb7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Apr 7, 2025
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
1 change: 1 addition & 0 deletions nose_ignores.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
--ignore-file=test_disks\.py
--ignore-file=test_offaxisprojection_pytestonly\.py
--ignore-file=test_sph_pixelization_pytestonly\.py
--ignore-file=test_off_axis_SPH\.py
--ignore-file=test_time_series\.py
--ignore-file=test_cf_radial_pytest\.py
1 change: 1 addition & 0 deletions tests/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -231,5 +231,6 @@ other_tests:
- "--ignore-file=test_offaxisprojection_pytestonly\\.py"
- "--ignore-file=test_sph_pixelization_pytestonly\\.py"
- "--ignore-file=test_cf_radial_pytest\\.py"
- "--ignore-file=test_off_axis_SPH\\.py"
cookbook:
- 'doc/source/cookbook/tests/test_cookbook.py'
23 changes: 21 additions & 2 deletions yt/data_objects/selection_objects/data_selection_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import uuid
from collections import defaultdict
from contextlib import contextmanager
from typing import Literal

import numpy as np
from more_itertools import always_iterable
Expand Down Expand Up @@ -567,7 +568,15 @@ def _get_pw(self, fields, center, width, origin, plot_type):
pw._setup_plots()
return pw

def to_frb(self, width, resolution, center=None, height=None, periodic=False):
def to_frb(
self,
width,
resolution,
center=None,
height=None,
periodic=False,
pixelmeaning: Literal["pixelave", "pencilbeam"] = "pixelave",
):
r"""This function returns a FixedResolutionBuffer generated from this
object.

Expand Down Expand Up @@ -595,7 +604,15 @@ def to_frb(self, width, resolution, center=None, height=None, periodic=False):
periodic : bool
Should the returned Fixed Resolution Buffer be periodic? (default:
False).
pixelmeaning:
"pixelav": a pixel represents an average surface density or
surface-density-weighted average across a pixel.

"pencilbeam": a pixel represents a column density or
column-density-weighted average integrated over a pencil
beam through the pixel center.

Only applies to projections of SPH datasets.
Returns
-------
frb : :class:`~yt.visualization.fixed_resolution.FixedResolutionBuffer`
Expand Down Expand Up @@ -659,7 +676,9 @@ def to_frb(self, width, resolution, center=None, height=None, periodic=False):
center[yax] - height * 0.5,
center[yax] + height * 0.5,
)
frb = FixedResolutionBuffer(self, bounds, resolution, periodic=periodic)
frb = FixedResolutionBuffer(
self, bounds, resolution, periodic=periodic, pixelmeaning=pixelmeaning
)
return frb


Expand Down
13 changes: 12 additions & 1 deletion yt/data_objects/selection_objects/slices.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Literal

import numpy as np

from yt.data_objects.selection_objects.data_selection_objects import (
Expand Down Expand Up @@ -313,7 +315,14 @@ def to_pw(self, fields=None, center="center", width=None, axes_unit=None):
pw._setup_plots()
return pw

def to_frb(self, width, resolution, height=None, periodic=False):
def to_frb(
self,
width,
resolution,
height=None,
periodic=False,
pixelmeaning: Literal["pixelave", "pencilbeam"] = "pixelave",
):
r"""This function returns a FixedResolutionBuffer generated from this
object.

Expand All @@ -338,6 +347,8 @@ def to_frb(self, width, resolution, height=None, periodic=False):
periodic : boolean
This can be true or false, and governs whether the pixelization
will span the domain boundaries.
pixelmeaning: ignored
argument meant for SPH projections

Returns
-------
Expand Down
47 changes: 42 additions & 5 deletions yt/geometry/coordinates/cartesian_coordinates.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Literal

import numpy as np

from yt.data_objects.index_subobjects.unstructured_mesh import SemiStructuredMesh
Expand All @@ -13,7 +15,8 @@
pixelize_element_mesh_line,
pixelize_off_axis_cartesian,
pixelize_sph_kernel_cutting,
pixelize_sph_kernel_projection,
pixelize_sph_kernel_projection_pencilbeam,
pixelize_sph_kernel_projection_pixelave,
pixelize_sph_kernel_slice,
)
from yt.utilities.math_utils import compute_stddev_image
Expand Down Expand Up @@ -170,13 +173,24 @@ def pixelize(
size,
antialias=True,
periodic=True,
pixelmeaning: Literal["pixelave", "pencilbeam"] = "pixelave",
*,
return_mask=False,
):
"""
Method for pixelizing datasets in preparation for
two-dimensional image plots. Relies on several sampling
routines written in cython

pixelmeaning:
"pixelave": a pixel represents an average surface density or
surface-density-weighted average across a pixel.

"pencilbeam": a pixel represents a column density or
column-density-weighted average integrated over a pencil
beam through the pixel center.

Only applies to SPH datasets.
"""
index = data_source.ds.index
if hasattr(index, "meshes") and not isinstance(
Expand Down Expand Up @@ -236,11 +250,18 @@ def pixelize(

elif self.axis_id.get(dimension, dimension) is not None:
buff, mask = self._ortho_pixelize(
data_source, field, bounds, size, antialias, dimension, periodic
data_source,
field,
bounds,
size,
antialias,
dimension,
periodic,
pixelmeaning,
)
else:
buff, mask = self._oblique_pixelize(
data_source, field, bounds, size, antialias
data_source, field, bounds, size, antialias, pixelmeaning
)

if return_mask:
Expand Down Expand Up @@ -314,7 +335,7 @@ def pixelize_line(self, field, start_point, end_point, npoints):
return arc_length, plot_values

def _ortho_pixelize(
self, data_source, field, bounds, size, antialias, dim, periodic
self, data_source, field, bounds, size, antialias, dim, periodic, pixelmeaning
):
from yt.data_objects.construction_data_containers import YTParticleProj
from yt.data_objects.selection_objects.slices import YTSlice
Expand Down Expand Up @@ -396,6 +417,20 @@ def _ortho_pixelize(
kernel_name = "cubic"

if isinstance(data_source, YTParticleProj): # projection
# pick out projection function. _pencilbeam does have
# one extra optional parameter (minimum number of
# subsampling pixels), but we just use the default value
# for now.
if pixelmeaning == "pencilbeam":
pixelize_sph_kernel_projection = (
pixelize_sph_kernel_projection_pencilbeam
)
elif pixelmeaning == "pixelave":
pixelize_sph_kernel_projection = (
pixelize_sph_kernel_projection_pixelave
)
else:
raise NotImplementedError(f"No pixelmeaning option {pixelmeaning}")
weight = data_source.weight_field
moment = data_source.moment
le, re = data_source.data_source.get_bbox()
Expand Down Expand Up @@ -667,7 +702,9 @@ def _ortho_pixelize(
assert mask is None or mask.dtype == bool
return buff, mask

def _oblique_pixelize(self, data_source, field, bounds, size, antialias):
def _oblique_pixelize(
self, data_source, field, bounds, size, antialias, pixelmeaning
):
from yt.data_objects.selection_objects.slices import YTCuttingPlane
from yt.frontends.sph.data_structures import ParticleDataset
from yt.frontends.stream.data_structures import StreamParticlesDataset
Expand Down
3 changes: 3 additions & 0 deletions yt/geometry/coordinates/coordinate_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def pixelize(
size,
antialias=True,
periodic=True,
pixelmeaning: Literal["pixelave", "pencilbeam"] = "pixelave",
*,
return_mask: Literal[False],
) -> "np.ndarray[Any, np.dtype[np.float64]]": ...
Expand All @@ -170,6 +171,7 @@ def pixelize(
size,
antialias=True,
periodic=True,
pixelmeaning: Literal["pixelave", "pencilbeam"] = "pixelave",
*,
return_mask: Literal[True],
) -> tuple[
Expand All @@ -186,6 +188,7 @@ def pixelize(
size,
antialias=True,
periodic=True,
pixelmeaning: Literal["pixelave", "pencilbeam"] = "pixelave",
*,
return_mask=False,
):
Expand Down
8 changes: 8 additions & 0 deletions yt/geometry/coordinates/cylindrical_coordinates.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from functools import cached_property
from typing import Literal

import numpy as np

Expand Down Expand Up @@ -87,9 +88,16 @@ def pixelize(
size,
antialias=True,
periodic=False,
pixelmeaning: Literal["pixelave", "pencilbeam"] = "pixelave",
*,
return_mask=False,
):
"""
Parameters
----------
pixelmeaning: ignored, argument meant for cartesian SPH data

"""
# Note that above, we set periodic by default to be *false*. This is
# because our pixelizers, at present, do not handle periodicity
# correctly, and if you change the "width" of a cylindrical plot, it
Expand Down
9 changes: 9 additions & 0 deletions yt/geometry/coordinates/geographic_coordinates.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Literal

import numpy as np
import unyt

Expand Down Expand Up @@ -228,9 +230,16 @@ def pixelize(
size,
antialias=True,
periodic=True,
pixelmeaning: Literal["pixelave", "pencilbeam"] = "pixelave",
*,
return_mask=False,
):
"""
Parameters
----------
pixelmeaning: ignored, argument meant for cartesian SPH data

"""
if self.axis_name[dimension] in ("latitude", "longitude"):
buff, mask = self._cyl_pixelize(
data_source, field, bounds, size, antialias, dimension
Expand Down
8 changes: 8 additions & 0 deletions yt/geometry/coordinates/spherical_coordinates.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from functools import cached_property
from typing import Literal

import numpy as np

Expand Down Expand Up @@ -90,9 +91,16 @@ def pixelize(
size,
antialias=True,
periodic=True,
pixelmeaning: Literal["pixelave", "pencilbeam"] = "pixelave",
*,
return_mask=False,
):
"""
Parameters
----------
pixelmeaning: ignored, argument meant for cartesian SPH data

"""
self.period
name = self.axis_name[dimension]
if name == "r":
Expand Down
4 changes: 4 additions & 0 deletions yt/geometry/coordinates/tests/test_sph_pixelization.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def test_sph_projection_basic1():
height=(2.5, "cm"),
center=np.array([1.5, 1.5, 1.5]),
periodic=False,
pixelmeaning="pencilbeam",
)
out = frb.get_image(("gas", "density"))

Expand Down Expand Up @@ -96,6 +97,7 @@ def test_sph_projection_basic2():
height=(2.5, "cm"),
center=np.array([1.375, 1.375, 1.5]),
periodic=False,
pixelmeaning="pencilbeam",
)
out = frb.get_image(("gas", "density"))

Expand Down Expand Up @@ -163,6 +165,7 @@ def getdata_test_gridproj2():
height=(2.5, "cm"),
center=np.array([1.5, 1.5, 1.5]),
periodic=False,
pixelmeaning="pencilbeam",
)
out = frb.get_image(("gas", "density"))
outlist.append(out)
Expand Down Expand Up @@ -205,6 +208,7 @@ def test_sph_gridproj_reseffect2():
height=(3.0 - 2.0 * margin, "cm"),
center=np.array([1.5, 1.5, 1.5]),
periodic=False,
pixelmeaning="pencilbeam",
)
out = frb.get_image(("gas", "density"))
imgs[rl] = out
Expand Down
Loading
Loading