def plot_pt_utm(edi_file_list, freq, save_path=None): """ UnboundLocalError: local variable 'zone1' referenced before assignment for GA_UA latest survey :param edi_file_list: :param freq: :param save_path: :return: """ ellipse_dict = { 'size': 20, 'colorby': 'phimin', 'range': (0, 90, 1), 'cmap': 'mt_bl2gr2rd' } pt2 = PlotPhaseTensorMaps( fn_list=edi_file_list, plot_freq=freq, save_fn=save_path, xpad= 20, # plot margin; change according to your dataset and mapscale km/m ypad=20, mapscale='km', # mapscale='m' can cause big numbers in ticks labels ellipse_dict=ellipse_dict, # plot_tipper='yri', # plot_title='??Customisable Title?? ' ) pt2.plot() if save_path is not None: pt2.save_figure(save_path, fig_dpi=300, file_format='jpg') # pdf)
def test_edifiles2_input(self): """ testing to use Z and tipper objects as input this fails because the constructor of PlotPhaseTensorMaps only initialize the Mplot object properly when reading from files :return: """ edi_path = test_params[4] freq = 1 mt_objs = load_edi_files(edi_path) z_objs = [mt.Z for mt in mt_objs] tipper = [mt.Tipper for mt in mt_objs] save_figure_path = os.path.join( self._temp_dir, "%s.png" % inspect.currentframe().f_code.co_name) save_param_path = os.path.join( self._temp_dir, "params_%s" % inspect.currentframe().f_code.co_name) pt_obj = PlotPhaseTensorMaps( z_object_list=z_objs, tipper_object_list=tipper, plot_freq=freq, ftol= 0.10, # freq tolerance,which will decide how many data points included mapscale='deg', # deg or m, or km xpad=0.4, # plot margin; change according to lat-lon in edifiles ypad=0.4, # ~ 2* ellipse size # ellipse_dict=self.ellipse_dict, # not implemented ellipse_size=.2, ellipse_colorby='phimin', ellipse_range=(0, 90, 1), ellipse_cmap='mt_bl2gr2rd', plot_tipper='yr', # arrow_dict=self.arrow_dict, # not implemented arrow_size=0.5, arrow_lw=0.2, arrow_head_width=0.04, arrow_head_length=0.04, arrow_direction=0, arrow_threshold=0.8, # arrow_legend_dict=arrow_legend_dict, # fig_spython examples/plot_phase_tensor_map.py data/edifiles/ 10 /e/MTPY2_Outputs/ptmap3deg.pngize=(6, 5), # fig_dpi=300, the default is OK. Higher dpi # may distort figure save_fn=save_figure_path, fig_size=(8, 6), fig_dpi=100) path2figure = pt_obj.plot() pt_obj.save_figure(save_figure_path) assert (os.path.isfile(save_figure_path)) pt_obj.export_params_to_file(save_path=save_param_path) assert (os.path.isdir(save_param_path))
def default(self): save_figure_path = os.path.join(self._temp_dir, "%s.png" % default.__name__) save_param_path = os.path.join(self._temp_dir, "params_%s" % default.__name__) edi_file_list = glob.glob(os.path.join(edi_path, "*.edi")) pt_obj = PlotPhaseTensorMaps( fn_list=edi_file_list, plot_freq=freq, ftol= 0.10, # freq tolerance,which will decide how many data points included mapscale='deg', # deg or m, or km xpad=0.4, # plot margin; change according to lat-lon in edifiles ypad=0.4, # ~ 2* ellipse size # ellipse_dict=self.ellipse_dict, # Not implemented ellipse_size=.2, ellipse_colorby='phimin', ellipse_range=(0, 90, 1), ellipse_cmap='mt_bl2gr2rd', plot_tipper='yr', #arrow_dict=self.arrow_dict, # Not implemented arrow_size=0.5, arrow_lw=0.2, arrow_head_width=0.04, arrow_head_length=0.04, arrow_direction=0, arrow_threshold=0.8, # arrow_legend_dict=arrow_legend_dict, # fig_spython examples/plot_phase_tensor_map.py data/edifiles/ 10 /e/MTPY2_Outputs/ptmap3deg.pngize=(6, 5), # fig_dpi=300, the default is OK. Higher dpi # may distort figure save_fn=save_figure_path) # 3) do the plot and save figure - if the param save_path provided path2figure = pt_obj.plot(show=True) pt_obj.save_figure(save_figure_path, close_plot='n') assert (os.path.isfile(save_figure_path)) pt_obj.export_params_to_file(save_path=save_param_path) assert (os.path.isdir(save_param_path))
def plot_pt(edi_file_list, freq, save_path=None): """ Plot Phase Tensor Map in Lat-Long (unprojected) Coordinate system :param edi_file_list: a list of edi files :param freq: the frequency value (within a certain tolerance ftol) :param save_path: path to file/dir to save the plot as jpg or png file :return: """ # 1) Define plots params # parameters describing ellipses, differ for different map scales: deg, m, km # Try different size to find a suitable value for your case. as a # guidance: 1 degree=100KM ellipse_dict = { 'size': 0.2, 'colorby': 'phimin', 'range': (0, 90, 1), 'cmap': 'mt_bl2gr2rd' } # adjust to suitable size: parameters describing the induction vector arrows arrow_dict = { 'size': 0.5, 'lw': 0.2, 'head_width': 0.04, 'head_length': 0.04, 'threshold': 0.8, 'direction': 0 } # parameters describing the arrow legend (not necessarily used) # arrow_legend_dict = {'position': 'upper right', # 'fontpad': 0.0025, # 'xborderpad': 0.07, # 'yborderpad': 0.015} # 2) Construct plotting object pt_obj = PlotPhaseTensorMaps( fn_list=edi_file_list, plot_freq=freq, ftol= 0.10, # freq tolerance,which will decide how many data points included mapscale='deg', # deg or m, or km xpad=0.4, # plot margin; change according to lat-lon in edifiles ypad=0.4, # ~ 2* ellipse size ellipse_dict=ellipse_dict, plot_tipper='yr', arrow_dict=arrow_dict, # arrow_legend_dict=arrow_legend_dict, # fig_spython examples/plot_phase_tensor_map.py tests/data/edifiles/ 10 /e/MTPY2_Outputs/ptmap3deg.pngize=(6, 5), # fig_dpi=300, the default is OK. Higher dpi # may distort figure save_fn=save_path) # 3) do the plot and save figure - if the param save_path provided path2figure = pt_obj.plot(save_path=save_path) pt_obj.export_params_to_file(save_path=save_path) print("Please check your output figure: %s" % path2figure) return
class PhaseTensorMap(VisualizationBase): def get_plot_tooltip(self): tipper = self._params['plot_tipper'] return "freq=%.5f, tolerance=%.2f%%, ellipse_size=%.2f, real_induction=%s, imaginary_induction=%s" % ( self._params['plot_freq'], self._params['ftol'] * 100, self._params['ellipse_size'], 'on' if tipper.find('r') >= 0 else 'off', 'on' if tipper.find('i') >= 0 else 'off' ) @staticmethod def plot_description(): return """ <p>Plot phase tensor map in Lat-Lon Coordinate System.</p> """ def update_ui(self): self._frequency_ui.set_data(self._mt_objs) @staticmethod def plot_name(): return "Phase Tensor Map" def plot(self): # get data # NOTE: this is a hack because the existing bug(s) in the PlotPhaseTensorMaps class, that is the # constructor of the class only populate all the necessary information correctly when reads from file # this is the only way before this bug(s) is fixed self._params = { 'fn_list': [mt_obj.fn for mt_obj in self._mt_objs], 'plot_freq': self._frequency_ui.get_frequencies(), 'ftol': self._tolerance_ui.get_tolerance_in_float(), 'mapscale': self._scale_ui.get_mapscale(), 'tscale': self._scale_ui.get_tscale(), 'plot_tipper': self._arrow_ui.get_plot_tipper(), # 'rot_z': self._rotation_ui.get_rotation_in_degree(), # not implemented in PlotPhaseTensorMaps # 'station_id': (0, 10), 'fig_num': get_next_fig_num(), 'fig_dpi': 100, 'fig_size': (8, 6), 'plot_yn': 'n' } self._params.update(self._ellipse_ui.get_ellipse_dict()) if self._colorbar_ui.isChecked(): self._params['cb_dict'] = self._colorbar_ui.get_colorbar_dict() # arrow_dict = { # 'size': 0.5, # 'lw': 0.2, # 'head_width': 0.04, # 'head_length': 0.04, # 'threshold': 0.8, # 'direction': 0} if self._arrow_ui.isChecked(): self._params.update(self._arrow_ui.get_arrow_dict()) if self._padding_ui.isChecked(): self._params['xpad'] = self._padding_ui.get_x_pad() self._params['ypad'] = self._padding_ui.get_y_pad() if self._label_font_ui.ui.checkBox_size.isChecked(): self._params['font_size'] = self._label_font_ui.get_size() station_dict = {} if self._station_font_ui.ui.checkBox_size.isChecked(): station_dict['size'] = self._station_font_ui.get_size() if self._station_font_ui.ui.checkBox_weight.isChecked(): station_dict['weight'] = self._station_font_ui.get_weight() if self._station_font_ui.ui.checkBox_color.isChecked(): station_dict['color'] = self._station_font_ui.get_color() if station_dict: station_dict['id'] = {0,10} self._params['station_dict'] = station_dict self._plotting_object = PlotPhaseTensorMaps(**self._params) self._plotting_object.plot(show=False) self._fig = self._plotting_object.fig def __init__(self, parent): VisualizationBase.__init__(self, parent) # set up ui self._scale_ui = Scale(self._parameter_ui) self._frequency_ui = FrequencySelection(self._parameter_ui, show_frequency=True, show_period=False, allow_range_select=False, select_multiple=False) # self._scale_ui.ui.comboBox_time.currentIndexChanged.connect( # lambda index: self._frequency_ui.show_period() if index == 0 # else self._frequency_ui.show_frequency() # ) self._parameter_ui.add_parameter_groupbox(self._scale_ui) self._parameter_ui.add_parameter_groupbox(self._frequency_ui) self._tolerance_ui = FrequencyTolerance(self._parameter_ui) self._parameter_ui.add_parameter_groupbox(self._tolerance_ui) self._ellipse_ui = Ellipse(self._parameter_ui) self._parameter_ui.add_parameter_groupbox(self._ellipse_ui) self._arrow_ui = Arrow(self._parameter_ui) self._parameter_ui.add_parameter_groupbox(self._arrow_ui) # not implemented in PlotPhaseTensorMaps # self._rotation_ui = Rotation(self._parameter_ui) # self._parameter_ui.add_parameter_groubox(self._rotation_ui) self._padding_ui = Padding(self._parameter_ui) self._parameter_ui.add_parameter_groupbox(self._padding_ui) self._colorbar_ui = ColorBar(self._parameter_ui) self._parameter_ui.add_figure_groupbox(self._colorbar_ui) self._label_font_ui = Font(self._parameter_ui) self._label_font_ui.setToolTip("Font of the plot labels") self._label_font_ui.hide_color() self._label_font_ui.hide_weight() self._parameter_ui.add_figure_groupbox(self._label_font_ui) self._station_font_ui = Font(self._parameter_ui, simple_color=False) self._station_font_ui.setTitle('Station Label Font') self._parameter_ui.add_figure_groupbox(self._station_font_ui) self._parameter_ui.end_of_parameter_components() # resize # self._parameter_ui.resize(self._parameter_ui.width(), # self._parameter_ui.sizeHint().height()) self.update_ui() self._params = None