def __init__(self, gal_ob, **kwargs): # handle default values and kwargs args = dict(type='Total', label='Summed Galaxy Profile', color='k', xlabel='x [kpc]', ylabel='y [kpc]', vlabel='km/s', flabel='Jy', silent=False) args = aux.update_dictionary(args, kwargs) for key in args: setattr(self, key, args[key]) for key in args: setattr(self, key, args[key]) if not self.silent: print("constructing datacube...") # add attributes self.gal_obj = gal_ob self.add_shape() if not self.silent: print("datacube constructed for %s.\n" % gal_ob.name)
def get_raw_data(self, **kwargs): # handle default args and kwargs args = dict(data='sim') args = aux.update_dictionary(args, kwargs) for key in args: exec(key + '=args[key]') # choose which particle_data to load 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(): data = aux.load_temp_file(name, 'data') # data1 = pd.read_pickle(name) # data1['type'] = key collection[key] = data #.append(data1) return collection
def get_map(self, **kwargs): # handle default values and kwargs args = dict(choose_map='GMC', grid_length=100) args = aux.update_dictionary(args, kwargs) for key in args: exec(key + '=args[key]') # pick data to load if choose_map == 'GMC' or choose_map == 'dif': data = self.get_raw_data(data='ISM') else: data = self.get_raw_data() # filter data for selected sim type or ISM phase data = data[choose_map] # get positional grid X = np.linspace(-x_max_pc, x_max_pc, grid_length) / 1000 dx = X[-1] - X[-2] grid = np.matmul(X[:, None], X[None, :]) # create empty map mass_map = np.zeros_like(grid) for j, y in enumerate(X[:-1]): for k, x in enumerate(X[:-1]): # create mask that selects particles in a pixel at position [x,y] gas1 = data[(data.y >= X[j]) & (data.y < X[j + 1]) & (data.x >= X[k]) & (data.x < X[k + 1])] # get total mass of pixel mass_map[j, k] = np.sum(gas1['m'].values) # collect results results = dict(X=X, Y=X, Z=mass_map, title='Total Mass', plot_style='map') results = aux.update_dictionary(results, kwargs) # return plot_it instance return plot_it(results)
def get_line_lum(self, **kwargs): # handle default values and kwargs args = dict(ISM_phases=ISM_phases) # args = dict(target='L_CII',ISM_phases=ISM_phases) args = aux.update_dictionary(args, kwargs) for key in args: exec(key + '=args[key]') tot_line_lum = 0 for i, ISM_phase in enumerate(ISM_phases): cube_i = self.get_dc(ISM_phase, **kwargs) # cube_i = self.__get_dc(ISM_phase=ISM_phase,target=target) tot_line_lum += cube_i['dc_sum'] return tot_line_lum
def __get_dc_file_location(self, **kwargs): # handle default values and kwargs args = dict(ISM_dc_phase='GMC', target='L_CII', test=False) args = aux.update_dictionary(args, kwargs) for key in args: exec(key + '=args[key]') # construct file name filename = d_data + 'datacubes/%s_%s_%s_i%s_G%s.h5' % ( z1, target, ISM_dc_phase, inc_dc, self.gal_obj.gal_index + 1) if test: filename = d_data + 'datacubes/%s_%s_%s_i%s_G%s.h5' % ( z1, target, ISM_dc_phase, inc_dc, self.gal_obj.gal_index + 1) return filename
def gas_quiver_plot(self, **kwargs): # get default plot params plot.set_mpl_params() # make figure fig = plt.figure(figsize=(8, 6)) ax = fig.add_subplot(111) # get gas data sim_data = self.get_data() # default is already data='sim' sim_gas = sim_data[sim_data.type == 'gas'] # make plot object and add it to ax results = dict(plot_style='quiver', data=sim_gas) results = aux.update_dictionary(results, kwargs) ob = plot_it(results) ob.add_to_axis(ax, **kwargs)
def __init__(self,**kwargs): args = dict(z1=z1) args = aux.update_dictionary(args,kwargs) for key in args: exec(key + '=args[key]') try: file_location = self.__get_GR_file_location(z1) GR_dict = pd.read_pickle(file_location) except IOError: print('Searched for %s ' % file_location) print('No file with model results found, will create one') GR_dict = self.__create_GR_file(z1) # Set values in stored dictionary as attributes to global result object for key in GR_dict: setattr(self,key,GR_dict[key]) # Search for and create attributes missing_attr = self.__find_missing_attr() # for key in missing_attr: setattr(self,key,missing_attr[key]) self.__save_GR_file(self.__dict__,file_location)
def print_galaxy_properties(self,**kwargs): args = dict(gal_index=0) args = aux.update_dictionary(args,kwargs) for key in args: exec(key + '=args[key]') print('\nProperties of Galaxy number %s, %s, at redshift %s' % (gal_index+1,self.galnames[gal_index],self.zreds[gal_index])) # Print these properties print('+%20s+%20s+%15s+' % ((20*'-'), (20*'-'), (15*'-'))) print('|%20s|%20s|%15s|' % ('Property'.center(20), 'Value'.center(20), 'Name in code'.center(15))) print('+%20s+%20s+%15s+' % ((20*'-'), (20*'-'), (15*'-'))) print('|%20s|%20s|%15s|' % ('Redshift'.center(20), '{:.3f}'.format(self.zreds[gal_index]), 'zred'.center(15))) print('|%20s|%20s|%15s|' % ('Radius'.center(20), '{:.3f}'.format(np.max(self.R_gal[gal_index])), 'R_gal'.center(15))) print('|%20s|%20s|%15s|' % ('Stellar mass'.center(20), '{:.3e}'.format(self.M_star[gal_index]), 'M_star'.center(15))) print('|%20s|%20s|%15s|' % ('ISM mass'.center(20), '{:.3e}'.format(self.M_gas[gal_index]), 'M_gas'.center(15))) print('|%20s|%20s|%15s|' % ('DM mass'.center(20), '{:.3e}'.format(self.M_dm[gal_index]), 'M_dm'.center(15))) print('|%20s|%20s|%15s|' % ('Dense gas mass'.center(20), '{:.3e}'.format(self.M_dense[gal_index]), 'M_dense'.center(15))) print('|%20s|%20s|%15s|' % ('SFR'.center(20), '{:.3f}'.format(self.SFR[gal_index]), 'SFR'.center(15))) print('|%20s|%20s|%15s|' % ('SFR surface density'.center(20), '{:.4f}'.format(self.SFRsd[gal_index]), 'SFRsd'.center(15))) print('|%20s|%20s|%15s|' % ('SFR-weighted Z'.center(20), '{:.4f}'.format(self.Zsfr[gal_index]), 'Zsfr'.center(15))) print('+%20s+%20s+%15s+' % ((20*'-'), (20*'-'), (15*'-')))
def __init__(self, **kwargs): # get global results import global_results as glo GR = glo.global_results() # handle default values and kwargs args = dict(gal_index=0, N_radial_bins=30, classification='spherical', silent=False) args = aux.update_dictionary(args, kwargs) for key in args: exec(key + '=args[key]') if not silent: print("constructing galaxy...") # grab some info from global results for this galaxy self.radius = GR.R_gal[gal_index] self.name = GR.galnames[gal_index] self.zred = GR.zreds[gal_index] self.SFR = GR.SFR[gal_index] self.SFRsd = GR.SFRsd[gal_index] self.UV_str = aux.get_UV_str(z1, self.SFRsd) self.lum_dist = GR.lum_dist[gal_index] self.ang_dist_kpc = self.lum_dist * 1000. / (1 + self.zred)**2 # add attributes from args for key in args: setattr(self, key, args[key]) # add objects objects = ['datacube', 'particle_data'] for ob in objects: self.add_attr(ob, **args) if not silent: print("galaxy %s constructed.\n" % self.name)
def __init__(self, gal_ob, **kwargs): # handle default values and kwargs args = dict(units='kpc', silent=False) args = aux.update_dictionary(args, kwargs) for key in args: setattr(self, key, args[key]) for key in args: exec(key + '=args[key]') if not self.silent: print("constructing particle_data...") # add labels for spatial dimentions dim = ['x', 'y', 'z'] for x in dim: setattr(self, x + 'label', '%s [%s]' % (x, units)) # add galaxy self.gal_ob = gal_ob # add dictionaries of names for all sim types and ISM phases self.add_names() if not self.silent: print("particle_data constructed for %s.\n" % gal_ob.name)
def preview(self, **kwargs): # handle default values and kwargs args = dict(phase='GMC', lw_velocity=True, lw_dispersion=True, l_summed=True, mw_velocity=True, mw_dispersion=True, m_summed=True) args = aux.update_dictionary(args, kwargs) for key in args: exec(key + '=args[key]') # make empty container for map objects maps = {} if lw_velocity: maps['lw_vel'] = self.get_map(xlabel='', ylabel='', phase=phase, cmap=cm.seismic, **kwargs) if lw_dispersion: maps['lw_dis'] = self.get_map(xlabel='', ylabel='', phase=phase, method='dispersion', cmap=cm.viridis, **kwargs) if l_summed: maps['l_sum'] = self.get_map(label='log(Z)', xlabel='', ylabel='', phase=phase, method='summed', **kwargs) if mw_velocity: maps['mw_vel'] = self.get_map(xlabel='', ylabel='', line='m', phase=phase, cmap=cm.seismic, **kwargs) if mw_dispersion: maps['mw_dis'] = self.get_map(xlabel='', ylabel='', line='m', phase=phase, method='dispersion', cmap=cm.viridis, **kwargs) if m_summed: maps['m_sum'] = self.get_map(label='log(Z)', xlabel='', ylabel='', line='m', phase=phase, method='summed', **kwargs) # convert maps to Series maps = pd.Series(maps) # find convenient number of rows and columns size = maps.size n_rows = int(divmod(size, np.sqrt(size))[0]) n_cols = int(divmod(size, n_rows)[0]) # organize panel display panels = np.empty(n_rows * n_cols, dtype='O') for i, m in enumerate(maps): panels[i] = m # set up default plot parameters plot.set_mpl_params() # make figure if n_rows > 3: figsize = (15, 15) else: figsize = (15, 5) fig, ax = plt.subplots(n_rows, n_cols, figsize=figsize, sharex=True, sharey=True) if n_rows == 1: panels = panels[None, :] ax = ax[None, :] panels = panels.reshape([n_rows, n_cols]) for i in range(n_rows): for j in range(n_cols): ob = panels[i, j] if ob == None: continue ob.add_to_axis(ax[i, j], **kwargs) fig.text(0.5, 0.04, self.xlabel, ha='center') fig.text(0.04, 0.5, self.ylabel, va='center', rotation='vertical') plt.show(block=False)
def get_map(self, **kwargs): # handle default values and kwargs args = dict(target='L_CII', ISM_phase='GMC', method='velocity') args = aux.update_dictionary(args, kwargs) for key in args: exec(key + '=args[key]') # variable for title selection if target == 'm': target_str = 'Mass' else: target_str = 'Luminosity' # pull datacube if ISM_phase in ISM_phases: cube = self.get_dc(ISM_phase=ISM_phase, target=target) else: cube = self.get_dc_summed(target=target, **kwargs) # set up X-Y axies X = np.linspace(-x_max_pc, x_max_pc, cube['x_axis'].shape[0]) / 1000 X, Y = np.meshgrid(X, X) # get map values if method == 'summed': # get the datacube summed over velocity axis Z = cube['data'].sum(axis=0) Z = np.log10(Z) # get plot title title = "Summed %s %s" % (ISM_phase, target_str) # raise the lower limit higher than what it is set to in make_map args['vmin'] = 0 elif method == 'dispersion': # make a copy of the datacube for manipulation dc = np.array(cube['data'], copy=True) # multiply spacial values by their coresponding velocity values for i, v in enumerate(cube['v_axis']): dc[i, :, :] *= v # divide result by the original datacube summed over velocity axis dc /= cube['data'].sum(axis=0) # get the standard deviation of the weighted datacube along velocity axis Z = np.std(dc, axis=0) # get plot title title = "%s %s-Weighted %s" % (ISM_phase, target_str, method.title()) else: # default # get the weighted values Z = -1. * np.tensordot(cube['v_axis'], cube['data'], 1) / cube['data'].sum(axis=0) # get plot title title = "%s %s-Weighted %s" % (ISM_phase, target_str, method.title()) # collect results results = kwargs results.update(dict(X=X, Y=Y, Z=Z.T, title=title)) # return generic object of results return make_map(results)
def positions_plot(self, **kwargs): # handle default values and kwargs args = dict(dm=False, gas=True, star=True, GMC=False, dif=False) args = aux.update_dictionary(args, kwargs) for key in args: exec(key + '=args[key]') # pull particle data if any([dm, gas, star]): sim_data = self.get_data() if any([GMC, dif]): ISM_data = self.get_data(data='ISM') # run default plot params plot.set_mpl_params() # make figure fig = plt.figure() ax = fig.add_subplot(111, projection='3d') # choose different plotting parameters for different sim types for sim_type in sim_types: if sim_type == 'dm': if not dm: continue alpha = .1 size = .5 data = sim_data[sim_data.type == 'dm'] elif sim_type == 'star': if not star: continue alpha = 1 size = 20 data = sim_data[sim_data.type == 'star'] else: if not gas: continue alpha = .5 size = 1 data = sim_data[sim_data.type == 'gas'] # gather sim results sim_results = dict(plot_style='scatter', dim3=True, data=data, alpha=alpha, size=size, color=sim_colors[sim_type], label=sim_labels[sim_type]) sim_results = aux.update_dictionary(sim_results, kwargs) # turn sim results into plot_it instance sim_ob = plot_it(sim_results) # add sim_ob onto ax sim_ob.add_to_axis(ax, **kwargs) # choose different plotting parameters for different ISM phases for phase in ISM_phases: if phase == 'GMC': if not GMC: continue alpha = .5 size = 1 data = ISM_data[ISM_data.type == 'GMC'] elif phase == 'dif': if not dif: continue alpha = .4 size = 1 data = ISM_data[ISM_data.type == 'dif'] # gather ISM results ISM_results = dict(plot_style='scatter', dim3=True, data=data, alpha=alpha, size=size, color=sim_colors[sim_type], label=sim_labels[sim_type]) ISM_results = aux.update_dictionary(ISM_results, kwargs) # turn sim results into plot_it instance ISM_ob = plot_it(sim_results) # add sim_ob onto ax ISM_ob.add_to_axis(ax, **kwargs) pad = 20 ax.set_xlabel(self.xlabel, labelpad=pad) ax.set_ylabel(self.xlabel, labelpad=pad) ax.set_zlabel(self.xlabel, labelpad=pad) ax.set_aspect(1) ax.legend() plt.show()