示例#1
0
def getUNK(file, srcnames=True):
    """returns fields and species found in a hdf5 file.
    (species is any unk with a number, plus (n, d, t))

    Args:
        file(str): path to file.
        srcnames(bool): return original names (else d > H2)

    Returns:
        (str list): field names.
        (str list): nuclide codes.

    """
    finn = h5py.File(file, "r")
    infval = finn['unknown names']
    unks = [decode(v[0]) for v in infval]
    fields, species = [], []
    exceptions = ['n', 'd', 't', 'd', 't']
    parsedvals = ['n1', 'H2', 'H3', 'd2', 't3']
    for field in unks:
        if any(char.isdigit() for char in field):
            species.append(field)
        elif field.strip() in exceptions:
            species.append(field)
        else:
            fields.append(field)
    species = sortNuclides(species)
    # once sorted, rename the exceptions
    if srcnames:
        for i, e in enumerate(parsedvals):
            if e in species:
                species[species.index(e)] = exceptions[i]
    finn.close()
    return fields, species
示例#2
0
def getFields(flist, srcnames=True):
    """filters flash checkpoint field list, extracting species found
    in the checkpoint (including named exceptions, see source).

    Args:
        flist(tuple list): ds.derived_field_list from yt.
        srcnames(bool): return original names for species (n, d, t).

    Returns:
        fields (list of str): field names in checkpoint.
        species (list of str): nuclide codes as in checkpoint.

    """
    fields, species = [], []
    exceptions = ['n', 'p', 'd', 't']
    parsedvals = ['n1', 'p1', 'd2', 't3']
    for (t, field) in flist:
        if any(char.isdigit() for char in field):
            species.append(field)
        elif field.strip() in exceptions:
            species.append(field)
        else:
            fields.append(field)
    species = sortNuclides(species)
    # once sorted, rename the exceptions
    if srcnames:
        for i, e in enumerate(parsedvals):
            if e in species:
                species[species.index(e)] = exceptions[i]
    return fields, species
示例#3
0
def plotDMatMerged(prof, thresh=1e-4, xrange=[0.0, 0.0], byM=True):
    """plots main properties of a profile in only two axes, merging 
    thermodynamic properties.
    
    Args:
        prof (dataMatrix): dataMatrix obj.
        thresh (float): ymin for species fraction plot.
        xrange (list of float): if set, change the range of the plots.
        byM (bool): abundance plot xaxis (by Mass or by Radius).
    
    """  
    fig = plt.figure()
    skip = ['radius', 'masses', 'density']
    plotp = [x for x in prof.bulkprops if x not in skip]
    keys = sortNuclides(prof.species)
    ncol = 4
    labelspace = -0.1
    if byM:
        xs = prof.masses
        xlab = 'Mass ($M_{\odot}$)'
        log = False  
    else:
        xs = prof.radius
        xlab = 'Radius ($cm$)'
        log = True

    layout = (2, 2)
    # Species
    spax = plt.subplot2grid(layout, (0, 0), colspan=2)
    skip = plotSpecies(spax, prof, byMass=byM, thresh=thresh, plotall=False)
    # remove last(lowest) yticklabel to avoid overlap
    spax.get_yticklabels()[1].set_visible(False)
    lgd = spax.legend(ncol=ncol, loc='upper left', bbox_to_anchor=(1.00, 1.02), 
                      columnspacing=0.0, labelspacing=0.0, markerfirst=False, 
                      numpoints=3, handletextpad=0.0, edgecolor='k')
    spax.axhline(1e0, linewidth=1, linestyle=':', color='black')
    spax.set_ylim(thresh, 2.0)
    spax.set_ylabel('Mass Frac.($X_{i}$)', size=13, rotation=90, labelpad=0)
    spax.yaxis.set_label_coords(labelspace, 0.5)
    spax.yaxis.set_minor_formatter(StrMethodFormatter(''))
    spax.tick_params(labelbottom=False) 
    if log:
        spax.set_yscale('log')
        spax.set_xscale('log')
    # Thermodynamical variables (reference is, as always, density)
    tdax = plt.subplot2grid(layout, (1, 0), colspan=2, sharex=spax)
    tdax.semilogy(xs, prof.density, label='Density')
    ylabels = ['$\\frac{g}{cm^3}$']
    tdax.yaxis.set_minor_formatter(StrMethodFormatter(''))
    tdax.tick_params(labelbottom=False)
    
    for i, p in enumerate(plotp):
        u = ut.getUnit(p)
        if p=='pressure':
            tdax.plot(xs, getattr(prof, p)/1e16, label=p.capitalize())#, color='k')
            ylabels.append(u+'$\\times10^{-16}$')
        else:
            tdax.plot(xs, getattr(prof, p), label=p.capitalize())#, color='k')
            ylabels.append(u)
        #spacer = labelspace if '\\' in u else labelspace - 0.02
    #tdax.set_ylabel('{}({})'.format(p.capitalize(), u), rotation=90, size=13, labelpad=0)
    tdax.yaxis.set_minor_formatter(StrMethodFormatter(''))
    tdax.tick_params(labelbottom=False)
    tdax.set_xlabel(xlab)
    tdax.tick_params(labelbottom=True)
    tdax.set_ylabel('({})'.format(','.join(ylabels)), size=13, rotation=90, labelpad=0)
    tdax.yaxis.set_label_coords(labelspace, 0.5)
    lgd = tdax.legend(ncol=1, loc='upper left', bbox_to_anchor=(1.00, 0.50), 
                      columnspacing=0.0, labelspacing=0.0, markerfirst=False, 
                      numpoints=3, handletextpad=0.0, edgecolor='k')
    if sum(xrange)!=0.0:
        spax.set_xlim(xrange)
    plt.subplots_adjust(hspace=0.001, wspace=0.0)
    plt.subplots_adjust(left=0.13, right=0.80)
    plt.subplots_adjust(top=0.99, bottom=0.10)
    fig.set_size_inches(8.5, 7.5, forward=True)
    return fig
示例#4
0
def plotDMat(prof, thresh=1e-4, xrange=[0.0, 0.0], byM=True):
    """plots main properties of a profile object.
    
    Args:
        prof (dataMatrix): dataMatrix obj.
        thresh (float): ymin for species fraction plot.
        xrange (list of float): if set, change the range of the plots.
        byM (bool): abundance plot xaxis (by Mass or by Radius).
    
    """  
    fig = plt.figure()
    skip = ['radius', 'masses', 'density']
    plotp = [x for x in prof.bulkprops if x not in skip]
    keys = sortNuclides(prof.species)
    ncol = 4
    labelspace = -0.15

    if byM:
        xs = prof.masses
        xlab = 'Mass ($M_{\odot}$)'
        log = False  
    else:
        xs = prof.radius
        xlab = 'Radius ($cm$)'
        log = True

    layout = (len(plotp)+2, 3)
    # Species
    ax1 = plt.subplot2grid(layout, (0, 0), colspan=2)
    skip = plotSpecies(ax1, prof, byMass=byM, thresh=thresh, plotall=False)
    # remove last(lowest) yticklabel to avoid overlap
    ax1.get_yticklabels()[1].set_visible(False)
    lgd = ax1.legend(ncol=ncol, loc='upper left', bbox_to_anchor=(1.00, 1.05), 
                     columnspacing=0.0, labelspacing=0.0, markerfirst=False, 
                     numpoints=3, handletextpad=0.0)
    ax1.axhline(1e0, linewidth=1, linestyle=':', color='black')
    ax1.set_ylim(thresh, 2.0)
    ax1.set_ylabel('Mass Frac.($X_{i}$)', size=13, rotation=90, labelpad=0)
    ax1.yaxis.set_label_coords(labelspace, 0.5)
    ax1.yaxis.set_minor_formatter(StrMethodFormatter(''))
    ax1.tick_params(labelbottom=False) 
    if log:
        ax1.set_yscale('log')
        ax1.set_xscale('log')
        
    ax2 = plt.subplot2grid(layout, (1, 0), sharex=ax1, colspan=2)
    ax2.semilogy(xs, prof.density)
    ax2.set_ylabel('Density($\\frac{g}{cm^3}$)', size=13, rotation=90, labelpad=0)
    ax2.yaxis.set_label_coords(labelspace, 0.5)
    ax2.yaxis.set_minor_formatter(StrMethodFormatter(''))
    ax2.tick_params(labelbottom=False) 
    
    for i, p in enumerate(plotp):
        ax3 = plt.subplot2grid(layout, (i+2, 0), sharex=ax1, colspan=2)
        for j in range(i+1):
            ax3.plot([], [])
        ax3.semilogy(xs, getattr(prof, p))#, color='k')
        u = ut.getUnit(p)
        spacer = labelspace if '\\' in u else labelspace - 0.02
        ax3.set_ylabel('{}({})'.format(p.capitalize(), u), rotation=90, size=13, labelpad=0)
        ax3.yaxis.set_minor_formatter(StrMethodFormatter(''))
        ax3.yaxis.set_label_coords(spacer, 0.5)
        ax3.tick_params(labelbottom=False)
    ax3.set_xlabel(xlab)
    ax3.tick_params(labelbottom=True)
    if sum(xrange)!=0.0:
        ax1.set_xlim(xrange)
    plt.subplots_adjust(hspace=0.001, wspace=0.0)
    plt.subplots_adjust(left=0.13, right=0.80)
    plt.subplots_adjust(top=0.99, bottom=0.10)
    fig.set_size_inches(8.5, 7.5, forward=True)
    return fig