[plotter] [map] Uses im_extent information to the speed overlay. Fixes #1

This commit is contained in:
Noe Brucy
2020-12-16 15:56:01 +01:00
parent c8f8e9cf26
commit 46ee57b622
+24 -19
View File
@@ -701,36 +701,41 @@ class Plotter(Aggregator, BaseProcessor):
label, unit_old, unit = self._ax_label_unit(dmap_vh_node, "", unit, unit_coeff)
vel_red = self.pp_params.plot.vel_red
radius = self.save.root.maps._v_attrs.radius
center = self.save.root.maps._v_attrs.center
lbox = self.save.root._v_attrs.lbox
map_vh_red = dmap_vh[::vel_red, ::vel_red] * unit_old.express(
unit
) # take only a subset of velocities
# take only a subset of velocities
map_vh_red = dmap_vh[::vel_red, ::vel_red] * unit_old.express(unit)
map_vv_red = dmap_vv[::vel_red, ::vel_red] * unit_old.express(unit)
# TODO : redo this with im_extent
nh = map_vh_red.shape[0]
nv = map_vv_red.shape[1]
vec_h = (
np.arange(nh) * 2.0 / nh * radius - radius + center[0] + radius / nh
) * lbox
vec_v = (
np.arange(nv) * 2.0 / nv * radius - radius + center[1] + radius / nv
) * lbox
hh, vv = np.meshgrid(vec_h, vec_v)
# get norm infomartion
norm_v = np.sqrt(map_vh_red ** 2 + map_vv_red ** 2)
max_v = np.max(norm_v)
min_v = np.min(norm_v)
Q = plt.quiver(hh, vv, map_vh_red, map_vv_red, units="width", **kwargs)
# Number of selected vectors
nh = map_vh_red.shape[0]
nv = map_vh_red.shape[1]
# Creates vectors position grid
size_h = im_extent[1] - im_extent[0] # size of the map
dh = size_h / dmap_vh.shape[0] # size of cell
seph = size_h / nh # separation between vectors
h = im_extent[0] + dh + np.arange(nh) * seph
size_v = im_extent[3] - im_extent[2]
dv = size_v / dmap_vh.shape[1]
sepv = size_v / nv
v = im_extent[2] + dv + np.arange(nv) * sepv
hh, vv = np.meshgrid(h, v)
# plot vector field
vec_field = plt.quiver(hh, vv, map_vh_red, map_vv_red, units="width", **kwargs)
# add vector key
if key_v is None:
key_v = (max_v + min_v) / 2.0
plt.quiverkey(
Q,
vec_field,
0.6,
0.98,
key_v,