Closed Martin-Rey closed 6 years ago
plot_extent()
is a class method so at present there is no way for it to vary according to other properties. Removing this limitation in a backward-compatible way would be worth considering. In the meantime, worth remembering that plot_extent literally just affects plotting in the browser interface so if you change the axis labels to be "x/virial_radius" etc, the situation can still be made clear.After a bit of investigation:
The problem is generated by this check in the C routines of pynbody: https://github.com/pynbody/pynbody/blob/cc70f0dd5cd7649ee977254c2e223f8271a671c5/pynbody/sph/smooth.cpp#L11-L27
For some reason, when given full access to the ancestor snapshot, the smooth array is always calculated across the entire snapshot, not just on a sub snap. I verified this in an independent ipython notebook:
In [1]: s51 = pynbody.load("/Users/mrey/Documents/simulations/ramses/DM_only/ramses_dmo_L50_N256_ZOOM4_Halo740/output_00051/")
...: s51.physical_units()
...:
/Users/mrey/anaconda3/lib/python3.6/site-packages/pynbody-0.44-py3.6-macosx-10.7-x86_64.egg/pynbody/snapshot/ramses.py:722: UserWarning: Using field at offset 9 to distinguish stars. If this is wrong, try editing your config.ini, section [ramses], entry particle-distinguisher.
warnings.warn("Using field %s to distinguish stars. If this is wrong, try editing your config.ini, section [ramses], entry particle-distinguisher."%pb_name)
In [2]: pynbody.analysis.halo.center(s51.halos()[10], vel=False) Out[2]: <pynbody.transformation.GenericTranslation at 0x18173b2f98>
In [3]: region = s51[pynbody.filt.Sphere(350)]
In [4]: s51.keys() Out[4]: ['hop_grp', 'pos', 'x', 'y', 'z', 'vel', 'vx', 'vy', 'vz', 'mass']
In [5]: region.keys() Out[5]: ['hop_grp', 'pos', 'x', 'y', 'z', 'vel', 'vx', 'vy', 'vz', 'mass']
In [6]: region.d['smooth'] Out[6]: SimArray([ 8.26333618, 17.87956619, 20.67194176, ..., 22.76054001, 17.42362976, 24.66303253], 'kpc')
In [7]: region.keys() Out[7]: ['hop_grp', 'pos', 'x', 'y', 'z', 'vel', 'vx', 'vy', 'vz', 'mass', 'smooth']
In [8]: s51.keys() Out[8]: ['hop_grp', 'pos', 'x', 'y', 'z', 'vel', 'vx', 'vy', 'vz', 'mass', 'smooth']
The smooth array has been calculated across the full s51 snapshot even though I only requested it on the spherical region. I don't know if this intentional behaviour or not.
3. The check fails not because of a boxsize problem but because of the state of the position arrays:
- The @centred calculation centres and wraps only the selected particle of the region specification meaning that particle_data['pos'] spawns [-sthing, +sthing]
- Pynbody then tries to calculate the smooth array on the full snapshot. The previously wrapped particles spawn [-sthing, +sthing], while the remaining spawn [0, boxsize]. Hence the full snapshot positions spawn [-sthing, boxsize] failing the test to fit in a boxsize.
4. One funny side effect is that removing access to the full ancestor by running calculations in server mode removes that behaviour and produces sensible images, which exactly what I want.
Thanks, this is a really helpful analysis. (2) is actually intentional behaviour; for example if you are creating an image of a subregion you need smooth the particles on the boundary to get the strictly correct internal smoothing properties. But in this case it would be better if the behaviour were different and perhaps there is a way tangos can actually prevent access to the ancestor.
It turns out that fixing this at the level of changing the behaviour of .ancestor
or .base
in a sensible, consistent way is extremely hard and likely to have side-effects that are undesirable.
I think, certainly for now, we have to deal with the conceptual wrinkle. On a practical front, PR #51 should fix the images problem - please let me know.
I can confirm that this get ride of the bug in default load-mode and still works in server mode.
On a conceptual level, what does halo.ancestor represents in server/partial loading mode since the ancestor snapshot is not meant to be fully available ?
Closing this issue following PR #51
I have been trying to generate dark matter projected images around my halos of interest (with pynbody handler). Following the baryonic example given in https://github.com/pynbody/tangos/blob/811444efd5b06c080470e0672da59784fffc87e9/tangos/properties/pynbody/images.py#L4
I derived the following class:
My first question is on plot_extent(). Let's say I want to make a plot of the surroundings of the halo up to 4 radii. How can this be incorporated in the plot_extent that is a class method ?
The second and main problem is that this calculation fails every time throwing:
I tracked it down to a problem when calculating the smooth pynbody array rather than the actual plotting itself. I think pynbody or tangos tries to calculate the smooth array on the ancestor snapshot rather than the particle data. Any insight would be much appreciated.