Exemple #1
0
def make_movie_plots(output):
    basename = os.path.basename(output)
    figname = '%s/%s.png'%(plot_folder, basename[2:])
    if not os.path.isfile(figname):
        ds = ytf.load('%s/%s'%(output, basename))
        fig, ax = plot_density_slices(ds)
        plt.savefig(figname, dpi = 300)
def plot_phase(output, sim, tctf, beta_list, cr_list, diff_list, stream_list,
               heat_list, title_list):

    cmap_list = [palettable.cmocean.sequential.Tempo_20.mpl_colormap]
    ncols = int(len(cr_list) / 2)
    nrows = 2
    fig, ax = plt.subplots(ncols=ncols,
                           nrows=nrows,
                           figsize=(4 * ncols, 4.4 * nrows))

    for i, cr in enumerate(cr_list):
        sim_loc = pt.get_sim_location(sim, tctf, beta_list[i], cr, \
                                      diff = diff_list[i], stream = stream_list[i], heat = heat_list[i], work_dir = workdir)
        ds = ytf.load('%s/DD%04d/DD%04d' % (sim_loc, output, output))

        ad = ds.all_data()
        ad_cut = ad.cut_region([
            "(obj[('gas', 'z')].in_units('kpc') > 4.3) | (obj[('gas', 'z')].in_units('kpc') < -4.3)"
        ])
        ph = yt.PhasePlot(ad_cut, ('gas', 'density'), ('gas', 'temperature'), ('gas', 'cell_mass'),\
                          weight_field = None, fractional = True)
        ph.save()
        prof = ph.profile
        xbins = prof.x
        ybins = prof.y
        data = prof[('gas', 'cell_mass')].T

        print(xbins, ybins, data)
        vmin = 1e-5
        vmax = 1e-2
        cmap = cmap_list[0]
        cmap = palettable.cubehelix.jim_special_16_r.mpl_colormap

        row = int(i / ncols)
        col = i - row * ncols
        print(i, row, col)
        ax[row][col].set_xscale('log')
        ax[row][col].set_yscale('log')
        ax[row][col].set_xlim(1.5e-28, 8e-26)
        ax[row][col].set_ylim(4e4, 1e7)

        pcm = ax[row][col].pcolormesh(xbins, ybins, data, norm = LogNorm(), cmap = cmap, \
                               vmax = vmax, vmin = vmin)

        ax[row][col].set_title(title_list[i], fontsize=16)
        ax[row][col].set_xlabel('Density (g cm$^{-3}$)')
        ax[row][col].set_ylabel('Temperature (K)')

    figname = '../../plots/production/phase_density_temperature_mass_%s_tctf_%.1f_cr_%.2f_%.1f.png' % (
        sim, tctf, cr, output)

    fig.tight_layout()
    print(figname)
    plt.savefig(figname, dpi=300)
def plot_phase(output, folder='.'):

    cmap_list = [palettable.cmocean.sequential.Tempo_20.mpl_colormap]
    ncols = int(len(cr_list) / 2)
    nrows = 2
    fig, ax = plt.subplots(ncols=ncols,
                           nrows=nrows,
                           figsize=(4 * ncols, 4.4 * nrows))

    for i, cr in enumerate(cr_list):
        sim_loc = pt.get_sim_location(sim, tctf, beta_list[i], cr, \
                diff = diff_list[i], stream = stream_list[i], heat = heat_list[i])

        ds = ytf.load('%s/DD%04d/DD%04d' % (sim_loc, output, output))

        ad = ds.all_data()
        ph = yt.PhasePlot(ad, ('gas', 'temperature'), ('gas', 'cr_eta'), ('gas', 'cell_mass'),\
                          weight_field = None, fractional = True)

        ph.set_ylim(cr / 1e3, cr * 1e3)
        prof = ph.profile

        xbins = prof.x
        ybins = prof.y
        data = prof[('gas', 'cell_mass')].T

        vmin = 1e-5
        vmax = 1e-2
        cmap = cmap_list[0]
        cmap = palettable.cubehelix.jim_special_16_r.mpl_colormap

        row = int(i / ncols)
        col = i - row * ncols
        print(i, row, col)
        ax[row][col].set_xscale('log')
        ax[row][col].set_yscale('log')
        #        ax[row][col].set_xlim(1.5e-28, 8e-26)
        ax[row][col].set_xlim(4e4, 1e7)

        pcm = ax[row][col].pcolormesh(xbins, ybins, data, norm = LogNorm(), cmap = cmap, \
                               vmax = vmax, vmin = vmin)

        ax[row][col].set_title(title_list[i], fontsize=16)
        #        ax[row][col].set_ylabel('Density (g cm$^{-3}$)')
        ax[row][col].set_ylabel('CR Pressure / Gas Pressure')
        ax[row][col].set_xlabel('Temperature (K)')

    figname = '../../plots/phase_temperature_cr_eta_tctf_%.1f_%.1f.png' % (
        tctf, output)
    #    if diff > 0:
    #        figname = '../../plots/phase_temperature_cr_eta_mass_tctf_%.1f_cr_diff_%.1f_%.1f.png'%(tctf, diff, output)
    fig.tight_layout()
    print(figname)
    plt.savefig(figname, dpi=300)
def calculate_time_data_wrapper(args):
    output_loc, data_type, field, T_min, zstart, zend, grid_rank = args
    ds = ytf.load(output_loc)
    if data_type == 'rms_fluctuation' or data_type == 'density_fluctuation':
        data = calculate_rms_fluctuation(ds, field = field, zstart = zstart, zend = zend, grid_rank = grid_rank).d
    elif data_type == 'cold_fraction':
        data = calculate_cold_fraction(ds, T_min = T_min, z_min = zstart, z_max = zend, grid_rank = grid_rank).d
    elif data_type == 'cold_flux':
        data = calculate_mass_flux(ds, T_min = T_min, z_min = zstart, z_max = zend, grid_rank = grid_rank)
    elif data_type == 'cold_creta':
        data = calculate_cold_creta(ds, T_min = T_min, z_min = zstart, z_max = zend, grid_rank = grid_rank)
    elif data_type == 'clump':
        data = calculate_cold_clump_properties(ds)
        
    time = ds.current_time.d
    return time, data
def plot_multipanel_slices(field, output, sim, compare, tctf, beta = 100, cr = 0,\
                           crdiff = 0, crstream = 0, crheat = 0, fixed_time = 0,
                           weight_field = 'density', projection = False, work_dir = '.'):
    ds_loc_list, label_list  = pt.get_sim_list(sim, compare, tctf, beta = beta,  cr = cr, \
                crdiff = diff, crstream = stream, crheat = heat, work_dir = work_dir, sim_fam = sim_fam)
    print(ds_loc_list)
    fig, ax = plt.subplots(ncols=len(ds_loc_list),
                           nrows=1,
                           figsize=(1.5 * len(ds_loc_list), 3.8),
                           constrained_layout=True)
    for i, ds_loc in enumerate(ds_loc_list):
        print(ds_loc)
        if fixed_time:
            output_list = [100, 33, 10, 3, 1]
            output = output_list[i]
        if not os.path.isfile('%s/DD%04d/DD%04d' % (ds_loc, output, output)):
            continue
        ds = ytf.load('%s/DD%04d/DD%04d' % (ds_loc, output, output))
        ds.add_field(('gas', 'invT'), function=_inv_T, units='')
        if projection:
            s = yt.ProjectionPlot(ds,
                                  'x', ('gas', field),
                                  center=(0, 0, 1),
                                  width=(1, 1.8),
                                  weight_field=weight_field)
        else:
            s = yt.SlicePlot(ds,
                             'x', ('gas', field),
                             center=(0, 0, 1),
                             width=(1, 1.8))
        s.save()
        s.set_buff_size(1024)
        frb = s.frb

        xbins = frb['y'].in_units('kpc')
        ybins = frb['z'].in_units('kpc')
        if field == 'density':
            data_norm = rho0
        elif field == 'temperature':
            data_norm = T0
        else:
            data_norm = p0

        data = frb[field] / data_norm

        if field == 'density':
            vmin = 1e-1
            vmax = 3
            if projection:
                vmax = 1.5
            label = '$\\rho / \\rho_0 $'
        elif field == 'temperature':
            vmin = 5e4 / T0
            vmax = 5e6 / T0
            label = 'T / T$_0$'
        elif field == 'cr_eta':
            cr_eta = pt.get_cr_eta(ds)
            vmin = cr_eta / 100
            vmax = cr_eta * 100
            label = 'P$_c$ / P$_g$'
        elif field == 'cr_pressure':
            label = 'P$_c$ / P$_{c,0}$'
            vmin = 0.2
            vmax = 2

        cmap = pt.get_cmap(field)
        pcm = ax[i].pcolormesh(xbins, ybins, data, cmap = cmap, norm = LogNorm(),\
                               vmax = vmax, vmin = vmin, zorder = 1)

        ax[i].set_aspect('equal')
        #        ax[i].tick_params(direction='in', top=True, right=True, zorder = 10)
        ax[i].set_xticklabels([])
        if i == 0:
            ax[i].set_ylabel('z (kpc)')
        else:
            ax[i].set_yticklabels([])
        H_kpc = 43.85  # scale height in kpc
        ax[i].axhline(0.8 * H_kpc,
                      linestyle='dashed',
                      color='black',
                      linewidth=0.7)
        ax[i].axhline(1.2 * H_kpc,
                      linestyle='dashed',
                      color='black',
                      linewidth=0.7)
        if field == 'temperature':
            ax[i].set_xlabel(label_list[i], fontsize=10)
        else:
            ax[i].set_title(label_list[i], fontsize=10)

    fig.tight_layout()
    fig.subplots_adjust(bottom=0.2)
    pos_l = ax[0].get_position().get_points()
    pos_r = ax[-1].get_position().get_points()

    dx = 0.02
    dy = pos_r[1][1] - pos_r[0][1]
    cbar_y = pos_r[0][1]
    cbar_x = pos_r[1][0] + .02
    print(cbar_x, cbar_y)
    cbax = fig.add_axes([cbar_x, cbar_y, dx, dy])
    if field == 'cr_pressure':
        cbar = fig.colorbar(pcm,
                            cax=cbax,
                            orientation='vertical',
                            ticks=[0.2, 2])
        cbar.ax.set_yticklabels(['0.2', '2'])
    else:
        cbar = fig.colorbar(pcm, cax=cbax, orientation='vertical')
    cbar.set_label(label)

    if projection:
        fig_base = '%s_multipanel_projection' % field
    else:
        fig_base = '%s_multipanel_slice' % field
    figname = pt.get_fig_name(fig_base, sim, compare, tctf, beta = beta, use_tctf = 1, \
                           cr=cr, crdiff = crdiff, crstream = crstream, crheat = crheat, \
                              time = output, sim_fam = sim_fam)
    plt.savefig(figname, dpi=300, bbox_inches='tight', pad_inches=0.1)
def plot_multipanel_slices(output, sim_name, sim_loc = '../simulations', sim_fam = 'production', plot_loc = '../../plots',
                           field_list = ['density', 'temperature', 'cr_eta'], weight_field = ('index', 'ones'), projection = False):
    fig, ax = plt.subplots(ncols = len(field_list), nrows = 1, figsize=(1.5*len(field_list), 3.8), constrained_layout = True)    
    ds_loc = '%s/%s/%s'%(sim_loc, sim_fam, sim_name)
    if not os.path.isfile('%s/DD%04d/DD%04d'%(ds_loc, output, output)):
        return
    ds = ytf.load('%s/DD%04d/DD%04d'%(ds_loc, output, output))

    yt_field_list = []
    for field in field_list:
        yt_field_list.append(('gas', field))
    if projection:
        s = yt.ProjectionPlot(ds, 'x', yt_field_list, center = (0, 0, 1), width = (1, 1.8),
                          weight_field = weight_field)
    else:
        s = yt.SlicePlot(ds, 'x', yt_field_list, center = (0, 0, 1), width = (1, 1.8))
    s.set_buff_size(1024)
    frb = s.frb

    xbins = frb['y'].in_units('kpc')
    ybins = frb['z'].in_units('kpc')

    for i, field in enumerate(field_list):
        if field == 'density':
            data_norm = rho0
            vmin = 1e-1
            vmax = 3   
            if projection:
                vmax = 1.5
            label = '$\\rho / \\rho_0 $'
        elif field == 'temperature':
            data_norm = T0
            vmin = 5e4 / T0
            vmax = 5e6 / T0
            label = 'T / T$_0$'
        elif field == 'cr_eta':
            cr_eta = pt.get_cr_eta(ds)
            data_norm = 1
            vmin = cr_eta / 10
            vmax = cr_eta * 10
            label = 'P$_c$ / P$_g$'
        elif field == 'cr_pressure':
            data_norm = p0
            label = 'P$_c$ / P$_{c,0}$'
            vmin = 0.2
            vmax = 2
        data   = frb[field] / data_norm
        cmap = pt.get_cmap(field)
        pcm = ax[i].pcolormesh(xbins, ybins, data, cmap = cmap, norm = LogNorm(),\
                               vmax = vmax, vmin = vmin, zorder = 1)
        
        ax[i].set_aspect('equal')
#        ax[i].tick_params(direction='in', top=True, right=True, zorder = 10)
        ax[i].set_xticklabels([])
        if i == 0:
            ax[i].set_ylabel('z (kpc)')
        else:
            ax[i].set_yticklabels([])
        H_kpc = 43.85 # scale height in kpc
        ax[i].axhline(0.8*H_kpc, linestyle = 'dashed', color = 'black', linewidth = 0.7)
        ax[i].axhline(1.2*H_kpc, linestyle = 'dashed', color = 'black', linewidth = 0.7)

        cbax = inset_axes(ax[i], width = '90%', height = '4%', loc = 'lower center', bbox_to_anchor = (0.0, -.075, 1, 1),
                          bbox_transform=ax[i].transAxes, borderpad = 0)
        cbar = fig.colorbar(pcm, cax = cbax, orientation = 'horizontal')
        cbar.set_ticks([vmin, vmax])
        cbar.set_ticklabels([vmin, vmax])
        cbar.set_label(label, labelpad = -2)

    fig_base = sim_name
    for field in field_list:
        fig_base += '_%s'%field
        
    if projection:
        fig_base += '_projection'
    else:
        fig_base += '_slice'
        
    figname = '%s/%s.png'%(plot_loc, fig_base)

    plt.savefig(figname, dpi = 300, bbox_inches = 'tight', pad_inches = 0.1)
Exemple #7
0
def make_movie_plots(output, folder='.'):

    ds_loc_list, label_list  = pt.get_sim_list('isocool', compare, tctf, beta = beta,  cr = cr, \
                crdiff = diff, crstream = stream, crheat = heat, work_dir = work_dir, sim_fam = sim_fam)

    fig, ax = plt.subplots(ncols=len(ds_loc_list),
                           nrows=1,
                           figsize=(1.5 * len(ds_loc_list), 3.8),
                           constrained_layout=True)
    cmap = pt.get_cmap(field)

    fig, ax = plt.subplots(ncols=len(ds_loc_list),
                           nrows=1,
                           figsize=(1.5 * len(ds_loc_list), 3.8),
                           constrained_layout=True)
    for i, ds_loc in enumerate(ds_loc_list):
        print(ds_loc)
        if os.path.isfile('%s/DD%04d/DD%04d' % (ds_loc, output, output)):

            ds = ytf.load('%s/DD%04d/DD%04d' % (ds_loc, output, output))
            if projection:
                s = yt.ProjectionPlot(ds,
                                      'x', ('gas', field),
                                      center=(0, 0, 1),
                                      width=(1, 1.8),
                                      weight_field=('index', 'ones'))
            else:
                s = yt.SlicePlot(ds,
                                 'x', ('gas', field),
                                 center=(0, 0, 1),
                                 width=(1, 1.8))
            s.set_buff_size(512)
            frb = s.frb

            xbins = frb['y'].in_units('kpc')
            ybins = frb['z'].in_units('kpc')
            if field == 'density':
                data_norm = rho0
            elif field == 'temperature':
                data_norm = T0
            elif field == 'cr_pressure':
                data_norm = p0 * cr

            data = frb[field] / data_norm

            if field == 'density':
                vmin = 1e-1
                vmax = 3
                if projection:
                    vmax = 1.5
            elif field == 'temperature':
                vmin = 5e4 / T0
                vmax = 5e6 / T0
                if projection:
                    vmin = 1e5 / T0
            elif field == 'cr_eta':
                cr_eta = pt.get_cr_eta(ds)
                vmin = cr_eta / 100
                vmax = cr_eta * 100
            elif field == 'cr_pressure':
                vmin = 0.2
                vmax = 2.0

            cmap = pt.get_cmap(field)
            pcm = ax[i].pcolormesh(xbins, ybins, data, norm = LogNorm(), cmap = cmap, \
                               vmax = vmax, vmin = vmin, zorder = 1)
        else:
            pcm = ax[i].scatter(0, 0, color='white')

        ax[i].set_aspect('equal')
        ax[i].set_xticks([])
        ax[i].set_yticks([])

        ax[i].set_xticklabels([])
        ax[i].set_yticklabels([])
        H_kpc = 43.85  # scale height in kpc

        if field == 'temperature':
            ax[i].set_xlabel(label_list[i], fontsize=10)
        else:
            ax[i].set_title(label_list[i], fontsize=10)

    fig.tight_layout()
    fig.subplots_adjust(bottom=0.2)
    pos_l = ax[0].get_position().get_points()
    pos_r = ax[-1].get_position().get_points()

    dx = 0.02
    dy = pos_r[1][1] - pos_r[0][1]
    cbar_y = pos_r[0][1]
    cbar_x = pos_r[1][0] + .02
    print(cbar_x, cbar_y)
    cbax = fig.add_axes([cbar_x, cbar_y, dx, dy])
    if field == 'cr_pressure':
        cbar = fig.colorbar(pcm,
                            cax=cbax,
                            orientation='vertical',
                            ticks=[0.2, 2])
        cbar.ax.set_yticklabels(['0.2', '2'])
    else:
        cbar = fig.colorbar(pcm, cax=cbax, orientation='vertical')

    if field == 'density':
        label = '$\\rho / \\rho_0 $'
    elif field == 'temperature':
        label = 'T / T$_0$'
    elif field == 'cr_pressure':
        label = 'P$_c$ / P$_{c,0}$'
    cbar.set_label(label)

    figname = '%s/%04d.png' % (plot_folder, output)
    plt.savefig(figname, dpi=300, bbox_inches='tight', pad_inches=0.2)
def calculate_histogram_data_wrapper(args):
    output_loc, xfield, yfield, weighted, T_min, zstart, zend = args
    ds = ytf.load(output_loc)
    logx, logy, mass = get_log_phase_data(ds, xfield = xfield, yfield = yfield, z_min = zstart, z_max = zend)
    return (logx, logy, mass)