[postprocessor] add option to degrade maps
This commit is contained in:
+52
-3
@@ -215,6 +215,46 @@ def pspec(map2D):
|
|||||||
return 0.5 * (kbins[1:] + kbins[:-1]), pspec
|
return 0.5 * (kbins[1:] + kbins[:-1]), pspec
|
||||||
|
|
||||||
|
|
||||||
|
def degrade_map(dmap, nnew, integrate=False):
|
||||||
|
"""Degrade a data dmap to a coarser resolution
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
-----------
|
||||||
|
cube
|
||||||
|
(numpy.ndarray, ndim=2) input data cube, lengths in each direction must
|
||||||
|
|
||||||
|
integrate
|
||||||
|
(bool, default False) if True, values are added instead of averaged
|
||||||
|
|
||||||
|
Return value:
|
||||||
|
-------------
|
||||||
|
degraded_cube
|
||||||
|
(numpy.ndarray, ndim=3) output data cube, 2**lvl values in each
|
||||||
|
direction
|
||||||
|
"""
|
||||||
|
|
||||||
|
assert dmap.ndim == 2
|
||||||
|
|
||||||
|
nold = dmap.shape[0]
|
||||||
|
assert nnew <= nold
|
||||||
|
nsum, rem = divmod(nold, nnew)
|
||||||
|
assert rem == 0
|
||||||
|
|
||||||
|
# For each direction, we split the corresponding axis (length nold) into
|
||||||
|
# 2 axes, the first one being the axis for the output dmap (length nnew),
|
||||||
|
# and the second one the axis to average or integrate over (fine cells).
|
||||||
|
|
||||||
|
# reshape creates a view, no copy is involved
|
||||||
|
v = dmap.reshape((nnew, nsum, nnew, nsum), order="C")
|
||||||
|
# Even indexes are kept, odd ones are to be summed
|
||||||
|
dmap_new = np.einsum("iajb->ij", v)
|
||||||
|
|
||||||
|
if not integrate:
|
||||||
|
dmap_new /= nsum
|
||||||
|
|
||||||
|
return dmap_new
|
||||||
|
|
||||||
|
|
||||||
class PostProcessor(HDF5Container):
|
class PostProcessor(HDF5Container):
|
||||||
"""
|
"""
|
||||||
This class enable to compute and save derived quantities from the raw output
|
This class enable to compute and save derived quantities from the raw output
|
||||||
@@ -944,7 +984,7 @@ class PostProcessor(HDF5Container):
|
|||||||
dmap_omega = rt_omega.process(self._cam[ax_los]).map.T
|
dmap_omega = rt_omega.process(self._cam[ax_los]).map.T
|
||||||
return dmap_omega
|
return dmap_omega
|
||||||
|
|
||||||
def _toomreQ_disk(self, ax_los, omega_approx=True, G1_units=True):
|
def _toomreQ_disk(self, ax_los, omega_approx=True, G1_units=True, coarsen_factor=1):
|
||||||
"""
|
"""
|
||||||
Compute the Toomre Q parameter
|
Compute the Toomre Q parameter
|
||||||
"""
|
"""
|
||||||
@@ -952,7 +992,7 @@ class PostProcessor(HDF5Container):
|
|||||||
# Get maps
|
# Get maps
|
||||||
|
|
||||||
if G1_units:
|
if G1_units:
|
||||||
G = 1.
|
G = 1.0
|
||||||
cs2 = self.get_value("/maps/T_mwavg_z")
|
cs2 = self.get_value("/maps/T_mwavg_z")
|
||||||
coldens = self.get_value("/maps/coldens_z")
|
coldens = self.get_value("/maps/coldens_z")
|
||||||
omega = self.get_value("/maps/omega_mwavg_z")
|
omega = self.get_value("/maps/omega_mwavg_z")
|
||||||
@@ -963,6 +1003,15 @@ class PostProcessor(HDF5Container):
|
|||||||
coldens = self.get_value("/maps/coldens_z", unit=U.kg * U.m ** -2)
|
coldens = self.get_value("/maps/coldens_z", unit=U.kg * U.m ** -2)
|
||||||
omega = self.get_value("/maps/omega_mwavg_z", unit=U.s ** -1)
|
omega = self.get_value("/maps/omega_mwavg_z", unit=U.s ** -1)
|
||||||
space_coeff = self.info["unit_length"].express(U.m)
|
space_coeff = self.info["unit_length"].express(U.m)
|
||||||
|
|
||||||
|
map_size = self.pp_params.pymses.map_size
|
||||||
|
|
||||||
|
if coarsen_factor > 1:
|
||||||
|
map_size = map_size // coarsen_factor
|
||||||
|
omega = degrade_map(omega, map_size)
|
||||||
|
coldens = degrade_map(coldens, map_size)
|
||||||
|
cs2 = degrade_map(cs2, map_size)
|
||||||
|
|
||||||
# Compute Q
|
# Compute Q
|
||||||
if omega_approx:
|
if omega_approx:
|
||||||
# Use angular frequency as epiciclic frequency (true if the disk is Keplerian)
|
# Use angular frequency as epiciclic frequency (true if the disk is Keplerian)
|
||||||
@@ -970,7 +1019,7 @@ class PostProcessor(HDF5Container):
|
|||||||
else:
|
else:
|
||||||
# Get coordinates
|
# Get coordinates
|
||||||
im_extent = np.array(self.save.root.maps._v_attrs.im_extent) * space_coeff
|
im_extent = np.array(self.save.root.maps._v_attrs.im_extent) * space_coeff
|
||||||
map_size = self.pp_params.pymses.map_size
|
|
||||||
center = np.array(self.pp_params.disk.center) * space_coeff
|
center = np.array(self.pp_params.disk.center) * space_coeff
|
||||||
|
|
||||||
# Physical size of cells
|
# Physical size of cells
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ def degrade_cube(cube, lvl, integrate=False):
|
|||||||
return cube_new
|
return cube_new
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def calc_k(n, nbinsk, nbig, dkbig, dim=3, saxis=2):
|
def calc_k(n, nbinsk, nbig, dkbig, dim=3, saxis=2):
|
||||||
"""Make cubes containing the wave vectors, a list of bins and the
|
"""Make cubes containing the wave vectors, a list of bins and the
|
||||||
associated normalization factors
|
associated normalization factors
|
||||||
|
|||||||
Reference in New Issue
Block a user