<commit_before>import deepdish as dd
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import glob
import numpy as np


workdir = '/mnt/ceph/users/emerick/enzo_runs/stampede/leo_p/fullphysics/fullres'

DATA_PATHS = { 'lm'        : workdir + '/run11/200cc',
               'lm_noRT'   : workdir + '/run11/200cc_noRT',
               'lm_nowind' : workdir + '/run11/200cc_nowind',
               'lm_xx'     : workdir + '/run11/othercloudy',
               'mm'        : workdir + '/run13',
               'mm_3pc'    : workdir + '/run13/3parsec',
               'hm'        : workdir + '/run15'}

ls_dict = { 'lm' : '-', 'lm_noRT' : '--', 'lm_nowind' : ':', 'lm_xx' : '--',
             'mm' : '-', 'mm_3pc' : '-.', 'hm' : '-'}


purple  = '#7d03a8'
magenta = '#cb4679'
blue    = '#0c0887'
orange  = '#fdc328'

color_dict = {'lm' : purple, 'lm_noRT' : purple, 'lm_nowind' : purple,
              'mm' : magenta  , 'mm_3pc'  : magenta  , 'hm' : orange, 'lm_xx' : blue}


linewidth = 4.5

ALL_DATA = {}
for s in DATA_PATHS.keys():
    ALL_DATA[s] = np.sort(glob.glob(DATA_PATHS[s] + '/DD*.h5'))

def plot_mass(sim_names = None, species = 'HI'):


    if sim_names is None:
        sim_names = DATA_PATHS.keys()

    fig,ax = plt.subplots()

    for s in sim_names:
        # always load most recent file in every case
        data = dd.io.load(ALL_DATA[s][-1])

        t    = data['time_data']['time']
        sfr  = data['time_data']['SFR']

        t_first = np.min( t[sfr > 0]) / 1.0E6

        if species == 'HI' or species == 'M_HI':
            fname = 'M_HI'
        elif species == 'total' or species == 'Total' or species == 'gas' or species == 'M_gas':
            fname = 'M_gas'
        elif species == 'star' or species == 'stars' or species == 'stellar' or species == 'M_star':
            fname = 'M_star'

        t = np.zeros(np.size(ALL_DATA[s]))
        mass = np.zeros(np.size(ALL_DATA[s]))
        for i,x in enumerate(ALL_DATA[s]):
            xdata = dd.io.load(x)
            t[i] = xdata['meta_data']['Time']
            mass[i] = xdata['meta_data'][fname]
        
        t = t - t_first
        t_plot   = t[t >= 0.0]
        mass_plot = mass[t >= 0.0]

        ax.plot(t_plot, mass_plot, lw = linewidth, ls = ls_dict[s], color = color_dict[s], label = s, drawstyle = 'steps-post')

    ax.set_xlabel(r'Time (Myr)')<commit_msg>begun mass loading plot function<commit_after>import deepdish as dd
import matplotlib as mpl
mpl.use('Agg')
import matplotlib.pyplot as plt
import glob
import numpy as np


workdir = '/mnt/ceph/users/emerick/enzo_runs/stampede/leo_p/fullphysics/fullres'

DATA_PATHS = { 'lm'        : workdir + '/run11/200cc',
               'lm_noRT'   : workdir + '/run11/200cc_noRT',
               'lm_nowind' : workdir + '/run11/200cc_nowind',
               'lm_xx'     : workdir + '/run11/othercloudy',
               'mm'        : workdir + '/run13',
               'mm_3pc'    : workdir + '/run13/3parsec',
               'hm'        : workdir + '/run15'}

ls_dict = { 'lm' : '-', 'lm_noRT' : '--', 'lm_nowind' : ':', 'lm_xx' : '--',
             'mm' : '-', 'mm_3pc' : '-.', 'hm' : '-'}


purple  = '#7d03a8'
magenta = '#cb4679'
blue    = '#0c0887'
orange  = '#fdc328'

color_dict = {'lm' : purple, 'lm_noRT' : purple, 'lm_nowind' : purple,
              'mm' : magenta  , 'mm_3pc'  : magenta  , 'hm' : orange, 'lm_xx' : blue}


linewidth = 4.5

ALL_DATA = {}
for s in DATA_PATHS.keys():
    ALL_DATA[s] = np.sort(glob.glob(DATA_PATHS[s] + '/DD*.h5'))

def time_first_star(data = None, t = None, sfr = None):
    if data is None and (t is None or sfr is None):
        print "If supplying no data set, must supply both time array and sfr array"
        raise ValueError

    if not data is None:
        t   = data['time_data']['time']
        sfr = data['time_data']['SFR']

    t_first = np.min( t[sfr > 0])

    return t_first

def plot_mass_loading(sim_names = None, species = 'total', z = 500.0):

    if sim_names is None:
        sim_names = DATA_PATHS.keys()

    fig, ax = plt.subplots()

    # loop over simulations
    for s in sim_names:
        # always load most recent file to check
        data = dd.io.load(ALL_DATA[s][-1])
        t_first = time_first_star(data) / 1.0E6 # now in Myr

        # make arrays for plotting
        t  = np.zeros(np.size(ALL_DATA[s]))
        ml = np.zeros(np.size(ALL_DATA[s]))

        # now go through every data analysis dump
        for i,x in enumerate(ALL_DATA[s]):
            xdata = dd.io.load(ALL_DATA[i])
            t[i]  = xdata['meta_data']['Time']

            ml[i] = xdata['

def plot_mass(sim_names = None, species = 'HI'):


    if sim_names is None:
        sim_names = DATA_PATHS.keys()

    fig,ax = plt.subplots()

    for s in sim_names:
        # always load most recent file in every case
        data = dd.io.load(ALL_DATA[s][-1])

        t_first = time_first_star(data)

        if species == 'HI' or species == 'M_HI':
            fname = 'M_HI'
        elif species == 'total' or species == 'Total' or species == 'gas' or species == 'M_gas':
            fname = 'M_gas'
        elif species == 'star' or species == 'stars' or species == 'stellar' or species == 'M_star':
            fname = 'M_star'

        t = np.zeros(np.size(ALL_DATA[s]))
        mass = np.zeros(np.size(ALL_DATA[s]))
        for i,x in enumerate(ALL_DATA[s]):
            xdata = dd.io.load(x)
            t[i] = xdata['meta_data']['Time']
            mass[i] = xdata['meta_data'][fname]
        
        t = t - t_first
        t_plot   = t[t >= 0.0]
        mass_plot = mass[t >= 0.0]

        ax.plot(t_plot, mass_plot, lw = linewidth, ls = ls_dict[s], color = color_dict[s], label = s, drawstyle = 'steps-post')

    ax.set_xlabel(r'Time (Myr)')
{'fraction_non_alphanumeric': 0.16033974692321026, 'fraction_numerical': 0.019934130698561276, 'mean_word_length': 2.1773127753303965, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4794117', 'n_tokens_mistral': 2252, 'n_tokens_neox': 2138, 'n_words': 495}