490 lines
18 KiB
Plaintext
490 lines
18 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os\n",
|
|
"import numpy as np\n",
|
|
"import matplotlib.pyplot as plt\n",
|
|
"import matplotlib as mpl\n",
|
|
"import hickle as hkl\n",
|
|
"import osyris"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"%matplotlib inline"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"snaps = [174, 175, 177, 178, 179, 180, 181, 182, 184, 185]\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"allresults = {}\n",
|
|
"for snap in snaps:\n",
|
|
" allresults[snap] = hkl.load(f\"/home/nbrucyci/src/mass-inflow/results_sinks_173_173_{snap}.h5\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"time = np.array([allresults[snap]['time'] for snap in snaps])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"\n",
|
|
"from matplotlib import ticker as tick\n",
|
|
"import matplotlib.colors as colors\n",
|
|
"\n",
|
|
"def get_colors(ax, labels, cmap, clabel=\"\", put_colorbar=True,\n",
|
|
" cbar_fmt=tick.FormatStrFormatter('%.3g')):\n",
|
|
" \n",
|
|
" colors = None\n",
|
|
" if isinstance(cmap, str):\n",
|
|
" cmap = plt.get_cmap(cmap)\n",
|
|
" bounds = np.concatenate([labels[0:1] - (labels[1] - labels[0]) / 2, (labels[:-1] + labels[1:]) / 2, labels[-1:] + (labels[-1] - labels[-2])/2 ])\n",
|
|
" norm = mpl.colors.BoundaryNorm(bounds, cmap.N) \n",
|
|
" sm = plt.cm.ScalarMappable(cmap=cmap, norm=norm)\n",
|
|
" if put_colorbar:\n",
|
|
" cb = plt.colorbar(sm, ticks=labels, ax=ax)\n",
|
|
" cb.set_label(clabel)\n",
|
|
" cb.ax.minorticks_off()\n",
|
|
" cb.ax.yaxis.set_major_formatter(cbar_fmt)\n",
|
|
" colors = lambda xi: sm.cmap(sm.norm(xi)) \n",
|
|
" return colors\n",
|
|
"\n",
|
|
"\n",
|
|
"def truncate_colormap(cmap, minval=0.0, maxval=1.0, n=100):\n",
|
|
" new_cmap = colors.LinearSegmentedColormap.from_list(\n",
|
|
" 'trunc({n},{a:.2f},{b:.2f})'.format(n=cmap.name, a=minval, b=maxval),\n",
|
|
" cmap(np.linspace(minval, maxval, n)))\n",
|
|
" return new_cmap"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"Hcc = (1.4 * osyris.units(\"m_p/cm**3\")).to(\"g/cm**3\")\n",
|
|
"sink_threshold = 1e3 * Hcc\n",
|
|
"CNM = 1e-23\n",
|
|
"H2 = 2e-22\n",
|
|
"\n",
|
|
"def density_to_n(density):\n",
|
|
" return (density /Hcc).magnitude\n",
|
|
"\n",
|
|
"fig, axs = plt.subplots(2, 1, figsize=(6,9), constrained_layout=True)\n",
|
|
"\n",
|
|
"greys2 = truncate_colormap(plt.get_cmap(\"Greys\"), 0.2, 1)\n",
|
|
"\n",
|
|
"ax = axs[0]\n",
|
|
"\n",
|
|
"c = get_colors(ax, time, greys2, clabel=\"$t_e$\", put_colorbar=True, cbar_fmt=tick.FormatStrFormatter('%.3g'))\n",
|
|
"\n",
|
|
"ax_top = ax.twiny()\n",
|
|
"ax_top.set_xlabel(r\"$n$ [cm$^{-3}$]\")\n",
|
|
"ax_top.set_xscale(\"log\")\n",
|
|
"\n",
|
|
"def convert_lim(ax):\n",
|
|
" x1, x2 = ax.get_xlim()\n",
|
|
" ax_top.set_xlim(density_to_n(x1), density_to_n(x2))\n",
|
|
" ax_top.figure.canvas.draw()\n",
|
|
"\n",
|
|
"ax.callbacks.connect(\"xlim_changed\", convert_lim)\n",
|
|
"\n",
|
|
"ax.vlines(sink_threshold.magnitude, 0, 60,color=\"darkorange\", lw=3, label=\"Sink threshold\")\n",
|
|
"ax.axvspan(CNM, H2, 0, 60, color=\"tab:blue\", alpha=0.2, label='\"CNM\"')\n",
|
|
"ax.axvspan(H2, 1.2*sink_threshold.magnitude, 0, 60, color=\"tab:blue\", alpha=0.5, label='\"Molecular gas\"')\n",
|
|
"\n",
|
|
"\n",
|
|
"ax.legend(loc=\"upper left\")\n",
|
|
"ax.set_title(\"Within 100 pc of the minimum of potential\")\n",
|
|
"\n",
|
|
"\n",
|
|
"ax.set_ylabel(r\"$\\dot{\\mathrm{M}}_\\mathrm{H}$($t_s$, $t_e$) [M$_\\odot$/kyr]\")\n",
|
|
"\n",
|
|
"ax.set_ylim(0, 30)\n",
|
|
"ax.legend(loc=\"upper left\", frameon=False, ncol=1)\n",
|
|
"\n",
|
|
"ax.set_xscale(\"log\")\n",
|
|
"ax.set_xlim(1e-25, 1.2*sink_threshold.magnitude)\n",
|
|
"ax.set_xlabel(r\"$\\rho$ [g cm$^{-3}$]\")\n",
|
|
"\n",
|
|
"\n",
|
|
"for i, snap in enumerate(snaps):\n",
|
|
" mass_inflow = allresults[snap][\"mass_inflow\"]\n",
|
|
" \n",
|
|
" t = time[i] \n",
|
|
"\n",
|
|
" ax.plot(mass_inflow[\"density\"], mass_inflow[\"flow_mask\"][\"dist\"]/1e3, label=\"Total\", alpha=0.7, lw=4, ls='-', color=c(t))\n",
|
|
" ax.plot(mass_inflow[\"density\"], mass_inflow[\"flow_mask\"][\"dist_gravdom\"]/1e3, label=\"Gravity-driven\", alpha=0.7, lw=4, ls='--', color=c(t))\n",
|
|
" #ax.plot(mass_inflow[\"density\"], mass_inflow[\"flow_mask\"][\"dist_gravdom\"]/mass_inflow[\"flow_mask\"][\"dist\"], \n",
|
|
" # label=\"Gravity-driven / Total\", lw=4, ls='-', color=c(t))\n",
|
|
"\n",
|
|
"\n",
|
|
"ax = axs[1]\n",
|
|
"\n",
|
|
"c = get_colors(ax, time, \"Reds\", clabel=\"$t_e$\", put_colorbar=True, cbar_fmt=tick.FormatStrFormatter('%.3g'))\n",
|
|
"\n",
|
|
"ax_top = ax.twiny()\n",
|
|
"ax_top.set_xlabel(r\"$n$ [cm$^{-3}$]\")\n",
|
|
"ax_top.set_xscale(\"log\")\n",
|
|
"\n",
|
|
"def convert_lim(ax):\n",
|
|
" x1, x2 = ax.get_xlim()\n",
|
|
" ax_top.set_xlim(density_to_n(x1), density_to_n(x2))\n",
|
|
" ax_top.figure.canvas.draw()\n",
|
|
"\n",
|
|
"ax.callbacks.connect(\"xlim_changed\", convert_lim)\n",
|
|
"\n",
|
|
"ax.vlines(sink_threshold.magnitude, 0, 60,color=\"darkorange\", lw=3, label=\"Sink threshold\")\n",
|
|
"ax.axvspan(CNM, H2, 0, 60, color=\"tab:blue\", alpha=0.2, label='\"CNM\"')\n",
|
|
"ax.axvspan(H2, 1.2*sink_threshold.magnitude, 0, 60, color=\"tab:blue\", alpha=0.5, label='\"Molecular gas\"')\n",
|
|
"\n",
|
|
"\n",
|
|
"ax.legend(loc=\"upper left\")\n",
|
|
"\n",
|
|
"\n",
|
|
"ax.set_ylabel(r\"Fraction of gravity-driven inflow\")\n",
|
|
"\n",
|
|
"ax.set_ylim(0, 0.58)\n",
|
|
"ax.legend(loc=\"upper left\", frameon=False, ncol=1)\n",
|
|
"\n",
|
|
"ax.set_xscale(\"log\")\n",
|
|
"ax.set_xlim(1e-25, 1.2*sink_threshold.magnitude)\n",
|
|
"ax.set_xlabel(r\"$\\rho$ [g cm$^{-3}$]\")\n",
|
|
"\n",
|
|
"for i, snap in enumerate(snaps):\n",
|
|
" mass_inflow = allresults[snap][\"mass_inflow\"]\n",
|
|
" \n",
|
|
" t = time[i] \n",
|
|
"\n",
|
|
" #ax.plot(mass_inflow[\"density\"], mass_inflow[\"flow_mask\"][\"dist\"]/1e3, label=\"Total\", alpha=0.7, lw=4, ls='-', color=\"k\")\n",
|
|
" #ax.plot(mass_inflow[\"density\"], mass_inflow[\"flow_mask\"][\"dist_gravdom\"]/1e3, label=\"Gravity-driven\", alpha=0.7, lw=4, ls='--', color=\"k\")\n",
|
|
" ax.plot(mass_inflow[\"density\"], mass_inflow[\"flow_mask\"][\"dist_gravdom\"]/mass_inflow[\"flow_mask\"][\"dist\"], \n",
|
|
" label=\"Gravity-driven / Total\", lw=4, ls='-', color=c(t))\n",
|
|
"\n",
|
|
"\n",
|
|
"plt.savefig(f\"mass_inflow_density_all.pdf\", bbox_inches=\"tight\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"Hcc = (1.4 * osyris.units(\"m_p/cm**3\")).to(\"g/cm**3\")\n",
|
|
"sink_threshold = 1e3 * Hcc\n",
|
|
"CNM = 1e-23\n",
|
|
"H2 = 2e-22\n",
|
|
"\n",
|
|
"def density_to_n(density):\n",
|
|
" return (density /Hcc).magnitude\n",
|
|
"\n",
|
|
"fig, ax = plt.subplots(1, 1, figsize=(6,4), constrained_layout=True)\n",
|
|
"\n",
|
|
"#c2 = get_colors(ax, time, \"Purples\", clabel=\"$t_e$ (without sinks' vicinity)\", put_colorbar=True, cbar_fmt=tick.FormatStrFormatter('%.3g'))\n",
|
|
"\n",
|
|
"c = get_colors(ax, time, \"Reds\", clabel=\"$t_e$\", put_colorbar=True, cbar_fmt=tick.FormatStrFormatter('%.3g'))\n",
|
|
"\n",
|
|
"\n",
|
|
"ax_top = ax.twiny()\n",
|
|
"ax_top.set_xlabel(r\"$n$ [cm$^{-3}$]\")\n",
|
|
"ax_top.set_xscale(\"log\")\n",
|
|
"\n",
|
|
"def convert_lim(ax):\n",
|
|
" x1, x2 = ax.get_xlim()\n",
|
|
" ax_top.set_xlim(density_to_n(x1), density_to_n(x2))\n",
|
|
" ax_top.figure.canvas.draw()\n",
|
|
"\n",
|
|
"ax.callbacks.connect(\"xlim_changed\", convert_lim)\n",
|
|
"\n",
|
|
"ax.vlines(sink_threshold.magnitude, 0, 60,color=\"darkorange\", lw=3, label=\"Sink threshold\")\n",
|
|
"ax.axvspan(CNM, H2, 0, 60, color=\"tab:blue\", alpha=0.2, label='\"CNM\"')\n",
|
|
"ax.axvspan(H2, 1.2*sink_threshold.magnitude, 0, 60, color=\"tab:blue\", alpha=0.5, label='\"Molecular gas\"')\n",
|
|
"\n",
|
|
"\n",
|
|
"ax.legend(loc=\"upper left\")\n",
|
|
"\n",
|
|
"\n",
|
|
"ax.set_ylabel(r\"Fraction of gravity-driven inflow\")\n",
|
|
"\n",
|
|
"ax.set_ylim(0, 0.58)\n",
|
|
"\n",
|
|
"ax.set_xscale(\"log\")\n",
|
|
"\n",
|
|
"ax.set_xlim(1e-25, 1.2*sink_threshold.magnitude)\n",
|
|
"ax.set_xlabel(r\"$\\rho$ [g cm$^{-3}$]\")\n",
|
|
"\n",
|
|
"for i, snap in enumerate(snaps):\n",
|
|
" mass_inflow = allresults[snap][\"mass_inflow\"]\n",
|
|
" \n",
|
|
" t = time[i] \n",
|
|
" \n",
|
|
" frac_with_sinks = mass_inflow[\"flow_mask\"][\"dist_gravdom\"]/mass_inflow[\"flow_mask\"][\"dist\"]\n",
|
|
" frac_without_sinks = mass_inflow[\"flow_mask\"][\"dist_sinks_gravdom\"]/mass_inflow[\"flow_mask\"][\"dist_sinks\"]\n",
|
|
" \n",
|
|
" ax.plot( mass_inflow[\"density\"], frac_with_sinks, lw=2, ls='-', color=c(t))\n",
|
|
"\n",
|
|
" ax.plot( mass_inflow[\"density\"], frac_without_sinks, lw=2, ls='-.', color=c(t))\n",
|
|
" \n",
|
|
"ax.plot([], [], lw=2, ls='-', color='k', label=\"with sinks' vicinity\")\n",
|
|
"ax.plot([], [], lw=2, ls='-.', color='k', label=\"without sinks' vicinity\")\n",
|
|
"ax.legend(loc=\"upper left\", frameon=False, ncol=1)\n",
|
|
"\n",
|
|
"\n",
|
|
"plt.savefig(f\"mass_inflow_density_sink_time_evo.pdf\", bbox_inches=\"tight\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"plt.figure(figsize=(6,5), constrained_layout=True)\n",
|
|
"ax = plt.gca()\n",
|
|
"\n",
|
|
"ax_top = ax.twiny()\n",
|
|
"ax_top.set_xlabel(r\"$n$ [cm$^{-3}$]\")\n",
|
|
"ax_top.set_xscale(\"log\")\n",
|
|
"\n",
|
|
"def convert_lim(ax):\n",
|
|
" x1, x2 = ax.get_xlim()\n",
|
|
" ax_top.set_xlim(density_to_n(x1), density_to_n(x2))\n",
|
|
" ax_top.figure.canvas.draw()\n",
|
|
"\n",
|
|
"ax.callbacks.connect(\"xlim_changed\", convert_lim)\n",
|
|
"c = get_colors(ax, time, greys2, clabel=\"t\", put_colorbar=True, cbar_fmt=tick.FormatStrFormatter('%.3g'))\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"ax.vlines(sink_threshold.magnitude, 0, 1e6, color=\"tab:orange\", lw=2, ls=\":\", label=\"Sink threshold\")\n",
|
|
"ax.axvspan(CNM, H2, 0, 60, color=\"tab:blue\", alpha=0.2, label=\"CNM\")\n",
|
|
"ax.axvspan(H2, 1.2*sink_threshold.magnitude, 0, 60, color=\"tab:blue\", alpha=0.5, label=\"Molecular gas\")\n",
|
|
"\n",
|
|
"ax.set_xlim(5e-25, 1.2* sink_threshold.magnitude)\n",
|
|
"ax.set_ylim(1e2, 1e6)\n",
|
|
"\n",
|
|
"for i, snap in enumerate(snaps):\n",
|
|
" mass_inflow = allresults[snap][\"mass_inflow\"]\n",
|
|
"\n",
|
|
" ax.loglog(mass_inflow[\"density\"], mass_inflow[\"enclosed_mass_end_mask\"][\"dist\"], lw=4, color=c(time[i]), alpha=0.6)\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"ax.set_xlabel(r\"$\\rho$ [g/cm$^3$]\")\n",
|
|
"ax.set_ylabel(r\"M($\\rho^\\prime > \\rho$ ) [M$_\\odot$]\")\n",
|
|
"ax.set_title(\"Tracer mass within 100 pc of the minimum of the potential\")\n",
|
|
"ax.legend()\n",
|
|
"plt.savefig(f\"mass_enclosed_density_evo.pdf\", bbox_inches=\"tight\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"\n",
|
|
"plt.figure(figsize=(5,4), constrained_layout=True)\n",
|
|
"ax = plt.gca()\n",
|
|
"c = get_colors(ax, time, \"Reds\", clabel=\"time [Myr]\", put_colorbar=True, cbar_fmt=tick.FormatStrFormatter('%.3g'))\n",
|
|
"\n",
|
|
"for i, snap in enumerate(snaps):\n",
|
|
" dist, frac_end = allresults[snap][\"mass_fraction\"][\"dist\"], allresults[snap][\"mass_fraction\"][\"frac_end\"]\n",
|
|
" t = time[i]\n",
|
|
" plt.plot(dist, frac_end, alpha=0.7, lw=4, ls='-', color=c(t), label=\"all\")\n",
|
|
"\n",
|
|
"plt.xlabel(\"Distance from potential minimum (pc)\")\n",
|
|
"plt.ylabel(\"Mass fraction of gravity-driven gas\")\n",
|
|
"plt.xscale(\"log\")\n",
|
|
"plt.savefig(\"mass_fraction_stratified_tracers.pdf\", bbox_inches=\"tight\")\n",
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Normalized time"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"allresults_normalized = {}\n",
|
|
"for snap in snaps[:-2]:\n",
|
|
" allresults_normalized[snap] = hkl.load(f\"/home/nbrucyci/src/mass-inflow/results__{snap}_184_185.h5\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"Hcc = (1.4 * osyris.units(\"m_p/cm**3\")).to(\"g/cm**3\")\n",
|
|
"sink_threshold = 1e3 * Hcc\n",
|
|
"CNM = 1e-23\n",
|
|
"H2 = 2e-22\n",
|
|
"\n",
|
|
"def density_to_n(density):\n",
|
|
" return (density /Hcc).magnitude\n",
|
|
"\n",
|
|
"plt.figure(figsize=(6,5), constrained_layout=True)\n",
|
|
"ax = plt.gca()\n",
|
|
"\n",
|
|
"\n",
|
|
"c = get_colors(ax, time, \"Reds\", clabel=\"t\", put_colorbar=True, cbar_fmt=tick.FormatStrFormatter('%.3g'))\n",
|
|
"\n",
|
|
"ax_top = ax.twiny()\n",
|
|
"ax_top.set_xlabel(r\"$n$ [cm$^{-3}$]\")\n",
|
|
"ax_top.set_xscale(\"log\")\n",
|
|
"\n",
|
|
"def convert_lim(ax):\n",
|
|
" x1, x2 = ax.get_xlim()\n",
|
|
" ax_top.set_xlim(density_to_n(x1), density_to_n(x2))\n",
|
|
" ax_top.figure.canvas.draw()\n",
|
|
"\n",
|
|
"ax.callbacks.connect(\"xlim_changed\", convert_lim)\n",
|
|
"\n",
|
|
"ax.vlines(sink_threshold.magnitude, 0, 60,color=\"darkorange\", lw=3, label=\"Sink threshold\")\n",
|
|
"ax.axvspan(CNM, H2, 0, 60, color=\"tab:blue\", alpha=0.2, label='\"CNM\"')\n",
|
|
"ax.axvspan(H2, 1.2*sink_threshold.magnitude, 0, 60, color=\"tab:blue\", alpha=0.5, label=\"Molecular gas\")\n",
|
|
"\n",
|
|
"\n",
|
|
"ax.legend(loc=\"upper left\")\n",
|
|
"ax.set_title(\"Within 100 pc of the minimum of potential\")\n",
|
|
"\n",
|
|
"\n",
|
|
"ax.set_ylabel(r\"Fraction of gravity-driven inflow\")\n",
|
|
"\n",
|
|
"ax.set_ylim(0, 0.45)\n",
|
|
"ax.legend(loc=\"upper left\", frameon=False, ncol=1)\n",
|
|
"\n",
|
|
"ax.set_xscale(\"log\")\n",
|
|
"ax.set_xlim(1e-25, 1.2*sink_threshold.magnitude)\n",
|
|
"\n",
|
|
"\n",
|
|
"for i, snap in enumerate(snaps):\n",
|
|
" mass_inflow = allresults_normalized[snap][\"mass_inflow\"]\n",
|
|
" \n",
|
|
" t = time[i] \n",
|
|
"\n",
|
|
" #ax.plot(mass_inflow[\"density\"], mass_inflow[\"flow_mask\"][\"dist\"]/1e3, label=\"Total\", alpha=0.7, lw=4, ls='-', color=\"k\")\n",
|
|
" #ax.plot(mass_inflow[\"density\"], mass_inflow[\"flow_mask\"][\"dist_gravdom\"]/1e3, label=\"Gravity-driven\", alpha=0.7, lw=4, ls='--', color=\"k\")\n",
|
|
" ax.plot(mass_inflow[\"density\"], mass_inflow[\"flow_mask\"][\"dist_gravdom\"]/mass_inflow[\"flow_mask\"][\"dist\"], \n",
|
|
" label=\"Gravity-driven / Total\", lw=4, ls='-', color=c(t))\n",
|
|
"\n",
|
|
"\n",
|
|
"plt.savefig(f\"mass_inflow_density_all_lastmyr.pdf\", bbox_inches=\"tight\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"Hcc = (1.4 * osyris.units(\"m_p/cm**3\")).to(\"g/cm**3\")\n",
|
|
"sink_threshold = 1e3 * Hcc\n",
|
|
"CNM = 1e-23\n",
|
|
"H2 = 2e-22\n",
|
|
"\n",
|
|
"def density_to_n(density):\n",
|
|
" return (density /Hcc).magnitude\n",
|
|
"\n",
|
|
"plt.figure(figsize=(6,5), constrained_layout=True)\n",
|
|
"ax = plt.gca()\n",
|
|
"\n",
|
|
"\n",
|
|
"c = get_colors(ax, time, \"Greys\", clabel=\"t\", put_colorbar=True, cbar_fmt=tick.FormatStrFormatter('%.3g'))\n",
|
|
"\n",
|
|
"ax_top = ax.twiny()\n",
|
|
"ax_top.set_xlabel(r\"$n$ [cm$^{-3}$]\")\n",
|
|
"ax_top.set_xscale(\"log\")\n",
|
|
"\n",
|
|
"def convert_lim(ax):\n",
|
|
" x1, x2 = ax.get_xlim()\n",
|
|
" ax_top.set_xlim(density_to_n(x1), density_to_n(x2))\n",
|
|
" ax_top.figure.canvas.draw()\n",
|
|
"\n",
|
|
"ax.callbacks.connect(\"xlim_changed\", convert_lim)\n",
|
|
"\n",
|
|
"ax.vlines(sink_threshold.magnitude, 0, 60,color=\"darkorange\", lw=3, label=\"Sink threshold\")\n",
|
|
"ax.axvspan(CNM, H2, 0, 60, color=\"tab:blue\", alpha=0.2, label='\"CNM\"')\n",
|
|
"ax.axvspan(H2, 1.2*sink_threshold.magnitude, 0, 60, color=\"tab:blue\", alpha=0.5, label=\"Molecular gas\")\n",
|
|
"\n",
|
|
"\n",
|
|
"ax.legend(loc=\"upper left\")\n",
|
|
"ax.set_title(\"Within 100 pc of the minimum of potential\")\n",
|
|
"\n",
|
|
"\n",
|
|
"ax.set_ylabel(r\"Mass inflow rate [M$_\\odot$/kyr]\")\n",
|
|
"\n",
|
|
"ax.set_ylim(0, 100)\n",
|
|
"ax.legend(loc=\"upper left\", frameon=False, ncol=1)\n",
|
|
"\n",
|
|
"ax.set_xscale(\"log\")\n",
|
|
"ax.set_xlim(1e-25, 1.2*sink_threshold.magnitude)\n",
|
|
"\n",
|
|
"\n",
|
|
"for i, snap in enumerate(snaps[:-2]):\n",
|
|
" mass_inflow = allresults_normalized[snap][\"mass_inflow\"]\n",
|
|
" \n",
|
|
" t = time[i] \n",
|
|
"\n",
|
|
" ax.plot(mass_inflow[\"density\"], mass_inflow[\"flow_mask\"][\"dist\"]/1e3, label=\"Total\", alpha=0.7, lw=4, ls='-', color=c(t))\n",
|
|
" ax.plot(mass_inflow[\"density\"], mass_inflow[\"flow_mask\"][\"dist_gravdom\"]/1e3, label=\"Gravity-driven\", alpha=0.7, lw=4, ls='--', color=c(t))\n",
|
|
" #ax.plot(mass_inflow[\"density\"], mass_inflow[\"flow_mask\"][\"dist_gravdom\"]/mass_inflow[\"flow_mask\"][\"dist\"], \n",
|
|
" # label=\"Gravity-driven / Total\", lw=4, ls='-', color=c(t))\n",
|
|
"\n",
|
|
"\n",
|
|
"plt.savefig(f\"mass_inflow_density_all_flow_lastmyr.pdf\", bbox_inches=\"tight\")"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|