def _calculate_halpha_view(self): for ileaf, offset in enumerate(self.dataset.block_offsets): block = datfile_utilities.get_single_block_data(self.dataset.file, offset, self.dataset.block_shape) # this adds the temperature and pressure to the block block = process_data.create_data_dict(block, self.dataset.header) # interpolate ionisation and f parameter for each block block_ion, block_fpar = ionisation.block_interpolate_ionisation_f(block, self.dataset) block_ne = super()._get_ne(block, block_ion) n2 = block_ne**2 / (block_fpar * 1e16) # parameter f is interpolated in units of 1e16 cm-3 # calculate block opacity block_kappa = (np.pi * self.dataset.units.ec**2 / (self.dataset.units.m_e * self.dataset.units.c)) * \ self.f23 * n2 * self._gaussian(block) # integrate block along line of sight to get opacity l_edge, r_edge = process_data.get_block_edges(ileaf, self.dataset) opacity = super()._integrate_block(block_kappa, l_edge, r_edge) S = self._source_function() intensity = S * (1 - np.exp(-opacity)) if self.simulation_type == 'filament': Ibgr = 2.2 * S intensity += Ibgr * np.exp(-opacity) # add integrated block to list, this preserves block index self.integrated_block_list.append(intensity) # merge all integrated blocks into one single 2D array view = super()._merge_integrated_blocks() # plot final result super()._plot_synthetic_view(view)
def plot_2d(self): varmin, varmax = self.dataset.get_extrema(self.var) norm = None if self.logscale: norm = matplotlib.colors.LogNorm() # iterate over blocks in dataset for ileaf, offset in enumerate(self.dataset.block_offsets): # retrieve x and y coordinates for each block l_edge, r_edge = process_data.get_block_edges(ileaf, self.dataset) # read in block data (contains all variables) block = datfile_utilities.get_single_block_data(self.dataset.file, offset, self.dataset.block_shape) block = process_data.create_data_dict(block, self.dataset.header) x = np.linspace(l_edge[0], r_edge[0], self.dataset.header['block_nx'][0]) y = np.linspace(l_edge[1], r_edge[1], self.dataset.header['block_nx'][1]) im = self.ax.pcolormesh(x, y, block[self.var].T, cmap=self.cmap, vmin=varmin, vmax=varmax, norm=norm) # logic to draw the mesh if self.draw_mesh: if not r_edge[0] == self.dataset.header["xmax"][0]: self.ax.vlines(x=r_edge[0], ymin=l_edge[1], ymax=r_edge[1], color=self.mesh_color, lw=self.mesh_linewidth, linestyle=self.mesh_linestyle, alpha=self.mesh_opacity) if not r_edge[1] == self.dataset.header["xmax"][1]: self.ax.hlines(y=r_edge[1], xmin=l_edge[0], xmax=r_edge[0], color=self.mesh_color, lw=self.mesh_linewidth, linestyle=self.mesh_linestyle, alpha=self.mesh_opacity) self.ax.set_aspect('equal') divider = make_axes_locatable(self.ax) cax = divider.append_axes("right", size="5%", pad=0.05) self.colorbar = self.fig.colorbar(im, cax=cax) self.ax.set_title(self.var) self.fig.tight_layout()
def plot_1d(self): for ileaf, offset in enumerate(self.dataset.block_offsets): l_edge, r_edge = process_data.get_block_edges(ileaf, self.dataset) block = datfile_utilities.get_single_block_data(self.dataset.file, offset, self.dataset.block_shape) block = process_data.create_data_dict(block, self.dataset.header) x = np.linspace(l_edge, r_edge, self.dataset.header['block_nx']) self.ax.plot(x, block[self.var], '-k') self.ax.set_title(self.var)
def load_all_data(self, nbprocs=None, regriddir=None): """ Loads in all the data to RAM, this can take up quite some space for huge datasets. Data will be regridded if this is not already done. """ if self.data_dict is not None: return self.data_dict if self._uniform: data = datfile_utilities.get_uniform_data(self) else: data = self._regrid_data(nbprocs, regriddir) # create dictionary containing the data self.data_dict = process_data.create_data_dict(data, self.header, self.adiab_constant) return self.data_dict
def get_extrema(self, var, print_result=False): """ Returns the maximum and minimum value of the requested variable :param var: variable, see ds.known_fields which are available :param print_result: if True, prints the extrema to the console :return: min, max of the given variable """ if var not in self.known_fields: raise KeyError("variable not known: {}".format(var)) varmax = -1e99 varmin = 1e99 for offset in self.block_offsets: block = datfile_utilities.get_single_block_data( self.file, offset, self.block_shape) block = process_data.create_data_dict(block, self.header) varmax = np.maximum(varmax, np.max(block[var])) varmin = np.minimum(varmin, np.min(block[var])) if print_result: print(">> minimum {}: {:2.3e} | maximum {}: {:2.3e}".format( var, varmin, var, varmax)) return varmin, varmax
def _calculate_faraday_view(self): for ileaf, offset in enumerate(self.dataset.block_offsets): block = datfile_utilities.get_single_block_data(self.dataset.file, offset, self.dataset.block_shape) # add pressure and temperature to block block = process_data.create_data_dict(block, self.dataset.header) block_ion, block_fpar = ionisation.block_interpolate_ionisation_f(block, self.dataset) block_ne = super()._get_ne(block, block_ion) prefactor = self.dataset.units.ec**3 / (2*np.pi*self.dataset.units.m_e**2 * self.dataset.units.c**4) if self.line_of_sight == 'x': b_key = 'b1' elif self.line_of_sight == 'y': b_key = 'b2' else: b_key = 'b3' b_para = block[b_key] * self.dataset.units.unit_magneticfield l_edge, r_edge = process_data.get_block_edges(ileaf, self.dataset) fara_measure = super()._integrate_block(block_ne*b_para, l_edge, r_edge) * prefactor self.integrated_block_list.append(fara_measure) view = super()._merge_integrated_blocks() super()._plot_synthetic_view(view) self.colorbar.set_label("rad cm$^{-2}$")