def load_dump(fname, hdr, geom, derived_vars=True, extras=True): dfile = h5py.File(fname, 'r') dump = {} # Carry pointers to header. Saves some pain getting shapes/parameters for plots # Geometry, however, _must be carried separately_ due to size in memory dump['hdr'] = hdr # TODO this necessarily grabs the /whole/ primitives array for key in [key for key in list(dfile['/'].keys()) if key not in ['header', 'extras', 'prims'] ]: dump[key] = dfile[key][()] # TODO should probably error at this one if 't' not in dump: dump['t'] = 0. for name, num in zip(hdr['prim_names'], list(range(hdr['n_prim']))): dump[name] = dfile['prims'][:,:,:,num] if extras and 'extras' in dfile.keys(): # Load the extras. for key in list(dfile['extras'].keys()): dump[key] = dfile['extras/' + key][()] dfile.close() # Recalculate all the derived variables, if we need to if derived_vars: dump['ucon'], dump['ucov'], dump['bcon'], dump['bcov'] = get_state(hdr, geom, dump) dump['bsq'] = (dump['bcon']*dump['bcov']).sum(axis=-1) dump['beta'] = 2.*(hdr['gam']-1.)*dump['UU']/(dump['bsq']) if hdr['has_electrons']: ref = units.get_cgs() dump['Thetae'] = ref['MP']/ref['ME']*dump['KEL']*dump['RHO']**(hdr['gam_e']-1.) dump['ue'] = dump['KEL']*dump['RHO']**(hdr['gam_e']) / (hdr['gam_e']-1.) dump['up'] = dump['UU'] - dump['ue'] dump['TpTe'] = (hdr['gam_p']-1.)*dump['up']/((hdr['gam_e']-1.)*dump['ue']) return dump
def plot_temp(): fig, ax = plt.subplots(1,1, figsize=(FIGX, FIGY)) if avgs[0]['r'][-1] > 50: txlim = [1e0, 1e3] else: txlim = [1e0, 1e2] fit_labs = [] for i,avg in enumerate(avgs): cgs = units.get_cgs() # We can't very well plot a temp we don't know if 'Pg_r' not in avg: return avg['Tp_r'] = cgs['MP'] * avg['Pg_r'] / (cgs['KBOL'] * avg['rho_r']) * cgs['CL']**2 # Add the fits. Aaaaaalll the fits x = avg['r'][i_of(avg['r'], 3):i_of(avg['r'], 30)] y = avg['Tp_r'][i_of(avg['r'], 3):i_of(avg['r'], 30)] coeffs = np.polyfit(np.log(x), np.log(y), deg=1) poly = np.poly1d(coeffs) yfit = lambda xf: np.exp(poly(np.log(xf))) avg['r_fit'] = x avg['Tp_r_fit'] = yfit(x) fit_lab = r"{:.2g} * r^{:.2g}".format(np.exp(coeffs[1]), coeffs[0]) print(labels[i], " Ti fit: ", fit_lab) fit_labs.append(fit_lab) # Plot the profiles themselves plot_multi(ax, 'r', 'Tp_r', r"$<T_{i}>$", logx=True, xlim=txlim, logy=True) plot_multi(ax, 'r_fit', 'Tp_r_fit', r"$<T_{i}>$", logx=True, xlim=txlim, logy=True, label_list=fit_labs, linestyle='--') if len(labels) > 1: ax.legend(loc='lower right') else: ax.set_title(labels[0]) plt.savefig(fname_out + "_Ti.png") plt.close(fig)
# # ################################################################################ from __future__ import print_function, division import os import sys sys.dont_write_bytecode = True sys.path.insert(0, '../script/') sys.path.insert(0, '../script/analysis') from subprocess import call import glob import numpy as np from scipy import optimize import hdf5_to_dict as io import units cgs = units.get_cgs() import util from bhlight import bcall TMP_DIR = 'TMP' util.safe_remove(TMP_DIR) PROBLEM = 'binning' AUTO = '-auto' in sys.argv MPI = '-mpi' in sys.argv if '-idim' in sys.argv: IDIM = int(sys.argv[sys.argv.index('-idim') + 1]) else: IDIM = 0 os.chdir('../prob/' + PROBLEM)
#!/usr/bin/env python # Little script to convert tracer data to a form suitable for PRISM # Author: Jonah Miller ([email protected]) # Based on the work of Matt Mumpower from __future__ import print_function, division import sys; sys.dont_write_bytecode = True import units; cgs = units.get_cgs() import numpy as np import os, shutil, stat from itertools import chain from scipy import integrate,interpolate from subprocess import Popen import hdf5_to_dict as io SMALL = 1e-20 class HomologousExpansion: "Assumes everything in CGS!" power = -3.0 gamma = 5./3. def __init__(self,tlast,rholast,kbTlast,Rlast): self.rho0 = self._get_rho0_homologous(rholast,tlast) self.C_adiabat = self._get_adiabatic_const(kbTlast,rholast) self.R0 = Rlast/tlast def rho(self,t): rho0 = self.rho0 p = self.power return rho0*((t+SMALL)**(p))
#!/usr/bin/env python ################################################################################ # # # Makes a text file from nuLnu from dumps # # # ################################################################################ from __future__ import print_function,division import h5py, argparse import numpy as np from units import get_cgs from scipy import integrate from hdf5_to_dict import get_dumps_full units = get_cgs() def get_data_dump(dumpname): with h5py.File(dumpname,'r') as f: nuLnu = f['nuLnu'].value nth = f['nth'][0] nphi = f['nphi'][0] nubins = f['nubins'][0] numin = f['numin'][0] numax = f['numax'][0] t_unit = f['T_unit'][0] t = f['t'][0]*t_unit R = f['Rout_rad'][0]*f['L_unit'][0] nu = np.zeros(nubins) lnumin = np.log(numin) lnumax = np.log(numax)