예제 #1
0
def extract_cycles(cycles, run, batch, source, basename='xrb', prefix=''):
    """Iterates over dump cycles and extracts profiles and tables
    """
    save_times(cycles,
               run,
               batch,
               source=source,
               basename=basename,
               prefix=prefix)
    copy_lightcurve(run, batch, source=source, basename=basename)

    dashes()
    print('Extracting profiles')
    for i, cycle in enumerate(cycles):
        dump = kepler_tools.load_dump(cycle,
                                      run,
                                      batch,
                                      source=source,
                                      basename=basename,
                                      prefix=prefix)

        table = get_profile(dump)
        save_table(table,
                   table_name=f'{cycle}',
                   run=run,
                   batch=batch,
                   source=source,
                   basename=basename,
                   subdir='profiles')
예제 #2
0
파일: temp.py 프로젝트: kahoTT/pyburst
def plot_temp_multi(cycles, runs, batches, sources, basename='xrb', prefix='',
                    fontsize=12, legend=True):
    """Plots Temp profiles of multiple different sources/batches/runs

    cycles,runs,batches,sources are arrays of length N, where the i'th entry
        correspond to a single model to plot
    """
    # TODO: auto use largest cycle common to all models
    runs, batches, sources = expand_lists(cycles, runs, batches, sources)
    fig, ax = plt.subplots()
    dump = None
    for i, cycle in enumerate(cycles):
        dump = kepler_tools.load_dump(cycle, runs[i], batches[i], source=sources[i],
                                      basename=basename, prefix=prefix)
        ax.plot(dump.y[1:-2], dump.tn[1:-2],
                label=f'{sources[i]}_{batches[i]}_{runs[i]}_#{cycle}')

    ax.set_yscale('log')
    ax.set_xscale('log')

    y0 = dump.y[1]   # column depth at inner zone
    y1 = dump.y[-3]  # outer zone
    ax.set_xlim([y1, y0])

    ax.set_xlabel(r'y (g cm$^{-2}$)', fontsize=fontsize)
    ax.set_ylabel(r'T (K)', fontsize=fontsize)
    if legend:
        ax.legend()
    plt.tight_layout()
    plt.show(block=False)
예제 #3
0
파일: temp.py 프로젝트: kahoTT/pyburst
def get_mean_qnuc(run, batch, source, cycles=None, dumps=None):
    """Return energy generation per mass averaged over model (erg/g)
    cycles: length 2 array
    """
    if dumps is None:
        dumps = []
        for i, cycle in enumerate(cycles):
            dumps += [kepler_tools.load_dump(cycle, run=run, batch=batch, source=source)]

    mass_diff = dumps[1].qparm('xmacc') - dumps[0].qparm('xmacc')
    energy_diff = dumps[1].qparm('epro') - dumps[0].qparm('epro')
    rate = energy_diff / mass_diff
    rate_mev = rate * (units.erg/units.g).to(units.MeV/units.M_p)
    print(f'{rate_mev:.2f}  MeV/nucleon')
    return rate
예제 #4
0
def extract_profile(cycle,
                    run,
                    batch,
                    source='frank',
                    basename='xrb',
                    endpoints=(1, -1)):
    """Returns DataFrame table of profile information for given dump cycle
    """
    table = pd.DataFrame()

    dump = kepler_tools.load_dump(cycle=cycle,
                                  run=run,
                                  batch=batch,
                                  source=source,
                                  basename=basename)
    _slice = slice(endpoints[0], endpoints[1])
    n_zones = len(dump.y[_slice])

    # --- Thermodynamics ---
    table['zone'] = np.arange(n_zones)
    table['radius'] = dump.rn[_slice]
    table['column'] = dump.y[_slice]
    table['pressure'] = dump.pn[_slice]
    table['density'] = dump.dn[_slice]
    table['temp'] = dump.tn[_slice]
    # table['heat_flux'] = dump.    # xln?
    table['velocity'] = dump.un[_slice]
    table['opacity'] = dump.xkn[_slice]
    table['energy_rate'] = dump.sburn[_slice]  # snn/sburn?
    table['gamma'] = dump.gamma[_slice]

    # --- Composition ---
    # table['h1'] = dump.abub['h1'][_slice]
    # table['he4'] = dump.abub['he4'][_slice]
    # table['n14'] = dump.abub['n14'][_slice]
    # table['fe54'] = dump.abub['fe54'][_slice]
    table['zbar'] = dump.zbar[_slice]
    table['abar'] = dump.abar[_slice]

    return table
예제 #5
0
def plot_dump_profile(run,
                      batch,
                      source,
                      y_param,
                      x_param='y',
                      cycles=None,
                      basename='xrb',
                      title=None,
                      display=True,
                      prefix='',
                      fontsize=14,
                      marker='',
                      relative=False,
                      xlims=None,
                      ylims=None,
                      legend=True):
    """Plot profile of given cycle dump, for some radial (zonal) quantity

    relative : bool
        plot y-axis relative to first cycle (y_n-y_0)
    """
    fig, ax = plt.subplots()
    cycles = kepler_tools.check_cycles(cycles,
                                       run=run,
                                       batch=batch,
                                       source=source)
    i0 = 2
    i1 = -3
    interp0 = None

    y_label = {'tn': r'$T$', 'xkn': r'$\kappa$'}.get(y_param, y_param)
    y_units = {'tn': 'K', 'xkn': r'cm$^2$ g$^{-1}$'}.get(y_param, '')
    x_label = {'y': 'y'}.get(x_param, x_param)
    x_units = {'y': r'g cm$^{-2}$'}.get(x_param, '')
    yscale = {'tn': 'log', 'xkn': 'linear'}.get(y_param, 'log')
    xscale = {'y': 'log'}.get(y_param, 'log')

    if relative:
        yscale = 'linear'
        dump0 = kepler_tools.load_dump(cycles[0],
                                       run,
                                       batch,
                                       source=source,
                                       basename=basename,
                                       prefix=prefix)
        interp0 = kepler_tools.interp_temp(dump=dump0)
        y_str = r'T - $T_{\#0}$ (K)'
    else:
        y_str = fr'{y_label} ({y_units})'

    for cycle in cycles:
        dump = kepler_tools.load_dump(cycle,
                                      run,
                                      batch,
                                      source=source,
                                      basename=basename,
                                      prefix=prefix)
        profile = kepler_tools.dump_dict(dump)
        x = profile[x_param][i0:i1]
        y = profile[y_param][i0:i1]
        if relative:
            y = y - interp0(x)

        ax.plot(x, y, label=f'#{cycle}', marker=marker)

    if title is None:
        title = f'{source}_{batch}_{run}'
    ax.set_title(title)
    x_str = fr'{x_label} ({x_units})'

    if xlims is not None:
        ax.set_xlim(xlims)
    if ylims is not None:
        ax.set_ylim(ylims)

    ax.set_yscale(yscale)
    ax.set_xscale(xscale)
    ax.set_xlabel(x_str, fontsize=fontsize)
    ax.set_ylabel(y_str, fontsize=fontsize)
    if legend:
        ax.legend()
    plt.tight_layout()

    if display:
        plt.show(block=False)
    return fig