In [3]:
%matplotlib inline
import yt 
import numpy as np
import matplotlib.pyplot as plt

from yt.visualization.base_plot_types import get_multi_plot
import matplotlib.colorbar as cb
from matplotlib.colors import LogNorm


from galaxy_analysis.yt_fields import field_generators as fg
from galaxy_analysis.utilities import convert_abundances as ca
from galaxy_analysis.utilities import utilities as galutil
from galaxy_analysis.plot.plot_styles import *

from matplotlib.ticker import (MultipleLocator, FormatStrFormatter,
                               AutoMinorLocator)

def plot_settings():
    fsize = 21
    rc('text',usetex=False)
    rc('font',size=fsize)
    return

plot_settings()

rc('text',usetex=False)
rc('font',size=fsize)

In [4]:
workdir = "/home/aemerick/work/enzo_runs/cosmo_testing/feedback/grid/"

In [11]:
dsname = 'DD0045'
dsname = dsname + '/' + dsname

ds = yt.load(workdir + dsname)
fg.generate_derived_fields(ds)
ds = yt.load(workdir + dsname)
fg.generate_particle_filters(ds)
data = ds.all_data()


defining for the following metals  ['C', 'N', 'O', 'Mg', 'Ca', 'Fe', 'Sr', 'Ba']
tracer species present:  ['C', 'N', 'O', 'Mg', 'Ca', 'Fe', 'Sr', 'Ba']
8 mass fields defined
8 mass fraction fields defined
8 number density fields defined
54 abundance ratio fields defined
54 particle abundance ratio fields defined
5 additional helper fields defined

In [12]:
field_units  =  {'Density' : 'g/cm**3',
                 'x_velocity' : 'km/s',
                 'y_velocity' : 'km/s','z_velocity':'km/s','vx' : 'km/s',
                 "Temperature" : 'K'}

print("%20s - %30s:    %5s   %5s   %5s"%("Type 0","Field","Sum","Min","Max"))
for field in ds.field_list:

    vals = data[field]

    if np.size(vals) > 0:
        if field[1] in field_units:
            vals = vals.to(field_units[field[1]])
        elif 'kph' in field[1]:
            vals = vals.to('1/s')
        elif '_Density' in field[1]:
            try:
                vals = vals.to('g/cm**3')
            except:
                vals = vals

        print("%20s - %30s:    %5.3E   %5.3E  %5.3E"%(field[0],field[1], np.sum(vals), np.min(vals), np.max(vals)))
    else:
        print("%20s - %30s:    None    None    None"%(field[0],field[1]))


              Type 0 -                          Field:      Sum     Min     Max
                 all -             agb_metal_fraction:    1.000E-16   1.000E-20  1.000E-20
                 all -                     birth_mass:    7.905E+04   7.900E+00  7.910E+00
                 all -                  creation_time:    0.000E+00   0.000E+00  0.000E+00
                 all -                 dynamical_time:    1.525E+36   1.443E+15  1.337E+35
                 all -           metallicity_fraction:    1.000E+02   1.000E-02  1.000E-02
                 all -           particle_Ba_fraction:    1.000E-12   1.000E-16  1.000E-16
                 all -            particle_C_fraction:    1.000E-12   1.000E-16  1.000E-16
                 all -           particle_Ca_fraction:    1.000E-12   1.000E-16  1.000E-16
                 all -           particle_Fe_fraction:    1.000E-12   1.000E-16  1.000E-16
                 all -            particle_H_fraction:    7.500E+07   7.500E+03  7.500E+03
                 all -           particle_He_fraction:    2.500E+07   2.500E+03  2.500E+03
                 all -           particle_Mg_fraction:    1.000E-12   1.000E-16  1.000E-16
                 all -            particle_N_fraction:    1.000E-12   1.000E-16  1.000E-16
                 all -            particle_O_fraction:    1.000E-12   1.000E-16  1.000E-16
                 all -           particle_Sr_fraction:    1.000E-12   1.000E-16  1.000E-16
                 all -                 particle_index:    5.000E+07   0.000E+00  9.999E+03
                 all -                  particle_mass:    2.614E+37   0.000E+00  2.620E+33
                 all -            particle_position_x:    4.490E+03   3.000E-01  6.000E-01
                 all -            particle_position_y:    4.513E+03   3.000E-01  6.000E-01
                 all -            particle_position_z:    3.695E+03   3.680E-01  3.710E-01
                 all -                  particle_type:    1.200E+05   1.200E+01  1.200E+01
                 all -            particle_velocity_x:    0.000E+00   0.000E+00  0.000E+00
                 all -            particle_velocity_y:    0.000E+00   0.000E+00  0.000E+00
                 all -            particle_velocity_z:    0.000E+00   0.000E+00  0.000E+00
                 all -          popIII_metal_fraction:    1.000E-16   1.000E-20  1.000E-20
                 all -    popIII_pisne_metal_fraction:    1.000E-16   1.000E-20  1.000E-20
                 all -        rprocess_metal_fraction:    1.000E-16   1.000E-20  1.000E-20
                 all -                sn_mass_ejected:    2.502E+01   0.000E+00  1.317E+00
                 all -       snia_hers_metal_fraction:    9.958E-17   -1.000E-20  1.000E-20
                 all -            snia_metal_fraction:    8.750E-17   -1.000E-20  1.000E-20
                 all -        snia_sch_metal_fraction:    8.370E-17   -1.000E-20  1.000E-20
                 all -        snia_sds_metal_fraction:    9.960E-17   -1.000E-20  1.000E-20
                 all -            snii_metal_fraction:    1.000E-16   1.000E-20  1.000E-20
                 all -              wind_mass_ejected:    5.010E+04   5.005E+00  5.015E+00
                enzo -              AGB_Metal_Density:    2.612E+06   2.279E-17  1.460E+06
                enzo -                     Ba_Density:    1.089E+00   2.279E-17  6.086E-01
                enzo -                      C_Density:    4.973E+04   2.279E-17  2.754E+04
                enzo -                     Ca_Density:    5.004E+03   2.279E-17  2.718E+03
                enzo -            Dark_Matter_Density:    3.644E-21   0.000E+00  9.510E-23
                enzo -                        Density:    3.692E-20   7.429E-30  1.953E-20
                enzo -               Electron_Density:    2.960E-24   5.557E-30  1.050E-26
                enzo -                FUV_FluxDensity:    1.383E+05   3.377E+01  3.377E+01
                enzo -                     Fe_Density:    1.136E+05   2.279E-17  5.960E+04
                enzo -                      GasEnergy:    4.902E+00   3.757E-06  2.354E-02
                enzo -                  GravPotential:    -5.962E+00   -1.500E-02  -7.249E-04
                enzo -                   H2II_Density:    2.784E-30   5.312E-38  4.310E-32
                enzo -                     H2II_kdiss:    0.000E+00   0.000E+00  0.000E+00
                enzo -                    H2I_Density:    1.524E-20   8.702E-37  1.454E-20
                enzo -                      H2I_kdiss:    0.000E+00   0.000E+00  0.000E+00
                enzo -                    HII_Density:    2.675E-24   5.030E-30  9.776E-27
                enzo -                     HI_Density:    1.259E-20   5.012E-31  3.993E-22
                enzo -                         HI_kph:    0.000E+00   0.000E+00  0.000E+00
                enzo -                     HM_Density:    2.440E-31   8.310E-43  4.146E-33
                enzo -                         HM_kph:    0.000E+00   0.000E+00  0.000E+00
                enzo -                  HeIII_Density:    1.204E-26   1.744E-49  9.341E-29
                enzo -                   HeII_Density:    1.117E-24   1.195E-30  2.888E-27
                enzo -                       HeII_kph:    0.000E+00   0.000E+00  0.000E+00
                enzo -                    HeI_Density:    8.790E-21   8.967E-32  4.649E-21
                enzo -                        HeI_kph:    0.000E+00   0.000E+00  0.000E+00
                enzo -                  Metal_Density:    2.922E-22   1.439E-31  1.611E-22
                enzo -                     Mg_Density:    6.822E+04   2.279E-17  3.814E+04
                enzo -                      N_Density:    6.173E+05   2.279E-17  3.451E+05
                enzo -                      O_Density:    3.805E+05   2.279E-17  2.120E+05
                enzo -                Pe_heating_rate:    2.481E+02   8.782E-25  3.305E+00
                enzo -                     PhotoGamma:    0.000E+00   0.000E+00  0.000E+00
                enzo -           PopIII_Metal_Density:    2.486E-12   4.766E-23  1.281E-12
                enzo -     PopIII_PISNe_Metal_Density:    2.486E-12   4.766E-23  1.281E-12
                enzo -         RProcess_Metal_Density:    2.486E-12   4.766E-23  1.281E-12
                enzo -                      RadAccel1:    0.000E+00   0.000E+00  0.000E+00
                enzo -                      RadAccel2:    0.000E+00   0.000E+00  0.000E+00
                enzo -                      RadAccel3:    0.000E+00   0.000E+00  0.000E+00
                enzo -             SNII_Metal_Density:    2.486E-12   4.766E-23  1.281E-12
                enzo -        SNIa_HeRS_Metal_Density:    2.486E-12   4.766E-23  1.281E-12
                enzo -             SNIa_Metal_Density:    4.810E+04   2.279E-17  2.015E+04
                enzo -         SNIa_SDS_Metal_Density:    2.486E-12   4.766E-23  1.281E-12
                enzo -         SNIa_sCh_Metal_Density:    2.486E-12   4.766E-23  1.281E-12
                enzo -                     Sr_Density:    4.139E+00   2.279E-17  2.314E+00
                enzo -                    Temperature:    3.990E+06   3.558E+00  1.791E+04
                enzo -                    TotalEnergy:    2.220E+01   2.548E-05  3.565E-02
                enzo -                     x-velocity:    5.551E+01   -1.725E-01  1.779E-01
                enzo -                     y-velocity:    -4.982E+00   -2.138E-01  2.037E-01
                enzo -                     z-velocity:    7.960E+01   -1.800E-01  2.344E-01
                  io -             agb_metal_fraction:    1.000E-16   1.000E-20  1.000E-20
                  io -                     birth_mass:    7.905E+04   7.900E+00  7.910E+00
                  io -                  creation_time:    0.000E+00   0.000E+00  0.000E+00
                  io -                 dynamical_time:    4.833E+22   4.572E+01  4.235E+21
                  io -           metallicity_fraction:    1.000E+02   1.000E-02  1.000E-02
                  io -           particle_Ba_fraction:    1.000E-12   1.000E-16  1.000E-16
                  io -            particle_C_fraction:    1.000E-12   1.000E-16  1.000E-16
                  io -           particle_Ca_fraction:    1.000E-12   1.000E-16  1.000E-16
                  io -           particle_Fe_fraction:    1.000E-12   1.000E-16  1.000E-16
                  io -            particle_H_fraction:    7.500E+07   7.500E+03  7.500E+03
                  io -           particle_He_fraction:    2.500E+07   2.500E+03  2.500E+03
                  io -           particle_Mg_fraction:    1.000E-12   1.000E-16  1.000E-16
                  io -            particle_N_fraction:    1.000E-12   1.000E-16  1.000E-16
                  io -            particle_O_fraction:    1.000E-12   1.000E-16  1.000E-16
                  io -           particle_Sr_fraction:    1.000E-12   1.000E-16  1.000E-16
                  io -                 particle_index:    5.000E+07   0.000E+00  9.999E+03
                  io -                  particle_mass:    8.896E+03   0.000E+00  8.916E-01
                  io -            particle_position_x:    4.490E+03   3.000E-01  6.000E-01
                  io -            particle_position_y:    4.513E+03   3.000E-01  6.000E-01
                  io -            particle_position_z:    3.695E+03   3.680E-01  3.710E-01
                  io -                  particle_type:    1.200E+05   1.200E+01  1.200E+01
                  io -            particle_velocity_x:    0.000E+00   0.000E+00  0.000E+00
                  io -            particle_velocity_y:    0.000E+00   0.000E+00  0.000E+00
                  io -            particle_velocity_z:    0.000E+00   0.000E+00  0.000E+00
                  io -          popIII_metal_fraction:    1.000E-16   1.000E-20  1.000E-20
                  io -    popIII_pisne_metal_fraction:    1.000E-16   1.000E-20  1.000E-20
                  io -        rprocess_metal_fraction:    1.000E-16   1.000E-20  1.000E-20
                  io -                sn_mass_ejected:    2.502E+01   0.000E+00  1.317E+00
                  io -       snia_hers_metal_fraction:    9.958E-17   -1.000E-20  1.000E-20
                  io -            snia_metal_fraction:    8.750E-17   -1.000E-20  1.000E-20
                  io -        snia_sch_metal_fraction:    8.370E-17   -1.000E-20  1.000E-20
                  io -        snia_sds_metal_fraction:    9.960E-17   -1.000E-20  1.000E-20
                  io -            snii_metal_fraction:    1.000E-16   1.000E-20  1.000E-20
                  io -              wind_mass_ejected:    5.010E+04   5.005E+00  5.015E+00

In [13]:
pt = data['particle_type']
print(np.unique(pt))


[12.] dimensionless

In [14]:
#
# Check to make sure no particles that are SNIa
# get double assigned SNIa types 
#

num_doubled = 0
nsnia = 0

for i in np.arange(np.size(pt)):
    num_neg = 0
    
    if (data['snia_metal_fraction'][i] < 0):
        num_neg += 1
    if (data['snia_sch_metal_fraction'][i] < 0):
        num_neg += 1
    if (data['snia_sds_metal_fraction'][i] < 0):
        num_neg += 1
    if (data['snia_hers_metal_fraction'][i] < 0):
        num_neg += 1
   
    if num_neg == 1:
        nsnia += 1
    elif num_neg > 1:
        num_doubled += 1
        print("doubled up on particle",i,num_neg)
        
print(num_doubled)


0

In [15]:
#
# Check out the WD particles
#

def check_SNIa_properties(data):
    pt = data['particle_type']
    m  = data['particle_mass'].to('Msun')
    WD_select = pt == 12

    complete_SNIa = (pt==12)*(m==0.0)

    n_part = np.size(pt)


    ideal = {'DDS' : 0.05126958193824957,'SDS': 0.005242912915506227, 'sCh' :0.09073471211157359,
               'HeRS' : 0.0035997607307840106, 'total' : 0.15084696769611342}


    print("Number of particles ", n_part)
    print("Number of WD particles ", np.size(pt[WD_select]))
    print("Number of particles that will (or have) gone SNIa ", nsnia)
    print("Number of particles that have gone SNIa ", np.size(pt[complete_SNIa]))

    sntypes = ['DDS','sCh','SDS','HeRS']
    #
    # Count the types
    #
    #
    num_snia = {}
    data_field = {'DDS' : 'snia_metal_fraction', 'sCh' : 'snia_sch_metal_fraction',
                  'SDS' : 'snia_sds_metal_fraction', 'HeRS' : 'snia_hers_metal_fraction'}
    for sntype in sntypes:
        select = data[ data_field[sntype] ] < 0

        num_snia[sntype] = np.size(pt[select])


    print("Fraction of SNIa Types")
    total_num = 0
    for sntype in sntypes:
        total_num += num_snia[sntype]
        print("%10s: Number = %4i  - Fraction = %.5f - Target Fraction %.5f"%(sntype, num_snia[sntype], num_snia[sntype]/(1.0*n_part), ideal[sntype]))

    print("%10s: Number = %4i - Fraction = %.5f - Target Fraction %.5f"%("Total", total_num, total_num/(1.0*n_part), ideal['total']))
    
check_SNIa_properties(data)


Number of particles  10000
Number of WD particles  10000
Number of particles that will (or have) gone SNIa  1481
Number of particles that have gone SNIa  19
Fraction of SNIa Types
       DDS: Number =  625  - Fraction = 0.06250 - Target Fraction 0.05127
       sCh: Number =  815  - Fraction = 0.08150 - Target Fraction 0.09073
       SDS: Number =   20  - Fraction = 0.00200 - Target Fraction 0.00524
      HeRS: Number =   21  - Fraction = 0.00210 - Target Fraction 0.00360
     Total: Number = 1481 - Fraction = 0.14810 - Target Fraction 0.15085

In [16]:
#
# Check lifetimes
#

lt = data['dynamical_time'].to('Myr')

select = lt < 15.0E3 # Myr

print(np.size(lt[select]))

print(np.min(lt[select]), np.max(lt[select]))
print(np.median(lt[select]))
print(np.average(lt[select]))


1462
45.719598489255766 Myr 13474.6658621177 Myr
1123.170382903028 Myr
2012.4369188683963 Myr

In [ ]:


In [ ]: