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')
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')
def extract_batches(source, batches=None, save_plots=True, multithread=True, reload=False, load_bursts=False, load_summary=False, basename='xrb', param_table=None): """Do burst analysis on arbitrary number of batches""" t0 = time.time() if param_table is not None: print('Using models from table provided') batches = np.unique(param_table['batch']) else: batches = grid_tools.ensure_np_list(batches) for batch in batches: print_title(f'Batch {batch}') analysis_path = grid_strings.batch_analysis_path(batch, source) for folder in ['input', 'output']: path = os.path.join(analysis_path, folder) grid_tools.try_mkdir(path, skip=True) if param_table is not None: subset = grid_tools.reduce_table(param_table, params={'batch': batch}) runs = np.array(subset['run']) else: n_runs = grid_tools.get_nruns(batch, source) runs = np.arange(n_runs) + 1 if multithread: args = [] for run in runs: args.append((run, batch, source, save_plots, reload, load_bursts, load_summary, basename)) with mp.Pool(processes=8) as pool: pool.starmap(extract_runs, args) else: extract_runs(runs, batch, source, reload=reload, save_plots=save_plots, load_bursts=load_bursts, load_summary=load_summary, basename=basename) print_title('Combining run tables') for table_name in ('summary', 'bursts'): burst_tools.combine_run_tables(batch, source, table_name=table_name) t1 = time.time() dt = t1 - t0 print_title(f'Time taken: {dt:.1f} s ({dt/60:.2f} min)')
def get_table_filepath(source, version, try_mkdir=False): """Returns filepath of synth table """ path = grid_strings.get_obs_data_path(source) if try_mkdir: grid_tools.try_mkdir(path, skip=True) filename = f'synth_{source}_{version}.txt' return os.path.join(path, filename)
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)
def load_save(load_filepath, save_filepath): lum_loaded = extract_lcdata(filepath=load_filepath, silent=silent) if save: grid_tools.try_mkdir(input_path, skip=True, verbose=False) save_ascii(lum=lum_loaded, filepath=save_filepath, verbose=verbose) return lum_loaded