Esempio n. 1
0
def save_comps(run, batch, source, dumpfiles, zero_times=True, cycles=None, times=None):
    """Iterate through cycles and save temperature profile plots
    """
    batch_str = grid_strings.get_batch_string(batch, source)
    path = os.path.join(grid_strings.plots_path(source), 'composition', batch_str, str(run))
    grid_tools.try_mkdir(path, skip=True)

    cycles = kepler_tools.check_cycles(cycles, run=run, batch=batch, source=source)

    if times is None:
        times = kepler_tools.get_cycle_times(cycles, run=run, batch=batch, source=source)
    if zero_times:
        times = times - times[0]

    for i, cycle in enumerate(cycles):
        kepler_tools.print_cycle_progress(cycle=cycle, cycles=cycles, i=i,
                                          prefix='Saving plots: ')
        # dumpfile = kepler_tools.load_dump(cycle, run, batch, source=source,
        #                                   basename='xrb')
        dumpfile = dumpfiles[cycle]
        title = f'cycle={cycle},  t={times[i]:.6f}'
        fig = kepler_plot.plot_composition_profile(dumpfile, title=title, display=False)

        filename = f'composition_{source}_{batch}_{run}_{i:04}.png'
        filepath = os.path.join(path, filename)
        fig.savefig(filepath)
        plt.close('all')
Esempio n. 2
0
def save_temps(run, batch, source, zero_times=True, cycles=None,
               ylims=(2e7, 1.5e9), xlims=(2e12, 1e3), times=None, **kwargs):
    """Iterate through cycles and save temperature profile plots
    """
    batch_str = grid_strings.get_batch_string(batch, source)
    path = os.path.join(grid_strings.plots_path(source), 'temp', batch_str, str(run))
    grid_tools.try_mkdir(path, skip=True)

    cycles = kepler_tools.check_cycles(cycles, run=run, batch=batch, source=source)
    if times is None:
        times = kepler_tools.get_cycle_times(cycles, run=run, batch=batch, source=source)

    if zero_times:
        times = times - times[0]

    for i, cycle in enumerate(cycles):
        kepler_tools.print_cycle_progress(cycle=cycle, cycles=cycles, i=i,
                                          prefix='Saving plots: ')
        title = f'cycle={cycle},  t={times[i]:.6f}'
        fig = kepler_plot.plot_dump_profile(cycles=[cycle], run=run, batch=batch,
                                            source=source, title=title, y_param='tn',
                                            display=False, ylims=ylims, xlims=xlims,
                                            **kwargs)

        filename = f'temp_{source}_{batch}_{run}_{i:04}.png'
        filepath = os.path.join(path, filename)
        fig.savefig(filepath)
        plt.close('all')
Esempio n. 3
0
def load_lum(run, batch, source, basename='xrb', reload=False, save=True,
             silent=True, check_monotonic=True):
    """Attempts to load pre-extracted luminosity data, or load raw binary.
    Returns [time (s), luminosity (erg/s)]
    """
    def load_save(load_filepath, save_filepath):
        lum_loaded = extract_lcdata(filepath=load_filepath, silent=silent)
        if save:
            try:
                save_ascii(lum=lum_loaded, filepath=save_filepath)
            except FileNotFoundError:
                print("Can't save preloaded luminosity file, path not found")
        return lum_loaded

    pyprint.print_dashes()
    batch_str = grid_strings.get_batch_string(batch, source)
    analysis_path = grid_strings.get_source_subdir(source, 'burst_analysis')
    input_path = os.path.join(analysis_path, batch_str, 'input')

    presaved_filepath = os.path.join(input_path, f'{batch_str}_{run}.txt')
    run_str = grid_strings.get_run_string(run, basename)
    model_path = grid_strings.get_model_path(run, batch, source, basename)
    binary_filepath = os.path.join(model_path, f'{run_str}.lc')
    print(binary_filepath)
    if reload:
        print('Deleting preloaded file, reloading binary file')
        subprocess.run(['rm', '-f', presaved_filepath])
        try:
            lum = load_save(binary_filepath, presaved_filepath)
        except FileNotFoundError:
            print('XXXXXXX lumfile not found. Skipping XXXXXXXX')
            return
    else:
        try:
            lum = load_ascii(presaved_filepath)
        except (FileNotFoundError, OSError):
            print('No preloaded file found. Reloading binary')
            try:
                lum = load_save(binary_filepath, presaved_filepath)
            except FileNotFoundError:
                print('XXXXXXX lumfile not found. Skipping XXXXXXX')
                return

    if check_monotonic:
        dt = np.diff(lum[:, 0])
        if True in (dt < 0):
            pyprint.print_warning('Lightcurve timesteps are not in order. '
                                  + 'Something has gone horribly wrong!', n=80)
            raise RuntimeError('Lightcurve timesteps are not in order')
    pyprint.print_dashes()
    return lum
Esempio n. 4
0
def load_dump(cycle,
              run,
              batch,
              source,
              basename='xrb',
              prefix='',
              verbose=False):
    batch_str = grid_strings.get_batch_string(batch, source)
    run_str = grid_strings.get_run_string(run, basename)
    filename = get_dump_filename(cycle, run, basename, prefix=prefix)

    filepath = os.path.join(MODELS_PATH, batch_str, run_str, filename)
    printv(f'Loading: {filepath}', verbose=verbose)
    return kepdump.load(filepath, graphical=False, silent=True)
Esempio n. 5
0
def save_table(table, table_name, run, batch, source, basename='xrb',
               subdir=''):
    """Save provided table to oscillations project
    """
    source_path = os.path.join(PROJECT_PATH, source)
    batch_str = grid_strings.get_batch_string(batch, source)
    run_str = get_run_string(run, basename)

    run_path = os.path.join(source_path, batch_str, run_str, subdir)
    grid_tools.try_mkdir(run_path, skip=True)

    filename = f'{table_name}.txt'
    filepath = os.path.join(run_path, filename)
    print(f'Saving: {filepath}')

    table_str = table.to_string(index=False, justify='left')
    with open(filepath, 'w') as f:
        f.write(table_str)
Esempio n. 6
0
def copy_lightcurve(run, batch, source, basename='xrb'):
    """Copies over full model lightcurve
    """
    dashes()
    print('Copying model lightcurve')

    path = grid_strings.get_source_subdir(source, 'burst_analysis')
    batch_str = grid_strings.get_batch_string(batch, source)
    run_str = get_run_string(run, basename)
    model_string = grid_strings.get_model_string(run=run,
                                                 batch=batch,
                                                 source=source)

    filename = f'{model_string}.txt'
    filepath = os.path.join(path, batch_str, 'input', filename)

    target_filename = f'model_lightcurve_{model_string}'
    target_filepath = os.path.join(PROJECT_PATH, source, batch_str, run_str,
                                   target_filename)

    print(f'from: \n{filepath}' + f'to: {target_filepath}')
    subprocess.run(['cp', filepath, target_filepath])
Esempio n. 7
0
def batch_path(batch, source='frank'):
    """Returns string of path to batch dir
    """
    path = grid_strings.get_source_subdir(source, 'profiles')
    batch_str = grid_strings.get_batch_string(batch=batch, source=source)
    return os.path.join(path, batch_str)