def _create_fig():
    t = np.arange(0.0, 2.0, 0.01)
    s = 1 + np.sin(2 * np.pi * t)
    plt.plot(t, s)
    plt.xlabel('time (s)')
    plt.ylabel('voltage (mV)')
    plt.title('About as simple as it gets, folks')
    plt.grid(True)
    # plt.savefig("test.png")
    # plt.show()
    plt_wait(1)
    return plt.gcf()  # get access to the current fig
Exemple #2
0
    def test_edi_files2(self):
        # path to edis
        epath = EDI_DATA_DIR2
        elst = [
            os.path.join(epath, edi) for edi in os.listdir(epath)
            if (edi.endswith('.edi'))
        ]

        for efile in elst[-1:]:
            # eo = mtedi.Edi(efile)
            pr = mtpr.PlotResponse(fn=efile,
                                   plot_num=2,
                                   plot_tipper='yri',
                                   plot_pt='y')
            plt_wait(1)

            figfile = os.path.join(self._temp_dir,
                                   os.path.basename(efile)[:-4] + '.png')
            pr.save_plot(figfile)

            assert (os.path.exists(figfile))
Exemple #3
0
 def tearDown(self):
     plt_wait(1)
     plt_close('all')
Exemple #4
0
 def test_display_on_image(self):
     #self.edi_collection.display_on_image()
     plt_wait(1)
Exemple #5
0
 def test_display_on_basemap(self):
     self.edi_collection.display_on_basemap()
     plt_wait(1)
Exemple #6
0
 def test_plot_stations(self):
     self.edi_collection.plot_stations()
     plt_wait(1)
Exemple #7
0
    def _main_func(self, edipath):
        """
        test function should be successful with a edipath
        :return:
        """
        # path to save to
        savepath = self._output_dir

        # list of stations
        slst = [
            edi[0:-4] for edi in os.listdir(edipath) if edi.find('.edi') > 0
        ]

        # create an occam data object
        ocd = occam2d.Data(
            edi_path=edipath,
            station_list=slst,
            #                  interpolate_freq=True,
            #                  freq=np.logspace(-3,1,30)
        )

        ocd.save_path = savepath

        # choose frequency range to invert

        # ocd.freq_num = 50
        ocd.freq_min = 1
        ocd.freq_max = 10000
        # ocd.freq_num = 50 # number of frequencies to invert for
        ###########make data file

        # error floors
        ocd.res_te_err = 10
        ocd.res_tm_err = 10
        ocd.phase_te_err = 5
        ocd.phase_tm_err = 5
        # ocd.model_mode= 4
        ocd.write_data_file()

        # make model and mesh files
        ocr = occam2d.Regularization(ocd.station_locations)
        # number of layers
        ocr.n_layers = 60
        # cell width to aim for, note this is the mesh size (2 mesh blocks per model block)
        ocr.cell_width = 200
        # controls number and size of padding
        ocr.num_x_pad_cells = 9
        ocr.x_pad_multiplier = 1.9
        # controls aspect ratio of blocks
        ocr.trigger = 0.25

        # z1 layer and target depth in metres
        ocr.z1_layer = 20
        ocr.z_target_depth = 10000
        ocr.num_z_pad_cells = 10
        ocr.z_bottom = 100000
        ocr.save_path = ocd.save_path
        ocr.build_mesh()
        ocr.build_regularization()
        ocr.write_mesh_file()
        ocr.write_regularization_file()

        ocr.plot_mesh()
        plt_wait(1)
        plt_close()

        # make startup file
        ocs = occam2d.Startup()
        ocs.iterations_to_run = 40
        ocs.data_fn = os.path.join(ocd.save_path, 'OccamDataFile.dat')
        ocs.resistivity_start = 2.0
        ocr.get_num_free_params()
        ocs.param_count = ocr.num_free_param
        ocs.save_path = ocd.save_path
        ocs.model_fn = ocr.reg_fn
        ocs.write_startup_file()

        return savepath
Exemple #8
0
    def test_plot_model_and_responses(self):
        """
            test function
            :return: T/F
            """

        # path to directory containing inversion files
        idir = os.path.join(SAMPLE_DIR, 'Occam2d')

        # save path, to save plots to
        savepath = self._temp_dir
        offset = 0

        # go to model results directory and find the latest iteration file
        iterfile = 'ITER12.iter'
        respfile = 'RESP12.resp'

        datafn = 'OccamDataFile.dat'
        # get the iteration number
        iterno = iterfile[-7:-5]
        outfilename = iterfile[:-5]

        plotmodel = True  # set to True to plot the resistivity model
        plotresponses = True  # set to True to plot the responses
        save = True

        # horizontal padding on the edges for plotting, in km
        xpad = 1

        # plot the model
        if plotmodel:
            plotm = occam2d.PlotModel(
                iter_fn=os.path.join(idir, iterfile),
                data_fn=os.path.join(idir, datafn),
                station_font_pad=0.5,
                station_font_size=6,
                station_font_rotation=75,
                climits=(0., 2.5),  # colour scale limits
                xpad=xpad,
                dpi=300,  # resolution of figure
                fig_aspect=
                0.5,  # aspect ratio between horizontal and vertical scale
                ylimits=(0, 10),  # depth limits
                stationid=(-1, 3),  # index of station name to plot
                plot_yn='n')
            plotm.plot()
            if save:
                plotm.save_figure(
                    os.path.join(savepath, outfilename + '_resmodel.png'),
                    close_fig='n')  # this will produce 1 figure .png
            plt_wait(1)

        # plot the responses
        if plotresponses:
            plotresponse = occam2d.PlotResponse(os.path.join(idir, datafn),
                                                resp_fn=os.path.join(
                                                    idir, respfile),
                                                plot_type=['pb35', 'pb40'])
            if save:
                plotresponse.save_figures(
                    savepath, close_fig='n')  # this will produce 2 .pdf file
            plt_wait(1)

        plt_close()