Skip to content

Commit

Permalink
BUG: fix FRB integration with CylindricalResolutionBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Jan 26, 2024
1 parent dbe0965 commit 7ee6a51
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ def to_frb(self, width, resolution, center=None, height=None, periodic=False):
if is_sequence(resolution):
resolution = max(resolution)
frb = CylindricalFixedResolutionBuffer(self, width, resolution)
# breakpoint()
return frb

if center is None:
Expand Down
2 changes: 1 addition & 1 deletion yt/data_objects/tests/test_data_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_to_frb(self):
)
frb = proj.to_frb((1.0, "unitary"), 64)
assert_equal(frb.radius, (1.0, "unitary"))
assert_equal(frb.buff_size, 64)
assert_equal(frb.buff_size, (64, 64))

def test_extract_isocontours(self):
# Test isocontour properties for AMRGridData
Expand Down
36 changes: 32 additions & 4 deletions yt/visualization/fixed_resolution.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import sys
import weakref
from functools import partial
from numbers import Number
from typing import TYPE_CHECKING, Optional

import numpy as np
from unyt import unyt_quantity

from yt._maintenance.deprecation import issue_deprecation_warning
from yt._typing import FieldKey, MaskT
Expand Down Expand Up @@ -584,16 +586,42 @@ class CylindricalFixedResolutionBuffer(FixedResolutionBuffer):
def __init__(self, data_source, radius, buff_size, antialias=True, *, filters=None):
self.data_source = data_source
self.ds = data_source.ds
self.radius = radius
self.buff_size = buff_size
self._set_radius(radius)
if np.isscalar(buff_size):
self.buff_size = (buff_size, buff_size)
else:
self.buff_size = buff_size
self.bounds = self._get_bounds()
self.antialias = antialias
self.data = {}
self.data: dict[str, ImageArray] = {}
self.mask: dict[str, MaskT] = {}
self._filters = filters if filters is not None else []

ds = getattr(data_source, "ds", None)
if ds is not None:
ds.plots.append(weakref.proxy(self))

def _set_radius(self, r) -> None:
if self.ds is None:
# not attempting to solve this case right now
raise RuntimeError("boom 1") # tmp
else:
if (
isinstance(r, tuple)
and len(r) == 2
and (isinstance(r[0], Number) and isinstance(r[1], str))
):
r = self.ds.quan(*r).to("code_length")
elif isinstance(r, unyt_quantity):
r = self.ds.quan(r).to("code_length")
else:
raise RuntimeError("boom 2") # tmp
self.radius = r

def _get_bounds(self) -> tuple[float, float, float, float]:
dx = dy = self.radius.item()
return (0.0, dx, 0.0, dy)

@override
def _generate_image_and_mask(self, item) -> None:
buff = np.zeros(self.buff_size, dtype="f8")
Expand All @@ -604,7 +632,7 @@ def _generate_image_and_mask(self, item) -> None:
self.data_source["theta"],
self.data_source["dtheta"],
self.data_source[item].astype("float64"),
self.radius,
extents=self.bounds,
return_mask=True,
)
self.data[item] = ImageArray(
Expand Down

0 comments on commit 7ee6a51

Please sign in to comment.