From d5f2dbb1415ef41f75de75f9334d06569c5140c0 Mon Sep 17 00:00:00 2001
From: loikki <loic.hausammann@protonmail.ch>
Date: Fri, 20 Mar 2020 09:14:51 +0100
Subject: [PATCH] GEAR: update plot script

---
 examples/GEAR/ZoomIn/check_data.py | 11 +++++++++
 examples/GEAR/ZoomIn/make_image.py |  7 +++---
 examples/GEAR/ZoomIn/metal_plot.py | 38 ++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+), 3 deletions(-)
 create mode 100644 examples/GEAR/ZoomIn/check_data.py
 create mode 100644 examples/GEAR/ZoomIn/metal_plot.py

diff --git a/examples/GEAR/ZoomIn/check_data.py b/examples/GEAR/ZoomIn/check_data.py
new file mode 100644
index 0000000000..43e5181602
--- /dev/null
+++ b/examples/GEAR/ZoomIn/check_data.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env
+
+from h5py import File
+from sys import argv
+
+f = File(argv[-1], "r")
+
+a = 0
+# a = f["Cosmology"].attrs["Scale-factor"]
+data = f["PartType0/Metals"][:]
+print(a, data.min(), data.max())
diff --git a/examples/GEAR/ZoomIn/make_image.py b/examples/GEAR/ZoomIn/make_image.py
index 499395676a..7cb96df377 100644
--- a/examples/GEAR/ZoomIn/make_image.py
+++ b/examples/GEAR/ZoomIn/make_image.py
@@ -24,9 +24,9 @@ gear = "gear/snapshot_%04i.hdf5" % snap
 
 width = 50 * kpc
 
-do_dmo = False
-do_hydro = False
-do_stars = False
+do_dmo = True
+do_hydro = True
+do_stars = True
 do_feedback = True
 do_plot = {
     # DMO
@@ -289,5 +289,6 @@ def doPlot(filename, i, name, center):
 center = None
 # center = np.array([1724.33547783, 1802.56263082, 1785.09893269])
 center = doPlot(gear, 1, "GEAR", center=center)
+center = None
 doPlot(swift, 0, "SWIFT", center=center)
 savePlot()
diff --git a/examples/GEAR/ZoomIn/metal_plot.py b/examples/GEAR/ZoomIn/metal_plot.py
new file mode 100644
index 0000000000..467bef8af8
--- /dev/null
+++ b/examples/GEAR/ZoomIn/metal_plot.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+
+import yt
+import matplotlib.pyplot as plt
+
+
+def save1DPlot(profiles):
+    plt.figure(figsize=(8, 8))
+    plt.tight_layout(pad=0.4, w_pad=0.5, h_pad=0.5)
+    markers = ["s", "o"]
+    for i, p in enumerate(profiles[0]):
+        z = p.x.in_units("")
+        m = p["Masses"].in_units("Msun").d
+        plt.plot(z, m, linestyle="-", marker=markers[i],
+                 markeredgecolor='none', linewidth=1.2, alpha=0.8)
+    plt.semilogx()
+    plt.semilogy()
+
+    plt.xlabel(r"Metal fraction", fontsize='large')
+    plt.ylabel("$\mathrm{Mass\ (Msun)}$", fontsize='large')
+    plt.legend(profiles[1], loc=4, frameon=True, ncol=2, fancybox=True)
+    leg = plt.gca().get_legend()
+    ltext = leg.get_texts()
+    plt.setp(ltext, fontsize='small')
+    plt.grid(True)
+
+    plt.savefig("metals.png", bbox_inches='tight', pad_inches=0.03, dpi=300)
+
+
+def do1DPlot(f, name, i):
+    sp = f.sphere(f.center, f.width)
+    # Because ParticleProfilePlot doesn't exist, I will do the following trick.
+    p = yt.create_profile(sp, ("PartType0", "Metallicity"),
+                          ("PartType0", "Masses"),
+                          weight_field=None, n_bins=50,
+                          accumulation=False)
+
+    return p
-- 
GitLab