def get_raw_data(self, **kwargs): """Returns raw **not rotated** particle data in dictionary. """ for key, val in kwargs.items(): exec('globals()["' + key + '"]' + '=val') # choose which particle_data to load sim_types if data == 'sim': names = self.sim_names if data == 'ISM': names = self.ISM_names # make empty container for pandas data collection = {} # collect all data into container for key, name in names.items(): if data == 'sim': data1 = aux.load_temp_file(gal_ob=self.gal_ob, sim_type=key) if data == 'ISM': data1 = aux.load_temp_file(gal_ob=self.gal_ob, ISM_phase=key) collection[key] = data1 return collection
def __get_dc_phase(self, **kwargs): """Returns datacube as a numpy array. Parameters ---------- ISM_dc_phase : str default: 'GMC' target : str default: 'L_CII' Returns ------- A numpy array or 0 if no datacube was found """ for key, val in kwargs.items(): exec('globals()["' + key + '"]' + '=val') dc = 0 dc = aux.load_temp_file(gal_ob=self.gal_ob, target=target, ISM_dc_phase=ISM_dc_phase) try: dc = aux.load_temp_file(gal_ob=self.gal_ob, target=target, ISM_dc_phase=ISM_dc_phase) except: pass return dc
def setup_tasks(self): """Controls tasks to be executed, based on existing files and the overwrite [ow] parameter """ self.gal_ob = dict(zred=self.zred, galname=self.name, gal_index=self.gal_index) # If overwriting, do all subgridding if ow: self.do_interpolate_GMCs = True self.do_interpolate_dif = True print('Overwrite is ON') # If not overwriting, check if subgridding has been done if not ow: self.do_interpolate_GMCs = True self.do_interpolate_dif = True # Check for GMCs GMCgas = aux.load_temp_file(gal_ob=self.gal_ob, ISM_phase='GMC') if type(GMCgas) != int: if 'L_CII' in GMCgas.keys(): self.do_interpolate_GMCs = False # Check for diffuse gas difgas = aux.load_temp_file(gal_ob=self.gal_ob, ISM_phase='dif') if type(difgas) != int: if 'L_CII_DNG' in difgas.keys(): self.do_interpolate_dif = False print('Overwrite is OFF, will do:') if self.do_interpolate_GMCs: print('- Interpolate in cloud models for GMCs') if self.do_interpolate_dif: print( '- Interpolate in cloud models for diffuse gas clouds (DNG and DIG)' ) if self.do_interpolate_GMCs + self.do_interpolate_dif == 0: print('Nothing!')
def add_Z_map(self, **kwargs): """Adds metallicity map as numpy array to particle data object, if not stored already in sigame/temp/maps/metallicity/. """ # handle default args and kwargs args = dict(ow=False) args = aux.update_dictionary(args, kwargs) for key in args: exec(key + '=args[key]') for key in args: exec(key + '=args[key]') file_location = aux.get_file_location(gal_ob=self.gal_ob, map_type='Z') if os.path.exists(file_location): print('Particle data object already has Z map - loading') if kwargs['ow'] == True: Z_map = self.get_Z_map(**kwargs) print('aa') setattr( self, 'Z_map', aux.load_temp_file(gal_ob=self.gal_ob, map_type='Z')['data'][0]) else: print( 'Z map not stored for this particle data object, creating it. ' ) Z_map = self.get_Z_map(**kwargs) setattr(self, 'Z_map', Z_map)
def add_dif(self): '''Generates diffuse gas clouds and creates new dif particle data file for a galaxy. ''' print('\nCREATING DIFFUSE GAS CLOUDS FOR THIS GALAXY') simgas = aux.load_temp_file(gal_ob=self.gal_ob, sim_type='gas') # TEST # simgas = simgas[0:1000] # Start new dataframe with only the diffuse gas difgas = simgas.copy() difgas['m'] = simgas['m'].values * (1. - simgas['f_H21'].values) print('Total gas mass in galaxy: %.2e Msun' % (sum(simgas['m']))) print('Diffuse gas mass in galaxy: %.2e Msun' % (sum(difgas['m']))) print('in percent: %.2f %%' % (sum(difgas['m']) / sum(simgas['m']) * 100.)) # Set radius of diffuse gas clouds difgas['R'] = difgas['h'] # Calculate density of diffuse gas clouds [Hydrogen atoms per cm^3] difgas['nH'] = 0.75 * np.array( difgas['m'], dtype=np.float64) / (4 / 3. * np.pi * np.array( difgas['R'], dtype=np.float64)**3.) * Msun / mH / kpc2cm**3 # Set nH and R to zero when there is no mass mask = difgas.m == 0 difgas.loc[mask, 'nH'] = 0 difgas.loc[mask, 'R'] = 0 # Store new difgas file aux.save_temp_file(difgas, gal_ob=self.gal_ob, ISM_phase='dif')
def setup_tasks(self): '''Controls tasks to be executed, based on existing files and the overwrite [ow] parameter ''' self.gal_ob = dict(zred=self.zred, galname=self.name, gal_index=self.gal_index) # If overwriting, do all subgridding if ow: self.do_FUV = True self.do_P_ext = True self.do_GMCs = True self.do_dif = True print('Overwrite is ON') # If not overwriting, check if subgridding has been done if not ow: self.do_FUV = False self.do_P_ext = False self.do_GMCs = False self.do_dif = False # Check for FUV and P_ext simgas = aux.load_temp_file(gal_ob=self.gal_ob, sim_type='gas') if 'FUV' not in simgas.keys(): self.do_FUV = True if 'P_ext' not in simgas.keys(): self.do_P_ext = True # Check for GMCs GMCgas = aux.load_temp_file( gal_ob=self.gal_ob, ISM_phase='gmc' ) #self.particle_data.get_raw_data(data='ISM')['GMC'] if type(GMCgas) == int: self.do_GMCs = True # Check for dif difgas = aux.load_temp_file( gal_ob=self.gal_ob, ISM_phase='dif' ) #self.particle_data.get_raw_data(data='ISM')['dif'] if type(difgas) == int: self.do_dif = True print('Overwrite is OFF, will do:') if self.do_FUV: print('- Add FUV') if self.do_P_ext: print('- Add P_ext') if self.do_GMCs: print('- Create GMCs') if self.do_dif: print('- Create diffuse gas clouds') if self.do_FUV + self.do_P_ext + self.do_GMCs + self.do_dif == 0: print('Nothing!')
def interpolate_dif(self): """Adds info from cloud model runs to diffuse gas clouds """ print('\nADDING EMISSION INFO TO DIFFUSE GAS IN THIS GALAXY') difgas = aux.load_temp_file(gal_ob=self.gal_ob, ISM_phase='dif') # Get diffuse background FUV to use for this galaxy (OLD WAY) self.UV_str = aux.get_UV_str(z1, self.SFRsd) # Load cloudy model grid: cloudy_grid_param = pd.read_pickle(d_cloudy_models + 'difgrid_' + self.UV_str + 'UV' + ext_DIFFUSE + '_' + z1 + '.param') cloudy_grid = pd.read_pickle(d_cloudy_models + 'difgrid_' + self.UV_str + 'UV' + ext_DIFFUSE + '_' + z1 + '_em.models') difgas_new = aux.interpolate_in_dif_models(difgas, cloudy_grid_param, cloudy_grid) aux.save_temp_file(difgas_new, gal_ob=self.gal_ob, ISM_phase='dif')
def interpolate_GMCs(self): """Adds info from cloud model runs to GMCs """ print('\nADDING EMISSION INFO TO GMCs IN THIS GALAXY') GMCgas = aux.load_temp_file(gal_ob=self.gal_ob, ISM_phase='GMC', verbose=True) # Load cloudy model grid: cloudy_grid_param = pd.read_pickle(d_cloudy_models + 'GMCgrid' + ext_DENSE + '_' + z1 + '.param') cloudy_grid_param['ms'] = cloudy_grid_param['Mgmcs'] cloudy_grid = pd.read_pickle(d_cloudy_models + 'GMCgrid' + ext_DENSE + '_' + z1 + '_em.models') # print(cloudy_grid_param['Mgmcs']) # print(cloudy_grid.shape) GMCgas_new = aux.interpolate_in_GMC_models(GMCgas, cloudy_grid_param, cloudy_grid) aux.save_temp_file(GMCgas_new, gal_ob=self.gal_ob, ISM_phase='GMC')
def __create_file(self, **kwargs): # create empty container for global_results GR = {} extracted_gals = pd.read_pickle(d_temp + 'galaxies/%s_extracted_gals' % z1) zreds, galnames = extracted_gals['zreds_unsorted'], extracted_gals[ 'galnames_unsorted'] GR['galnames'] = galnames GR['zreds'] = zreds GR['N_gal'] = len(galnames) # convert DF to DataFrame GR = pd.DataFrame(GR) # add un-populated targets to DF targets = [ 'R_gal', 'M_gas', 'M_star', 'M_GMC', 'M_dense', 'M_dm', 'SFR', 'SFRsd', 'Zsfr' ] N_gal = GR.shape[0] for target in targets: GR[target] = np.zeros(N_gal) # collect sim data for i, zred, galname in zip(range(N_gal), zreds, galnames): # get data gal_ob = dict(galname=galname, zred=zred, gal_index=i) # dummy gal object simgas = aux.load_temp_file(gal_ob=gal_ob, sim_type='gas', gal_ob_present=True) simstar = aux.load_temp_file(gal_ob=gal_ob, sim_type='star', gal_ob_present=True) simdm = aux.load_temp_file(gal_ob=gal_ob, sim_type='dm', gal_ob_present=True) # check if f_H21 is there, if not, make a copy so the rest of the code works (temporary fix): if 'f_H21' not in simgas.keys(): simgas['f_H21'] = simgas['f_H2'].values gal_ob = dict(galname=galname, zred=zred, gal_index=i + 1) # dummy gal object aux.save_temp_file(simgas, gal_ob=gal_ob, sim_type='gas', gal_ob_present=True) # get radii r_gas = np.sqrt( sum([simgas[x].values**2. for x in ['x', 'y', 'z']])) r_star = np.sqrt( sum([simstar[x].values**2. for x in ['x', 'y', 'z']])) # set R_gal rmax = np.max(r_gas) GR.at[i, 'R_gal'] = rmax # set M_* # mask = r_star < rmax # age = simstar['age'].values[mask] # m_stars = simstar['m'].values[mask] age = simstar['age'].values m_stars = simstar['m'].values GR.at[i, 'M_star'] = np.sum(m_stars) GR.at[i, 'M_dm'] = np.sum(simdm['m'].values) GR.at[i, 'M_gas'] = np.sum(simgas['m'].values) GR.at[i, 'f_dense'] = (np.sum( simgas['m'].values * simgas['f_H21'].values)) / np.sum( simgas['m'].values) # ratios and metalicities if np.sum(m_stars) <= 0.5: print(i) import pdb pdb.set_trace() GR.at[i, 'mw_age'] = (np.sum(age * m_stars) / np.sum(m_stars) ) # mass-weighted age GR.at[i, 'SFR'] = np.sum(m_stars[age < 100.]) / 100e6 GR.at[i, 'SFRsd'] = GR.SFR[i] / (np.pi * rmax**2.) GR.at[i, 'Zsfr'] = np.sum( simgas['Z'].values * (simgas['SFR'].values + 1.e-8)) / np.sum(simgas['SFR'].values + 1.e-8) for attr in ['lum_dist', 'M_dense', 'M_GMC', 'M_dif', 'Zmw']: GR = self.__set_attr(GR, attr) for line in lines: GR = self.__set_attr(GR, 'L_' + line) # # set M_tot # DF['M_tot'] = DF['M_gas'].values + DF['M_star'].values + DF['M_dm'].values # Only consider galaxies with a SFR > 0 GR = GR[GR['SFR'] > 0].reset_index(drop=True) # If z=0, only consider low-z galaxies (out to ~ 100 Mpc) if z1 == 'z0': GR = GR[GR['zreds'] < 0.04].reset_index(drop=True) # sort DF by stellar mass GR = GR.sort_values('M_star').reset_index(drop=True) # Make sure we only extract a sample of size nGal # GR = GR[0:nGal] # save DF of global results filename = self.__get_file_location() GR.to_pickle(filename) return GR
def __set_attr(self, GR_int, attr): # Get missing attributes for gal_index in range(0, GR_int['N_gal'][0]): gal_ob = dict(galname=GR_int['galnames'][gal_index], zred=GR_int['zreds'][gal_index], gal_index=gal_index) # dummy gal object if attr == 'lum_dist': LD = aux.get_lum_dist(GR_int['zreds']) GR_int['lum_dist'] = LD if attr == 'M_GMC': if gal_index == 0: M_GMC = np.zeros( GR_int['N_gal'] [0]) # get length of sample, only once (ugly method) GMCgas = aux.load_temp_file(gal_ob=gal_ob, verbose=False, ISM_phase='GMC') if type(GMCgas) != int: M_GMC[gal_index] = np.sum(GMCgas['m']) GR_int['M_GMC'] = M_GMC if attr == 'M_dense': if gal_index == 0: M_dense = np.zeros( GR_int['N_gal'] [0]) # get length of sample, only once (ugly method) simgas = pd.read_pickle( aux.get_file_location(gal_ob=gal_ob, sim_type='gas', gal_ob_present=True)) # simgas = aux.load_temp_file(gal_ob=gal_ob, verbose=False, sim_type='gas') if type(simgas) != int: M_dense[gal_index] = np.sum(simgas['m'].values * simgas['f_H21'].values) GR_int['M_dense'] = M_dense if attr == 'M_dif': if gal_index == 0: M_dif = np.zeros(GR_int['N_gal'][0]) difgas = aux.load_temp_file(gal_ob=gal_ob, verbose=False, ISM_phase='dif') if type(difgas) != int: M_dif[gal_index] = np.sum(difgas['m']) GR_int['M_dif'] = M_dif if attr == 'Zmw': if gal_index == 0: Zmw = np.zeros(GR_int['N_gal'][0]) difgas = aux.load_temp_file(gal_ob=gal_ob, verbose=False, ISM_phase='dif') GMCgas = aux.load_temp_file(gal_ob=gal_ob, verbose=False, ISM_phase='GMC') if (type(difgas) != int) & (type(GMCgas) != int): Zmw[gal_index] = np.sum( (difgas['Z'] * difgas['m'] + difgas['Z'] * difgas['m']) / (np.sum(difgas['m']) + np.sum(GMCgas['m']))) GR_int['Zmw'] = Zmw if 'L_' in attr: if gal_index == 0: L = np.zeros(GR_int['N_gal'][0]) L_DNG = np.zeros(GR_int['N_gal'][0]) L_DIG = np.zeros(GR_int['N_gal'][0]) # from GMCs GMCgas = aux.load_temp_file(gal_ob=gal_ob, verbose=False, ISM_phase='GMC') if type(GMCgas) != int: try: L[gal_index] = np.sum(GMCgas[attr].values) except: L[gal_index] = 0 GR_int[attr + '_GMC'] = L # from dif difgas = aux.load_temp_file(gal_ob=gal_ob, verbose=False, ISM_phase='dif') if type(difgas) != int: try: L_DNG[gal_index] = np.sum(difgas[attr + '_DNG'].values) L_DIG[gal_index] = np.sum(difgas[attr + '_DIG'].values) except: L_DNG[gal_index] = 0 L_DIG[gal_index] = 0 GR_int[attr + '_DNG'] = L_DNG GR_int[attr + '_DIG'] = L_DIG GR_int[attr] = L + L_DNG + L_DIG return (GR_int)
def add_GMCs(self): '''Generates GMCs and creates new GMC particle data file for a galaxy. ''' print('\nSPLITTING DENSE GAS INTO GMCs FOR THIS GALAXY') simgas = aux.load_temp_file(gal_ob=self.gal_ob, sim_type='gas', verbose=True) # Checking that the sim gas data has what we need if 'P_ext' not in simgas.keys(): print('\nExternal pressure not calculated, doing so now') self.add_P_ext() if 'FUV' not in simgas.keys(): print('\nFUV radiation field not calculated, doing so now') self.add_FUV() simgas = simgas[['Z','a_C','a_Ca','a_Fe','a_He','a_Mg','a_N','a_Ne','a_O','a_S','a_Si','f_H21','f_HI1','f_neu','m','h',\ 'vx','vy','vz','x','y','z','FUV','CR','P_ext','surf_gas','surf_star','sigma_gas','sigma_star','vel_disp_gas']] # TEST # simgas = simgas[0:100] # Neutral (dense) gas mass Mneu = simgas['m'].values * simgas['f_H21'].values print('Number of particles with enough dense mass: %s' % (len(simgas.loc[Mneu > 1e4]['m']))) print('Out of: %s' % (len(simgas))) print('Dense gas mass fraction out of total ISM mass: %s %%' % (np.sum(Mneu) / np.sum(simgas['m']) * 100.)) if len(Mneu[Mneu > 1e4]) == 0: print( " No dense gas w/ mass > 10^4 Msun. Skipping subgrid for this galaxy." ) pdb.set_trace() print('Min and max particle dense gas mass: %s Msun' % (np.min(Mneu[Mneu > 0])) + ' ' + str(np.max(Mneu))) print('Throwing away this much gas mass: %s Msun' % (np.sum(Mneu[Mneu < 1e4]))) print('In percent: %s %%' % (np.sum(Mneu[Mneu < 1e4]) / np.sum(Mneu))) # Create mass spectrum (probability function = dN/dM normalized) b = 1.8 # MW powerlaw slope [Blitz+07] if ext_DENSE == '_b3p0': b = 3.0 # outer MW and M33 powerlaw slope [Rosolowsky+05, Blitz+07] if ext_DENSE == '_b1p5': b = 1.5 # inner MW powerlaw slope [Rosolowsky+05, Blitz+07] print('Powerlaw slope for mass spectrum (beta) used is %s' % b) Mmin = 1.e4 # min mass of GMC Mmax = np.max(Mneu) # max mass of GMC tol = Mmin # precision in reaching total mass nn = 100 # max draw of masses in each run n_elements = simgas.size simgas = simgas[Mneu > 1e4] # Cut out those with masses < 1e4 !! Mneu = Mneu[Mneu > 1e4] h = simgas['h'].values simgas.index = range(0, len(simgas)) if N_cores == 1: print('(Not using multiprocessing - 1 core in use)') f1, Mgmc, newx, newy, newz = aux.GMC_generator( np.arange(0, len(simgas)), Mneu, h, Mmin, Mmax, b, tol, nn, N_cores) GMCs = [f1, Mgmc, newx, newy, newz] print('(Done!)') print('Append results to new dataframe') GMCgas = pd.DataFrame() Mgmc = np.array([]) newx = np.array([]) newy = np.array([]) newz = np.array([]) part = 0.1 for i in range(0, len(simgas)): Mgmc = np.append(Mgmc, GMCs[1][i]) # appending mass newx = np.append(newx, simgas.loc[i]['x'] + GMCs[2][i]) # appending x position newy = np.append(newy, simgas.loc[i]['y'] + GMCs[3][i]) # appending y position newz = np.append(newz, simgas.loc[i]['z'] + GMCs[4][i]) # appending z position for ii in range(0, int(GMCs[0][i])): # For each GMC created, duplicate remaining sim gas particle properties GMCgas = pd.DataFrame.append(GMCgas, simgas.loc[i], ignore_index=True) if 1. * i / len(simgas) > part: percent = np.floor(1. * i / len(simgas) * 10.) * 10. print('%s %% done!' % percent) part = percent / 100. + 0.1 try: GMCgas['m'] = Mgmc except: print(Mgmc) pdb.set_trace() if N_cores > 1: print('(Multiprocessing starting up! %s cores in use)' % N_cores) pool = mp.Pool(processes=N_cores) np.random.seed( len(simgas) ) # so we don't end up with the same random numbers for every galaxy results = [ pool.apply_async(aux.GMC_generator, ( [i], Mneu, h, Mmin, Mmax, b, tol, nn, N_cores, )) for i in range(0, len(simgas)) ] pool.close() pool.join() GMCs = [p.get() for p in results] GMCs.sort(key=lambda x: x[0]) print('(Multiprocessing done!)') print('Append results to new dataframe') GMCgas = pd.DataFrame() Mgmc = np.array([]) newx = np.array([]) newy = np.array([]) newz = np.array([]) part = 0.1 for i in range(0, len(simgas)): # For each sim gas particle with enough dense gas, add GMCs created # pdb.set_trace() Mgmc = np.append(Mgmc, GMCs[i][2]) # appending mass newx = np.append(newx, simgas.loc[i]['x'] + GMCs[i][3]) # appending x position newy = np.append(newy, simgas.loc[i]['y'] + GMCs[i][4]) # appending y position newz = np.append(newz, simgas.loc[i]['z'] + GMCs[i][5]) # appending z position for i1 in range(0, int(GMCs[i][1])): # For each GMC created, duplicate remaining sim gas particle properties GMCgas = pd.DataFrame.append(GMCgas, simgas.loc[i], ignore_index=True) # Keep track of GMCs added if 1. * i / len(simgas) > part: percent = np.floor(1. * i / len(simgas) * 10.) * 10. print('%s %% done!' % percent) part = percent / 100. + 0.1 try: GMCgas['m'] = Mgmc except: print(Mgmc) pdb.set_trace() GMCgas['x'] = newx GMCgas['y'] = newy GMCgas['z'] = newz GMCgas['Rgmc'] = (GMCgas['m'] / 290.0)**(1.0 / 2.0) print('Mass of all GMCs created: %.2e - should not exceed:' % np.sum(GMCgas['m'])) print('Total neutral gas: %.2e ' % np.sum(Mneu)) print(np.min(GMCgas['Rgmc']), np.max(GMCgas['Rgmc'])) print(str(len(GMCgas)) + ' GMCs created!') # Store new GMCgas file # GMCgas.metadata = {'beta':b} aux.save_temp_file(GMCgas, gal_ob=self.gal_ob, ISM_phase='GMC')
def add_P_ext(self): '''Adds external pressure to galaxy and stores gas/star sim particle data files again with the new information. ''' print('\nADDING EXTERNAL PRESSURE FIELD TO GALAXY') # Make global variables for Pfunc function global simgas, simgas1, simstar, m_gas, m_star simgas = aux.load_temp_file(gal_ob=self.gal_ob, sim_type='gas') simstar = aux.load_temp_file(gal_ob=self.gal_ob, sim_type='star') # TEST # simgas = simgas[0:1000] # simstar = simstar[0:1000] # Extract star forming gas only: simgas1 = simgas.copy() simgas1 = simgas1[simgas1['SFR'] > 0].reset_index() # Extract gas and star masses m_gas, m_star = simgas1['m'].values, simstar['m'].values print('(Multiprocessing starting up! %s cores in use)' % N_cores) pool = mp.Pool( processes=N_cores) # 8 processors on my Mac Pro, 16 on Betty results = [ pool.apply_async(aux.Pfunc, args=( i, simgas1, simgas, simstar, m_gas, m_star, )) for i in range(0, len(simgas)) ] #len(simgas) pool.close() pool.join() # sort results since apply_async doesn't return results in order res = [p.get() for p in results] res.sort(key=lambda x: x[0]) print('(Multiprocessing done!)') # Store pressure,velocity dispersion and surface densities for i, key in enumerate([ 'P_ext', 'surf_gas', 'surf_star', 'sigma_gas', 'sigma_star', 'vel_disp_gas' ]): simgas[key] = [res[_][i + 1] for _ in range(len(res))] if key == 'P_ext': simgas[key] = simgas[ key] * Msun**2 / kpc2m**4 / kB / 1e6 # K/cm^3 # Store new simgas and simstar files aux.save_temp_file(simgas, gal_ob=self.gal_ob, sim_type='gas', subgrid=True) aux.save_temp_file(simstar, gal_ob=self.gal_ob, sim_type='star', subgrid=True) del simgas, simgas1, simstar, m_gas, m_star setattr(self, 'P_ext_added', True)
def add_FUV(self): '''Adds FUV radiation field to galaxy and stores gas/star sim particle data files again with the new information. ''' print('\nADDING FUV RADIATION FIELD TO GALAXY') global simgas, simstar, L_FUV simgas = aux.load_temp_file(gal_ob=self.gal_ob, sim_type='gas') simstar = aux.load_temp_file(gal_ob=self.gal_ob, sim_type='star') # TEST # simgas = simgas[0:1000] # simstar = simstar[0:1000] # Get FUV grid results from starburst99 Zs, ages, L_FUV_grid = aux.get_FUV_grid_results(z1) # Get stellar metallicity and FUV from simulation Zsim = simstar.copy()['Z'] agesim = simstar.copy()['age'] agesim[agesim > 1e4] = 1e4 # since sb99 cannot handle anything older than 10Gyr # Calculate FUV luminosity of each stellar particle [ergs/s] part = 0.1 L_FUV = np.zeros(len(simstar)) for i in range(0, len(simstar)): f = interp2d(np.log10(Zs), np.log10(ages), np.log10(L_FUV_grid)) L_FUV[i] = simstar.loc[i]['m'] / 1e5 * 10.**f( np.log10(Zsim[i]), np.log10(agesim[i])) if np.isnan(L_FUV[i]) > 0: pdb.set_trace() if 1. * i / len(simstar) > part: print(int(part * 100), ' % done!') part = part + 0.1 simstar['L_FUV'] = L_FUV print('Minimum FUV luminosity: %s Lsun' % (np.min(L_FUV))) print('Maximum FUV luminosity: %s Lsun' % (np.max(L_FUV))) if np.min(L_FUV) < 0: print( 'SB99 grid not sufficient: Some FUV stellar luminosity is negative' ) pdb.set_trac() # Find FUV flux at gas particle positions F_FUV = np.zeros(len(simgas)) print('(Multiprocessing starting up! %s cores in use)' % N_cores) pool = mp.Pool( processes=N_cores) # 8 processors on my Mac Pro, 16 on Betty results = [ pool.apply_async(aux.FUVfunc, args=( i, simstar, simgas, L_FUV, )) for i in range(0, len(simgas)) ] #len(simgas) pool.close() pool.join() res = [p.get() for p in results] res.sort(key=lambda x: x[0]) F_FUV = [res[_][1] for _ in range(len(res))] print('(Multiprocessing done!)') # Store FUV field in local FUV field units F_FUV_norm = np.array(F_FUV) / (kpc2cm**2 * FUV_ISM) simgas['FUV'] = F_FUV_norm # Store CR intensity in local CR intensity units simgas['CR'] = F_FUV_norm * CR_ISM print('Minimum FUV flux: %s x ISM value' % (np.min(F_FUV_norm))) print('Maximum FUV flux: %s x ISM value' % (np.max(F_FUV_norm))) # Store new simgas and simstar files aux.save_temp_file(simgas, gal_ob=self.gal_ob, sim_type='gas', subgrid=True) aux.save_temp_file(simstar, gal_ob=self.gal_ob, sim_type='star', subgrid=True) del simgas, simstar, L_FUV setattr(self, 'FUV_added', True)