Skip to content

Commit

Permalink
update comments, notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishavlin committed Oct 3, 2024
1 parent 2c1ee6f commit afe63c3
Show file tree
Hide file tree
Showing 6 changed files with 1,771 additions and 855 deletions.
841 changes: 0 additions & 841 deletions examples/tiled_grids.ipynb

This file was deleted.

767 changes: 767 additions & 0 deletions examples/tiled_grids_intro.ipynb

Large diffs are not rendered by default.

321 changes: 321 additions & 0 deletions examples/tiled_grids_light_cone.ipynb

Large diffs are not rendered by default.

637 changes: 637 additions & 0 deletions examples/tiled_grids_optimizing.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/tiled_pyramid_napari_multiscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
add_progressive_loading_image(
multiscale_img,
viewer=viewer,
contrast_limits=(-28, -24),
contrast_limits=(-26, -24),
colormap="viridis",
ndisplay=3,
rendering="mip",
Expand Down
58 changes: 45 additions & 13 deletions yt_experiments/tiled_grid/tiled_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,15 @@ def __init__(
parallel_method
data_source
Notes
-----
With yt < 4.4.0, YTTiledArbitraryGrid may contain artifacts at chunk boundaries
along the z-axis. If observed, try upgrading yt (you may need to install from
source).
"""

self.left_edge = left_edge
self.right_edge = right_edge
self.ds = ds
Expand Down Expand Up @@ -93,10 +101,10 @@ def _get_grid_by_ijk(self, ijk_grid):
re_val[idim] = rei_val

slc = np.s_[
le_index[0]: re_index[0],
le_index[1]: re_index[1],
le_index[2]: re_index[2],
]
le_index[0] : re_index[0],
le_index[1] : re_index[1],
le_index[2] : re_index[2],
]

le_index = np.array(le_index, dtype=int)
re_index = np.array(re_index, dtype=int)
Expand Down Expand Up @@ -157,6 +165,24 @@ def to_xarray(self, field, chunks=None, backend: str = "dask") -> xr.DataArray:
return xr_ds

def single_grid_values(self, igrid, field, *, ops=None):
"""
Get the values for a field for a single grid chunk as in-memory array.
Parameters
----------
igrid
field
ops
Returns
-------
tuple
(vals, slcs) where vals is a np array for the specified chunk
and slcs are the index-slices for each dimension for the global
array.
"""
if ops is None:
ops = []
_, _, le, re, slc, shp = self._get_grid(igrid)
Expand Down Expand Up @@ -202,8 +228,6 @@ def my_func(values):
"""
if full_domain is None:
full_domain = np.empty(self.dims, dtype="float64")
if ops is None:
ops = []

if dtype is None:
dtype = np.float64
Expand Down Expand Up @@ -314,6 +338,9 @@ def __init__(
if isinstance(level_chunks[ilev], int):
level_chunks[ilev] = (level_chunks[ilev],) * self._ndim

# should be ready by this point
self._validate_levels(levels)

for ilev in range(n_levels):
chunksizes = np.array(level_chunks[ilev], dtype=int)
current_dims = np.asarray(level_dims[ilev], dtype=int)
Expand All @@ -334,6 +361,18 @@ def __init__(

self.levels: [YTTiledArbitraryGrid] = levels

def _validate_levels(self, levels):
for ilev in range(2, len(levels)):
res = np.prod(levels[ilev])
res_higher = np.prod(levels[ilev - 1])
if res > res_higher:
msg = (
"Image pyramid initialization failed: expected highest resolution "
"at level 0, with decreasing resolution with increasing level but found "
f" that level {ilev} resolution is higher than {ilev-1}."
)
raise ValueError(msg)

def to_zarr(
self,
field,
Expand Down Expand Up @@ -407,13 +446,6 @@ def __init__(


def _get_filled_grid(le, re, shp, field, ds, field_parameters):

# grid = ds.r[
# le[0]: re[0]: complex(0, shp[0]), # noqa: E203
# le[1]: re[1]: complex(0, shp[1]), # noqa: E203
# le[2]: re[2]: complex(0, shp[2]), # noqa: E203
# ]

grid = YTArbitraryGrid(le, re, shp, ds=ds, field_parameters=field_parameters)
vals = grid[field]
return vals

0 comments on commit afe63c3

Please sign in to comment.