示例#1
0
 def PreExit(self):
     msg = 'GriPy Application is preparing to terminate....'
     logging.info(msg)
     
     OM = ObjectManager()
     UIM = UIManager()
     UIM.PreExit()
     OM._reset()
示例#2
0
 def PreExit(self):
     msg = "Application is preparing to terminate...."
     logging.debug(msg)
     #
     OM = ObjectManager()
     UIM = UIManager()
     UIM.PreExit()
     OM._reset()
示例#3
0
def on_save_image(*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='Save image file')
    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")
    
    
        wildcard = "Save image file (*.png, *.tif)|*.png;*.tif"
    
        fdlg = wx.FileDialog(wx.App.Get().GetTopWindow(), 
                             "Save file", 
                             wildcard=wildcard, 
                             style=wx.FD_SAVE
        )
        
        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("fullfilename: ", fullfilename)

        image = OM.get(image_uid)
        img = Image.fromarray(image.data)
        img.save(fullfilename)
示例#4
0
def create_properties_dialog(obj_uid, size=None):
    if not size:
        size = (300, 330)
    UIM = UIManager()
    try:      
        dlg = UIM.create('object_properties_dialog_controller')
        #print(dlg)
        dlg.obj_uid = obj_uid
        dlg.view.SetSize(size)
        dlg.view.ShowModal()            
    except Exception as e:
        print ('\nERROR create_properties_dialog:', e)
        raise
    finally:
        UIM.remove(dlg.uid)    
示例#5
0
def on_create_teste(*args, **kwargs):
    OM = ObjectManager()
    UIM = UIManager()
    #        
    mwc = wx.GetApp().get_main_window_controller()
    tc = UIM.create('testeplot_controller', mwc.uid)      
                
                
                
                
                
                
                
                
                
示例#6
0
def load():

    if wx.GetApp().get_main_window_controller():
        raise Exception("Main app Interface cannot be loaded again.")

    app = wx.GetApp()
    UIM = UIManager()

    # mwc = UIM.create('frame_controller',
    #                   icon='add.ico',  # Relative Path to icons dir
    #                   size=(800, 600),
    #                   pos=(100, 100),
    #                   #maximized=True,
    #                   title="That's My app!"
    # )

    mwc = UIM.create(
        'main_window_controller',
        #icon='signal_32_32.bmp',
        size=(1000, 800),
        pos=(100, 100),
        #maximized=True,
        title="SonicSim 0.1b")

    # Tree Controller
    UIM.create('tree_controller', mwc.uid)

    # Menubar
    menubar_ctrl = UIM.create('menubar_controller', mwc.uid)

    mc_model = UIM.create('menu_controller', menubar_ctrl.uid, label=u"&Model")
    UIM.create(
        'menu_item_controller',
        mc_model.uid,
        label="&Load model",
        help="Load a model from file",
        id=wx.ID_OPEN,
        #callback='app.menu_functions.on_load_model'
    )
    UIM.create('menu_item_controller',
               mc_model.uid,
               label="&Create model",
               help="Create a new model",
               enabled=False
               #id=wx.ID_OPEN,
               #callback='app.menu_functions.on_open'
               )
    UIM.create('menu_item_controller',
               mc_model.uid,
               label="&Save model",
               help="Save a model into file",
               enabled=False
               #id=wx.ID_OPEN,
               #callback='app.menu_functions.on_open'
               )
    UIM.create('menu_item_controller', mc_model.uid, kind=wx.ITEM_SEPARATOR)
    UIM.create(
        'menu_item_controller',
        mc_model.uid,
        label=u'Exit',
        help=u'Exits application.',
        id=wx.ID_EXIT  #,
        #callback='app.menu_functions.on_exit'
    )

    mc_wavelet = UIM.create('menu_controller',
                            menubar_ctrl.uid,
                            label="Wavelet")
    UIM.create('menu_item_controller',
               mc_wavelet.uid,
               label="Create Wavelet",
               callback='app.menu_functions.on_create_wavelet')

    mc_sim = UIM.create('menu_controller',
                        menubar_ctrl.uid,
                        label="Simulation type")
    UIM.create(
        'menu_item_controller',
        mc_sim.uid,
        label="Staggered grid",
        #callback='app.menu_functions.on_create_simulation'
    )
    UIM.create('menu_item_controller',
               mc_sim.uid,
               label="Rotated Staggered grid",
               enabled=False
               #callback='app.menu_functions.on_open'
               )

    mc_about = UIM.create('menu_controller', menubar_ctrl.uid, label="About")

    UIM.create('menu_item_controller',
               mc_about.uid,
               label="Console",
               callback='app.menu_functions.on_console')

    # mwc = UIM.create('main_window_controller',
    #                  icon='add.ico',  # Relative Path to icons dir
    #                  size=(800, 600),
    #                  pos=(100, 100),
    #                  #maximized=True,
    #                  title="That's My app!"
    # )

    # Tree Controller
    # UIM.create('tree_controller', mwc.uid)

    # Menubar
    # menubar_ctrl = UIM.create('menubar_controller', mwc.uid)

    # mc_model = UIM.create('menu_controller', menubar_ctrl.uid,
    #                         label=u"&Model")
    # UIM.create('menu_item_controller', mc_model.uid,
    #         label="&Load model",
    #         help="Load a model from file",
    #         id=wx.ID_OPEN,
    #         callback='app.menu_functions.on_open_model'
    # )
    # UIM.create('menu_item_controller', mc_model.uid,
    #         label="&Create model",
    #         help="Create a new model",
    #         enabled=False
    #         #id=wx.ID_OPEN,
    #         #callback='app.menu_functions.on_open'
    # )
    # UIM.create('menu_item_controller', mc_model.uid,
    #         label="&Save model",
    #         help="Save a model into file",
    #         enabled=False
    #         #id=wx.ID_OPEN,
    #         #callback='app.menu_functions.on_open'
    # )
    # UIM.create('menu_item_controller', mc_model.uid,
    #                 kind=wx.ITEM_SEPARATOR
    # )
    # UIM.create('menu_item_controller', mc_model.uid,
    #         label=u'Exit',
    #         help=u'Exits application.',
    #         id=wx.ID_EXIT#,
    #         #callback='app.menu_functions.on_exit'
    # )

    # Main ToolBar
    # tbc = UIM.create('toolbar_controller', mwc.uid)
    # UIM.create('toolbartool_controller', tbc.uid,
    #                 label=u"New project",
    #                 bitmap='new_file-30.png',
    #                 help='New project',
    #                 long_help='Start a new Gripy project, closes existing',
    #                 callback='app.menu_functions.on_new'
    # )
    # UIM.create('toolbartool_controller', tbc.uid,
    #                 label=u"Abrir projeto",
    #                 bitmap='open_folder-30.png',
    #                 help='Abrir projeto',
    #                 long_help='Abrir projeto GriPy',
    #                 callback='app.menu_functions.on_open'
    # )
    # UIM.create('toolbartool_controller', tbc.uid,
    #                 label=u"Salvar projeto",
    #                 bitmap='save_close-30.png',
    #                 help='Salvar projeto',
    #                 long_help='Salvar projeto GriPy',
    #                 callback='app.menu_functions.on_save'
    # )
    # UIM.create('toolbartool_controller', tbc.uid,
    #                 label=u"Well Plot",
    #                 bitmap='oil_rig-30.png',
    #                 help='Well Plot',
    #                 long_help='Well Plot',
    #                 callback='app.menu_functions.on_new_wellplot'
    # )
    # UIM.create('toolbartool_controller', tbc.uid,
    #                 label=u"Crossplot",
    #                 bitmap='scatter_plot-30.png',
    #                 help='Crossplot',
    #                 long_help='Crossplot',
    #                 callback='app.menu_functions.on_new_crossplot'
    # )

    # StatusBar
    # UIM.create('statusbar_controller', mwc.uid,
    #     label='Bem vindo ao ' + \
    #     app.gripy_app.GripyApp.Get()._gripy_app_state.get('app_display_name')
    # )

    _LOADED = True
    return mwc
示例#7
0
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)        
示例#8
0
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)
示例#9
0
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)
示例#10
0
def on_console(*args, **kwargs):
    
    UIM = UIManager()
    mwc = wx.App.Get().get_main_window_controller()
    UIM.create('console_controller', mwc.uid)
示例#11
0
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)
示例#12
0
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)
示例#13
0
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)            
示例#14
0
    def __init__(self, simulation_uid, cc_uid, *args, **kwargs):

        OM = ObjectManager()
        simulation = OM.get(simulation_uid)
        model = OM.get(simulation.model_uid)
        wavelet = OM.get(simulation.wavelet_uid)

        UIM = UIManager()
        cc = UIM.get(cc_uid)

        # layers = OM.list(parent_uid=model.uid)
        # geo_layer_1 = layers[0]
        # geo_layer_2 = layers[1]

        # nx = input_vec.shape[0]  # Number of grid points in X
        # ny = input_vec.shape[1]  # Number of grid points in Y

        # dx = kwargs['dx']
        # dy = kwargs['dy']

        # f0 = kwargs['f0']
        # amp = kwargs['amp']

        # sou_x = kwargs['sou_x']    # Source position (in grid points) in X
        # sou_y = kwargs['sou_y']    # Source position (in grid points) in Y

        self.dt = simulation.dt
        self.steps = simulation.nt

        vmax = kwargs['vmax']
        vmin = kwargs['vmin']

        #title = kwargs['title']

        # # Receiver Position
        self._xrec1 = kwargs.get('x_rec1')
        self._yrec1 = kwargs.get(
            'y_rec1')  # Position Reciever 1 (in grid points)

        self._xrec2 = kwargs.get('x_rec2')
        self._yrec2 = kwargs.get(
            'y_rec2')  # Position Reciever 2 (in grid points)

        self._xrec3 = kwargs.get('x_rec3')
        self._yrec3 = kwargs.get(
            'y_rec3')  # Position Reciever 3 (in grid points)

        self.main_ax = cc._main_panel.plot_axes

        sec_axes = cc._main_panel.get_secondary_axes()

        #
        #
        self.t = np.arange(0, self.dt * self.steps, self.dt)  # Time vector
        self.nt = np.arange(0, self.steps)
        #
        #

        if self._xrec1 and self._yrec1:
            rec1_color = 'black'
            self.ax0 = sec_axes[0]
            self.ax0.set_xlabel('Step')
            self.ax0.set_ylabel('Amplitude')
            self.ax0.set_xticks((0, self.steps / 4, self.steps / 2,
                                 3 * self.steps / 4, self.steps))
            self.ax0.set_yticks((vmin, 0, vmax))
            self.seis_line0 = matplotlib.lines.Line2D((0.0, 0.0), (0.0, 0.0),
                                                      c=rec1_color)
            self.ax0.set_xlim(0, len(self.t))
            self.ax0.set_ylim(vmin, vmax)
            self.ax0.add_line(self.seis_line0)
            self.path_scatter1 = self.main_ax.scatter(self._xrec1,
                                                      self._yrec1,
                                                      s=30,
                                                      c=rec1_color,
                                                      marker="v")
            #
            self.ax0.xaxis.labelpad = 1.0
            self.ax0.xaxis.label.update({'size': '8'})
            self.ax0.yaxis.labelpad = 1.0
            self.ax0.yaxis.label.update({'size': '8'})

            self.ax0.xaxis.labelpad = 1.0
            self.ax0.yaxis.labelpad = 1.0
            self.ax0.yaxis.set_tick_params(which="both", labelsize=8)
            self.ax0.xaxis.set_tick_params(which="both", labelsize=8)

        else:
            self.ax0 = None
            self.seis_line0 = None
            self.path_scatter1 = None

        if self._xrec2 and self._yrec2:
            rec2_color = 'red'
            self.ax1 = sec_axes[1]
            self.ax1.set_xlabel('Step')
            self.ax1.set_ylabel('Amplitude')
            self.ax1.set_xticks((0, self.steps / 4, self.steps / 2,
                                 3 * self.steps / 4, self.steps))
            self.ax1.set_yticks((vmin, 0, vmax))
            self.seis_line1 = matplotlib.lines.Line2D((0.0, 0.0), (0.0, 0.0),
                                                      c=rec2_color)
            self.ax1.set_xlim(0, len(self.t))
            self.ax1.set_ylim(vmin, vmax)
            self.ax1.add_line(self.seis_line1)
            self.path_scatter2 = self.main_ax.scatter(self._xrec2,
                                                      self._yrec2,
                                                      s=30,
                                                      c=rec2_color,
                                                      marker="v")
            #
            self.ax1.xaxis.labelpad = 1.0
            self.ax1.xaxis.label.update({'size': '8'})
            self.ax1.yaxis.labelpad = 1.0
            self.ax1.yaxis.label.update({'size': '8'})

            self.ax1.xaxis.labelpad = 1.0
            self.ax1.yaxis.labelpad = 1.0
            self.ax1.yaxis.set_tick_params(which="both", labelsize=8)
            self.ax1.xaxis.set_tick_params(which="both", labelsize=8)

        else:
            self.ax1 = None
            self.seis_line1 = None
            self.path_scatter2 = None

        if self._xrec3 and self._yrec3:
            rec3_color = 'teal'
            self.ax2 = sec_axes[2]
            self.ax2.set_xlabel('Step')
            self.ax2.set_ylabel('Amplitude')
            self.ax2.set_xticks((0, self.steps / 4, self.steps / 2,
                                 3 * self.steps / 4, self.steps))
            self.ax2.set_yticks((vmin, 0, vmax))
            self.seis_line2 = matplotlib.lines.Line2D((0.0, 0.0), (0.0, 0.0),
                                                      c=rec3_color)
            self.ax2.set_xlim(0, len(self.t))
            self.ax2.set_ylim(vmin, vmax)
            self.ax2.add_line(self.seis_line2)
            self.path_scatter3 = self.main_ax.scatter(self._xrec3,
                                                      self._yrec3,
                                                      s=30,
                                                      c=rec3_color,
                                                      marker="v")
            #
            self.ax2.xaxis.labelpad = 1.0
            self.ax2.xaxis.label.update({'size': '8'})
            self.ax2.yaxis.labelpad = 1.0
            self.ax2.yaxis.label.update({'size': '8'})

            self.ax2.xaxis.labelpad = 1.0
            self.ax2.yaxis.labelpad = 1.0
            self.ax2.yaxis.set_tick_params(which="both", labelsize=8)
            self.ax2.xaxis.set_tick_params(which="both", labelsize=8)

        else:
            self.ax2 = None
            self.seis_line2 = None
            self.path_scatter3 = None

        # No vetor grid, pontos com valor 1 estao associados a Fase 1 (rocha,
        # cor preta). Os pontos com valor 0 estao associados a Fase 2 (poros,
        # de cor branca).
        # self.rho1 = 3.0
        # self.vp1 = 5000.0
        # #
        # self.rho2 = 2.2
        # self.vp2 = 3000.0

        cc.view._main_panel.draw()
        #super().draw(drawDC)

        self.main_ax = cc._main_panel.plot_axes

        # (left, right, bottom, top)
        extent = (0, simulation.nx, simulation.ny, 0)

        print("\n\n")
        print(extent)
        print("\n\n")

        # self.img_base = cc._main_panel.append_artist("AxesImage",
        #                                       cmap="Greys",
        #                                       extent=extent)

        # self.img_base.set_data(model.data)

        # self.img_base = matplotlib.image.AxesImage(self.main_ax) #, *args, **kwargs)
        # self.main_ax.add_image(self.img_base)

        # self.img_base.set_data(model.data)
        #self.img_base.set_alpha(0.8)
        #self.img_base = main_ax.imshow(vec)
        #self.img_base.set_cmap("Greys")

        #self.img_wavefield = self.main_ax.imshow(simulation.data[0,:,:])

        self.img_wavefield = cc._main_panel.append_artist("AxesImage",
                                                          cmap="seismic_r",
                                                          extent=extent)
        self.img_wavefield.set_data(simulation.data[0, :, :])

        self.img_wavefield.set_cmap("seismic_r")
        #self.img_wavefield.set_cmap("RdBu")

        self.cpc = UIM.list('canvas_plotter_controller_jun21', cc.uid)[0]
        self.cpc.figure_titletext = simulation.name

        # xlim = (0, simulation.nx)
        # cpc.xlim = xlim
        # cpc.set_plot_lim("x", xlim)

        # ylim = (simulation.ny, 0)
        # cpc.ylim = ylim
        # cpc.set_plot_lim("y", ylim)

        # print((0, simulation.nx), (simulation.ny, 0))

        # # self.main_ax.set_title(title)
        # # self.main_ax.set_xticks(range(0, nx+1, np.int(nx/5)))
        # # self.main_ax.set_yticks(range(0, ny+1, np.int(ny/5)))
        # # self.main_ax.set_xlabel('Grid-points in X axis')
        # # self.main_ax.set_ylabel('Grid-points in Y axis')

        # vmin = -0.2
        # vmax = 0.2

        self.img_wavefield.set_alpha(0.95)
        self.img_wavefield.set_clim(vmin, vmax)

        #self.img_wavefield.autoscale()
        # fig = self.main_ax.get_figure()

        # fig.colorbar(self.img_wavefield, ax=main_ax, orientation='horizontal', shrink=0.5) #, ticklocation='bottom')

        self._min_value = 0
        self._max_value = 0

        # # Output model parameter:
        # print('\n===========================================================')
        # print('DX MODELO: ', dx)
        # print("Model size: x:", dx*nx, "in m, y:", dy*ny, "in m")
        # print("Temporal discretization: ", self.dt," s")
        # print("Spatial discretization: ", dx, " m")
        # #print("Number of gridpoints per minimum wavelength: ", self.lampda_min/self._dx)
        # print("Wavefield Min-Max: ", np.min(wavefield), " - ",  np.max(wavefield))
        # print('===========================================================\n')

        # model_size_text_template = "Model size - X: %.3fm (%d x %.6fm), Y: %.3fm (%d x %.6fm)"
        # model_size_text = main_ax.text(0.01, 0.97, '', transform=main_ax.transAxes)
        # model_size_text.set_text(model_size_text_template % (dx*nx,
        #                                                 nx, dx,
        #                                                 dy*ny,
        #                                                 ny, dy))

        # wavelet_text_template = "Ricker wavelet: %.1fHz, Amplitude: %.1f"
        # wavelet_text = main_ax.text(0.01, 0.94, '', transform=main_ax.transAxes)
        # wavelet_text.set_text(wavelet_text_template % (f0, amp))

        # black_rock_text_template = 'Fase 1 (cinza) - Vp: %.1f m/s,  Rho: %.2f g/cm3'
        # black_rock_text = main_ax.text(0.01, 0.91, '', transform=main_ax.transAxes)
        # black_rock_text.set_text(black_rock_text_template % (self.vp1, self.rho1))

        # white_rock_text_template = 'Fase 2 (branco) - Vp: %.1f m/s,  Rho: %.2f g/cm3'
        # white_rock_text = main_ax.text(0.01, 0.88, '', transform=main_ax.transAxes)
        # white_rock_text.set_text(white_rock_text_template % (self.vp2, self.rho2))

        self.time_template = 'Step: %d/%d - Time: %.7fs'
        #self.time_text = main_ax.text(0.01, 0.85, '', transform=main_ax.transAxes)
        self.time_text = cc._main_panel.base_axes.title

        sou_color = 'green'
        # rec1_color = 'black'
        # rec2_color = 'red'
        # rec3_color = 'teal'

        self.main_ax.scatter(simulation.sou_x,
                             simulation.sou_y,
                             s=30,
                             c=sou_color,
                             marker=(5, 2))

        # self.main_ax.scatter(self._xrec1, self._yrec1, s=30, c=rec1_color, marker="v")
        # self.main_ax.scatter(self._xrec2, self._yrec2, s=30, c=rec2_color, marker="v")
        # self.main_ax.scatter(self._xrec3, self._yrec3, s=30, c=rec3_color, marker="v")

        # seis_ax0 = args[0]
        # seis_ax1 = args[1]
        # seis_ax2 = args[2]

        # #seis_ax0.set_title('Receiver 1 (' + rec1_color + ')')
        # seis_ax0.set_xlabel('Step')
        # seis_ax0.set_ylabel('Amplitude')
        # seis_ax0.set_xticks((0, self.steps/4, self.steps/2, 3*self.steps/4, self.steps))
        # seis_ax0.set_yticks((vmin, 0, vmax))
        # self.seis_line0 = matplotlib.lines.Line2D((0.0, 0.0), (0.0, 0.0), c=rec1_color)
        # seis_ax0.set_xlim(0, len(self.t))
        # seis_ax0.set_ylim(vmin, vmax)
        # seis_ax0.add_line(self.seis_line0)

        # #seis_ax1.set_title('Receiver 2 (' + rec2_color + ')')
        # seis_ax1.set_xlabel('Step')
        # seis_ax1.set_ylabel('Amplitude')
        # seis_ax1.set_xticks((0, self.steps/4, self.steps/2, 3*self.steps/4, self.steps))
        # seis_ax1.set_yticks((vmin, 0, vmax))
        # self.seis_line1 = matplotlib.lines.Line2D(self.t, wavefield[:, self._yrec2, self._xrec2], c=rec2_color)
        # seis_ax1.set_xlim(0, len(self.t))
        # seis_ax1.set_ylim(vmin, vmax)
        # seis_ax1.add_line(self.seis_line1)

        # #seis_ax2.set_title('Receiver 3 (' + rec3_color + ')')
        # seis_ax2.set_xlabel('Step')
        # seis_ax2.set_ylabel('Amplitude')
        # seis_ax2.set_xticks((0, self.steps/4, self.steps/2, 3*self.steps/4, self.steps))
        # seis_ax2.set_yticks((vmin, 0, vmax))
        # self.seis_line2 = matplotlib.lines.Line2D(self.t, wavefield[:, self._yrec3, self._xrec3], c=rec3_color)
        # seis_ax2.set_xlim(0, len(self.t))
        # seis_ax2.set_ylim(vmin, vmax)
        # seis_ax2.add_line(self.seis_line2)

        self.wavefield = simulation.data
示例#15
0
def load():

    if wx.GetApp().get_main_window_controller():
        raise Exception("Main app Interface cannot be loaded again.")

    app = wx.GetApp()
    UIM = UIManager()

    mwc = UIM.create(
        'frame_controller',
        icon='add.ico',  # Relative Path to icons dir
        size=(800, 600),
        pos=(100, 100),
        #maximized=True,
        title="That's My app!")

    # OM = ObjectManager()
    # well = OM.new('well', name="MEU POCO SINISTRO")
    # print(well)
    # print(well.name)

    # mwc = UIM.create('main_window_controller',
    #                  icon='add.ico',  # Relative Path to icons dir
    #                  size=(800, 600),
    #                  pos=(100, 100),
    #                  #maximized=True,
    #                  title="That's My app!"
    # )

    # Tree Controller
    # UIM.create('tree_controller', mwc.uid)

    # Menubar
    # menubar_ctrl = UIM.create('menubar_controller', mwc.uid)

    # mc_model = UIM.create('menu_controller', menubar_ctrl.uid,
    #                         label=u"&Model")
    # UIM.create('menu_item_controller', mc_model.uid,
    #         label="&Load model",
    #         help="Load a model from file",
    #         id=wx.ID_OPEN,
    #         callback='app.menu_functions.on_open_model'
    # )
    # UIM.create('menu_item_controller', mc_model.uid,
    #         label="&Create model",
    #         help="Create a new model",
    #         enabled=False
    #         #id=wx.ID_OPEN,
    #         #callback='app.menu_functions.on_open'
    # )
    # UIM.create('menu_item_controller', mc_model.uid,
    #         label="&Save model",
    #         help="Save a model into file",
    #         enabled=False
    #         #id=wx.ID_OPEN,
    #         #callback='app.menu_functions.on_open'
    # )
    # UIM.create('menu_item_controller', mc_model.uid,
    #                 kind=wx.ITEM_SEPARATOR
    # )
    # UIM.create('menu_item_controller', mc_model.uid,
    #         label=u'Exit',
    #         help=u'Exits application.',
    #         id=wx.ID_EXIT#,
    #         #callback='app.menu_functions.on_exit'
    # )

    # Main ToolBar
    # tbc = UIM.create('toolbar_controller', mwc.uid)
    # UIM.create('toolbartool_controller', tbc.uid,
    #                 label=u"New project",
    #                 bitmap='new_file-30.png',
    #                 help='New project',
    #                 long_help='Start a new Gripy project, closes existing',
    #                 callback='app.menu_functions.on_new'
    # )
    # UIM.create('toolbartool_controller', tbc.uid,
    #                 label=u"Abrir projeto",
    #                 bitmap='open_folder-30.png',
    #                 help='Abrir projeto',
    #                 long_help='Abrir projeto GriPy',
    #                 callback='app.menu_functions.on_open'
    # )
    # UIM.create('toolbartool_controller', tbc.uid,
    #                 label=u"Salvar projeto",
    #                 bitmap='save_close-30.png',
    #                 help='Salvar projeto',
    #                 long_help='Salvar projeto GriPy',
    #                 callback='app.menu_functions.on_save'
    # )
    # UIM.create('toolbartool_controller', tbc.uid,
    #                 label=u"Well Plot",
    #                 bitmap='oil_rig-30.png',
    #                 help='Well Plot',
    #                 long_help='Well Plot',
    #                 callback='app.menu_functions.on_new_wellplot'
    # )
    # UIM.create('toolbartool_controller', tbc.uid,
    #                 label=u"Crossplot",
    #                 bitmap='scatter_plot-30.png',
    #                 help='Crossplot',
    #                 long_help='Crossplot',
    #                 callback='app.menu_functions.on_new_crossplot'
    # )

    # StatusBar
    # UIM.create('statusbar_controller', mwc.uid,
    #     label='Bem vindo ao ' + \
    #     app.gripy_app.GripyApp.Get()._gripy_app_state.get('app_display_name')
    # )

    _LOADED = True
    return mwc