[plotter] add sinks overlays
This commit is contained in:
+29
-7
@@ -21,6 +21,7 @@ from numpy.polynomial.polynomial import polyfit
|
|||||||
from scipy import optimize
|
from scipy import optimize
|
||||||
from scipy.ndimage.filters import gaussian_filter1d
|
from scipy.ndimage.filters import gaussian_filter1d
|
||||||
from scipy.stats import linregress
|
from scipy.stats import linregress
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
if os.environ.get("DISPLAY", "") == "":
|
if os.environ.get("DISPLAY", "") == "":
|
||||||
print("No display found. Using non-interactive Agg backend")
|
print("No display found. Using non-interactive Agg backend")
|
||||||
@@ -189,6 +190,7 @@ class Plotter(Aggregator, BaseProcessor):
|
|||||||
self.gen_simus()
|
self.gen_simus()
|
||||||
|
|
||||||
self.save = None
|
self.save = None
|
||||||
|
self.current_snap = None
|
||||||
|
|
||||||
def gen_simus(self):
|
def gen_simus(self):
|
||||||
self.simulations = {}
|
self.simulations = {}
|
||||||
@@ -336,7 +338,7 @@ class Plotter(Aggregator, BaseProcessor):
|
|||||||
real_ax = ax[i]
|
real_ax = ax[i]
|
||||||
except TypeError as e:
|
except TypeError as e:
|
||||||
if ax is None:
|
if ax is None:
|
||||||
fig, real_ax = plt.subplots(1, 1)
|
_, real_ax = plt.subplots(1, 1)
|
||||||
elif not_array_error(e):
|
elif not_array_error(e):
|
||||||
real_ax = ax
|
real_ax = ax
|
||||||
else:
|
else:
|
||||||
@@ -344,12 +346,14 @@ class Plotter(Aggregator, BaseProcessor):
|
|||||||
|
|
||||||
# Find plot save
|
# Find plot save
|
||||||
if from_cells or rule.kind == "cells":
|
if from_cells or rule.kind == "cells":
|
||||||
if not os.path.exists(self.snaps[run][num].cells_filename):
|
self.current_snap = self.snaps[run][num]
|
||||||
|
if not os.path.exists(self.current_snap.cells_filename):
|
||||||
self.snaps[run][num].load_cells()
|
self.snaps[run][num].load_cells()
|
||||||
self.snaps[run][num].unload_cells()
|
self.snaps[run][num].unload_cells()
|
||||||
save = tables.open_file(self.snaps[run][num].cells_filename)
|
save = tables.open_file(self.snaps[run][num].cells_filename)
|
||||||
elif rule.kind == "snapshot":
|
elif rule.kind == "snapshot":
|
||||||
save = tables.open_file(self.snaps[run][num].filename)
|
self.current_snap = self.snaps[run][num]
|
||||||
|
save = tables.open_file( self.current_snap.filename)
|
||||||
else:
|
else:
|
||||||
save = tables.open_file(self.study.filename, "r")
|
save = tables.open_file(self.study.filename, "r")
|
||||||
|
|
||||||
@@ -786,18 +790,36 @@ class Plotter(Aggregator, BaseProcessor):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def _overlay_particles(
|
def _overlay_particles(
|
||||||
self, ax_los, im_extent, unit_space=U.pc, center_space=False, **kwargs
|
self,
|
||||||
|
ax_los,
|
||||||
|
im_extent,
|
||||||
|
unit_space=U.pc,
|
||||||
|
center_space=False,
|
||||||
|
parts = True,
|
||||||
|
sinks = False,
|
||||||
|
|
||||||
|
**kwargs
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Add an overlay with particles data
|
Add an overlay with particles data
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Open particle HDF5 file
|
unit_length = self.current_snap.info["unit_length"]
|
||||||
|
|
||||||
|
if sinks:
|
||||||
|
self.current_snap.sinks()
|
||||||
|
sinks = pd.DataFrame(self.current_snap.get_value("/datasets/sinks"))
|
||||||
|
part_pos = sinks[["x", "y", "z"]].values
|
||||||
|
mass = sinks.M
|
||||||
|
|
||||||
|
if parts:
|
||||||
|
# Open particle HDF5 filetype_from_ext
|
||||||
filename = self.save.get_node("/hdf5/write_particles").read()[0].decode()
|
filename = self.save.get_node("/hdf5/write_particles").read()[0].decode()
|
||||||
hdf5_parts = tables.open_file(filename, "r")
|
hdf5_parts = tables.open_file(filename, "r")
|
||||||
part_pos = hdf5_parts.get_node("/data/pos").read()
|
part_pos = hdf5_parts.get_node("/data/pos").read()
|
||||||
|
mass = hdf5_parts.get_node("/data/mass").read()
|
||||||
|
mass *= self.current_snap.info["unit_mass"].express(U.Msun)
|
||||||
hdf5_parts.close()
|
hdf5_parts.close()
|
||||||
unit_length = self.save.root._v_attrs["unit_length"]
|
|
||||||
|
|
||||||
# index of the horizontal axis
|
# index of the horizontal axis
|
||||||
ih = self._ax_nb[self._axes_h[ax_los]]
|
ih = self._ax_nb[self._axes_h[ax_los]]
|
||||||
@@ -831,7 +853,7 @@ class Plotter(Aggregator, BaseProcessor):
|
|||||||
part_v = part_v[mask]
|
part_v = part_v[mask]
|
||||||
|
|
||||||
# Scatter plot
|
# Scatter plot
|
||||||
plt.scatter(part_h, part_v, **kwargs)
|
plt.scatter(part_h, part_v, s=mass/5e3, **kwargs)
|
||||||
|
|
||||||
def _overlay_speed(
|
def _overlay_speed(
|
||||||
self, ax_los, im_extent, unit=U.km_s, unit_coeff=1.0, key_v=None, **kwargs
|
self, ax_los, im_extent, unit=U.km_s, unit_coeff=1.0, key_v=None, **kwargs
|
||||||
|
|||||||
Reference in New Issue
Block a user