def on_import_selected(self, evt): # Setting well and run imports flag for well in self.model.wells: for run in well.data: for log in run.data: if log._import: well._import = True run._import = True # OM = ObjectManager() PM = ParametersManager.get() # for well in self.model.wells: if well._import: well_obj = OM.new('well', name=well.name) OM.add(well_obj) # for run in well.data: curve_set_obj = OM.new('curve_set', name=run.name) OM.add(curve_set_obj, well_obj.uid) indexes_uid = [] # for index in run.get_indexes(): if index._import: index_obj = OM.new('data_index', index.data, name=index.mnem, unit=index.unit.lower(), datatype=index.datatype) OM.add(index_obj, curve_set_obj.uid) indexes_uid.append(index_obj.uid) self.model.SetProgress(index, 100) PM.vote_for_datatype(index.mnem, index.datatype) # for log in run.get_logs(): if log._import: log_obj = OM.new('log', log.data, name=log.mnem, unit=log.unit.lower(), datatype=log.datatype) OM.add(log_obj, curve_set_obj.uid) log_obj._create_data_index_map(indexes_uid) self.model.SetProgress(log, 100) PM.vote_for_datatype(log.mnem, log.datatype) # PM.register_votes()
def _create_data_index_map(self, *args): """ args: List of lists of DataIndex uids. Examples: 1-D data: [index.uid, owt_index.uid, twt_index.uid] 5-D data: [i_line_index.uid], [x_line_index.uid], [offset_index.uid], [freq_index.uid], [time_index.uid, prof_index.uid] """ max_dims = self._get_max_dimensions() if len(args) > max_dims: msg = 'Exceed number of dimensions [{}] - {}.'.format( max_dims, args) print('\n' + msg) raise Exception(msg) OM = ObjectManager() data = [] for di_objs in args: if not isinstance(di_objs, list): # arg should be a object uid. di_objs = [di_objs] for di_obj in di_objs: try: # Then, test if object exist this is a valid object uid. obj = OM.get(di_obj) if not obj.tid == 'data_index': raise Exception() except: print('\n\nDEU RUIM:', di_obj) msg = 'Error in objects informed as ' + \ 'Data Indexes: {}.'.format(args) raise Exception(msg) data.append(di_objs) try: di_map = OM.new('data_index_map', data) except Exception as e: msg = 'ERROR DataObject._create_data_index_map: {} - data: {}'.format( e, data) print('\n' + msg) raise if not OM.add(di_map, self.uid): msg = 'Cannot add {} to {}.'.format(di_map, self.uid) print('\n' + msg) raise Exception(msg) msg = 'Criado {} com sucesso.'.format(di_map)
def create_new_curve_set(self, curve_set_name=None): OM = ObjectManager() existing_csets = OM.list('curve_set', self.uid) # if curve_set_name: for cset in existing_csets: if cset.name == curve_set_name: curve_set_name = None break # if not curve_set_name: curve_set_idx = len(existing_csets) + 1 curve_set_name = 'Run ' + str(curve_set_idx) # curve_set = OM.new('curve_set', name=curve_set_name) OM.add(curve_set, self.uid) return curve_set
class RockTable(wx.grid.GridTableBase): @debugdecorator def __init__(self, rocktableuid): super(RockTable, self).__init__() self.OM = ObjectManager() self.rocktypeuid = [] self.rocktableuid = rocktableuid self.rocktypemap = [ rocktype.uid for rocktype in self.OM.list('rocktype', self.rocktableuid) ] self.N_COLS = 4 self.N_ROWS = 0 @debugdecorator def AppendRows(self, numRows=1): rocktype = self.GrainEntry() # rocktype = self.OM.new('rocktype') rocktype.defaultdata = np.nan self.OM.add(rocktype, self.rocktableuid) self.rocktypemap.append(rocktype.uid) color = self.get_color(0) self.set_color(-1, color) self.GetView().BeginBatch() msg = wx.grid.GridTableMessage(self, wx.grid.GRIDTABLE_NOTIFY_ROWS_APPENDED, numRows) self.GetView().ProcessTableMessage(msg) self.GetView().EndBatch() return True @debugdecorator def GrainEntry(self): UIM = UIManager() dlg = UIM.create('dialog_controller', title='Rock creator') cont_grain = dlg.view.AddCreateContainer('StaticBox', label='Grain Parts', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND | wx.TOP, border=5) cont_matr = dlg.view.AddCreateContainer('StaticBox', label='Matrix Parts', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND | wx.TOP, border=5) json_file = '\\Temp\\min.json' # fullpath_json = 'C:\\Users\\rtabelini\\Documents\\Github\\GRIPy'+json_file fullpath_json = cwd() + json_file dictmin = app.app_utils.read_json_file(fullpath_json) def on_change_mineral(name, old_value, new_value, **kwargs): print('new\n', name, new_value, new_value['name'], dictmin.iterkeys()) if name == 'mineralgrain': textctrl_k = dlg.view.get_object('kmod1') textctrl_g = dlg.view.get_object('gmod1') textctrl_rho = dlg.view.get_object('dens1') elif name == 'mineralmatrix': textctrl_k = dlg.view.get_object('kmod2') textctrl_g = dlg.view.get_object('gmod2') textctrl_rho = dlg.view.get_object('dens2') if new_value['name'] in dictmin.iterkeys(): textctrl_k.set_value(new_value['K']) textctrl_g.set_value(new_value['G']) textctrl_rho.set_value(new_value['Dens']) dlg.view.AddChoice(cont_grain, widget_name='mineralgrain', options=dictmin, flag=wx.EXPAND) choice_grain = dlg.view.get_object('mineralgrain') choice_grain.set_trigger(on_change_mineral) dlg.view.AddChoice(cont_matr, widget_name='mineralmatrix', options=dictmin, flag=wx.EXPAND) choice_matrix = dlg.view.get_object('mineralmatrix') choice_matrix.set_trigger(on_change_mineral) gr_frac = dlg.view.AddCreateContainer('BoxSizer', cont_grain, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) dlg.view.AddStaticText(gr_frac, proportion=1, initial='Fraction ', flag=wx.ALIGN_RIGHT) dlg.view.AddTextCtrl(gr_frac, proportion=1, widget_name='frac1', initial='0.8', flag=wx.ALIGN_RIGHT) gr_poro = dlg.view.AddCreateContainer('BoxSizer', cont_grain, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) dlg.view.AddStaticText(gr_poro, proportion=1, initial='Porosity ', flag=wx.ALIGN_RIGHT) dlg.view.AddTextCtrl(gr_poro, proportion=1, widget_name='poro1', initial='0.20', flag=wx.ALIGN_RIGHT) gr_kmod = dlg.view.AddCreateContainer('BoxSizer', cont_grain, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) dlg.view.AddStaticText(gr_kmod, proportion=1, widget_name='K_Modulus', initial='K Modulus (GPa) ', flag=wx.ALIGN_RIGHT) dlg.view.AddTextCtrl(gr_kmod, proportion=1, widget_name='kmod1', initial='36.5', flag=wx.ALIGN_RIGHT) gr_gmod = dlg.view.AddCreateContainer('BoxSizer', cont_grain, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) dlg.view.AddStaticText(gr_gmod, proportion=1, widget_name='G_Modulus', initial='G Modulus (GPa) ', flag=wx.ALIGN_RIGHT) dlg.view.AddTextCtrl(gr_gmod, proportion=1, widget_name='gmod1', initial='78.6', flag=wx.ALIGN_RIGHT) gr_dens = dlg.view.AddCreateContainer('BoxSizer', cont_grain, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) dlg.view.AddStaticText(gr_dens, proportion=1, widget_name='Density', initial='Density (g/cc) ', flag=wx.ALIGN_RIGHT) dlg.view.AddTextCtrl(gr_dens, proportion=1, widget_name='dens1', initial='2.65', flag=wx.ALIGN_RIGHT) mtr_frac = dlg.view.AddCreateContainer('BoxSizer', cont_matr, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) dlg.view.AddStaticText(mtr_frac, proportion=1, widget_name='fraction2', initial='Fraction ', flag=wx.ALIGN_RIGHT) dlg.view.AddTextCtrl(mtr_frac, proportion=1, widget_name='frac2', initial='0.2', flag=wx.ALIGN_LEFT) mtr_poro = dlg.view.AddCreateContainer('BoxSizer', cont_matr, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) dlg.view.AddStaticText(mtr_poro, proportion=1, initial='Porosity ', flag=wx.ALIGN_RIGHT) dlg.view.AddTextCtrl(mtr_poro, proportion=1, widget_name='poro2', initial='0.10', flag=wx.ALIGN_RIGHT) mtr_kmod = dlg.view.AddCreateContainer('BoxSizer', cont_matr, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) dlg.view.AddStaticText(mtr_kmod, proportion=1, widget_name='K_Modulus2', initial='K Modulus (GPa) ', flag=wx.ALIGN_RIGHT) dlg.view.AddTextCtrl(mtr_kmod, proportion=1, widget_name='kmod2', initial='36.5', flag=wx.ALIGN_LEFT) mtr_gmod = dlg.view.AddCreateContainer('BoxSizer', cont_matr, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) dlg.view.AddStaticText(mtr_gmod, proportion=1, widget_name='G_Modulus2', initial='G Modulus (GPa) ', flag=wx.ALIGN_RIGHT) dlg.view.AddTextCtrl(mtr_gmod, proportion=1, widget_name='gmod2', initial='78.6', flag=wx.ALIGN_LEFT) mtr_dens = dlg.view.AddCreateContainer('BoxSizer', cont_matr, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) dlg.view.AddStaticText(mtr_dens, proportion=1, widget_name='Density2', initial='Density (g/cc) ', flag=wx.ALIGN_RIGHT) dlg.view.AddTextCtrl(mtr_dens, proportion=1, widget_name='dens2', initial='2.65', flag=wx.ALIGN_LEFT) # try: if dlg.view.ShowModal() == wx.ID_OK: results = dlg.get_results() gr_f = results.get('frac1') mtr_f = results.get('frac2') ngrain = results.get('mineralgrain')['name'] nmatrix = results.get('mineralmatrix')['name'] gr_phi = results.get('poro1') gr_k = results.get('kmod1') gr_mi = results.get('gmod1') gr_rho = results.get('dens1') mtr_phi = results.get('poro2') mtr_k = results.get('kmod2') mtr_mi = results.get('gmod2') mtr_rho = results.get('dens2') # kk = RP.VRHill (gr_k, gr_f, mtr_k) # g = RP.VRHill (gr_mi, gr_f, mtr_mi) print('\ngrd', gr_k, gr_f, mtr_k, type(float(mtr_k))) rocktype = self.OM.new( 'rocktype', fracgrain=gr_f, fracmatrix=mtr_f, grain=ngrain, matrix=nmatrix, k=10, mi=20) #vp=vp, vs=vs, rho = rho, k=k, mi=mi, poi=poi return rocktype except Exception as e: print('ERROR:', str(e)) finally: UIM.remove(dlg.uid) @debugdecorator def DeleteRows(self, pos=0, numRows=1): if pos >= self.N_ROWS: i = pos - self.N_ROWS for j in range(numRows)[::-1]: self.OM.remove(self.rocktypemap.pop(i + j)) self.GetView().BeginBatch() msg = wx.grid.GridTableMessage( self, wx.grid.GRIDTABLE_NOTIFY_ROWS_DELETED, pos, numRows) self.GetView().ProcessTableMessage(msg) self.GetView().EndBatch() return True else: return False @debugdecorator def GetColLabelValue(self, col): if col == 0: return "Nome" elif col == 1: return "Cor" elif col == 2: return "Grain" elif col == 3: return "Matrix" else: return @debugdecorator def GetRowLabelValue(self, row): return str(row + 1) @debugdecorator def SetRowLabelValue(self, row, label): return @debugdecorator def GetNumberCols(self): return self.N_COLS # return len(self.propmap) + self.N_COLS @debugdecorator def GetNumberRows(self): return len(self.rocktypemap) @debugdecorator def GetAttr(self, row, col, kind): #if _iswxphoenix: attr = wx.grid.GridCellAttr().Clone() if col >= self.N_COLS: attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER) elif col == 0: attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER) elif col == 1: rocktype = self.OM.get(self.rocktypemap[row]) attr.SetBackgroundColour(rocktype.color) attr.SetReadOnly(True) elif col == 2: attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER) elif col == 3: attr.SetAlignment(wx.ALIGN_RIGHT, wx.ALIGN_CENTER) return attr @debugdecorator def GetValue(self, row, col): if col >= self.N_COLS: i = col - self.N_COLS prop = self.OM.get(self.propmap[i]) value = prop.getdata(self.rocktypemap[row]) if not np.isnan(value): return str(value) else: return '' elif col == 0: rocktype = self.OM.get(self.rocktypemap[row]) return rocktype.name elif col == 1: return '' elif col == 2: rocktype = self.OM.get(self.rocktypemap[row]) return rocktype.fracgrain + ' ' + rocktype.grain elif col == 3: rocktype = self.OM.get(self.rocktypemap[row]) return rocktype.fracmatrix + ' ' + rocktype.matrix @debugdecorator def SetValue(self, row, col, value): if col >= self.N_COLS: i = col - self.N_COLS if value: value = float(value) else: value = np.nan prop = self.OM.get(self.propmap[i]) prop.setdata(self.rocktypemap[row], value) elif col == 0: rocktype = self.OM.get(self.rocktypemap[row]) rocktype.name = value elif col == 1: return elif col == 2: return elif col == 3: return @debugdecorator def set_color(self, row, color): rocktype = self.OM.get(self.rocktypemap[row]) rocktype.color = color @debugdecorator def get_color(self, row): rocktype = self.OM.get(self.rocktypemap[row]) return rocktype.color @debugdecorator def get_nameunit(self, col): if col >= self.N_COLS: i = col - self.N_COLS prop = self.OM.get(self.propmap[i]) return prop.name, prop.unit @debugdecorator def set_nameunit(self, col, name, unit): if col >= self.N_COLS: i = col - self.N_COLS prop = self.OM.get(self.propmap[i]) prop.name = name prop.unit = unit
def on_create_wavelet(*args, **kwargs): OM = ObjectManager() UIM = UIManager() # dlg = UIM.create('dialog_controller', title='Create Wavelet') # ctn_wavelet = dlg.view.AddCreateContainer('StaticBox', label='Wavelet', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddChoice(ctn_wavelet, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='wavelet', options=WAVELET_TYPES, initial=0) # ctn_f0 = dlg.view.AddCreateContainer('StaticBox', label='Base frequency (f0)', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_f0, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='f0', initial='10.0') # ctn_amp = dlg.view.AddCreateContainer('StaticBox', label='Amplitude', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_amp, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='amp', initial='1.0') # ctn_name = dlg.view.AddCreateContainer('StaticBox', label='New wavelet name', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_name, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='wavelet_name', initial='My Ricker Wavelet') # dlg.view.SetSize((300, 400)) result = dlg.view.ShowModal() # try: disableAll = wx.WindowDisabler() wait = wx.BusyInfo("Creating wavelet. Wait...") if result == wx.ID_OK: results = dlg.get_results() print (results) wavelet = OM.new('wavelet', _type="Ricker", f0=results.get('f0'), amp=results.get('amp'), name=results.get('wavelet_name')) result = OM.add(wavelet) print ('result wavelet:', result, args, kwargs) except Exception as e: print ('ERROR [on_create_model]:', str(e)) raise finally: del wait del disableAll UIM.remove(dlg.uid)
def on_load_model(*args, **kwargs): wildcard = "Load segmentated file (*.png, *.tif)|*.png;*.tif" fdlg = wx.FileDialog(wx.App.Get().GetTopWindow(), "Choose file", wildcard=wildcard, style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST ) if fdlg.ShowModal() == wx.ID_OK: file_name = fdlg.GetFilename() dir_name = fdlg.GetDirectory() fdlg.Destroy() else: fdlg.Destroy() return fullfilename = os.path.join(dir_name, file_name) print("\n\n") print (fullfilename) input_vec = plt.imread(fullfilename) print(input_vec.shape) print(input_vec.dtype) if (len(input_vec.shape) == 2): print(input_vec[100,100]) elif (len(input_vec.shape) == 3): ny, nx, ncolor = input_vec.shape new_vec = np.zeros((ny, nx), dtype=np.int8) if (input_vec.shape[2] == 4): # RGBA for y in range(ny): for x in range(nx): new_vec[y, x] = (input_vec[y, x, 0] + input_vec[y, x, 1] + input_vec[y, x, 2] + input_vec[y, x, 3])/4 #new_vec = np.array(Image.open(fullfilename).convert('L')) print(new_vec) print(new_vec[100,100]) values = np.unique(new_vec) print(values.size) input_vec = new_vec #print(input_vec[100,100]) values = np.unique(input_vec) print(values.size) if values.size > 2: msg = "File {} is not a binary segmentated file!".format(file_name) logging.error(msg) raise Exception(msg) OM = ObjectManager() UIM = UIManager() # dlg = UIM.create('dialog_controller', title='Create 2 layers model') # ctn_name = dlg.view.AddCreateContainer('StaticBox', label='New model name', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_name, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='model_name', initial=file_name.split(".")[0]) # # ctn_xaxis = dlg.view.AddCreateContainer('StaticBox', label="X Axis spacing", orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_xaxis, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='dx', initial=0.000296) # ctn_yaxis = dlg.view.AddCreateContainer('StaticBox', label="Y Axis spacing", orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_yaxis, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='dy', initial=0.000296) # # ctn_layer_1 = dlg.view.AddCreateContainer('StaticBox', label='Layer 1 - Value: ' + str(values[0]), orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) # ctn_vp1 = dlg.view.AddCreateContainer('StaticBox', ctn_layer_1, label='Vp(m/s)', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_vp1, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='vp1', initial=2500.0) # ctn_rho1 = dlg.view.AddCreateContainer('StaticBox', ctn_layer_1, label='Rho(g/cm3)', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_rho1, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='rho1', initial=2.2) # # if values.size == 2: ctn_layer_2 = dlg.view.AddCreateContainer('StaticBox', label='Layer 2 - Value: ' + str(values[1]), orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) # ctn_vp2 = dlg.view.AddCreateContainer('StaticBox', ctn_layer_2, label='Vp(m/s)', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_vp2, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='vp2', initial=4000.0) # ctn_rho2 = dlg.view.AddCreateContainer('StaticBox', ctn_layer_2, label='Rho(g/cm3)', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_rho2, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='rho2', initial=3.0) # # # ctn_layer_3 = dlg.view.AddCreateContainer('StaticBox', label='Layer 3', orient=wx.HORIZONTAL) # # # ctn_start3 = dlg.view.AddCreateContainer('StaticBox', ctn_layer_3, label='Start', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) # dlg.view.AddTextCtrl(ctn_start3, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='start3', initial=200.0) # # # ctn_vp3 = dlg.view.AddCreateContainer('StaticBox', ctn_layer_3, label='Vp(m/s)', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) # dlg.view.AddTextCtrl(ctn_vp3, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='vp3', initial=2645.0) # # # ctn_vs3 = dlg.view.AddCreateContainer('StaticBox', ctn_layer_3, label='Vs(m/s)', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) # dlg.view.AddTextCtrl(ctn_vs3, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='vs3', initial=1170.0) # # # ctn_rho3 = dlg.view.AddCreateContainer('StaticBox', ctn_layer_3, label='Rho(g/cm3)', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) # dlg.view.AddTextCtrl(ctn_rho3, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='rho3', initial=2.29) # # # ctn_q3 = dlg.view.AddCreateContainer('StaticBox', ctn_layer_3, label='Q', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) # dlg.view.AddTextCtrl(ctn_q3, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='q3', initial=2000.0) # # dlg.view.SetSize((300, 550)) result = dlg.view.ShowModal() try: disableAll = wx.WindowDisabler() wait = wx.BusyInfo("Creating model. Wait...") if result == wx.ID_OK: results = dlg.get_results() am = OM.new('acoustic_2d_model', input_vec, dx=results.get('dx'), dy=results.get('dy'), name=results.get('model_name')) result = OM.add(am) print ('result acoustic_2d_model:', result, args, kwargs) layer1 = OM.new('geolayer', value=values[0], vp=results.get('vp1'), rho=results.get('rho1'), name="Layer 1") result = OM.add(layer1, am.uid) print ('result layer 1:', result) if values.size == 2: layer2 = OM.new('geolayer', value=values[1], vp=results.get('vp2'), rho=results.get('rho2'), name="Layer 2") result = OM.add(layer2, am.uid) print ('result layer 2:', result) print(input_vec.shape) # UIM = UIManager() # mwc = wx.GetApp().get_main_window_controller() # cc = UIM.create('crossplot_controller', mwc.uid) # xlim_max, ylim_max = input_vec.shape # # (left, right, bottom, top) # extent = (0, 0, xlim_max, ylim_max) # image = cc._main_panel.append_artist("AxesImage", # cmap="Greys") #, # #extent=extent) # #cc._main_panel.add_image(image) # cc._main_panel.set_plot_lim('x', (0, xlim_max)) # cc._main_panel.set_plot_lim('y', (ylim_max, 0)) # print(xlim_max, ylim_max) # image.set_data(input_vec) # image.set_label('crossplot_controller') # if image.get_clip_path() is None: # # image does not already have clipping set, # # clip to axes patch # image.set_clip_path(image.axes.patch) #gripy_app = wx.App.Get() #gripy_app.load_project_data(fullfilename) except Exception as e: print ('ERROR [on_create_model]:', str(e)) raise finally: del wait del disableAll UIM.remove(dlg.uid)
def on_create_1_layer_image(*args, **kwargs): OM = ObjectManager() UIM = UIManager() # dlg = UIM.create('dialog_controller', title='Create 1 layer image') ctn_model = dlg.view.AddCreateContainer('StaticBox', label='Image', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) # box_name = dlg.view.AddCreateContainer('BoxSizer', ctn_model, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND|wx.ALL, border=5) dlg.view.AddStaticText(box_name, label='Name:', proportion=1) dlg.view.AddTextCtrl(box_name, proportion=1, flag=wx.ALIGN_LEFT, border=5, widget_name='image_name', initial="My image") # box_color = dlg.view.AddCreateContainer('BoxSizer', ctn_model, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND|wx.ALL, border=5) dlg.view.AddStaticText(box_color, label='Color:', proportion=1) dlg.view.AddChoice(box_color, proportion=1, flag=wx.ALIGN_LEFT, widget_name='color', options=COLOR_TYPES, initial=0) # # box_width_pixels = dlg.view.AddCreateContainer('BoxSizer', ctn_model, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND|wx.ALL, border=5) dlg.view.AddStaticText(box_width_pixels, label='Width pixels:', proportion=1) dlg.view.AddTextCtrl(box_width_pixels, proportion=1, flag=wx.ALIGN_LEFT, border=5, widget_name='width_pixels', initial=100) # # box_height_pixels = dlg.view.AddCreateContainer('BoxSizer', ctn_model, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND|wx.ALL, border=5) dlg.view.AddStaticText(box_height_pixels, label='Height pixels:', proportion=1) dlg.view.AddTextCtrl(box_height_pixels, proportion=1, flag=wx.ALIGN_LEFT, border=5, widget_name='height_pixels', initial=100) # # dlg.view.SetSize((400, 250)) result = dlg.view.ShowModal() try: disableAll = wx.WindowDisabler() wait = wx.BusyInfo("Creating model. Wait...") if result == wx.ID_OK: results = dlg.get_results() print(results) width = int(results.get('width_pixels')) height = int(results.get('height_pixels')) if results.get('color') == "white": data = np.ones((height, width), dtype=np.ubyte) data *= 255 else: data = np.zeros((height, width), dtype=np.ubyte) img = OM.new('image', data, name=results.get('image_name')) result = OM.add(img) except Exception as e: print ('ERROR [on_create_model]:', str(e)) raise finally: del wait del disableAll UIM.remove(dlg.uid)
def on_create_model(*args, **kwargs): OM = ObjectManager() UIM = UIManager() # images_od = OrderedDict() images = OM.list('image') for image in images: images_od[image.name] = image.uid # dlg = UIM.create('dialog_controller', title='Chose image for model input') ctn_image = dlg.view.AddCreateContainer('StaticBox', label='Select Image', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddChoice(ctn_image, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='images_choice', options=images_od, initial=0) # dlg.view.SetSize((300, 180)) result = dlg.view.ShowModal() if result == wx.ID_OK: results = dlg.get_results() print(results) image_uid = results.get("images_choice") if not image_uid: return image = OM.get(image_uid) values = np.unique(image.data) print(values) print(values.size) if values.size > 2: raise Exception("ERRO!") # dlg = UIM.create('dialog_controller', title='Create model') ctn_model = dlg.view.AddCreateContainer('StaticBox', label='Model', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) # box_img_input = dlg.view.AddCreateContainer('BoxSizer', ctn_model, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND|wx.ALL, border=5) dlg.view.AddStaticText(box_img_input, label='Image input:', proportion=1) dlg.view.AddTextCtrl(box_img_input, proportion=1, flag=wx.ALIGN_LEFT, border=5, widget_name='image_name', initial=image.name) textctrl_image_name = dlg.view.get_object('image_name') textctrl_image_name.disable() # box_name = dlg.view.AddCreateContainer('BoxSizer', ctn_model, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND|wx.ALL, border=5) dlg.view.AddStaticText(box_name, label='Name:', proportion=1) dlg.view.AddTextCtrl(box_name, proportion=1, flag=wx.ALIGN_LEFT, border=5, widget_name='model_name', initial="My model") # # X Axis # def on_change_x_size(name, old_value, new_value, **kwargs): try: x_samples = float(dlg.view.get_object('x_samples').get_value()) x_spacing = float(dlg.view.get_object('x_spacing').get_value()) res = str(x_samples * x_spacing) except: res = "" textctrl_x_size = dlg.view.get_object('x_size') textctrl_x_size.set_value(res) # # ctn_x_axis = dlg.view.AddCreateContainer('StaticBox', label='X axis', orient=wx.HORIZONTAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) # ctn_x_samples = dlg.view.AddCreateContainer('StaticBox', ctn_x_axis, label='Samples(pixels)', orient=wx.VERTICAL, proportion=1, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_x_samples, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='x_samples', initial=image.width) textctrl_x_pixels = dlg.view.get_object('x_samples') textctrl_x_pixels.disable() #textctrl_x_samples.set_trigger(on_change_x_size) # ctn_x_spacing = dlg.view.AddCreateContainer('StaticBox', ctn_x_axis, label='Spacing(m)', orient=wx.VERTICAL, proportion=1, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_x_spacing, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='x_spacing', initial=1) textctrl_x_spacing = dlg.view.get_object('x_spacing') textctrl_x_spacing.set_trigger(on_change_x_size) # ctn_x_size = dlg.view.AddCreateContainer('StaticBox', ctn_x_axis, label='Size(m)', orient=wx.VERTICAL, proportion=1, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_x_size, proportion=1, flag=wx.EXPAND|wx.TOP, border=5, widget_name='x_size') textctrl_x_size = dlg.view.get_object('x_size') textctrl_x_size.disable() # on_change_x_size(None, None, None) # # Y Axis # def on_change_y_size(name, old_value, new_value, **kwargs): try: y_samples = float(dlg.view.get_object('y_samples').get_value()) y_spacing = float(dlg.view.get_object('y_spacing').get_value()) res = str(y_samples * y_spacing) except: res = "" textctrl_y_size = dlg.view.get_object('y_size') textctrl_y_size.set_value(res) # # ctn_y_axis = dlg.view.AddCreateContainer('StaticBox', label='Y axis', orient=wx.HORIZONTAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) # ctn_y_samples = dlg.view.AddCreateContainer('StaticBox', ctn_y_axis, label='Samples(pixels)', orient=wx.VERTICAL, proportion=1, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_y_samples, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='y_samples', initial=image.height) textctrl_y_pixels = dlg.view.get_object('y_samples') textctrl_y_pixels.disable() #textctrl_y_samples.set_trigger(on_change_y_size) # ctn_y_spacing = dlg.view.AddCreateContainer('StaticBox', ctn_y_axis, label='Spacing(m)', orient=wx.VERTICAL, proportion=1, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_y_spacing, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='y_spacing', initial=1) textctrl_y_spacing = dlg.view.get_object('y_spacing') textctrl_y_spacing.set_trigger(on_change_y_size) # ctn_y_size = dlg.view.AddCreateContainer('StaticBox', ctn_y_axis, label='Size(m)', orient=wx.VERTICAL, proportion=1, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_y_size, proportion=1, flag=wx.EXPAND|wx.TOP, border=5, widget_name='y_size') textctrl_y_size = dlg.view.get_object('y_size') textctrl_y_size.disable() # on_change_y_size(None, None, None) # if values[0] == 0: value_layer_1_text = "color: Black" elif values[0] == 255: value_layer_1_text = "color: White" else: value_layer_1_text = "value: " + str(values[0]) ctn_prop_matrix = dlg.view.AddCreateContainer('StaticBox', label="Layer 1 properties (" + value_layer_1_text + ")", orient=wx.HORIZONTAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) # ctn_matrix_vp = dlg.view.AddCreateContainer('StaticBox', ctn_prop_matrix, label='Vp(m/s)', orient=wx.VERTICAL, proportion=1, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_matrix_vp, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='matrix_vp', initial=4000.0) # ctn_matrix_rho = dlg.view.AddCreateContainer('StaticBox', ctn_prop_matrix, label='Rho(m/s)', orient=wx.VERTICAL, proportion=1, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_matrix_rho, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='matrix_rho', initial=3.0) # if values.size == 2: if values[1] == 0: value_layer_2_text = "color: Black" elif values[1] == 255: value_layer_2_text = "color: White" else: value_layer_2_text = "value: " + str(values[1]) ctn_prop_pores = dlg.view.AddCreateContainer('StaticBox', label="Layer 2 properties (" + value_layer_2_text + ")", orient=wx.HORIZONTAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) # ctn_pores_vp = dlg.view.AddCreateContainer('StaticBox', ctn_prop_pores, label='Vp(m/s)', orient=wx.VERTICAL, proportion=1, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_pores_vp, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='pores_vp', initial=2500.0) # ctn_pores_rho = dlg.view.AddCreateContainer('StaticBox', ctn_prop_pores, label='Rho(m/s)', orient=wx.VERTICAL, proportion=1, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_pores_rho, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='pores_rho', initial=2.2) # dlg.view.SetSize((400, 580)) result = dlg.view.ShowModal() try: disableAll = wx.WindowDisabler() wait = wx.BusyInfo("Creating model. Wait...") if result == wx.ID_OK: results = dlg.get_results() print(results) am = OM.new('acoustic_2d_model', image_uid=image.uid, dx=results.get('x_spacing'), dy=results.get('y_spacing'), name=results.get('model_name')) result = OM.add(am) print ('result acoustic_2d_model:', result, args, kwargs) layer1 = OM.new('geolayer', value=values[0], vp=results.get('matrix_vp'), rho=results.get('matrix_rho'), name="Layer 1") result = OM.add(layer1, am.uid) print ('result layer 1:', result) if values.size == 2: layer2 = OM.new('geolayer', value=values[1], vp=results.get('pores_vp'), rho=results.get('pores_rho'), name="Layer 2") result = OM.add(layer2, am.uid) print ('result layer 2:', result) except Exception as e: print ('ERROR [on_create_model]:', str(e)) raise finally: del wait del disableAll UIM.remove(dlg.uid)
def on_load_image(*args, **kwargs): wildcard = "Load image file (*.png, *.tif)|*.png;*.tif" fdlg = wx.FileDialog(wx.App.Get().GetTopWindow(), "Choose file", wildcard=wildcard, style=wx.FD_OPEN|wx.FD_FILE_MUST_EXIST ) if fdlg.ShowModal() == wx.ID_OK: file_name = fdlg.GetFilename() dir_name = fdlg.GetDirectory() fdlg.Destroy() else: fdlg.Destroy() return fullfilename = os.path.join(dir_name, file_name) print("\n\n") print (fullfilename) img = Image.open(fullfilename) data = np.asarray(img) print(data.shape) print(data.dtype) if (len(data.shape) == 2): print(data[100,100]) # elif (len(input_vec.shape) == 3): # ny, nx, ncolor = input_vec.shape # new_vec = np.zeros((ny, nx), dtype=np.int8) # if (input_vec.shape[2] == 4): # # RGBA # for y in range(ny): # for x in range(nx): # new_vec[y, x] = (input_vec[y, x, 0] + input_vec[y, x, 1] + # input_vec[y, x, 2] + input_vec[y, x, 3])/4 # #new_vec = np.array(Image.open(fullfilename).convert('L')) # print(new_vec) # print(new_vec[100,100]) # values = np.unique(new_vec) # print(values.size) # input_vec = new_vec # #print(input_vec[100,100]) OM = ObjectManager() img_obj = OM.new('image', data, name=file_name) result = OM.add(img_obj)
def on_create_2_layers_image(*args, **kwargs): OM = ObjectManager() UIM = UIManager() # dlg = UIM.create('dialog_controller', title='Create 2 layers image') # ctn_image = dlg.view.AddCreateContainer('StaticBox', label='Image', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) # box_name = dlg.view.AddCreateContainer('BoxSizer', ctn_image, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND|wx.ALL, border=5) dlg.view.AddStaticText(box_name, label='Name:', proportion=1) dlg.view.AddTextCtrl(box_name, proportion=1, flag=wx.ALIGN_LEFT, border=5, widget_name='image_name', initial="") # box_lattice = dlg.view.AddCreateContainer('BoxSizer', ctn_image, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND|wx.ALL, border=5) dlg.view.AddStaticText(box_lattice, label='Lattice:', proportion=1) dlg.view.AddChoice(box_lattice, proportion=1, flag=wx.ALIGN_LEFT, widget_name='lattice', options=LATTICE_TYPES, initial=0) # box_width = dlg.view.AddCreateContainer('BoxSizer', ctn_image, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND|wx.ALL, border=5) dlg.view.AddStaticText(box_width, label='Width (pixels):', proportion=1) dlg.view.AddTextCtrl(box_width, proportion=1, flag=wx.ALIGN_LEFT, border=5, widget_name='image_width', initial="200") # box_height = dlg.view.AddCreateContainer('BoxSizer', ctn_image, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND|wx.ALL, border=5) dlg.view.AddStaticText(box_height, label='Height (pixels):', proportion=1) dlg.view.AddTextCtrl(box_height, proportion=1, flag=wx.ALIGN_LEFT, border=5, widget_name='image_height', initial="200") # box_diameter = dlg.view.AddCreateContainer('BoxSizer', ctn_image, orient=wx.HORIZONTAL, proportion=1, flag=wx.EXPAND|wx.ALL, border=5) dlg.view.AddStaticText(box_diameter, label='Circle diameter (pixels):', proportion=1) dlg.view.AddTextCtrl(box_diameter, proportion=1, flag=wx.ALIGN_LEFT, border=5, widget_name='diameter', initial=10) # 10px # # dlg.view.SetSize((400, 380)) result = dlg.view.ShowModal() try: disableAll = wx.WindowDisabler() wait = wx.BusyInfo("Creating image. Wait...") if result == wx.ID_OK: results = dlg.get_results() print(results) #filename='crystal_777.png' crystal = Crystal(ngrains=1, #seed_minimum_distance=float(results.get('seed_min_dist')), lattice = results.get('lattice'), atom_diameter=float(results.get('diameter')), xsize= float(results.get('image_width')), ysize=float(results.get('image_height'))) crystal.grow_crystal() input_vec = crystal.plot_crystal(linewidth=0) #, filename=filename) print("\n\n") print ("\n\nfilename: ", results.get('image_name')) #input_vec = plt.imread(fullfilename) print(input_vec.shape) print(input_vec.dtype) ny, nx, ncolor = input_vec.shape new_vec = np.zeros((ny, nx), dtype=np.ubyte) if (input_vec.shape[2] == 4): # RGBA for y in range(ny): for x in range(nx): #print("haha: ", (input_vec[y, x, 0], input_vec[y, x, 1], input_vec[y, x, 2], input_vec[y, x, 3])) #a, b, c = input_vec[y, x] r = int(input_vec[y, x, 0]) b = int(input_vec[y, x, 1]) g = int(input_vec[y, x, 2]) soma = r + g + b # print((input_vec[y, x, 0], input_vec[y, x, 1], input_vec[y, x, 2]), (input_vec[y, x, 0] + input_vec[y, x, 1] + input_vec[y, x, 2])) # print(type(r), type(g), type(soma), soma) # print(int(r), int(g), int(soma)) print(soma/3) if (soma/3) > 128: new_vec[y, x] = 255 else: new_vec[y, x] = 0 #new_vec = np.array(Image.open(fullfilename).convert('L')) print(new_vec) #print(new_vec[100,100]) values = np.unique(new_vec) print("\n\nVALUES.SIZE: ", values.size) input_vec = new_vec print(input_vec.shape) print(input_vec.dtype) img_obj = OM.new('image', input_vec, name=results.get('image_name')) result = OM.add(img_obj) # if (len(input_vec.shape) == 2): # print(input_vec[100,100]) # elif (len(input_vec.shape) == 3): # ny, nx, ncolor = input_vec.shape # new_vec = np.zeros((ny, nx), dtype=np.int8) # if (input_vec.shape[2] == 4): # # RGBA # for y in range(ny): # for x in range(nx): # new_vec[y, x] = (input_vec[y, x, 0] + input_vec[y, x, 1] + # input_vec[y, x, 2] + input_vec[y, x, 3])/4 # #new_vec = np.array(Image.open(fullfilename).convert('L')) # #print(new_vec) # #print(new_vec[100,100]) # values = np.unique(new_vec) # #print(values.size) # input_vec = new_vec # #print(input_vec[100,100]) # values = np.unique(input_vec) # am = OM.new('acoustic_2d_model', input_vec, # dx=results.get('x_spacing'), # dy=results.get('y_spacing'), # name=results.get('image_name')) # result = OM.add(am) # print ('result acoustic_2d_model:', result, args, kwargs) # layer1 = OM.new('geolayer', value=values[0], vp=results.get('matrix_vp'), rho=results.get('matrix_rho'), name="Layer 1") # result = OM.add(layer1, am.uid) # print ('result layer 1:', result) # if values.size == 2: # layer2 = OM.new('geolayer', value=values[1], vp=results.get('pores_vp'), rho=results.get('pores_rho'), name="Layer 2") # result = OM.add(layer2, am.uid) # print ('result layer 2:', result) # print(input_vec.shape) except Exception as e: print ('ERROR [on_create_model]:', str(e)) raise finally: del wait del disableAll UIM.remove(dlg.uid)
def on_create_simulation(*args, **kwargs): OM = ObjectManager() UIM = UIManager() # models_od = OrderedDict() models = OM.list('acoustic_2d_model') for model in models: models_od[model.name] = model.uid # wavelets_od = OrderedDict() wavelets = OM.list('wavelet') for wavelet in wavelets: wavelets_od[wavelet.name] = wavelet.uid # dlg = UIM.create('dialog_controller', title='Create Staggered Grid Simulation') # ctn_models = dlg.view.AddCreateContainer('StaticBox', label='Select Model', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddChoice(ctn_models, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='model', options=models_od, initial=0) # ctn_wavelet = dlg.view.AddCreateContainer('StaticBox', label='Select Wavelet', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddChoice(ctn_wavelet, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='wavelet', options=wavelets_od, initial=0) # # # ctn_dt = dlg.view.AddCreateContainer('StaticBox', # label='Wavelet Time Step (dt)', # orient=wx.VERTICAL, # proportion=0, # flag=wx.EXPAND|wx.TOP, border=5) # dlg.view.AddTextCtrl(ctn_dt, proportion=0, flag=wx.EXPAND|wx.TOP, # border=5, widget_name='dt', initial='0.01') # # # ctn_time_stop = dlg.view.AddCreateContainer('StaticBox', # label='Wavelet Time Stop', # orient=wx.VERTICAL, # proportion=0, # flag=wx.EXPAND|wx.TOP, border=5) # dlg.view.AddTextCtrl(ctn_time_stop, proportion=0, flag=wx.EXPAND|wx.TOP, # border=5, widget_name='time_stop', initial='1.0') # # # ctn_soux = dlg.view.AddCreateContainer('StaticBox', label='Source point X', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_soux, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='soux', initial='0') # ctn_souy = dlg.view.AddCreateContainer('StaticBox', label='Source point Y', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_souy, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='souy', initial='0') # ctn_sim_steps = dlg.view.AddCreateContainer('StaticBox', label='Simulation Steps', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_sim_steps, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='sim_steps', initial='200') # # ctn_name = dlg.view.AddCreateContainer('StaticBox', label='Simulation name', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND|wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_name, proportion=0, flag=wx.EXPAND|wx.TOP, border=5, widget_name='simulation_name', initial='Staggered Grid 2 Layers Model') # dlg.view.SetSize((300, 500)) result = dlg.view.ShowModal() # try: #disableAll = wx.WindowDisabler() #wait = wx.BusyInfo("Creating simulation. Wait...") if result == wx.ID_OK: results = dlg.get_results() #print (results) dialog = wx.ProgressDialog("Staggered grid simulation", "Time remaining", int(results.get('sim_steps')), style=wx.PD_CAN_ABORT|wx.PD_ELAPSED_TIME|wx.PD_REMAINING_TIME ) wavefield, dx, dy, dt, cfl, c1 = staggeredGrid(results.get('model'), results.get('wavelet'), int(results.get('sim_steps')), sou_x=int(results.get('soux')), sou_y=int(results.get('souy')), progress_dialog=dialog ) # # simulation = OM.new('simulation', wavefield, dx=dx, dy=dy, dt=dt, sou_x=int(results.get('soux')), sou_y=int(results.get('souy')), model_uid= results.get('model'), wavelet_uid= results.get('wavelet'), name=results.get('simulation_name'), cfl=cfl, c1=c1) #_type="Ricker", # wavelet = OM.new('wavelet', _type="Ricker", # f0=results.get('f0'), # amp=results.get('amp'), # name=results.get('wavelet_name')) result = OM.add(simulation) print ('result simulation:', result, args, kwargs) except Exception as e: print ('ERROR [on_create_model]:', str(e)) #raise finally: dialog.Destroy() #del wait #del disableAll UIM.remove(dlg.uid)
def _do_initial_tests(): # pass mwc = get_main_window_controller() # mwc.size = (1000, 700) depth = [ 2240.07, 2240.22, 2240.38, 2240.53, 2240.68, 2240.83, 2240.99, 2241.14, 2241.29, 2241.44, 2241.60, 2241.75, 2241.90, 2242.05, 2242.21, 2242.36, 2242.51, 2242.66, 2242.81, 2242.97, 2243.12, 2243.27, 2243.42, 2243.58, 2243.73, 2243.88, 2244.03, 2244.19, 2244.34, 2244.49, 2244.64, 2244.80, 2244.95, 2245.10, 2245.25, 2245.41, 2245.56, 2245.71, 2245.86, 2246.02, 2246.17, 2246.32, 2246.47, 2246.62, 2246.78, 2246.93, 2247.08, 2247.23, 2247.39, 2247.54, 2247.69, 2247.84, 2248.00, 2248.15, 2248.30, 2248.45, 2248.61, 2248.76, 2248.91, 2249.06, 2249.22, 2249.37, 2249.52, 2249.67, 2249.83, 2249.98, 2250.13, 2250.28, 2250.43, 2250.59, 2250.74, 2250.89, 2251.04, 2251.20, 2251.35, 2251.50, 2251.65, 2251.81, 2251.96, 2252.11, 2252.26, 2252.42, 2252.57, 2252.72, 2252.87, 2253.03, 2253.18, 2253.33, 2253.48, 2253.64, 2253.79, 2253.94, 2254.09, 2254.24, 2254.40, 2254.55, 2254.70, 2254.85, 2255.01, 2255.16, 2255.31, 2255.46, 2255.62, 2255.77, 2255.92, 2256.07, 2256.23, 2256.38, 2256.53, 2256.68, 2256.84, 2256.99, 2257.14, 2257.29, 2257.45, 2257.60, 2257.75, 2257.90, 2258.05, 2258.21, 2258.36, 2258.51, 2258.66, 2258.82, 2258.97, 2259.12, 2259.27, 2259.43, 2259.58, 2259.73, 2259.88, 2260.04, 2260.19, 2260.34, 2260.49, 2260.65, 2260.80, 2260.95, 2261.10, 2261.26, 2261.41, 2261.56, 2261.71, 2261.86, 2262.02, 2262.17, 2262.32, 2262.47, 2262.63, 2262.78, 2262.93, 2263.08, 2263.24, 2263.39, 2263.54, 2263.69, 2263.85, 2264.00, 2264.15, 2264.30, 2264.46, 2264.61, 2264.76, 2264.91, 2265.07, 2265.22, 2265.37, 2265.52, 2265.67, 2265.83, 2265.98, 2266.13, 2266.28, 2266.44, 2266.59, 2266.74, 2266.89, 2267.05, 2267.20, 2267.35, 2267.50, 2267.66, 2267.81, 2267.96, 2268.11, 2268.27, 2268.42, 2268.57, 2268.72, 2268.88, 2269.03, 2269.18, 2269.33, 2269.48, 2269.64, 2269.79, 2269.94, 2270.09, 2270.25, 2270.40, 2270.55, 2270.70, 2270.86, 2271.01, 2271.16, 2271.31, 2271.47, 2271.62, 2271.77, 2271.92, 2272.08, 2272.23, 2272.38, 2272.53, 2272.69, 2272.84, 2272.99, 2273.14, 2273.29, 2273.45, 2273.60, 2273.75, 2273.90, 2274.06, 2274.21, 2274.36, 2274.51, 2274.67, 2274.82, 2274.97, 2275.12, 2275.28, 2275.43, 2275.58, 2275.73, 2275.89, 2276.04, 2276.19, 2276.34, 2276.50, 2276.65, 2276.80, 2276.95, 2277.10, 2277.26, 2277.41, 2277.56, 2277.71, 2277.87, 2278.02, 2278.17, 2278.32, 2278.48, 2278.63, 2278.78, 2278.93, 2279.09, 2279.24, 2279.39, 2279.54, 2279.70, 2279.85, 2280.00, 2280.15, 2280.31, 2280.46, 2280.61, 2280.76, 2280.91, 2281.07, 2281.22, 2281.37, 2281.52, 2281.68, 2281.83, 2281.98, 2282.13, 2282.29, 2282.44, 2282.59, 2282.74, 2282.90, 2283.05, 2283.20, 2283.35, 2283.51, 2283.66, 2283.81, 2283.96, 2284.12, 2284.27, 2284.42, 2284.57, 2284.72, 2284.88, 2285.03 ] phi = [ 12.71, 13.03, 13.91, 14.24, 14.14, 14.05, 13.56, 14.80, 18.43, 18.44, 18.44, 21.12, 21.15, 17.38, 15.26, 13.14, 13.79, 13.79, 17.52, 20.47, 23.41, 25.46, 25.37, 25.39, 25.40, 25.40, 27.12, 30.32, 29.79, 29.28, 28.77, 28.77, 27.44, 28.19, 28.16, 28.13, 28.36, 28.37, 26.91, 24.28, 21.66, 16.64, 13.95, 13.96, 16.51, 19.06, 23.68, 25.13, 19.13, 19.13, 19.13, 11.90, 9.31, 9.70, 11.75, 13.81, 13.82, 18.41, 21.13, 20.91, 20.69, 20.68, 20.37, 21.27, 21.83, 22.39, 20.46, 20.46, 16.11, 14.51, 12.92, 12.37, 12.38, 14.83, 15.59, 16.35, 15.95, 14.55, 14.56, 14.06, 13.56, 11.95, 11.58, 11.58, 11.53, 11.47, 11.62, 11.91, 11.91, 12.19, 12.48, 11.73, 11.46, 11.47, 11.22, 10.96, 9.73, 13.72, 13.73, 16.19, 18.65, 18.03, 13.38, 13.38, 12.02, 10.66, 10.46, 10.19, 10.19, 10.04, 9.89, 9.97, 9.97, 10.42, 10.55, 10.67, 10.72, 10.72, 10.56, 10.65, 10.75, 11.36, 11.36, 11.22, 11.09, 10.96, 9.82, 9.82, 7.87, 7.16, 6.46, 5.33, 5.33, 4.40, 3.59, 2.77, 2.37, 2.37, 5.29, 7.49, 9.69, 10.75, 10.76, 8.09, 6.05, 4.00, 1.81, 1.81, 1.41, 2.65, 3.90, 5.53, 5.52, 7.33, 7.22, 7.10, 7.38, 7.39, 6.75, 7.39, 8.02, 11.19, 11.20, 11.50, 10.28, 9.05, 6.72, 6.72, 7.45, 7.65, 7.84, 7.10, 7.10, 5.83, 5.72, 5.61, 4.59, 4.10, 4.10, 4.79, 5.48, 6.55, 7.06, 7.06, 7.21, 7.36, 8.14, 9.52, 10.88, 10.88, 10.89, 11.31, 11.47, 11.27, 11.27, 11.27, 11.02, 10.32, 10.17, 11.47, 12.78, 12.78, 16.69, 19.24, 20.08, 20.92, 20.92, 20.50, 19.54, 19.01, 18.48, 19.14, 19.14, 21.05, 22.17, 23.28, 24.52, 24.55, 24.56, 23.37, 22.18, 19.87, 20.66, 25.14, 27.49, 29.85, 29.85, 27.70, 20.82, 18.12, 15.42, 17.81, 17.81, 24.27, 26.65, 29.04, 30.60, 30.29, 29.74, 29.55, 29.35, 29.35, 29.75, 30.04, 30.74, 31.44, 32.84, 34.00, 33.49, 33.49, 33.49, 31.75, 30.09, 29.21, 29.32, 29.43, 29.69, 29.54, 29.54, 29.33, 29.11, 29.05, 29.68, 30.06, 29.81, 29.55, 28.75, 28.50, 28.76, 28.76, 28.77, 28.43, 27.98, 26.45, 25.01, 23.57, 20.54, 19.43, 20.82, 21.88, 22.94, 23.35, 21.23, 17.69, 17.69, 17.69, 15.08, 13.85, 13.22, 14.04, 14.86, 16.63, 15.77, 12.90, 11.81, 10.72 ] k = [ 3.17, 3.73, 5.40, 6.05, 6.04, 6.03, 4.90, 6.40, 21.92, 21.94, 21.96, 39.61, 35.40, 9.82, 5.63, 1.45, 4.24, 4.24, 22.42, 58.34, 94.26, 151.13, 143.73, 117.33, 117.42, 117.51, 125.67, 215.58, 158.82, 155.51, 152.19, 152.12, 120.77, 180.07, 207.44, 234.81, 256.96, 257.26, 128.33, 85.05, 41.76, 15.27, 7.26, 7.27, 20.29, 33.32, 88.98, 155.43, 36.55, 36.55, 36.54, 1.99, 0.00, 0.00, 1.49, 2.97, 2.98, 17.56, 40.01, 37.44, 34.87, 34.84, 28.78, 42.96, 61.04, 79.13, 49.58, 49.58, 12.45, 7.08, 1.70, 0.47, 0.47, 3.35, 5.34, 7.33, 7.46, 3.98, 3.99, 2.77, 1.56, 0.82, 0.63, 0.63, 0.66, 0.69, 1.16, 0.49, 0.49, 0.47, 0.44, 0.09, 0.07, 0.07, 0.48, 0.88, 0.60, 11.45, 11.47, 20.36, 29.25, 19.84, 3.37, 3.36, 1.73, 0.10, 0.08, 0.11, 0.11, 0.12, 0.14, 0.15, 0.15, 0.15, 0.15, 0.15, 0.17, 0.17, 0.18, 0.28, 0.37, 0.56, 0.56, 0.64, 0.87, 1.10, 1.73, 1.73, 1.76, 1.23, 0.69, 0.17, 0.17, 0.13, 0.08, 0.04, 0.01, 0.01, 0.52, 3.90, 7.28, 16.15, 16.16, 6.50, 3.48, 0.47, 0.03, 0.03, 0.02, 0.32, 0.62, 1.04, 1.04, 1.82, 1.30, 0.79, 0.84, 0.84, 0.51, 1.58, 2.66, 13.37, 13.39, 13.48, 8.85, 4.22, 0.38, 0.38, 0.61, 0.59, 0.56, 0.25, 0.25, 0.04, 0.03, 0.03, 0.01, 0.02, 0.02, 0.02, 0.02, 0.02, 0.01, 0.01, 0.03, 0.06, 0.48, 1.42, 2.44, 2.44, 2.44, 2.06, 2.13, 2.31, 2.31, 2.31, 1.68, 1.08, 1.06, 2.60, 4.15, 4.15, 12.25, 27.08, 38.61, 50.14, 50.13, 55.07, 44.74, 40.26, 35.79, 46.19, 46.22, 80.29, 105.75, 131.21, 185.27, 171.19, 171.31, 129.09, 86.87, 41.32, 41.43, 119.83, 325.13, 530.42, 530.63, 453.72, 85.49, 52.88, 20.27, 33.22, 33.23, 149.22, 329.19, 509.16, 900.93, 590.33, 343.81, 296.22, 248.63, 248.46, 259.63, 328.47, 421.46, 514.44, 628.84, 692.98, 445.79, 445.70, 445.61, 335.99, 301.97, 295.60, 302.84, 310.09, 311.65, 323.01, 323.06, 299.90, 276.74, 234.65, 231.59, 257.46, 267.27, 277.08, 244.13, 246.43, 245.78, 245.91, 246.05, 197.69, 187.18, 95.09, 63.74, 32.39, 13.97, 15.42, 30.43, 35.40, 40.37, 35.11, 19.13, 8.35, 8.35, 8.35, 2.52, 0.69, 0.85, 3.02, 5.20, 13.43, 8.33, 1.22, 0.62, 0.01 ] from classes.om import ObjectManager import numpy as np OM = ObjectManager() # well = OM.new('well', name='Winland-Lorenz') OM.add(well) # iset = OM.new('curve_set', name='Run 001') OM.add(iset, well.uid) # # """ index = OM.new('data_index', np.array(depth), name='Depth', dimension=0, datatype='MD', unit='m') OM.add(index, iset.uid) # log = OM.new('log', np.array(phi) / 100, index_uid=index.uid, name='Phi', unit='dec', datatype='NMRperm') OM.add(log, iset.uid) # """ """ # log = OM.new('log', np.array(k), index_uid=index.uid, name='K', unit='mD', datatype='CorePerm') OM.add(log, iset.uid) # # # """ iset2 = OM.new('curve_set', name='Run 002') OM.add(iset2, well.uid) # index = OM.new('data_index', np.array(depth), name='Depth', dimension=0, datatype='MD', unit='m') OM.add(index, iset2.uid) # log = OM.new('log', np.array(phi) / 100, index_uid=index.uid, name='Phi', unit='dec', datatype='NMRperm') OM.add(log, iset2.uid) # log = OM.new('log', np.array(k), index_uid=index.uid, name='K', unit='mD', datatype='CorePerm') OM.add(log, iset2.uid) # # """ # Trabalho Sala GBDI/PCE # mwc.pos = (-1900, -700) # mwc.maximized = False # CASA mwc.pos = (-8, 0) mwc.size = (1240, 1046) mwc.maximized = False # BR # mwc.pos = (-1925, -921) # mwc.size = (1116, 1131) # mwc.pos = (-1300,600) # mwc.maximized = True """ from om.manager import ObjectManager OM = ObjectManager() well = OM.new('well', name='ZZZ') OM.add(well) """ """ mwc = get_main_window_controller() mwc.size = wx.Size(900, 200) mwc.size = wx.Size(900, 460) print (mwc.name) print (mwc['name']) del mwc.name # del mwc['name'] """ ''' mwc = get_main_window_controller() mwc.pos = (-1092, 606) mwc.size = (900, 600) mwc.maximized = False ''' ''' print ('\n\n\n\n\n\n\n\n\n\n') from om.manager import ObjectManager OM = ObjectManager() OM.print_info() well = OM.new('well', name='ZZZ') OM.add(well) ''' """
def do_STFT(*args, **kwargs): toc = kwargs.get('toc') if not toc: raise Exception('Trabalhando somente com o TrackObjectController.') # OM = ObjectManager() UIM = UIManager() dlg = UIM.create('dialog_controller', title='Short Time Fourier Transform') # try: ctn_spec_type = dlg.view.AddCreateContainer('StaticBox', label='Spectrogram type', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND | wx.TOP, border=5) dlg.view.AddChoice(ctn_spec_type, proportion=0, flag=wx.EXPAND | wx.TOP, border=5, widget_name='spectrogram_type', options=SPECGRAM_TYPES) # ctn_win_size = dlg.view.AddCreateContainer( 'StaticBox', label='Window size (samples)', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND | wx.TOP, border=5) dlg.view.AddSpinCtrl(ctn_win_size, proportion=0, flag=wx.EXPAND, widget_name='window_size', max=1024, initial=256) # ctn_overlap_size = dlg.view.AddCreateContainer( 'StaticBox', label='Overlap size (samples)', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND | wx.TOP, border=5) dlg.view.AddSpinCtrl(ctn_overlap_size, proportion=0, flag=wx.EXPAND, widget_name='noverlap', max=512, initial=128) # dlg.view.SetSize((230, 260)) result = dlg.view.ShowModal() # if result == wx.ID_OK: results = dlg.get_results() if results.get('spectrogram_type'): # print('\ndo_STFT:', toc.get_data_object_uid()) # di_uid, di_data = toc.get_last_dimension_index() data_index = OM.get(di_uid) unit = uom.get_unit(data_index.unit) dim = uom.get_unit_dimension(unit.dimension) print(unit.dimension, dim, dim.name) if dim.name == 'time': print('\nConvertendo {} de {} para {}.'.format( dim.name, data_index.unit, 's')) di_data = uom.convert(di_data, data_index.unit, 's') elif dim.name == 'length': print('\nConvertendo {} de {} para {}.'.format( dim.name, data_index.unit, 'm')) di_data = uom.convert(di_data, data_index.unit, 'm') else: print('\nNao converteu') # new_data = uom.convert(obj.data, obj.unit, new_unit_name) # start_value = di_data[0] step_value = di_data[1] - di_data[0] # print('start_value: {} - step_value: {}'.format( start_value, step_value)) # dm_data = toc.get_filtered_data() # # STFT(x, window_size, noverlap, time_start, Ts, mode='psd'): # print('start_value, step_value:', start_value, step_value) spec_type = results.get('spectrogram_type') stft_data, freq_values, index_values = STFT( dm_data, results.get('window_size'), results.get('noverlap'), start_value, step_value, mode=spec_type) # freq_values *= 1000 # # print ('\n\nRetornou') data_out = np.zeros((len(di_data), len(freq_values))) stft_index_step = index_values[1] - index_values[0] stft_index_start = index_values[0] - (stft_index_step / 2) stft_index_end = index_values[-1] + (stft_index_step / 2) # # print('Orig shape:', dm_data.shape) # print('Freq Index Shape:', len(freq_values), len(index_values), stft_data.shape) # print('Freqs:', np.nanmin(freq_values), np.nanmax(freq_values)) # print('Indexes:', index_values) # # print ('\n\n', stft_index_start, stft_index_end) for idx, time in enumerate(di_data): if time >= stft_index_start and time < stft_index_end: stft_index_idx = int( (time - stft_index_start) // stft_index_step) # print(idx, time, stft_index_start, stft_index_step, stft_index_idx) data_out[idx] = stft_data[stft_index_idx] # print '\n\n' data_out = data_out.T # print() # print('data_out.shape:', data_out.shape) # print() # if spec_type == 'PHASE': spec_type = 'PHASE_UNWRAPPED' elif spec_type == 'ANGLE': spec_type = 'PHASE' # spectogram = OM.new('spectogram', data_out, name=toc.get_data_name() + '_STFT', datatype=results.get('spectrogram_type')) if not OM.add(spectogram, toc.get_data_object_uid()): msg = 'Object was not added. tid={\'spectogram\'}' raise Exception(msg) # freq_index = OM.new('data_index', freq_values, name='Frequency', unit='Hz', datatype='FREQUENCY') if not OM.add(freq_index, spectogram.uid): raise Exception('Frequency Index was not added.') # spectogram._create_data_index_map([freq_index.uid], [di_uid]) except Exception as e: print('ERROR:', e) # pass finally: UIM.remove(dlg.uid)
def do_CWT(*args, **kwargs): toc = kwargs.get('toc') if not toc: raise Exception('Trabalhando somente com o TrackObjectController.') # # obj = args[0] UIM = UIManager() dlg = UIM.create('dialog_controller', title='Continuous Wavelet Transform') # try: ctn_wavelet = dlg.view.AddCreateContainer('StaticBox', label='Wavelet', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND | wx.TOP, border=5) dlg.view.AddChoice(ctn_wavelet, proportion=0, flag=wx.EXPAND | wx.TOP, border=5, widget_name='wavelet', options=WAVELET_TYPES) # ctn_scale_res = dlg.view.AddCreateContainer('StaticBox', label='Scale resolution', orient=wx.VERTICAL, proportion=0, flag=wx.EXPAND | wx.TOP, border=5) dlg.view.AddTextCtrl(ctn_scale_res, proportion=0, flag=wx.EXPAND | wx.TOP, border=5, widget_name='dj', initial='0.125') # dlg.view.SetSize((230, 260)) result = dlg.view.ShowModal() if result == wx.ID_OK: results = dlg.get_results() print(results) dj = None try: dj = float(results.get('dj')) except: pass if dj is None: return wavelet = results.get('wavelet') if wavelet == 'morlet': func = MorletWavelet() elif wavelet == 'ricker': func = RickerWavelet() elif wavelet == 'dog3': func = DOGWavelet(m=3) elif wavelet == 'dog4': func = DOGWavelet(m=4) elif wavelet == 'dog5': func = DOGWavelet(m=5) elif wavelet == 'dog6': func = DOGWavelet(m=6) elif wavelet == 'paul2': func = PaulWavelet(m=2) elif wavelet == 'paul3': func = PaulWavelet(m=3) elif wavelet == 'paul4': func = PaulWavelet(m=4) elif wavelet == 'paul5': func = PaulWavelet(m=5) elif wavelet == 'paul6': func = PaulWavelet(m=6) else: raise Exception() # TODO: Rever tudo isso abaixo valid_data = obj.data[np.isfinite(obj.data)] valid_index_data = obj.get_indexes().data[np.isfinite(obj.data)] # wt = WaveletTransform(valid_data, dj=dj, wavelet=func, dt=obj.step, time=valid_index_data) # OM = ObjectManager() seismic = OM.new('scalogram', wt.wavelet_power, name=obj.name + '_CWT', unit='m', domain='depth', sample_rate=wt.time[1] - wt.time[0], datum=wt.time[0], samples=len(wt.time), frequencies=wt.fourier_frequencies, periods=wt.fourier_periods, scales=wt.scales) OM.add(seismic) print(wt.wavelet_transform.shape) # except Exception: pass finally: UIM.remove(dlg.uid)