yt-project / yt

Main yt repository
http://yt-project.org
Other
464 stars 276 forks source link

Filter out unused values in projections before flattening quad tree #1623

Open matthewturk opened 6 years ago

matthewturk commented 6 years ago

At present, the mesh for the quad tree projection is initialized independently of whether or not a given point in the mesh will contribute to the final projection (add_chunk_to_tree). This can happen, for instance, when creating projections from regions that cut across individual quads or index objects. The quad tree is turned into flattened arrays inside get_all.

What could be done here is to filter out those values that are not used before turning things into flattened arrays. We could do this by one of the following:

  1. Being more careful with how the tree is initialized in _initialize_chunk so that we don't get unused values. (Not sure how to do this.)
  2. Have a bool that corresponds to whether or not a mesh point is used, and don't include those in the flattening.
  3. Filter out all zero-weighted values in the flattening process, either in Cython or in the Python where we turn off error-correction.

The third is my favorite.

ngoldbaum commented 6 years ago

To motivate this discussion, the following script will include NaNs in the flat projection array:

import yt
import numpy as np
ds = yt.load('IsolatedGalaxy/galaxy0030/galaxy0030')
disk = ds.disk('c', [0, 0, 1], (1000, 'pc'), (100, 'pc'))
proj = ds.proj('density', axis='z', weight_field='density', data_source=disk,
               method='integrate')
dens_proj = proj['density']

Matt's proposal would make it so that dens_proj in the above script is the same as dens_proj[np.isfinite(dens_proj)].

We'd also need to make sure that the FRB machinery still inserts NaNs into images where there is no data so it will be properly masked by matplotlib.