Example #1
0
    def loads(self, stream, fileroot):
        self.wipe_slate()

        design = PropertyNode()
        if props_json.loads(stream, design, ""):
            print("json parse successful")
        else:
            error = QErrorMessage(self)
            error.showMessage("json parse failed")
            return False
        # design.pretty_print()

        self.setWindowTitle(self.default_title + " - " + fileroot)

        node = design.getChild('overview', True)
        self.overview.load(node)

        design.setLen('wing', 1)  # force to be enumerated if not already
        num_wings = design.getLen('wing')
        for i in range(num_wings):
            wing_node = design.getChild('wing[%d]' % i)
            wing = WingUI(changefunc=self.onChange)
            wing.load(wing_node)
            self.wings.append(wing)
            self.tabs.addTab(wing.get_widget(), "Wing: " + wing.get_name())
        self.rebuildWingLists()
        self.setClean()
Example #2
0
    def loads(self, stream, fileroot):
        self.wipe_slate()

        design = PropertyNode()
        if props_json.loads(stream, design, ""):
            print "json parse successful"
        else:
            error = QErrorMessage(self)
            error.showMessage( "json parse failed" )
            return False
        # design.pretty_print()

        self.setWindowTitle( self.default_title + " - " + fileroot )

        node = design.getChild('overview', True)
        self.overview.load(node)

        design.setLen('wing', 1) # force to be enumerated if not already
        num_wings = design.getLen('wing')
        for i in range(num_wings):
            wing_node = design.getChild('wing[%d]' % i)
            wing = WingUI(changefunc=self.onChange)
            wing.load(wing_node)
            self.wings.append(wing)
            self.tabs.addTab( wing.get_widget(), "Wing: " + wing.get_name() )
        self.rebuildWingLists()
        self.setClean()
Example #3
0
    def gen_property_tree(self):
        # create a new design root
        design = PropertyNode()

        # overview
        node = design.getChild('overview', True)
        self.overview.save(node)

        # wings
        i = 0
        for wing in self.wings:
            if wing.valid:
                node = design.getChild('wing[%d]' % i, True)
                wing.save(node)
                i += 1

        return design
Example #4
0
    def gen_property_tree(self):
        # create a new design root
        design = PropertyNode()

        # overview
        node = design.getChild('overview', True)
        self.overview.save(node)

        # wings
        i = 0
        for wing in self.wings:
            if wing.valid:
                node = design.getChild('wing[%d]' % i, True)
                wing.save(node)
                i += 1
                
        return design
Example #5
0
    def save(self, cal_file):
        config = PropertyNode()
        config.setFloat('min_temp_C', self.min_temp)
        config.setFloat('max_temp_C', self.max_temp)

        node = config.getChild('p', create=True)
        p = self.p_bias
        node.setString('bias', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))
        p = self.p_scale
        node.setString('scale', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))

        node = config.getChild('q', create=True)
        p = self.q_bias
        node.setString('bias', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))
        p = self.q_scale
        node.setString('scale', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))

        node = config.getChild('r', create=True)
        p = self.r_bias
        node.setString('bias', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))
        p = self.r_scale
        node.setString('scale', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))

        node = config.getChild('ax', create=True)
        p = self.ax_bias
        node.setString('bias', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))
        p = self.ax_scale
        node.setString('scale', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))

        node = config.getChild('ay', create=True)
        p = self.ay_bias
        node.setString('bias', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))
        p = self.ay_scale
        node.setString('scale', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))

        node = config.getChild('az', create=True)
        p = self.az_bias
        node.setString('bias', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))
        p = self.az_scale
        node.setString('scale', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))

        affine_str = []
        for x in self.mag_affine.flat:
            affine_str.append('%.10f' % x)
        print(' '.join(affine_str))
        config.setString('mag_affine', ' '.join(affine_str))

        try:
            props_json.save(cal_file, config)
        except:
            print("error saving " + cal_file + ": " + str(sys.exc_info()[1]))
            return
Example #6
0
    def save(self, cal_file):
        config = PropertyNode()
        config.setFloat('min_temp_C', self.min_temp)
        config.setFloat('max_temp_C', self.max_temp)

        node = config.getChild('p', create=True)
        p = self.p_bias
        node.setString('bias', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))
        p = self.p_scale
        node.setString('scale', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))

        node = config.getChild('q', create=True)
        p = self.q_bias
        node.setString('bias', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))
        p = self.q_scale
        node.setString('scale', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))

        node = config.getChild('r', create=True)
        p = self.r_bias
        node.setString('bias', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))
        p = self.r_scale
        node.setString('scale', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))

        node = config.getChild('ax', create=True)
        p = self.ax_bias
        node.setString('bias', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))
        p = self.ax_scale
        node.setString('scale', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))

        node = config.getChild('ay', create=True)
        p = self.ay_bias
        node.setString('bias', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))
        p = self.ay_scale
        node.setString('scale', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))

        node = config.getChild('az', create=True)
        p = self.az_bias
        node.setString('bias', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))
        p = self.az_scale
        node.setString('scale', "%.8f %.8f %.8f" % (p[0], p[1], p[2]))

        affine_str = []
        for x in self.mag_affine.flat:
            affine_str.append('%.10f' % x)
        print ' '.join(affine_str)
        config.setString('mag_affine', ' '.join(affine_str))
        
        try:
            props_json.save(cal_file, config)
        except:
            print "error saving " + cal_file + ": " + str(sys.exc_info()[1])
            return
Example #7
0
    def load(self, cal_file):
        config = PropertyNode()
        try:
            name, ext = os.path.splitext(cal_file)
            if ext == '.json':
                props_json.load(cal_file, config)
                self.valid = True
            elif ext == '.xml':
                props_xml.load(cal_file, config)
                self.valid = True
            else:
                return False
        except:
            print(cal_file + ": load error:\n" + str(sys.exc_info()[1]))
            return False

        root.pretty_print()

        self.min_temp = config.getFloat('min_temp_C')
        self.max_temp = config.getFloat('max_temp_C')

        node = config.getChild('p')
        if node:
            p1, p2, p3 = node.getString('bias').split()
            self.p_bias = np.array([p1, p2, p3], dtype=np.float64)
            p1, p2, p3 = node.getString('scale').split()
            self.p_scale = np.array([p1, p2, p3], dtype=np.float64)

        node = config.getChild('q')
        if node:
            p1, p2, p3 = node.getString('bias').split()
            self.q_bias = np.array([p1, p2, p3], dtype=np.float64)
            p1, p2, p3 = node.getString('scale').split()
            self.q_scale = np.array([p1, p2, p3], dtype=np.float64)

        node = config.getChild('r')
        if node:
            p1, p2, p3 = node.getString('bias').split()
            self.r_bias = np.array([p1, p2, p3], dtype=np.float64)
            p1, p2, p3 = node.getString('scale').split()
            self.r_scale = np.array([p1, p2, p3], dtype=np.float64)

        node = config.getChild('ax')
        if node:
            p1, p2, p3 = node.getString('bias').split()
            self.ax_bias = np.array([p1, p2, p3], dtype=np.float64)
            p1, p2, p3 = node.getString('scale').split()
            self.ax_scale = np.array([p1, p2, p3], dtype=np.float64)

        node = config.getChild('ay')
        if node:
            p1, p2, p3 = node.getString('bias').split()
            self.ay_bias = np.array([p1, p2, p3], dtype=np.float64)
            p1, p2, p3 = node.getString('scale').split()
            self.ay_scale = np.array([p1, p2, p3], dtype=np.float64)

        node = config.getChild('az')
        if node:
            p1, p2, p3 = node.getString('bias').split()
            self.az_bias = np.array([p1, p2, p3], dtype=np.float64)
            p1, p2, p3 = node.getString('scale').split()
            self.az_scale = np.array([p1, p2, p3], dtype=np.float64)

        tokens = config.getString('mag_affine').split()
        if len(tokens) == 16:
            r = 0
            c = 0
            for i, x in enumerate(tokens):
                self.mag_affine[r, c] = float(x)
                c += 1
                if c > 3:
                    c = 0
                    r += 1
            self.mag_affine_inv = np.linalg.inv(self.mag_affine)
        else:
            print("mag_affine requires 16 values")
        #print 'mag_affine:\n', self.mag_affine
        #print 'mag_affine_inv:\n', self.mag_affine_inv

        return True
Example #8
0
    def load(self, cal_file):
        config = PropertyNode()
        try:
            name, ext = os.path.splitext(cal_file)
            if ext == '.json':
                props_json.load(cal_file, config)
                self.valid = True
            elif ext == '.xml':
                props_xml.load(cal_file, config)
                self.valid = True
            else:
                return False
        except:
            print cal_file + ": load error:\n" + str(sys.exc_info()[1])
            return False

        root.pretty_print()
        
        self.min_temp = config.getFloat('min_temp_C')
        self.max_temp = config.getFloat('max_temp_C')
        
        node = config.getChild('p')
        if node:
            p1, p2, p3 = node.getString('bias').split()
            self.p_bias = np.array([p1, p2, p3], dtype=np.float64)
            p1, p2, p3 = node.getString('scale').split()
            self.p_scale = np.array([p1, p2, p3], dtype=np.float64)

        node = config.getChild('q')
        if node:
            p1, p2, p3 = node.getString('bias').split()
            self.q_bias = np.array([p1, p2, p3], dtype=np.float64)
            p1, p2, p3 = node.getString('scale').split()
            self.q_scale = np.array([p1, p2, p3], dtype=np.float64)

        node = config.getChild('r')
        if node:
            p1, p2, p3 = node.getString('bias').split()
            self.r_bias = np.array([p1, p2, p3], dtype=np.float64)
            p1, p2, p3 = node.getString('scale').split()
            self.r_scale = np.array([p1, p2, p3], dtype=np.float64)

        node = config.getChild('ax')
        if node:
            p1, p2, p3 = node.getString('bias').split()
            self.ax_bias = np.array([p1, p2, p3], dtype=np.float64)
            p1, p2, p3 = node.getString('scale').split()
            self.ax_scale = np.array([p1, p2, p3], dtype=np.float64)

        node = config.getChild('ay')
        if node:
            p1, p2, p3 = node.getString('bias').split()
            self.ay_bias = np.array([p1, p2, p3], dtype=np.float64)
            p1, p2, p3 = node.getString('scale').split()
            self.ay_scale = np.array([p1, p2, p3], dtype=np.float64)

        node = config.getChild('az')
        if node:
            p1, p2, p3 = node.getString('bias').split()
            self.az_bias = np.array([p1, p2, p3], dtype=np.float64)
            p1, p2, p3 = node.getString('scale').split()
            self.az_scale = np.array([p1, p2, p3], dtype=np.float64)

        tokens = config.getString('mag_affine').split()
        if len(tokens) == 16:
            r = 0
            c = 0
            for i, x in enumerate(tokens):
                self.mag_affine[r,c] = float(x)
                c += 1
                if c > 3:
                    c = 0
                    r += 1
            self.mag_affine_inv = np.linalg.inv(self.mag_affine)
        else:
            print "mag_affine requires 16 values"
        #print 'mag_affine:\n', self.mag_affine
        #print 'mag_affine_inv:\n', self.mag_affine_inv

        return True