Exemple #1
0
def PhasePlot(Param_Dict, worker):
    """Takes a DataSet object loaded with yt and performs a phasePlot on it.
    Parameters:
        Param_Dict: to access the relevant parameters
    """
    if Param_Dict["WeightField"] is None:
        GUILogger.warning('Having <font color="DarkViolet">None</font> as the '
                          "weight field just accumulates, "
                          "so the extrema might be inaccurate.")
    ds = Param_Dict["CurrentDataSet"]
    XField, YField, ZField = Param_Dict["XAxis"], Param_Dict["YAxis"], \
        Param_Dict["ZAxis"]
    ad = ds.all_data()
    if Param_Dict["ParticlePlot"]:
        plot = yt.ParticlePhasePlot(ad, XField, YField, ZField,
                                    weight_field=Param_Dict["WeightField"],
                                    fontsize=14)
    else:
        plot = yt.PhasePlot(ad, XField, YField, ZField,
                            weight_field=Param_Dict["WeightField"],
                            fontsize=14)
    emitStatus(worker, "Setting phase plot modifications")
    # Set min, max, unit log and color scheme:
    setAxisSettings(plot, Param_Dict, "X")
    setAxisSettings(plot, Param_Dict, "Y")
    setAxisSettings(plot, Param_Dict, "Z")
    emitStatus(worker, "Annotating the phase plot")
    plot.annotate_title(Param_Dict["PlotTitle"])
    finallyDrawPlot(plot, Param_Dict, worker)
Exemple #2
0
def pp(folder):
    ds = yt.load("/u/yali/" + folder + "/test/output/snapshot_001.hdf5",
                 unit_base=unit_base,
                 bounding_box=bbox)
    #plot = yt.ParticleProjectionPlot(ds, 'z', fields = "Masses")
    #plot = yt.ProjectionPlot(ds, "x", "density")

    # Modify the projection
    # The argument specifies the region along the line of sight for which particles will be gathered.
    # 1.0 signifies the entire domain in the line of sight
    # p.annotate_particles(1.0)
    # but in this case we only go 10 Mpc in depth

    #plot.annotate_particles((10, 'km'))
    plot = yt.ParticlePhasePlot(ds.all_data(),
                                ('PartType3', 'particle_position_y'),
                                ('PartType3', 'particle_position_z'),
                                ('PartType3', 'Masses'))
    #fig = plot.plots['PartType3','Density'].figure
    #fig.show()
    #ad = ds.all_data()
    #density = ad[("PartType0","density")]
    #plot = yt.ProjectionPlot(ds, 'x', ('gas', 'density'))

    plot.show()
Exemple #3
0
                                center=cen,
                                width=((ext, 'kpccm/h'), (ext / asp,
                                                          'kpccm/h')),
                                depth=thk,
                                density=True)  #, data_source=ad)
prj.set_unit(('PartType4', 'Masses'), 'Msun/(kpccm/h)**2')
prj.set_buff_size((xb, yb))
prj.annotate_title('$z={:.2f}$'.format(z))
prj.save(rep + 'stardis_' + str(sn) + '.png')
#prj.save('snapshot_'+str(sn).zfill(3)+'_stellar.png')
#"""

#"""
plot = yt.ParticlePhasePlot(ad, ('PartType0', 'Density'),
                            ('PartType0', 'InternalEnergy'),
                            [('PartType0', 'Masses')],
                            weight_field=None,
                            x_bins=xb,
                            y_bins=yb)
plot.set_unit(('PartType0', 'Density'), 'g/cm**3')
plot.set_unit(('PartType0', 'InternalEnergy'), 'km**2/s**2')
plot.set_unit(('PartType0', 'Masses'), 'Msun')
plot.set_log(('PartType0', 'Density'), True)
#plot.set_zlim('all', 9e3, 1e9)
#plot.annotate_text(xpos=0, ypos=0, text='O')
#ax = plot.plots[('PartType0', 'Masses')].axes
#ax.set_ylim(9e3, 1e9)
plot.annotate_title('$z={:.2f}$'.format(z))
plot.save(rep + 'phasedg_' + str(sn) + '.png')
#"""

ad = ds.all_data()
Exemple #4
0
    box = ds.box(center - width / 2, center + width / 2)

    sp = ds.sphere(center, (10, 'kpc'))
    m = sp['all', 'particle_mass']
    v = sp['all', 'particle_velocity']
    box.set_field_parameter('bulk_velocity', np.average(v, weights=m, axis=0))

    m = box['all', 'particle_mass']
    p = box['all', 'particle_position']
    r_vir = virial_radius(ds, m, p, center)

    for finfo in FIELDS:
        plot_field(box, center, width, r_vir, finfo, AXIS)

    sp = ds.sphere(center, r_vir)
    p = yt.ParticlePhasePlot(
        box,
        ('gas', 'H_nuclei_density'),
        ('gas', 'temperature'),
        ('gas', 'mass'),
        x_bins=500,
        y_bins=500,
    )
    p.set_unit('H_nuclei_density', 'cm**-3')
    p.set_unit('temperature', 'K')
    p.set_unit('mass', 'Msun')
    p.set_xlim(1e-5, 1e0)
    p.set_ylim(1e2, 1e7)
    p.annotate_title(f'z = {ds.current_redshift:.2f}')
    p.save('gas-phase.png', mpl_kwargs={'dpi': 300})
def plot_phase_diagram(ts,
                       snapshot_number,
                       snapshot_number_to_index_map,
                       SN_times,
                       plots_dir,
                       weight_field,
                       field_type="all",
                       save_plot=True,
                       show_plot=True,
                       seaborn_style="ticks",
                       bins=50):
    """Create [and optionally save] a density-temperature phase diagram.

    Inputs
    ------
    ts : yt.data_objects.time_series.DatasetSeries object
        - contains all the uncompressed snapshots in a directory
    snapshot_number : int
        - the specific snapshot you want to plot
    snpashot_number_to_index_map : dict (int -> int)
        - maps snapshot_number to an index of `ts`
    SN_times : np.ndarray (dtype: float)
        - the times that SNe occur for this simulation (in Myr)
    plots_dir : str
        - where plots should be saved, if they are to be saved
    weight_field : str
        - the field you'll be creating your 2D histogram of
          (e.g. `particle_mass`)
    field_type : Optional(str)
        - the yt field type (e.g. `all`, `deposit` or your own particle filter)
    save_plot : Optional(bool)
        - True if you want to save plot images
    show_plot : Optional(bool)
        - True if you want to show plots
         (you might want to disable this for non-interactive sessions)
    seaborn_style : Optional(str)
        - a valid argument for `seaborn.axes_style`
    bins : Optional(int)
        - number of bins in the x and y axes

    Returns
    -------
    ppp

    """
    i = snapshot_number_to_index_map[snapshot_number]
    ds = load_ds_from_ts(ts, i)
    dd = ds.all_data()

    ppp = yt.ParticlePhasePlot(
        dd,
        (field_type, "density"),
        (field_type, "temperature"),
        z_fields=(field_type, weight_field),
        x_bins=bins,
        y_bins=bins,
    )

    if weight_field == "particle_mass":
        ppp.profile.set_field_unit("particle_mass", "Msun")
        ppp.plots[(field_type, "particle_mass")].zmin, ppp.plots[(
            field_type, "particle_mass")].zmax = (None, None)

    elif weight_field == "cooling_rate":
        ppp.profile.set_field_unit("cooling_rate", "erg / Myr")
        ppp.plots[(field_type, "cooling_rate")].zmin, ppp.plots[(
            field_type, "cooling_rate")].zmax = (None, None)

    ppp.profile.set_x_unit("amu/cm**3")
    ppp.set_xlabel("Density $ [ m_\mathrm{H} \; \mathrm{cm}^{-3} ] $")

    ppp.set_xlim(1e-4, 1e3)
    ppp.set_ylim(1e1, 1e7)

    ppp.set_log("density", True)
    ppp.set_log("temperature", True)
    ppp.set_log(weight_field, True)

    ppp.set_background_color((field_type, weight_field), color="white")

    if show_plot:
        with sns.axes_style(seaborn_style):
            ppp.show()

    if save_plot:
        subdir = "phase_plot"
        if not os.path.exists(os.path.join(plots_dir, subdir)):
            os.mkdir(os.path.join(plots_dir, subdir))
        plot_name = os.path.join(
            subdir, "snapshot_{:0>3}_{}-{}".format(snapshot_number,
                                                   weight_field, field_type))
        yt_plot_saver(ppp, plot_name, plots_dir)

    return ppp
Exemple #6
0
# ---------------------
fig = plt.figure()
grid = AxesGrid(fig, (0.075,0.075,0.85,0.85),
                nrows_ncols = (1, len(models)),
                axes_pad = 0.05,
                label_mode = "L",
                share_all = True,
                cbar_location="right",
                cbar_mode="single",
                cbar_size="5%",
                cbar_pad="1%")

for i in range(len(models)):
  print(i)
  my_sphere = ds[i].sphere("c", (1000.0, "kpc"))
  px = yt.ParticlePhasePlot(my_sphere, "density", "temperature", ["mass", ])
  px.set_unit("density", 'g/cm/cm/cm')
  px.set_unit("mass", 'Msun')
  px.set_log("density", True)
  px.set_log("temperature", True)
  px.set_font({'size':20})  
  px.set_xlim(1e-32, 1e-21)
  px.set_ylim(5e1, 1e8)
  px.set_zlim("mass" , zmin=1e4, zmax=1e7)
  plot = px.plots["mass"]
  plot.figure = fig
  plot.axes = grid[i].axes
  plot.cax = grid.cbar_axes[i]
  px._setup_plots()
  plot.axes.xaxis.set_minor_locator(plt.LogLocator(base=10.0, subs=[2.0, 5.0, 8.0]))
plt.show()