def _load_par(self): self.par = pa.get_params(self.files['par']) self.dz = self.par['x3max'] / self.par['Nx3'] * 2 self.Lx = self.par['x1max'] - self.par['x1min'] self.Ly = self.par['x2max'] - self.par['x2min'] self.Lz = self.par['x3max'] - self.par['x3min'] self.area = self.Lx * self.Ly
def doall(base,problem_id,problem_dir=None,do_pickling=True,use_yt=True, force_recal=False, force_redraw=False,vtkdir=None): """ This function will do following tasks: (1) reoranizing files * .hst, .sn --> hst/ * .zprof --> zprof/ * .starpar.vtk --> starpar/ * .rst --> rst/ (2) creating a parameter file from a restart header (3) creating merged (along the time axis) zprof files for each thermal phase (using xarray) (4) creating history data using zprof dumps, including new fields (5) [if do_pickling] creating pickle files for slice and projection (will use yt [if use_yt]) """ if problem_dir is None: problem_dir = problem_id print('preparing metadata for {}...'.format(problem_id)) done=cleanup_directory(base,problem_id,problem_dir=problem_dir) for k in done: if done[k]: print('{}.{} is moved'.format(problem_id,k)) parfile='{}{}/{}.par'.format(base,problem_dir,problem_id) params=pa.get_params(parfile) zpfile='{}{}/zprof_merged/{}.phase5.zprof.nc'.format(base,problem_dir,problem_id) from pyathena.utils import compare_files zpfiles=glob.glob('{}{}/zprof/{}.*.whole.zprof'.format(base,problem_dir,problem_id)) zpfiles.sort() if len(zpfiles) > 0: if not compare_files(zpfiles[-1],zpfile): zprof_to_xarray(base,problem_dir,problem_id) #zpfile='{}{}/zprof_merged/{}.zprof.nc'.format(base,problem_id,problem_id) #if not os.path.isfile(zpfile): merge_xarray(base,problem_id) hstzpfile='{}{}/hst/{}.hst_zp.p'.format(base,problem_dir,problem_id) if os.path.isfile(zpfile): recal_history(base,problem_dir,problem_id) if do_pickling: kwargs={'base_directory':base, 'directory':'{}/'.format(problem_dir), 'id':problem_id, 'parallel':False, 'phase':False, 'rotation':params['Omega']*1.e3, 'range':'' } if use_yt: print('slicing and projecting with yt ...') from pyathena.yt_analysis import yt_analysis yt_analysis.main(force_recal=force_recal,force_redraw=force_redraw,verbose=50,**kwargs) else: if not (vtkdir is None): kwargs['vtk_directory']=vtkdir print('slicing and projecting with pyathena ...') from pyathena.create_pickle import create_all_pickles create_all_pickles(force_recal=force_recal,force_redraw=force_redraw,verbose=True,**kwargs)
def doall(base, problem_id, problem_dir=None, do_pickling=True, use_yt=True): """ do all preprocessing for a model """ if problem_dir is None: problem_dir = problem_id print('preparing metadata for {}...'.format(problem_id)) done = cleanup_directory(base, problem_id, problem_dir=problem_dir) for k in done: if done[k]: print('{}.{} is moved'.format(problem_id, k)) parfile = '{}{}/{}.par'.format(base, problem_dir, problem_id) params = pa.get_params(parfile) zpfile = '{}{}/zprof_merged/{}.whole.zprof.nc'.format( base, problem_dir, problem_id) from pyathena.utils import compare_files zpfiles = glob.glob('{}{}/zprof/{}.*.whole.zprof'.format( base, problem_dir, problem_id)) zpfiles.sort() if not compare_files(zpfiles[-1], zpfile): zprof_to_xarray(base, problem_dir, problem_id) #zpfile='{}{}/zprof_merged/{}.zprof.nc'.format(base,problem_id,problem_id) #if not os.path.isfile(zpfile): merge_xarray(base,problem_id) hstzpfile = '{}{}/hst/{}.hst_zp.p'.format(base, problem_dir, problem_id) if os.path.isfile(zpfile): recal_history(base, problem_dir, problem_id) if do_pickling: kwargs = { 'base_directory': base, 'directory': '{}/'.format(problem_dir), 'id': problem_id, 'parallel': False, 'phase': False, 'rotation': params['Omega'] * 1.e3, 'range': '' } if use_yt: print('slicing and projecting with yt ...') from pyathena.yt_analysis import yt_analysis yt_analysis.main(force_recal=False, force_redraw=False, verbose=50, **kwargs) else: print('slicing and projecting with pyathena ...') from pyathena.create_pickle import create_all_pickles create_all_pickles(force_recal=False, force_redraw=False, verbose=True, **kwargs)
def recal_history(base, problem_dir, problem_id): parfile = '{}{}/{}.par'.format(base, problem_dir, problem_id) params = pa.get_params(parfile) hstfile = '{}{}/hst/{}.hst'.format(base, problem_dir, problem_id) hst = pa.hst_reader(hstfile) hstrecalfile = '{}_cal.p'.format(hstfile) h = processing_history_dump(hst, params, hstrecalfile) snfile = '{}{}/hst/{}.sn'.format(base, problem_dir, problem_id) sn = pa.hst_reader(snfile) rates = recal_rates(h, sn, base, problem_dir, problem_id) hstzpfile = '{}_zp.p'.format(hstfile) zprof_ds = merge_xarray(base, problem_dir, problem_id) #print("zprof dataset is loaded") h_zp = processing_zprof_dump(h, rates, params, zprof_ds, hstzpfile)
def print_info(parfile, h, h_zp, pid=None, outdir='./'): if pid is None: problem_id = os.path.basename(parfile).replace('.par', '') else: problem_id = pid params = pa.get_params(parfile) with open('{}/mds/{}.md'.format(outdir, problem_id), 'w') as fp: fp.write('## {}\n'.format(problem_id)) # gas info fp.write('### INITIAL CONDITIONS\n') fp.write( '* Surface Density of Gas (M_sun/pc^2): {surf}\n'.format(**params)) fp.write('* Surface Density of Stars (M_sun/pc^2): {SurfS}\n'.format( **params)) fp.write('* Scale Heights of Stars (pc): {zstar}\n'.format(**params)) fp.write('* Midplane density of DM (M_sun/pc^3): {rhodm}\n'.format( **params)) fp.write('* Galactocentric Distance (pc): {R0}\n'.format(**params)) fp.write('* Galactic Rotation (km/s/pc): {Omega}\n'.format(**params)) fp.write('* Nscalars (Metal tracers): {nscalars}\n'.format(**params)) # domain info fp.write('\n### DOMAIN\n') for i in range(3): params['Lx{:d}'.format(i + 1)] = params['x{:d}max'.format( i + 1)] - params['x{:d}min'.format(i + 1)] params['dx{:d}'.format(i + 1)] = params['Lx{:d}'.format( i + 1)] / params['Nx{:d}'.format(i + 1)] params['Lx{:d}'.format(i + 1)] = int(params['Lx{:d}'.format(i + 1)]) params['dx{:d}'.format(i + 1)] = int(params['dx{:d}'.format(i + 1)]) params['Nx{:d}'.format(i + 1)] = int(params['Nx{:d}'.format(i + 1)]) fp.write('* Lx: {Lx1} x {Lx2} x {Lx3}\n'.format(**params)) fp.write('* Nx: {Nx1} x {Nx2} x {Nx3}\n'.format(**params)) fp.write('* dx: {dx1} x {dx2} x {dx3}\n'.format(**params)) # perturbation info fp.write('\n### SNe\n') params['runaways'] = False if 'fbin' in params: if params['fbin'] > 0: params['runaways'] = True params['random_SN_driving'] = False if 'snrate_random' in params: if (params['iprob'] == 5) & (params['snrate_random'] > 0): params['random_SN_driving'] = True #params['turb_driving']=False #if params.has_key('dedt'): # if (params['dedt'] >0) & ((params['iprob'] ==4) | (params['iprob'] == 5)): params['turb_driving']=True # tdrive = params['driving_time'] params['Ia_SN'] = False if 'Ia_amp' in params: if (params['Ia_amp'] == 1): params['Ia_SN'] = True for k in ['runaways', 'Ia_SN', 'random_SN_driving']: fp.write('* {}: {}\n'.format(k, params[k])) fp.write('\n### Movies\n') fp.write( '* [Slice](../movies/{}_slice_proj.mp4)\n\n'.format(problem_id)) fp.write('* [Surface Density](../movies/{}_surf.mp4)\n\n'.format( problem_id)) fp.write('\n### History\n') fp.write('* `{}`\n\n'.format(h)) fp.write('* `{}`\n\n'.format(h_zp)) fp.write('![{} history](../figures/{}-history.png)\n'.format( problem_id, problem_id)) print('output: {}/mds/{}.md'.format(outdir, problem_id))
if os.path.isdir(dd): if os.path.isdir(dd + '/slice/'): ids.append(os.path.basename(dd)) if narg > 3: overwrite = eval(sys.argv[3]) else: overwrite = False for pid in ids: print(pid) if os.path.isdir('{}{}/slab/'.format(base, pid)): pdir = '{}/slab/'.format(pid) else: pdir = pid + '/' par = get_params('{}{}{}.par'.format(base, pdir, pid)) if 'pattern' in par: vy0 = par['Omega'] * (1.0 - par['pattern']) * par['R0'] print('v_y,circ = {}'.format(vy0)) else: vy0 = 0.0 slc_files = glob.glob('{}{}/slice/{}.????.slice.p'.format(base, pdir, pid)) slc_files.sort() nf = len(slc_files) aux = set_aux.set_aux(pid) aux_surf = aux['surface_density'] if system == 'tigress_rps': field_list = [ 'star_particles', 'surface_density', 'specific_scalar3_proj', 'nH', 'specific_scalar3', 'temperature', 'pok', 'ram_pok_z' ]