예제 #1
0
def RandomTests(TESTS, dim=3, N=10000, repeat=3, log_file=sys.stdout):
    nerr = 0
    id = str(threading.current_thread().name)
    log_file.write("%s\n" % LINE_SPLIT)
    log_file.write("Thread: %s, Transforming %d %dd-points...\n" %
                   (id, N, dim))
    for test in TESTS:
        if len(test) == 6:
            label_in, label_out, x, y, z, scale = test
            geoid = ""
        else:
            label_in, label_out, x, y, z, scale, geoid = test

        log_file.write("%s\n" % LINE_SPLIT)
        log_file.write("Label_in: %s, Label_out: %s\n" % (label_in, label_out))
        xyz = RandomPoints(N, dim, x, y, z, scale)
        if N <= 10:
            log_file.write("in:\n%s\n" % repr(xyz))
        elif HAS_NUMPY:
            log_file.write("Center of mass: %s\n" % xyz.mean(axis=0).tolist())
        nok = 0
        try:
            ct = TrLib.CoordinateTransformation(label_in, label_out, geoid)
        except Exception, msg:
            log_file.write(repr(msg) + "\n")
            sys.stderr.write(repr(msg) + "\n")
            msg = "Failed to open %s->%s, geoid: %s, last error: %d\n" % (
                label_in, label_out, geoid, TrLib.GetLastError())
            log_file.write(msg)
            sys.stderr.write(msg)
            nerr += 1
            if THREAD_TEST:
                return nerr
            continue
        for i in range(repeat):
            tstart = time.clock()
            try:
                xyz_out = ct.Transform(xyz)
            except Exception, msg:
                log_file.write(repr(msg) + "\n")
                sys.stderr.write(repr(msg) + "\n")
                msg = "From: %s To: %s, Last error: %d\n" % (
                    label_in, label_out, TrLib.GetLastError())
                log_file.write(msg)
                sys.stderr.write(msg)
                if N < 10:
                    sys.stderr.write("Input: %s\n" % repr(xyz))
                nerr += 1
                if THREAD_TEST:
                    return nerr
            else:
                nok += 1
                log_file.write("Forward running time: %.5f s\n" %
                               (time.clock() - tstart))
예제 #2
0
    def doBesselHelmert(self):
        # Check if we need to update data....
        is_custom = self.chb_bshlm_custom_ellipsoid.isChecked()
        self.cache.is_valid = False
        self.logBshlm("", clear=True)
        if is_custom or str(self.cb_bshlm_system.currentText()) != self.cache.mlb:
            self.onBshlmSystemChanged(False)
        if not self.cache.valid_label:
            self.logBshlm("Invalid input label...", "red")
            self.clearOutput()
            return
        is_mode1 = self.rdobt_bshlm_mode1.isChecked()
        # Get needed input
        mlb = self.cache.mlb
        geo_mlb = self.cache.geo_mlb
        is_geo_in = is_custom or TrLib.IsGeographic(mlb)
        if is_mode1:
            coords, msg = WidgetUtils.getInput(
                self.input_bshlm, is_geo_in, z_fields=[], angular_unit=self.geo_unit)
            if len(coords) != 4:
                self.logBshlm("Input coordinate %d not OK.\n%s" %
                              (len(coords) + 1, msg), "red")
                self.input_bshlm[len(coords)].setFocus()
                self.clearOutput()
                return
            x1, y1, x2, y2 = coords

        else:
            coords, msg = WidgetUtils.getInput(
                self.input_bshlm[0:2], is_geo_in, z_fields=[], angular_unit=self.geo_unit)
            if len(coords) != 2:
                self.logBshlm("Station1 coordinates not OK.\n%s" % msg, "red")
                self.input_bshlm[len(coords)].setFocus()
                self.clearOutput()
                return
            input_data, msg = WidgetUtils.getInput(self.input_bshlm_azimuth, True, z_fields=[
                                                   0], angular_unit=self.geo_unit_derived)
            if len(input_data) != 2:
                self.logBshlm(
                    "Input distance and azimuth not OK.\n%s" % msg, "red")
                self.input_bshlm_azimuth[len(input_data)].setFocus()
                self.clearOutput()
                return
            x1, y1 = coords

            dist, a1 = input_data
        a = self.cache.axis
        f = self.cache.flattening
        #end get needed input#
        #transform to geo coords if needed#
        if not is_custom:
            try:
                ct = TrLib.CoordinateTransformation(mlb, geo_mlb)
            except:
                self.logBshlm("Input label not OK!", "red")
                self.clearOutput()
                return
            try:
                x1, y1, z = ct.Transform(x1, y1)
            except:
                msg = ""
                err = TrLib.GetLastError()
                if err in ERRORS:
                    msg = "\n%s" % ERRORS[err]
                self.logBshlm(
                    "Error in transformation of coords for station1" + msg, "red")
                self.clearOutput()
                return
        # display output of first transformation, x1,y1 should now alwyas be in
        # geo-coords#
        WidgetUtils.setOutput([x1, y1], self.output_bshlm_geo[
                              :2], True, z_fields=[], angular_unit=self.geo_unit)

        # Now get the other output from bshlm and transformations....
        if is_mode1:
            if not is_custom:
                try:  # transform to geographic
                    x2, y2, z = ct.Transform(x2, y2)
                except:
                    msg = ""
                    err = TrLib.GetLastError()
                    if err in ERRORS:
                        msg = "\n%s" % ERRORS[err]
                    self.logBshlm(
                        "Error in transformation of coords for station2" + msg, "red")
                    self.clearOutput()
                    return
            data = TrLib.BesselHelmert(a, f, x1, y1, x2, y2)
            if data[0] is not None:
                a1, a2 = data[1:]
                # WidgetUtils.setOutput(data,self.output_bshlm_azimuth,True,z_fields=[0],angular_unit=self.geo_unit_derived)
                self.output_bshlm_azimuth[0].setText("%.3f m" % data[0])
                self.output_bshlm_azimuth[1].setText(translateFromDegrees(
                    data[1], self.geo_unit_derived, precision=1))
                self.output_bshlm_azimuth[2].setText(translateFromDegrees(
                    data[2], self.geo_unit_derived, precision=1))
            else:
                self.message("Error: could not calculate azimuth!")
                self.clearOutput()
                return
        else:
            data = TrLib.InverseBesselHelmert(a, f, x1, y1, a1, dist)
            if data[0] is not None:
                x2, y2, a2 = data
                if not is_custom:
                    try:
                        x2_out, y2_out, z2 = ct.InverseTransform(x2, y2)
                    except:
                        msg = ""
                        err = TrLib.GetLastError()
                        if err in ERRORS:
                            msg = "\n%s" % ERRORS[err]
                        self.logBshlm(
                            "Error in transformation of coords for station2" + msg, "red")
                        self.clearOutput()
                        return
                else:
                    x2_out = x2
                    y2_out = y2
                # display result...
                WidgetUtils.setOutput([x2_out, y2_out], self.input_bshlm[
                                      2:], is_geo_in, z_fields=[], angular_unit=self.geo_unit)
                self.txt_bshlm_azimuth2.setText(translateFromDegrees(
                    a2, self.geo_unit_derived, precision=1))
            else:
                self.message(
                    "Error: could not do inverse Bessel Helmert calculation")
                self.clearOutput()
                return
        # always display ouput in geo field - even if not transformed
        self.cache.a1 = a1
        self.cache.a2 = a2
        WidgetUtils.setOutput([x2, y2],
                              self.output_bshlm_geo[2:], True, z_fields=[], angular_unit=self.geo_unit)
        self.cache.is_valid = True
        self.cache.mode = int(not is_mode1)
예제 #3
0
                nok += 1
                log_file.write("Forward running time: %.5f s\n" %
                               (time.clock() - tstart))

        if nok == 0:
            continue
        log_file.write("Running inverse...\n")
        for i in range(repeat):
            tstart = time.clock()
            try:
                xyz_back = ct.InverseTransform(xyz_out)
            except Exception, msg:
                log_file.write(repr(msg) + "\n")
                sys.stderr.write(repr(msg) + "\n")
                msg = "From: %s To: %s, Last error: %d\n" % (
                    label_out, label_in, TrLib.GetLastError())
                log_file.write(msg)
                sys.stderr.write(msg)
                if N < 10:
                    sys.stderr.write("Input: %s\n" % repr(xyz_out))
                nerr += 1
                if THREAD_TEST:
                    return nerr
            else:
                log_file.write("Inverse running time: %.5f s\n" %
                               (time.clock() - tstart))
                if HAS_NUMPY and N <= 10:
                    err_xy = np.fabs(xyz[:, 0:2] - xyz_back[:, 0:2]).max()
                    if dim == 3:
                        err_z = np.fabs(xyz[:, 2] - xyz_back[:, 2]).max()
                    else: