Esempio n. 1
0
    def testExtrinsicAndProjection(self):
        ''' Try a simple example for extrinsic parameters of a camera. '''

        intrinsic = np.array([
            [1000,    0, 500, 0],
            [   0, 1000, 500, 0],
            [   0,    0,   1, 0],
        ])

        rot1 = np.array([
            [1,0,0],
            [0,1,0],
            [0,0,1],
        ])
        trans1 = np.array([0,0,0])

        rot2 = np.array([
            [0,0,1],
            [0,1,0],
            [1,0,0],
        ])
        trans2 = np.array([1000,1000,0])

        ext1 = Reconstruction.extrinsic_matrix(rot1, trans1)
        ext2 = Reconstruction.extrinsic_matrix(rot2, trans2)

        P1 = Reconstruction.projection_matrix(ext1, None)
        P2 = Reconstruction.projection_matrix(ext2, ext1)
Esempio n. 2
0
    def calibrate(self, instance):
        '''
        Calibrates the current instance with another by finding the relative
        fundamental, essential, and extrinsic matrix.

        Args:
            instance (ImageInstance): The other instance to calibrate with.
        '''

        kp1, _ = self.features
        kp2, _ = instance.features

        fundamental, self.matches[instance] = Reconstruction.\
                estimate_fundamental(kp1, kp2, self.matches[instance])

        essential = Reconstruction.essential_from_fund(self.intrinsic,
                                                       instance.intrinsic,
                                                       fundamental)

        rotation, translation = Reconstruction.extract_relative_pos(essential)
        extrinsic = Reconstruction.extrinsic_matrix(rotation, translation)

        # Store information in relative calibration dict entry

        calibration_info = dict()
        calibration_info['essential'] = essential
        calibration_info['fundamental'] = fundamental
        calibration_info['rotation'] = rotation
        calibration_info['translation'] = translation
        calibration_info['extrinsic'] = extrinsic

        self.calibration[instance] = calibration_info
Esempio n. 3
0
def Diff_FSPM():
    '''
    Diff-FSPM 算法分为如下3个步骤:
        - 原始序列数据集局部转换
            - 获取最优序列长度 l_opt            ok
            - 截断原始序列数据集                ok
        - 层次遍历构建绕动闭前缀序列树
            - min_sup 约束剪枝
            - 闭等价关系 剪枝
            - 预测计数值 PK. 噪音计数值
        - 描述上是挖掘FSP树, 实际直接输出结果集
            
    @summary: Diff-FSPM algorithm
    '''
    dplog.info( " === Phase 1: Decomposing input sequence dataset to n-grams (%d<=n<=%d) Begin ===" % (1, conf.l_opt) )
    conf.l_opt = GetOptSeqLength(conf.dataset, conf.epsilon, mechanism="Exponential")
    ngram_set = NGramSet( int(conf.l_opt), N_max=int(conf.n_max) )
    ngram_set.load_dataset( conf.dataset, conf.dataset_ngrams % (conf.l_opt) )
    dplog.info( " === Phase 1: Decomposing input sequence dataset to n-grams (%d<=n<=%d) End ===" % (1, conf.l_opt) )

    dplog.info( " === Phase 2: Sanitizing n-grams to build noisy frequent sequential patterns Tree Begin ===" )
    ngram_set = Sanitizer.ngram( ngram_set, conf.n_max, conf.epsilon, conf.l_opt, conf.min_sup)
    ngram_set.dump( conf.dataset_noisy % (conf.l_opt, conf.epsilon))
    dplog.info( " === Phase 2: Sanitizing n-grams to build noisy frequent sequential patterns Tree End ===" )
    
    dplog.info( " === Phase 3: Synthetic frequent sequential patterns from santized n-grams Begin ===" )
    factory = Reconstruction( ngram_set, conf.min_sup )
    factory.extend()
    factory.ngramset.dump( conf.dataset_result % (conf.l_opt, conf.epsilon))
    dplog.info( " === Phase 3: Synthetic frequent sequential patterns from santized n-grams End ===" )
Esempio n. 4
0
    def calibrate(self, instance):
        '''
        Calibrates the current instance with another by finding the relative
        fundamental, essential, and extrinsic matrix.

        Args:
            instance (ImageInstance): The other instance to calibrate with.
        '''

        kp1, _ = self.features
        kp2, _ = instance.features

        fundamental, self.matches[instance] = Reconstruction.\
                estimate_fundamental(kp1, kp2, self.matches[instance])

        essential = Reconstruction.essential_from_fund(self.intrinsic,
                instance.intrinsic, fundamental)

        rotation, translation = Reconstruction.extract_relative_pos(essential)
        extrinsic = Reconstruction.extrinsic_matrix(rotation, translation)

        # Store information in relative calibration dict entry

        calibration_info = dict()
        calibration_info['essential']   = essential
        calibration_info['fundamental'] = fundamental
        calibration_info['rotation']    = rotation
        calibration_info['translation'] = translation
        calibration_info['extrinsic']   = extrinsic

        self.calibration[instance] = calibration_info
Esempio n. 5
0
    def testExtrinsicAndProjection(self):
        ''' Try a simple example for extrinsic parameters of a camera. '''

        intrinsic = np.array([
            [1000, 0, 500, 0],
            [0, 1000, 500, 0],
            [0, 0, 1, 0],
        ])

        rot1 = np.array([
            [1, 0, 0],
            [0, 1, 0],
            [0, 0, 1],
        ])
        trans1 = np.array([0, 0, 0])

        rot2 = np.array([
            [0, 0, 1],
            [0, 1, 0],
            [1, 0, 0],
        ])
        trans2 = np.array([1000, 1000, 0])

        ext1 = Reconstruction.extrinsic_matrix(rot1, trans1)
        ext2 = Reconstruction.extrinsic_matrix(rot2, trans2)

        P1 = Reconstruction.projection_matrix(ext1, None)
        P2 = Reconstruction.projection_matrix(ext2, ext1)
Esempio n. 6
0
def test_minmod(u, extents, dim):
    def minmod(a, b):
        if a * b <= 0.0:
            return 0.0
        if abs(a) < abs(b):
            return a
        return b

    def compute_face_values(recons_upper_of_cell, recons_lower_of_cell, v, i,
                            j, k, dim_to_recons):
        if dim_to_recons == 0:
            slope = minmod(v[i, j, k] - v[i - 1, j, k],
                           v[i + 1, j, k] - v[i, j, k])
            recons_lower_of_cell.append(v[i, j, k] - 0.5 * slope)
            recons_upper_of_cell.append(v[i, j, k] + 0.5 * slope)
        if dim_to_recons == 1:
            slope = minmod(v[i, j, k] - v[i, j - 1, k],
                           v[i, j + 1, k] - v[i, j, k])
            recons_lower_of_cell.append(v[i, j, k] - 0.5 * slope)
            recons_upper_of_cell.append(v[i, j, k] + 0.5 * slope)
        if dim_to_recons == 2:
            slope = minmod(v[i, j, k] - v[i, j, k - 1],
                           v[i, j, k + 1] - v[i, j, k])
            recons_lower_of_cell.append(v[i, j, k] - 0.5 * slope)
            recons_upper_of_cell.append(v[i, j, k] + 0.5 * slope)

    return Reconstruction.reconstruct(u, extents, dim, [1, 1, 1],
                                      compute_face_values)
Esempio n. 7
0
def test_monotised_central(u, extents, dim):
    def monotised_central(a, b):
        sign = lambda x: -1 if x < 0 else 1
        sign_a = sign(a)
        sign_b = sign(b)
        return 0.5 * (sign_a + sign_b) * min(0.5 * abs(a + b),
                                             min(2.0 * abs(a), 2.0 * abs(b)))

    def compute_face_values(recons_upper_of_cell, recons_lower_of_cell, v, i,
                            j, k, dim_to_recons):
        if dim_to_recons == 0:
            slope = monotised_central(v[i, j, k] - v[i - 1, j, k],
                                      v[i + 1, j, k] - v[i, j, k])
            recons_lower_of_cell.append(v[i, j, k] - 0.5 * slope)
            recons_upper_of_cell.append(v[i, j, k] + 0.5 * slope)
        if dim_to_recons == 1:
            slope = monotised_central(v[i, j, k] - v[i, j - 1, k],
                                      v[i, j + 1, k] - v[i, j, k])
            recons_lower_of_cell.append(v[i, j, k] - 0.5 * slope)
            recons_upper_of_cell.append(v[i, j, k] + 0.5 * slope)
        if dim_to_recons == 2:
            slope = monotised_central(v[i, j, k] - v[i, j, k - 1],
                                      v[i, j, k + 1] - v[i, j, k])
            recons_lower_of_cell.append(v[i, j, k] - 0.5 * slope)
            recons_upper_of_cell.append(v[i, j, k] + 0.5 * slope)

    return Reconstruction.reconstruct(u, extents, dim, [1, 1, 1],
                                      compute_face_values)
Esempio n. 8
0
    def triangulate_points(self, instance):
        '''
        Finds the depth map of the image using calibration information from
        another image.

        Args:
            instance (ImageInstance): The other instance to triangulate from.
        Returns:
            numpy.ndarray, triangulated points in the world.
        '''

        rows, cols, _ = self.img.shape

        # Find corresponding points between images

        correspondences = Reconstruction.find_correspondences(self.img,
                instance.img, self.calibration[instance]['fundamental'],
                self.transforms[instance])

        pts1 = np.float32(
            [key for key, val in correspondences.iteritems()]
        ).reshape(-1, 1, 2)
        pts2 = np.float32(
            [val for key, val in correspondences.iteritems()]
        ).reshape(-1, 1, 2)

        # Triangulate points from correspondences

        P1 = np.hstack( (np.eye(3), np.zeros((3,1))) )
        P2 = self.calibration[instance]['extrinsic']

        points = Reconstruction.triangulate_points(pts1, pts2, P1, P2,
                self.intrinsic)

        # Create depth map

        depth = np.empty((rows, cols))
        depth.fill(np.min(points[:,-1]))

        skip = sfm.CORRESPONDENCE_SKIP

        for idx, pos in enumerate(correspondences.iteritems()):
            x,y = pos[0]
            depth[y:y+skip,x:x+skip] = points[idx][-1]


        return points, depth
Esempio n. 9
0
    def triangulate_points(self, instance):
        '''
        Finds the depth map of the image using calibration information from
        another image.

        Args:
            instance (ImageInstance): The other instance to triangulate from.
        Returns:
            numpy.ndarray, triangulated points in the world.
        '''

        rows, cols, _ = self.img.shape

        # Find corresponding points between images

        correspondences = Reconstruction.find_correspondences(
            self.img, instance.img, self.calibration[instance]['fundamental'],
            self.transforms[instance])

        pts1 = np.float32([key for key, val in correspondences.iteritems()
                           ]).reshape(-1, 1, 2)
        pts2 = np.float32([val for key, val in correspondences.iteritems()
                           ]).reshape(-1, 1, 2)

        # Triangulate points from correspondences

        P1 = np.hstack((np.eye(3), np.zeros((3, 1))))
        P2 = self.calibration[instance]['extrinsic']

        points = Reconstruction.triangulate_points(pts1, pts2, P1, P2,
                                                   self.intrinsic)

        # Create depth map

        depth = np.empty((rows, cols))
        depth.fill(np.min(points[:, -1]))

        skip = sfm.CORRESPONDENCE_SKIP

        for idx, pos in enumerate(correspondences.iteritems()):
            x, y = pos[0]
            depth[y:y + skip, x:x + skip] = points[idx][-1]

        return points, depth
Esempio n. 10
0
    def match_features(self, instance):
        '''
        Matches features to another image and computes relevant matrices.

        Args:
            instance (ImageInstance): The image to match to.
        '''

        kp1, des1 = self.features
        kp2, des2 = instance.features

        matches = Reconstruction.find_matches(kp1, des1, kp2, des2)
        matches, xform = Reconstruction.find_inliers(kp1, kp2, matches)

        self.matches[instance] = matches
        self.transforms[instance] = xform

        # Perform calibration as well
        self.calibrate(instance)
Esempio n. 11
0
    def match_features(self, instance):
        '''
        Matches features to another image and computes relevant matrices.

        Args:
            instance (ImageInstance): The image to match to.
        '''

        kp1, des1 = self.features
        kp2, des2 = instance.features

        matches = Reconstruction.find_matches(kp1, des1, kp2, des2)
        matches, xform = Reconstruction.find_inliers(kp1, kp2, matches)

        self.matches[instance] = matches
        self.transforms[instance] = xform

        # Perform calibration as well
        self.calibrate(instance)
Esempio n. 12
0
    def testFundamentalEssential(self):
        ''' Check that the fundamental and essential matrix equations are
            equivalent. '''

        kp1, _ = self.instances[0].features
        kp2, _ = self.instances[1].features
        matches = self.instances[0].matches[self.instances[1]]

        fund, _ = Reconstruction.estimate_fundamental(kp1, kp2, matches)

        esst = Reconstruction.essential_from_fund(
                self.instances[0].intrinsic,
                self.instances[1].intrinsic,
                fund,
        )
        fund2 = Reconstruction.fundamental_from_esst(
                self.instances[0].intrinsic,
                self.instances[1].intrinsic,
                esst,
        )
        self.assertTrue( self.checkArrays(fund, fund2) )
Esempio n. 13
0
    def testFundamentalEssential(self):
        ''' Check that the fundamental and essential matrix equations are
            equivalent. '''

        kp1, _ = self.instances[0].features
        kp2, _ = self.instances[1].features
        matches = self.instances[0].matches[self.instances[1]]

        fund, _ = Reconstruction.estimate_fundamental(kp1, kp2, matches)

        esst = Reconstruction.essential_from_fund(
            self.instances[0].intrinsic,
            self.instances[1].intrinsic,
            fund,
        )
        fund2 = Reconstruction.fundamental_from_esst(
            self.instances[0].intrinsic,
            self.instances[1].intrinsic,
            esst,
        )
        self.assertTrue(self.checkArrays(fund, fund2))
Esempio n. 14
0
    print "\n=== Phase 2.1: Sanitizing clos_n-grams\n"
    ngram_set = Sanitizer.Equivalence(
        ngram_set, output_dir + dataset_name + "-" + str(scale) +
        "-original-" + str(n_max) + "grams.dat", output_dir + dataset_name +
        "-" + str(scale) + "-original-" + str(n_max) + "_clo_grams.dat")
    print "\n=== Phase 2.2: Sanitizing n-grams\n"
    ngram_set = Sanitizer.ngram(ngram_set,
                                n_max,
                                budget=epsilon,
                                sensitivity=l_max)

    ngram_set.dump(output_dir + dataset_name + file_id + ".dat")

    print "\n=== Phase 3: Synthetic sequential database generation from sanitized n-grams\n"
    factory = Reconstruction(ngram_set, lUp)

    # Reconstruct longer grams from shorter ones using the Markov approach
    factory.extend()

    # Saving the extended ngramset
    factory.ngramset.dump(outdataset_name_info %
                          (scale, n_max, topN, lLeft, lUp, deta, epsilon) +
                          "-extended.dat")

    # Generating dataset
    factory.reconstruct(outdataset_name_info %
                        (scale, n_max, topN, lLeft, lUp, deta, epsilon) +
                        "-reconstructed.dat")

    print "\n=== Phase 4: Get Consolidated Frequency"
Esempio n. 15
0
    def __init__(self):

        self.root = Tkinter.Tk()
        self.root.wm_title("Test Bench Dashboard")
        self.top = None
        self.topplot = None
        self.topcanvas = None
        self.topcbar = None
        self.topcbaxes = None

        menu = Tkinter.Menu(self.root)
        self.root.config(menu=menu)

        filemenu = Menu(menu)
        menu.add_cascade(label="File", menu=filemenu)
        filemenu.add_command(label="Exit", command=self.root.quit)
        viewmenu = Menu(menu)
        menu.add_cascade(label="View", menu=viewmenu)
        viewmenu.add_command(label="Dedicated Reconstruction Window",
                             command=self.Eitwin)
        viewmenu.add_separator()
        viewmenu.add_command(label="something else",
                             command=self.Something_else)
        helpmenu = Menu(menu)
        menu.add_cascade(label="Help", menu=helpmenu)
        helpmenu.add_command(label="About...", command=self.About)

        self.root.protocol("WM_DELETE_WINDOW", self.quit)
        # make Esc exit the program
        self.root.bind('<Escape>', lambda e: self.root.destroy())

        # Matplotlibbing.
        fig = mpl.figure.Figure(figsize=(5, 4), dpi=100)
        # pos = [left, bottom, width, height]
        image_position = [0.1, 0.25, 0.7, 0.7]
        histogram_position = [0.1, 0.08, 0.8, 0.1]
        colorbar_position = [0.85, 0.25, 0.03, 0.7]
        self.imageplt = fig.add_axes(image_position)
        self.histplt = fig.add_axes(histogram_position)
        self.cbaxes = fig.add_axes(colorbar_position)

        # 180,225,270,315,0,45,90,135
        # 1,2,3,4,5,6,7,8
        # Add text for electrode locations.
        self.imageplt.annotate('180d(AFE1)',
                               xy=(0.4, 0.9),
                               xycoords='axes fraction')
        self.imageplt.annotate('225d(AFE2)',
                               xy=(0.15, 0.75),
                               xycoords='axes fraction')
        self.imageplt.annotate('270d(AFE3)',
                               xy=(0.0, 0.5),
                               xycoords='axes fraction')
        self.imageplt.annotate('315d(AFE4)',
                               xy=(0.2, 0.2),
                               xycoords='axes fraction')
        self.imageplt.annotate('0d(AFE5)',
                               xy=(0.5, 0.1),
                               xycoords='axes fraction')
        self.imageplt.annotate('45d(AFE6)',
                               xy=(0.75, 0.25),
                               xycoords='axes fraction')
        self.imageplt.annotate('90d(AFE7)',
                               xy=(0.9, 0.5),
                               xycoords='axes fraction')
        self.imageplt.annotate('135d(AFE8)',
                               xy=(0.8, 0.8),
                               xycoords='axes fraction')

        ypadding = 10
        xpadding = 20

        #
        #
        self.file_marker = 0
        self.file_name = ''
        self.data_file_array = []
        # Will this often need to be changed?
        scale_max = 90000
        self.sliders = [0, scale_max, 0, scale_max]

        min_cbar = 0
        max_cbar = scale_max
        scale_tick_interval = float(scale_max / 10)
        # intialize the reconstruction library.
        self.image_reconstruct = eit.Reconstruction()
        self.img = self.image_reconstruct.img

        self.plot = self.imageplt.imshow(self.img, interpolation='nearest')

        # self.imageplt.set_position(image_position) # set a new position
        # self.histplt.set_position(histogram_position)
        self.cbar = mpl.pyplot.colorbar(self.plot, cax=self.cbaxes)
        # self.cbar = mpl.pyplot.colorbar(self.imageplt,cax = self.cbaxes)
        self.cbar.set_clim([min_cbar, max_cbar])
        #
        self.canvas = mpl.backends.backend_tkagg.FigureCanvasTkAgg(
            fig, master=self.root)

        self.canvas.show()
        self.canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
        toolbar = mpl.backends.backend_tkagg.NavigationToolbar2TkAgg(
            self.canvas, self.root)
        toolbar.update()
        self.canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1)
        # canvas.mpl_connect('key_press_event', on_key_event)

        self.use_blit = False
        # cache the background, in the init.
        if self.use_blit:  # cache the background.
            self.background = self.canvas.copy_from_bbox(self.imageplt.bbox)
            self.histbackground = self.canvas.copy_from_bbox(self.histplt.bbox)
            self.cbbackground = self.canvas.copy_from_bbox(self.cbaxes.bbox)
        self.total_rendering_time = 0.0
        self.total_processing_time = 0.0
        # ---------------
        # defining frames
        # ---------------
        bottomframe0 = Frame(self.root)
        bottomframe1 = Frame(self.root)
        bottomframe2 = Frame(self.root)
        bottomframe3 = Frame(self.root)

        bottomframe0.pack(side=TOP)
        bottomframe1.pack(side=TOP)
        bottomframe2.pack(side=TOP)
        bottomframe3.pack(side=TOP)

        # This is the text box...
        self.msg = Tkinter.Text(bottomframe0,
                                height=1.0,
                                bg="light cyan",
                                state=Tkinter.NORMAL)
        self.msg.grid(row=1, column=0, columnspan=3)
        self.msg.pack(fill="x", expand=True)

        # sliders.
        self.w1 = Tkinter.Scale(bottomframe0,
                                from_=self.sliders[0],
                                to=self.sliders[1],
                                length=600,
                                tickinterval=scale_tick_interval,
                                orient=HORIZONTAL,
                                label='MIN')
        self.w1.set(scale_max / 10)
        self.w1.pack(fill="x", expand=True)
        self.w2 = Tkinter.Scale(bottomframe0,
                                from_=self.sliders[2],
                                to=self.sliders[3],
                                length=600,
                                tickinterval=scale_tick_interval,
                                orient=HORIZONTAL,
                                label='MAX')
        self.w2.set(9 * scale_max / 10)
        self.w2.pack(fill="x", expand=True)

        # Text entry boxes for min and max range of each slider bar.
        #
        #
        cbarbut = Tkinter.Button(bottomframe0,
                                 text='Update HIST',
                                 command=self.update_hist)
        cbarbut.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)

        cbarbut = Tkinter.Button(bottomframe0,
                                 text='Update CBAR',
                                 command=self.update_cbar)
        cbarbut.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)

        self.hist_update = False

        self.min_slider_l = Tkinter.Entry(bottomframe0)
        self.min_slider_h = Tkinter.Entry(bottomframe0)
        self.max_slider_l = Tkinter.Entry(bottomframe0)
        self.max_slider_h = Tkinter.Entry(bottomframe0)
        self.max_slider_h.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)
        self.max_slider_h_label = Tkinter.Label(
            bottomframe0, text="max_h:").pack(side=Tkinter.RIGHT)
        self.max_slider_l.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)
        self.max_slider_l_label = Tkinter.Label(
            bottomframe0, text="max_l:").pack(side=Tkinter.RIGHT)
        self.min_slider_h.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)
        self.min_slider_h_label = Tkinter.Label(
            bottomframe0, text="min_h:").pack(side=Tkinter.RIGHT)
        self.min_slider_l.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)
        self.min_slider_l_label = Tkinter.Label(
            bottomframe0, text="min_l:").pack(side=Tkinter.RIGHT)
        self.min_slider_l.bind("<Return>", self.evaluate)
        self.min_slider_h.bind("<Return>", self.evaluate)
        self.max_slider_l.bind("<Return>", self.evaluate)
        self.max_slider_h.bind("<Return>", self.evaluate)

        full_ports = list(serial.tools.list_ports.comports())
        portnames = [item[0] for item in full_ports]
        if len(portnames) > 0:
            self.menuselect = StringVar(self.root)
            self.menuselect.set(portnames[0])
            # apply has been deprecated.
            # listboxdataconnect = apply(OptionMenu, (self.root, self.menuselect) + tuple(portnames ))

            listboxdataconnect = OptionMenu(*(self.root, self.menuselect) +
                                            tuple(portnames))

            listboxdataconnect.pack(in_=bottomframe1,
                                    side=Tkinter.LEFT,
                                    padx=3,
                                    pady=ypadding)

            self.baselinebut = Tkinter.Button(master=bottomframe1,
                                              text="Baseline",
                                              command=self.baseline)
            self.baselinebut.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)

            self.recorddata = Tkinter.Button(master=bottomframe1,
                                             text='Record',
                                             command=self.record)
            self.recorddata.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)

            self.buttonconnect = Tkinter.Button(master=bottomframe1,
                                                text='Connect',
                                                command=self.connect)
            self.buttonconnect.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)

        else:
            # no serial port detected.
            print('no serial port found, hope that\'s OK')
            self.text = "no serial port found, hope that's OK"
            if expertMode is False:
                tkMessageBox.showwarning(
                    "No serial port",
                    "No device detected\nCheck cable and connection")

        readfilerunbut = Tkinter.Button(bottomframe2,
                                        text='Run',
                                        command=self.run_file)
        readfilerunbut.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)

        readfilestartbut = Tkinter.Button(bottomframe2,
                                          text='Step',
                                          command=self.step_file)
        readfilestartbut.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)

        readfilebut = Tkinter.Button(bottomframe2,
                                     text='ReadFromFile',
                                     command=self.load_file)
        readfilebut.pack(side=Tkinter.RIGHT, padx=3, pady=ypadding)

        # start Serial handler off in a separate process.
        self.s = Serialhandler.Serialhandler()
        self.s.start()
        self.s.join()
        self.text = 'hi'
        self.root.after(200, self.process_data)
        self.root.mainloop()
Esempio n. 16
0
def test_aoweno53(u, extents, dim):
    gamma_hi = 0.85
    gamma_lo = 0.999
    epsilon = 1.0e-12
    exponent = 8

    def aoweno53(q):
        j = 2
        moments_sr3_1 = [
            1.041666666666666 * q[j] - 0.08333333333333333 * q[j - 1] +
            0.04166666666666666 * q[j - 2],
            0.5 * q[j - 2] - 2.0 * q[j - 1] + 1.5 * q[j],
            0.5 * q[j - 2] - q[j - 1] + 0.5 * q[j]
        ]
        moments_sr3_2 = [
            0.04166666666666666 * q[j + 1] + 0.9166666666666666 * q[j] +
            0.04166666666666666 * q[j - 1], 0.5 * (q[j + 1] - q[j - 1]),
            0.5 * q[j - 1] - q[j] + 0.5 * q[j + 1]
        ]
        moments_sr3_3 = [
            0.04166666666666666 * q[j + 2] - 0.08333333333333333 * q[j + 1] +
            1.04166666666666666 * q[j],
            -1.5 * q[j] + 2.0 * q[j + 1] - 0.5 * q[j + 2],
            0.5 * q[j] - q[j + 1] + 0.5 * q[j + 2]
        ]
        moments_sr5 = [
            -2.95138888888888881e-03 * q[j - 2] +
            5.34722222222222196e-02 * q[j - 1] +
            8.98958333333333304e-01 * q[j] +
            5.34722222222222196e-02 * q[j + 1] +
            -2.95138888888888881e-03 * q[j + 2],
            7.08333333333333315e-02 * q[j - 2] +
            -6.41666666666666718e-01 * q[j - 1] +
            6.41666666666666718e-01 * q[j + 1] +
            -7.08333333333333315e-02 * q[j + 2],
            -3.27380952380952397e-02 * q[j - 2] +
            6.30952380952380931e-01 * q[j - 1] +
            -1.19642857142857140e+00 * q[j] +
            6.30952380952380931e-01 * q[j + 1] +
            -3.27380952380952397e-02 * q[j + 2],
            -8.33333333333333287e-02 * q[j - 2] +
            1.66666666666666657e-01 * q[j - 1] +
            -1.66666666666666657e-01 * q[j + 1] +
            8.33333333333333287e-02 * q[j + 2],
            4.16666666666666644e-02 * q[j - 2] +
            -1.66666666666666657e-01 * q[j - 1] +
            2.50000000000000000e-01 * q[j] +
            -1.66666666666666657e-01 * q[j + 1] +
            4.16666666666666644e-02 * q[j + 2]
        ]

        beta_r3_1 = moments_sr3_1[1]**2 + 37.0 / 3.0 * moments_sr3_1[2]**2
        beta_r3_2 = moments_sr3_2[1]**2 + 37.0 / 3.0 * moments_sr3_2[2]**2
        beta_r3_3 = moments_sr3_3[1]**2 + 37.0 / 3.0 * moments_sr3_3[2]**2
        beta_sr5 = (moments_sr5[1]**2 +
                    61.0 / 5.0 * moments_sr5[1] * moments_sr5[3] +
                    37.0 / 3.0 * moments_sr5[2]**2 +
                    1538.0 / 7.0 * moments_sr5[2] * moments_sr5[4] +
                    8973.0 / 50.0 * moments_sr5[3]**2 +
                    167158.0 / 49.0 * moments_sr5[4]**2)

        linear_weights = [
            gamma_hi, 0.5 * (1.0 - gamma_hi) * (1.0 - gamma_lo),
            (1.0 - gamma_hi) * gamma_lo,
            0.5 * (1.0 - gamma_hi) * (1.0 - gamma_lo)
        ]
        nonlinear_weights = np.asarray([
            linear_weights[0] / (beta_sr5 + epsilon)**exponent,
            linear_weights[1] / (beta_r3_1 + epsilon)**exponent,
            linear_weights[2] / (beta_r3_2 + epsilon)**exponent,
            linear_weights[3] / (beta_r3_3 + epsilon)**exponent
        ])
        normalization = np.sum(nonlinear_weights)
        nonlinear_weights = nonlinear_weights / normalization

        moments = np.asarray([
            nonlinear_weights[0] / linear_weights[0] *
            (moments_sr5[0] - linear_weights[1] * moments_sr3_1[0] -
             linear_weights[2] * moments_sr3_2[0] -
             linear_weights[3] * moments_sr3_3[0]) +
            nonlinear_weights[1] * moments_sr3_1[0] +
            nonlinear_weights[2] * moments_sr3_2[0] +
            nonlinear_weights[3] * moments_sr3_3[0],
            nonlinear_weights[0] / linear_weights[0] *
            (moments_sr5[1] - linear_weights[1] * moments_sr3_1[1] -
             linear_weights[2] * moments_sr3_2[1] -
             linear_weights[3] * moments_sr3_3[1]) +
            nonlinear_weights[1] * moments_sr3_1[1] +
            nonlinear_weights[2] * moments_sr3_2[1] +
            nonlinear_weights[3] * moments_sr3_3[1],
            nonlinear_weights[0] / linear_weights[0] *
            (moments_sr5[2] - linear_weights[1] * moments_sr3_1[2] -
             linear_weights[2] * moments_sr3_2[2] -
             linear_weights[3] * moments_sr3_3[2]) +
            nonlinear_weights[1] * moments_sr3_1[2] +
            nonlinear_weights[2] * moments_sr3_2[2] +
            nonlinear_weights[3] * moments_sr3_3[2],
            nonlinear_weights[0] / linear_weights[0] * moments_sr5[3],
            nonlinear_weights[0] / linear_weights[0] * moments_sr5[4]
        ])

        polys_at_plus_half = np.asarray(
            [1.0, 0.5, 0.16666666666666666, 0.05, 0.014285714285714289])
        polys_at_minus_half = np.asarray(
            [1.0, -0.5, 0.16666666666666666, -0.05, 0.014285714285714289])
        return [
            np.sum(moments * polys_at_minus_half),
            np.sum(moments * polys_at_plus_half)
        ]

    def compute_face_values(recons_upper_of_cell, recons_lower_of_cell, v, i,
                            j, k, dim_to_recons):
        if dim_to_recons == 0:
            lower, upper = aoweno53(
                np.asarray([
                    v[i - 2, j, k], v[i - 1, j, k], v[i, j, k], v[i + 1, j, k],
                    v[i + 2, j, k]
                ]))
            recons_lower_of_cell.append(lower)
            recons_upper_of_cell.append(upper)
        if dim_to_recons == 1:
            lower, upper = aoweno53(
                np.asarray([
                    v[i, j - 2, k], v[i, j - 1, k], v[i, j, k], v[i, j + 1, k],
                    v[i, j + 2, k]
                ]))
            recons_lower_of_cell.append(lower)
            recons_upper_of_cell.append(upper)
        if dim_to_recons == 2:
            lower, upper = aoweno53(
                np.asarray([
                    v[i, j, k - 2], v[i, j, k - 1], v[i, j, k], v[i, j, k + 1],
                    v[i, j, k + 2]
                ]))
            recons_lower_of_cell.append(lower)
            recons_upper_of_cell.append(upper)

    return Reconstruction.reconstruct(u, extents, dim, [2, 2, 2],
                                      compute_face_values)