예제 #1
0
    def test_vincdir(self):
        # Flinders Peak
        lat1 = hp2dec(-37.57037203)
        lon1 = hp2dec(144.25295244)
        lat1_DMS = DMSAngle(-37, 57, 3.7203)
        lon1_DMS = DMSAngle(144, 25, 29.5244)

        # To Buninyong
        azimuth1to2 = hp2dec(306.520537)
        azimuth1to2_DMS = DMSAngle(306, 52, 5.37)
        ell_dist = 54972.271

        # Test Decimal Degrees Input
        lat2, lon2, azimuth2to1 = vincdir(lat1, lon1, azimuth1to2, ell_dist)
        self.assertEqual(round(dec2hp(lat2), 8), -37.39101561)
        self.assertEqual(round(dec2hp(lon2), 8), 143.55353839)
        self.assertEqual(round(dec2hp(azimuth2to1), 6), 127.102507)

        # Test DMSAngle Input
        lat2, long2, azimuth2to1 = vincdir(lat1_DMS, lon1_DMS, azimuth1to2_DMS,
                                           ell_dist)
        self.assertEqual(round(dec2hp(lat2), 8), -37.39101561)
        self.assertEqual(round(dec2hp(long2), 8), 143.55353839)
        self.assertEqual(round(dec2hp(azimuth2to1), 6), 127.102507)

        # Test DDMAngle Input
        lat2, long2, azimuth2to1 = vincdir(lat1_DMS.ddm(), lon1_DMS.ddm(),
                                           azimuth1to2_DMS.ddm(), ell_dist)
        self.assertEqual(round(dec2hp(lat2), 8), -37.39101561)
        self.assertEqual(round(dec2hp(long2), 8), 143.55353839)
        self.assertEqual(round(dec2hp(azimuth2to1), 6), 127.102507)
예제 #2
0
def conform7(x, y, z, trans):
    """
    Performs a Helmert 7 Parameter Conformal Transformation using Cartesian point co-ordinates
    and a predefined transformation object.
    :param x: Cartesian X (m)
    :param y: Cartesian Y (m)
    :param z: Cartesian Z (m)
    :param trans: Transformation Object (note: this function ignores all time-dependent variables)
    :return: Transformed X, Y, Z Cartesian Co-ordinates
    """
    if type(trans) != Transformation:
        raise ValueError('trans must be a Transformation Object')
    # Create XYZ Vector
    xyz_before = np.array([[x], [y], [z]])
    # Convert Units for Transformation Parameters
    scale = trans.sc / 1000000
    rx = radians(hp2dec(trans.rx / 10000))
    ry = radians(hp2dec(trans.ry / 10000))
    rz = radians(hp2dec(trans.rz / 10000))
    # Create Translation Vector
    translation = np.array([[trans.tx], [trans.ty], [trans.tz]])
    # Create Rotation Matrix
    rotation = np.array([[1., rz, -ry], [-rz, 1., rx], [ry, -rx, 1.]])
    # Conformal Transform Eq
    xyz_after = translation + (1 + scale) * np.dot(rotation, xyz_before)
    # Convert Vector to Separate Variables
    xtrans = float(xyz_after[0])
    ytrans = float(xyz_after[1])
    ztrans = float(xyz_after[2])
    return xtrans, ytrans, ztrans
예제 #3
0
def vincinvio():
    # Enter Filename
    print('Enter co-ordinate file:')
    fn = input()
    # Open Filename
    csvfile = open(fn)
    csvreader = csv.reader(csvfile)
    # Create Output File
    fn_part = (os.path.splitext(fn))
    fn_out = fn_part[0] + '_out' + fn_part[1]
    outfile = open(fn_out, 'w')
    # Write Output
    outfilewriter = csv.writer(outfile)
    outfilewriter.writerow(['Ell_Dist', 'Azimuth1to2', 'Azimuth2to1'])
    for row in csvreader:
        lat1 = hp2dec(float(row[0]))
        long1 = hp2dec(float(row[1]))
        lat2 = hp2dec(float(row[2]))
        long2 = hp2dec(float(row[3]))
        ell_dist, azimuth1to2, azimuth2to1 = vincinv(lat1, long1, lat2, long2)
        azimuth1to2 = dec2hp(azimuth1to2)
        azimuth2to1 = dec2hp(azimuth2to1)
        output = (ell_dist, azimuth1to2, azimuth2to1)
        outfilewriter.writerow(output)
    # Close Files
    outfile.close()
    csvfile.close()
예제 #4
0
    def test_llh2xyz(self):

        # Test of single point
        x, y, z = llh2xyz(hp2dec(-37.482667598), hp2dec(144.581644114),
                          39.6514)
        self.assertAlmostEqual(x, -4131654.2815, 3)
        self.assertAlmostEqual(y, 2896107.9738, 3)
        self.assertAlmostEqual(z, -3888601.3067, 3)

        # Test DMSAngle input
        x, y, z = llh2xyz(DMSAngle(-37, 48, 26.67598),
                          DMSAngle(144, 58, 16.44114), 39.6514)
        self.assertAlmostEqual(x, -4131654.2815, 3)
        self.assertAlmostEqual(y, 2896107.9738, 3)
        self.assertAlmostEqual(z, -3888601.3067, 3)

        # Test DDMAngle input
        x, y, z = llh2xyz(DDMAngle(-37, 48.4445996), DDMAngle(144, 58.274019),
                          39.6514)
        self.assertAlmostEqual(x, -4131654.2815, 3)
        self.assertAlmostEqual(y, 2896107.9738, 3)
        self.assertAlmostEqual(z, -3888601.3067, 3)

        # Tests comparing results from DynAdjust Adjusted Coordinate File
        # including 109 Points Across Australia
        abs_path = os.path.abspath(os.path.dirname(__file__))

        testdata = read_dnacoord(
            os.path.join(abs_path, 'resources/natadjust_rvs_example.dat'))
        for coord in testdata:
            coord.converthptodd()
            xcomp, ycomp, zcomp = llh2xyz(coord.lat, coord.long, coord.ell_ht)
            assert (abs(coord.x - xcomp) < 2e-4)
            assert (abs(coord.y - ycomp) < 2e-4)
            assert (abs(coord.z - zcomp) < 2e-4)
예제 #5
0
 def test_dd2sec(self):
     self.assertEqual(dd2sec(1), 3600)
     self.assertEqual(dd2sec(-1), -3600)
     self.assertEqual(dd2sec(hp2dec(0.0001)), 1)
     self.assertEqual(dd2sec(hp2dec(-0.0001)), -1)
     self.assertEqual(dd2sec(hp2dec(0.00001)), 0.1)
     self.assertEqual(dd2sec(dec_ex4), 189)
     self.assertEqual(dd2sec(-dec_ex4), -189)
     self.assertEqual(dd2sec(dec_ex2), 45270)
     self.assertEqual(dd2sec(-dec_ex2), -45270)
예제 #6
0
 def test_vincinv(self):
     # Flinders Peak
     lat1 = hp2dec(-37.57037203)
     long1 = hp2dec(144.25295244)
     # Buninyong
     lat2 = hp2dec(-37.39101561)
     long2 = hp2dec(143.55353839)
     ell_dist, azimuth1to2, azimuth2to1 = vincinv(lat1, long1, lat2, long2)
     self.assertEqual(round(ell_dist, 3), 54972.271)
     self.assertEqual(round(dec2hp(azimuth1to2), 6), 306.520537)
     self.assertEqual(round(dec2hp(azimuth2to1), 6), 127.102507)
예제 #7
0
 def test_vincdir(self):
     # Flinders Peak
     lat1 = hp2dec(-37.57037203)
     long1 = hp2dec(144.25295244)
     # To Buninyong
     azimuth1to2 = hp2dec(306.520537)
     ell_dist = 54972.271
     lat2, long2, azimuth2to1 = vincdir(lat1, long1, azimuth1to2, ell_dist)
     self.assertEqual(round(dec2hp(lat2), 8), -37.39101561)
     self.assertEqual(round(dec2hp(long2), 8), 143.55353839)
     self.assertEqual(round(dec2hp(azimuth2to1), 6), 127.102507)
예제 #8
0
    def test_vincinv(self):
        # Flinders Peak
        lat1 = hp2dec(-37.57037203)
        lon1 = hp2dec(144.25295244)
        lat1_DMS = DMSAngle(-37, 57, 3.7203)
        lon1_DMS = DMSAngle(144, 25, 29.5244)

        # Buninyong
        lat2 = hp2dec(-37.39101561)
        lon2 = hp2dec(143.55353839)
        lat2_DMS = DMSAngle(-37, 39, 10.1561)
        lon2_DMS = DMSAngle(143, 55, 35.3839)

        # Test Decimal Degrees Input
        ell_dist, azimuth1to2, azimuth2to1 = vincinv(lat1, lon1, lat2, lon2)
        self.assertEqual(round(ell_dist, 3), 54972.271)
        self.assertEqual(round(dec2hp(azimuth1to2), 6), 306.520537)
        self.assertEqual(round(dec2hp(azimuth2to1), 6), 127.102507)

        # additional test case:
        pl1 = (-29.85, 140.71666666666667)
        pl2 = (-29.85, 140.76666666666667)
        ell_dist, azimuth1to2, azimuth2to1 = vincinv(pl1[0], pl1[1], pl2[0],
                                                     pl2[1])
        self.assertEqual(round(ell_dist, 3), 4831.553)
        self.assertEqual(round(dec2hp(azimuth1to2), 6), 90.004480)
        self.assertEqual(round(dec2hp(azimuth2to1), 6), 269.591520)

        test2 = vincinv(lat1, lon1, lat1, lon1)
        self.assertEqual(test2, (0, 0, 0))

        # Test DMSAngle Input
        ell_dist, azimuth1to2, azimuth2to1 = vincinv(lat1_DMS, lon1_DMS,
                                                     lat2_DMS, lon2_DMS)
        self.assertEqual(round(ell_dist, 3), 54972.271)
        self.assertEqual(round(dec2hp(azimuth1to2), 6), 306.520537)
        self.assertEqual(round(dec2hp(azimuth2to1), 6), 127.102507)

        test2 = vincinv(lat1_DMS, lon1_DMS, lat1_DMS, lon1_DMS)
        self.assertEqual(test2, (0, 0, 0))

        # Test DDMAngle Input
        (ell_dist, azimuth1to2, azimuth2to1) = vincinv(lat1_DMS.ddm(),
                                                       lon1_DMS.ddm(),
                                                       lat2_DMS.ddm(),
                                                       lon2_DMS.ddm())
        self.assertEqual(round(ell_dist, 3), 54972.271)
        self.assertEqual(round(dec2hp(azimuth1to2), 6), 306.520537)
        self.assertEqual(round(dec2hp(azimuth2to1), 6), 127.102507)

        test2 = vincinv(lat1_DMS.ddm(), lon1_DMS.ddm(), lat1_DMS.ddm(),
                        lon1_DMS.ddm())
        self.assertEqual(test2, (0, 0, 0))
예제 #9
0
def MkLine(ln, s):
    strg = ('   <Placemark>\n' + '      <name>' + str(ln[1]) + ' - - ' +
            str(ln[2]) + '</name>\n' + '    <description>' + str(s[0]) + ', ' +
            str(s[1]) + '\nStart: ' + fmt_int_date(ln[7]) + '\nFinish: ' +
            fmt_int_date(ln[8]) + '</description>\n' +
            '    <styleUrl>#trivlineStyle</styleUrl>\n' +
            '    <LineString>\n' + '      <extrude>1</extrude>\n' +
            '      <tessellate>1</tessellate>\n' +
            '      <altitudeMode>ClampToGround</altitudeMode>\n' +
            '      <coordinates>\n' + '       ' + str(hp2dec(ln[4])) + ',' +
            str(hp2dec(ln[3])) + ',0 ' + str(hp2dec(ln[6])) + ',' +
            str(hp2dec(ln[5])) + ',0 \n' + '      </coordinates>\n' +
            '    </LineString>\n')
    return strg + '  </Placemark>'
예제 #10
0
    def test_vincdir_utm(self):
        # Flinders Peak (UTM 55)
        zone1 = 55
        east1 = 273741.2966
        north1 = 5796489.7769
        # Grid Dimensions to Point 2 (Buninyong)
        grid_dist = 54992.279
        grid1to2 = hp2dec(305.17017259)
        grid1to2_DMS = DMSAngle(305, 17, 1.7259)

        # Test Decimal Degrees Input
        (zone2, east2, north2, grid2to1,
         lsf) = vincdir_utm(zone1, east1, north1, grid1to2, grid_dist)
        self.assertEqual(zone2, zone1)
        self.assertAlmostEqual(east2, 228854.0513, 3)
        self.assertAlmostEqual(north2, 5828259.0384, 3)
        self.assertAlmostEqual(dec2hp(grid2to1), 125.17418518, 7)
        self.assertAlmostEqual(lsf, 1.00036397, 8)

        # Test DMSAngle Input
        (zone2, east2, north2, grid2to1,
         lsf) = vincdir_utm(zone1, east1, north1, grid1to2_DMS, grid_dist)
        self.assertEqual(zone2, zone1)
        self.assertAlmostEqual(east2, 228854.0513, 3)
        self.assertAlmostEqual(north2, 5828259.0384, 3)
        self.assertAlmostEqual(dec2hp(grid2to1), 125.17418518, 7)
        self.assertAlmostEqual(lsf, 1.00036397, 8)
예제 #11
0
def va_conv(verta_hp, slope_dist, height_inst=0, height_tgt=0):
    """
    Function to convert vertical angles (zenith distances) and slope distances
    into horizontal distances and changes in height. Instrument and Target
    heights can be entered to allow computation of zenith and slope distances
    between ground points.

    :param verta_hp:        Vertical Angle from Instrument to Target, expressed
                            in HP Format (DDD.MMSSSSSS)
    :param slope_dist:      Slope Distance from Instrument to Target in metres
    :param height_inst:     Height of Instrument. Optional - Default Value of 0m
    :param height_tgt:      Height of Target. Optional - Default Value of 0m

    :return: verta_pt_hp:   Vertical Angle between Ground Points, expressed
                            in HP Format (DDD.MMSSSSSS)
    :return: slope_dist_pt: Slope Distance between Ground Points in metres
    :return: hz_dist:       Horizontal Distance
    :return: delta_ht:      Change in height between Ground Points in metres
    """
    # Convert Zenith Angle to Vertical Angle
    try:
        if verta_hp == 0 or verta_hp == 180:
            raise ValueError
        elif 0 < verta_hp < 180:
            verta = radians(90 - hp2dec(verta_hp))
        elif 180 < verta_hp < 360:
            verta = radians(270 - hp2dec(verta_hp))
        else:
            raise ValueError
    except ValueError:
        print('ValueError: Vertical Angle Invalid')
        return
    # Calculate Horizontal Dist and Delta Height
    hz_dist = slope_dist * cos(verta)
    delta_ht = slope_dist * sin(verta)
    # Account for Target and Instrument Heights
    if height_inst == 0 and height_tgt == 0:
        verta_pt_hp = verta_hp
        slope_dist_pt = slope_dist
    else:
        delta_ht = height_inst + delta_ht - height_tgt
        slope_dist_pt = sqrt(delta_ht**2 + hz_dist**2)
        verta_pt = asin(delta_ht / slope_dist)
        verta_pt_hp = dec2hp(degrees(verta_pt) + 90)
    return verta_pt_hp, slope_dist_pt, hz_dist, delta_ht
예제 #12
0
def vincdirio():
    """
    No Input:
    Prompts the user for the name of a file in csv format. Data in the file
    must be in the form Latitude, Longitude of Point 1 in Degrees Minutes
    Seconds, Geodetic Azimuth from Point 1 to 2 in Degrees Minutes Seconds and
    Distance in metres with no header line.

    No Output:
    Uses the function vincdir to calculate for each row in the csv file the
    geographic coordinate (lat, long) of Point 2 and the Azimuth from Point 2
    to Point 1, all in Degrees Minutes Seconds. This data is written to a new
    file with the name <inputfile>_out.csv
    """
    # Enter Filename
    fn = input('Enter co-ordinate file:\n')
    # Open Filename
    csvfile = open(fn)
    csvreader = csv.reader(csvfile)
    # Create Output File
    fn_part = (os.path.splitext(fn))
    fn_out = fn_part[0] + '_out' + fn_part[1]
    outfile = open(fn_out, 'w')
    # Write Output
    outfilewriter = csv.writer(outfile)
    # outfilewriter.writerow(['Latitude2', 'Longitude2', 'azimuth2to1'])
    for row in csvreader:
        lat1 = hp2dec(float(row[0]))
        long1 = hp2dec(float(row[1]))
        azimuth1to2 = hp2dec(float(row[2]))
        ell_dist = float(row[3])
        lat2, long2, azimuth2to1 = vincdir(lat1, long1, azimuth1to2, ell_dist)
        lat2 = dec2hp(lat2)
        long2 = dec2hp(long2)
        azimuth2to1 = dec2hp(azimuth2to1)
        output = [lat2, long2, azimuth2to1]
        outfilewriter.writerow(output)
    # Close Files
    outfile.close()
    csvfile.close()
예제 #13
0
def geo2gridio():
    """
    No Input:
    Prompts the user for the name of a file in csv format. Data in the file
    must be in the form Point ID, Latitude, Longitude in Decimal Degrees with
    no header line.

    No Output:
    Uses the function geo2grid to convert each row in the csv file into a
    coordinate with UTM Zone, Easting (m), Northing (m). This data is written
    to a new file with the name <inputfile>_out.csv
    """
    # Enter Filename
    print('Enter co-ordinate file:')
    fn = input()
    # Open Filename
    csvfile = open(fn)
    csvreader = csv.reader(csvfile)
    # Create Output File
    fn_part = (os.path.splitext(fn))
    fn_out = fn_part[0] + '_out' + fn_part[1]
    outfile = open(fn_out, 'w')
    # Write Output
    outfilewriter = csv.writer(outfile)
    # Optional Header Row
    # outfilewriter.writerow(['Pt', 'Zone', 'Easting', 'Northing', 'Point Scale Factor', 'Grid Convergence'])
    for row in csvreader:
        pt_num = row[0]
        lat = hp2dec(float(row[1]))
        long = hp2dec(float(row[2]))
        # Calculate Conversion
        hemisphere, zone, east, north, psf, grid_conv = geo2grid(lat, long)
        grid_conv = hp2dec(grid_conv)
        output = [pt_num] + [hemisphere, zone, east, north, psf, grid_conv]
        outfilewriter.writerow(output)
    # Close Files
    outfile.close()
    csvfile.close()
예제 #14
0
 def test_vincdir_utm(self):
     # Flinders Peak (UTM)
     zone1 = 55
     east1 = 273741.2966
     north1 = 5796489.7769
     # To Buninyong
     azimuth1to2 = hp2dec(306.520537)
     ell_dist = 54972.271
     hemisphere2, zone2, east2, north2, azimuth2to1 = vincdir_utm(zone1, east1, north1, azimuth1to2, ell_dist)
     self.assertEqual(hemisphere2, 'South')
     self.assertEqual(zone2, 54)
     self.assertEqual(round(east2, 4), 758173.7968)
     self.assertEqual(round(north2, 4), 5828674.3395)
     self.assertEqual(round(dec2hp(azimuth2to1), 6), 127.102507)
예제 #15
0
    def test_vincdir_utm(self):
        # Flinders Peak (UTM)
        zone1 = 55
        east1 = 273741.2966
        north1 = 5796489.7769
        # To Buninyong
        azimuth1to2 = hp2dec(306.520537)
        azimuth1to2_DMS = DMSAngle(306, 52, 5.37)

        ell_dist = 54972.271

        # Test Decimal Degrees Input
        (hemisphere2, zone2, east2,
         north2, azimuth2to1) = vincdir_utm(zone1, east1, north1,
                                            azimuth1to2, ell_dist)
        self.assertEqual(hemisphere2, 'South')
        self.assertEqual(zone2, 54)
        self.assertEqual(round(east2, 4), 758173.7968)
        self.assertEqual(round(north2, 4), 5828674.3395)
        self.assertEqual(round(dec2hp(azimuth2to1), 6), 127.102507)

        # Test DMSAngle Input
        (hemisphere2, zone2, east2,
         north2, azimuth2to1) = vincdir_utm(zone1, east1, north1,
                                            azimuth1to2_DMS, ell_dist)
        self.assertEqual(hemisphere2, 'South')
        self.assertEqual(zone2, 54)
        self.assertEqual(round(east2, 4), 758173.7968)
        self.assertEqual(round(north2, 4), 5828674.3395)
        self.assertEqual(round(dec2hp(azimuth2to1), 6), 127.102507)

        # Test DDMAngle Input
        (hemisphere2, zone2, east2,
         north2, azimuth2to1) = vincdir_utm(zone1, east1, north1,
                                            azimuth1to2_DMS.ddm(), ell_dist)
        self.assertEqual(hemisphere2, 'South')
        self.assertEqual(zone2, 54)
        self.assertEqual(round(east2, 4), 758173.7968)
        self.assertEqual(round(north2, 4), 5828674.3395)
        self.assertEqual(round(dec2hp(azimuth2to1), 6), 127.102507)
예제 #16
0
        # Z = None

        stn = line[0:20].strip()
        con = line[20:23]
        results = line[25:].split()
        r_count = 0

        for ct in coord_types:
            if ct == 'E':
                E = float(results[r_count])
            if ct == 'N':
                N = float(results[r_count])
            if ct == 'z':
                z = int(results[r_count])
            if ct == 'P':
                P = gc.hp2dec(float(results[r_count]))
            if ct == 'L':
                L = gc.hp2dec(float(results[r_count]))
            if ct == 'H':
                H = float(results[r_count])
            if ct == 'h':
                h = float(results[r_count])
            # if ct == 'X':
            #     X = float(results[r_count])
            # if ct == 'Y':
            #     Y = float(results[r_count])
            # if ct == 'Z':
            #     Z = float(results[r_count])

            r_count += 1
예제 #17
0
 def test_hp2dec(self):
     self.assertAlmostEqual(dec_ex, hp2dec(hp_ex), 13)
     self.assertAlmostEqual(-dec_ex, hp2dec(-hp_ex), 13)
     self.assertAlmostEqual(
         hp2dec(hp_ex) + hp2dec(hp_ex2), dec_ex + dec_ex2, 13)
예제 #18
0
파일: transform.py 프로젝트: mfkiwl/GeodePy
def conform7(x, y, z, trans, vcv=None):
    """
    Performs a Helmert 7 Parameter Conformal Transformation using Cartesian point co-ordinates
    and a predefined transformation object.
    :param x: Cartesian X (m)
    :param y: Cartesian Y (m)
    :param z: Cartesian Z (m)
    :param trans: Transformation Object (note: this function ignores all time-dependent variables)
    :param vcv: Optional 3*3 numpy array in Cartesian units to propagate tf uncertainty
    :return: Transformed X, Y, Z Cartesian Co-ordinates, vcv matrix
    """
    if type(trans) != Transformation:
        raise ValueError('trans must be a Transformation Object')
    # Create XYZ Vector
    xyz_before = np.array([[x], [y], [z]])
    # Convert Units for Transformation Parameters
    scale = 1 + trans.sc / 1000000
    rx = radians(hp2dec(trans.rx / 10000))
    ry = radians(hp2dec(trans.ry / 10000))
    rz = radians(hp2dec(trans.rz / 10000))
    # Create Translation Vector
    translation = np.array([[trans.tx], [trans.ty], [trans.tz]])
    # Create Rotation Matrix
    rotation = np.array([[1., rz, -ry], [-rz, 1., rx], [ry, -rx, 1.]])

    rot_xyz = rotation @ xyz_before

    # Conformal Transform Eq
    xyz_after = translation + scale * rot_xyz
    # Convert Vector to Separate Variables
    xtrans = float(xyz_after[0])
    ytrans = float(xyz_after[1])
    ztrans = float(xyz_after[2])

    # Transformation uncertainty propagation
    # Adapted from Harvey B.R. (1998) Practical least squares and statistics for surveyors,
    # Monograph 13 Section 8.7.2, p.274
    if (type(trans.tf_sd) == TransformationSD) and (vcv is not None):
        # Q matrix:
        q_mat = np.zeros((10, 10))
        # xyz_before vcv
        for i in range(3):
            for j in range(3):
                q_mat[i, j] = vcv[i, j]

        # transformation variances
        q_mat[3, 3] = (trans.tf_sd.sd_sc / 1000000)**2
        q_mat[4, 4] = radians(trans.tf_sd.sd_rx / 3600)**2
        q_mat[5, 5] = radians(trans.tf_sd.sd_ry / 3600)**2
        q_mat[6, 6] = radians(trans.tf_sd.sd_rz / 3600)**2
        q_mat[7, 7] = trans.tf_sd.sd_tx**2
        q_mat[8, 8] = trans.tf_sd.sd_ty**2
        q_mat[9, 9] = trans.tf_sd.sd_tz**2

        # Jacobian matrix:
        j_mat = np.zeros((3, 10))

        # scaled rotations
        j_mat[0, 0] = scale
        j_mat[0, 1] = scale * rz
        j_mat[0, 2] = -scale * ry
        j_mat[1, 0] = -j_mat[0, 1]
        j_mat[1, 1] = scale
        j_mat[1, 2] = scale * rx
        j_mat[2, 0] = -j_mat[0, 2]
        j_mat[2, 1] = -j_mat[1, 2]
        j_mat[2, 2] = scale

        # XYZ rotated
        j_mat[0, 3] = rot_xyz[0]
        j_mat[1, 3] = rot_xyz[1]
        j_mat[2, 3] = rot_xyz[2]

        # scaled XYZ
        j_mat[0, 5] = -scale * xyz_before[2]
        j_mat[0, 6] = scale * xyz_before[1]
        j_mat[1, 4] = scale * xyz_before[2]
        j_mat[1, 6] = -scale * xyz_before[0]
        j_mat[2, 4] = -scale * xyz_before[1]
        j_mat[2, 5] = scale * xyz_before[0]

        # Identity
        j_mat[0, 7] = 1
        j_mat[1, 8] = 1
        j_mat[2, 9] = 1

        # multiply J Q J_trans
        vcv_after = j_mat @ q_mat @ j_mat.transpose()

        return xtrans, ytrans, ztrans, vcv_after

    else:
        return xtrans, ytrans, ztrans, None
예제 #19
0
        if xml_m[i].find('<DnaMeasurement>') != -1:
            msr_out = ''
            while xml_m[i].find('</DnaMeasurement>') == -1:
                msr_out = msr_out + xml_m[i] + '\n'
                i += 1
            msr_out = msr_out + xml_m[i]

            # Test if the measurement needs changing
            m = xmltodict.parse(
                msr_out.replace('<!--', '<').replace('-->',
                                                     '>'))['DnaMeasurement']
            if (m['Type'] == 'G' and
                ('FirstStdDevSetupStyle' in m or 'SecondStdDevSetupStyle' in m
                 or 'StdDevObsStyle' in m)):
                #find the coordinates of the at and to station
                at_lat = hp2dec(stn[m['First']]['P'])
                at_lng = hp2dec(stn[m['First']]['L'])
                to_lat = hp2dec(stn[m['Second']]['P'])
                to_lng = hp2dec(stn[m['Second']]['L'])

                #Initialise the required matricies
                at_sd = np.zeros([3, 3])
                to_sd = np.zeros([3, 3])
                orig_vcv = np.zeros([3, 3])
                cal_vcv = np.zeros([3, 3])

                orig_vcv[0, 0] = float(m['GPSBaseline']['SigmaXX'])
                orig_vcv[0, 1] = float(m['GPSBaseline']['SigmaXY'])
                orig_vcv[0, 2] = float(m['GPSBaseline']['SigmaXZ'])
                orig_vcv[1, 1] = float(m['GPSBaseline']['SigmaYY'])
                orig_vcv[1, 2] = float(m['GPSBaseline']['SigmaYZ'])
예제 #20
0
def DynaGeol(adj_file):
    with open(adj_file) as f:
        first_line = f.readline()
    if first_line.startswith(
            'This DynAdjust file has been re-formatted by program DynaGEOL2020.'
    ):
        print(adj_file +
              ' has already been re-formatted by program DynaGEOL2020.\n')
    else:
        try:
            os.remove('$' + adj_file)
        except:
            ''
        os.rename(adj_file, '$' + adj_file)
        f_in = open('$' + adj_file, 'r')
        f_out = open(adj_file, 'w')
        part_G_cnt = 1
        base_cnt = 0
        coords = {}
        xyz_bases = {}
        read_msr = False
        read_coord = -1
        angular_msr_type = ''
        f_out.write(
            'This GEOLAB file has been re-formatted by program DynaGEOL2020.\n'
        )
        f_out.write('DYNADJUST ADJUSTMENT OUTPUT FILE\n')
        for linestr in f_in.readlines():
            f_out.write(linestr)
            if (linestr.find('Command line arguments:') != -1
                    and linestr.find('--angular-msr-type 1') != -1):
                angular_msr_type = 'dd'
            if linestr.find('Station coordinate types:') != -1:
                coord_types = linestr[35:].strip()
            if linestr.find('Adjusted Measurements') != -1: read_msr = True
            if read_msr and linestr[0:2] == 'G ':
                a_obs = linestr[67:].split()
                if part_G_cnt == 1:
                    dX = float(a_obs[0])
                    sdev_x = float(a_obs[3])
                    nstat_x = float(a_obs[6])
                if part_G_cnt == 2:
                    dY = float(a_obs[0])
                    sdev_y = float(a_obs[3])
                    nstat_y = float(a_obs[6])
                if part_G_cnt == 3:
                    dZ = float(a_obs[0])
                    sdev_z = float(a_obs[3])
                    nstat_z = float(a_obs[6])
                    xyz_bases[base_cnt] = {
                        'first': linestr[2:22].strip(),
                        'second': linestr[22:42].strip(),
                        'dX': dX,
                        'dY': dY,
                        'dZ': dZ,
                        'sdev_x': sdev_x,
                        'sdev_y': sdev_y,
                        'sdev_z': sdev_z,
                        'nstat_x': nstat_x,
                        'nstat_y': nstat_y,
                        'nstat_z': nstat_z
                    }
                    f_out.write('\n')
                    base_cnt += 1
                    part_G_cnt = 0
                part_G_cnt += 1

            if linestr.find('Adjusted Coordinates') != -1:
                read_msr = False
                read_coord = 0
            if read_coord > 4 and linestr != '\n':
                stn = linestr[0:20].strip()
                results = linestr[25:].split()
                r_count = 0
                for ct in coord_types:
                    if ct == 'E': E = float(results[r_count])
                    if ct == 'N': N = float(results[r_count])
                    if ct == 'z': z = int(results[r_count])
                    if ct == 'P':
                        if angular_msr_type != 'dd':
                            P = hp2dec(float(results[r_count]))
                        else:
                            P = float(results[r_count])
                    if ct == 'L':
                        if angular_msr_type != 'dd':
                            L = hp2dec(float(results[r_count]))
                        else:
                            L = float(results[r_count])
                    if ct == 'H': H = float(results[r_count])
                    if ct == 'h': h = float(results[r_count])
                    r_count += 1

                coords[str(stn)] = {
                    'E': E,
                    'N': N,
                    'Z': z,
                    'LAT': P,
                    'LON': L,
                    'OHGT': H,
                    'EHGT': h
                }
            if read_coord >= 0: read_coord += 1
        f_in.close()
        f_out.close()
        os.remove('$' + adj_file)
        return coords, xyz_bases
예제 #21
0
    def test_geo2grid(self):
        # Single Point Test
        hem, zone, east, north, psf, grid_conv = geo2grid(
            hp2dec(-37.482667598), hp2dec(144.581644114))
        self.assertEqual(hem, 'South')
        self.assertEqual(zone, 55)
        self.assertAlmostEqual(east, 321405.5592, 3)
        self.assertAlmostEqual(north, 5813614.1613, 3)
        self.assertAlmostEqual(psf, 0.99999287, 8)
        self.assertAlmostEqual(grid_conv, -1.2439811331, 9)

        # Test DMSAngle Input
        (hem, zone, east, north, psf,
         grid_conv) = geo2grid(DMSAngle(-37, 48, 26.67598),
                               DMSAngle(144, 58, 16.44114))
        self.assertEqual(hem, 'South')
        self.assertEqual(zone, 55)
        self.assertAlmostEqual(east, 321405.5592, 3)
        self.assertAlmostEqual(north, 5813614.1613, 3)
        self.assertAlmostEqual(psf, 0.99999287, 8)
        self.assertAlmostEqual(grid_conv, -1.2439811331, 9)

        # Test DDMAngle Input
        (hem, zone, east, north, psf,
         grid_conv) = geo2grid(DDMAngle(-37, 48.4445997),
                               DDMAngle(144, 58.274019))
        self.assertEqual(hem, 'South')
        self.assertEqual(zone, 55)
        self.assertAlmostEqual(east, 321405.5592, 3)
        self.assertAlmostEqual(north, 5813614.1613, 3)
        self.assertAlmostEqual(psf, 0.99999287, 8)
        self.assertAlmostEqual(grid_conv, -1.2439811331, 9)

        abs_path = os.path.abspath(os.path.dirname(__file__))

        # Test various coordinates in Australia
        testdata = read_dnacoord(
            os.path.join(abs_path, 'resources/natadjust_rvs_example.dat'))
        for coord in testdata:
            coord.converthptodd()
            hem, zonecomp, eastcomp, northcomp, psf, grid_conv = geo2grid(
                coord.lat, coord.long)
            self.assertEqual(zonecomp, coord.zone)
            self.assertLess(abs(eastcomp - coord.easting), 4e-4)
            self.assertLess((northcomp - coord.northing), 4e-4)

        # Test North and South Hemisphere Output
        north_ex = (DMSAngle(34, 57,
                             00.79653).dec(), DMSAngle(117, 48,
                                                       36.68783).dec())
        south_ex = (DMSAngle(-34, 57,
                             00.79653).dec(), DMSAngle(117, 48,
                                                       36.68783).dec())
        north_grid = geo2grid(north_ex[0], north_ex[1])
        south_grid = geo2grid(south_ex[0], south_ex[1])
        self.assertEqual(north_grid[0], 'North')
        self.assertEqual(south_grid[0], 'South')
        self.assertEqual(north_grid[1], south_grid[1])  # Zone
        self.assertEqual(north_grid[2], south_grid[2])  # Easting
        self.assertEqual(north_grid[3], 10000000 - south_grid[3])  # Northing
        self.assertEqual(north_grid[4], south_grid[4])  # PSF
        self.assertEqual(north_grid[5], -south_grid[5])  # Grid Convergence

        # Test Input Validation
        with self.assertRaises(ValueError):
            geo2grid(0, 45, -1)
        with self.assertRaises(ValueError):
            geo2grid(0, 45, 61)
        with self.assertRaises(ValueError):
            geo2grid(-81, 45, 0)
        with self.assertRaises(ValueError):
            geo2grid(85, 45, 0)
        with self.assertRaises(ValueError):
            geo2grid(0, -181, 0)
        with self.assertRaises(ValueError):
            geo2grid(0, 181, 0)
예제 #22
0
            #Header row will be written if 1 is passed to the headerout input variable
            if headerout == 1:
                outfilewriter.writerow(['Pt', 'Hemisphere', 'Zone', 'Easting', 'Northing', 'Point Scale Factor', 'Grid Convergence'])

            # Selects converstion to DD if required
            for row in csvreader:
                pt_num = row[0]
                if geotypein.get() == 'DD':
                    lat = (float(row[1]))
                    long = (float(row[2]))
                elif geotypein.get() == 'DMS':
                    lat = dms2dd(float(row[1]))
                    long = dms2dd(float(row[2]))
                elif geotypein.get() == 'HP':
                    lat = hp2dec(float(row[1]))
                    long = hp2dec(float(row[2]))

                # Calculate Conversion
                hemisphere, zone, east, north, psf, grid_conv = geo2grid(lat, long)
                grid_conv = dms2dd(grid_conv)
                output = [pt_num] + [hemisphere, zone, east, north, psf, grid_conv]
                outfilewriter.writerow(output)
=======
    # Enter Filename
    print('Enter co-ordinate file:')
    fn = input()
    # Open Filename
    csvfile = open(fn)
    csvreader = csv.reader(csvfile)
    # Create Output File
예제 #23
0
        if line == '\n':
            msr_switch = False
            continue

    if (stn_switch):
        if len(line) < 20:
            stn_switch = False
            continue

        stn = line[0:20].strip()
        con = line[20:23]
        east = float(line[28:39])
        north = float(line[40:54])
        zone = int(line[60:62])
        lat = gc.hp2dec(float(line[62:76]))
        lon = gc.hp2dec(float(line[77:91]))
        OHGT = float(line[91:102])
        EHGT = float(line[102:113])
        SD_E = float(line[161:170])
        SD_N = float(line[170:180])
        SD_U = float(line[180:190])

        stns[stn] = {
            'con': con,
            'E': east,
            'N': north,
            'Z': zone,
            'P': lat,
            'L': lon,
            'H': OHGT,
예제 #24
0
            if len(line) < 20:
                print(line, file=apu_typeB, end='')
                continue
        if line[:36] == 'Station                     Latitude':
            print(line, file=apu_typeB, end='')
            continue

        # account for station names with spaces.
        temp = line[0:20]
        if temp != (' ' * 20):
            numCols = len(line[21:].split()) + 1

        # Station variance line 1
        if numCols == 11:
            stn = line[:20]
            lat = gc.hp2dec(float(line[23:36]))
            lon = gc.hp2dec(float(line[38:51]))
            hPU = float(line[51:62].strip())
            vPU = float(line[62:73].strip())
            semiMajor = float(line[73:86].strip())
            semiMinor = float(line[86:99].strip())
            orient = float(line[99:112].strip())
            xVar = float(line[112:131].strip())
            xyCoVar = float(line[131:150].strip())
            xzCoVar = float(line[150:].strip())
            continue

        # covariance block line
        elif numCols == 4:
            print(line, file=apu_typeB, end='')
            continue
예제 #25
0
 def converthptodd(self):
     self.lat = hp2dec(self.lat)
     self.long = hp2dec(self.long)
예제 #26
0
파일: DynaDiff.py 프로젝트: whigg/PynAdjust
def read_xyz(xyz_file, read_switch=False):
    coords = {}

    print()
    print(' Reading {:s}'.format(xyz_file))

    with open(xyz_file, 'r') as xyz_fh:

        for line in xyz_fh:
            # skip empty lines
            if line == '':
                continue
            if line == '\n':
                continue

            if read_switch is False:
                if line[:35] == 'Version:                           ':
                    vers = line[35:].strip()
                if line[:35] == 'File name:                         ':
                    file = line[35:].strip()
                if line[:35] == 'Reference frame:                   ':
                    ref_frame = line[35:].strip()
                if line[:35] == 'Epoch:                             ':
                    epoch = line[35:].strip()
                if line[:35] == 'Geoid model:                       ':
                    geoid = line[35:].strip()
                if line[:35] == 'Station coordinate types:          ':
                    coord_types = line[35:].strip()
                    for l in mandatory_coord_types:
                        if l not in coord_types:
                            print('*' * 20)
                            print(
                                ' Warning! Mandatory coordinate types not present in {:s}'
                                .format(xyz_file))
                            print(
                                ' .xyz file must contain coord types ENzPLHh')
                            print('')
                            print('Exiting...')
                            exit()

            if line[87:88] == '-':
                read_switch = True
                continue

            if read_switch:
                stn = line[0:20].strip()
                results = line[25:].split()
                r_count = 0

                for ct in coord_types:
                    if ct == 'E':
                        E = float(results[r_count])
                    if ct == 'N':
                        N = float(results[r_count])
                    if ct == 'z':
                        z = int(results[r_count])
                    if ct == 'P':
                        P = gc.hp2dec(float(results[r_count]))
                    if ct == 'L':
                        L = gc.hp2dec(float(results[r_count]))
                    if ct == 'H':
                        H = float(results[r_count])
                    if ct == 'h':
                        h = float(results[r_count])
                    # Cartesian coords disabled for now
                    # if ct == 'X':
                    #     X = float(results[r_count])
                    # if ct == 'Y':
                    #     Y = float(results[r_count])
                    # if ct == 'Z':
                    #     Z = float(results[r_count])

                    r_count += 1

                # Don't forget about the qualities
                SE = float(results[r_count])
                SN = float(results[r_count + 1])
                SU = float(results[r_count + 2])

                coords[stn] = {
                    'E': E,
                    'N': N,
                    'Z': z,
                    'LAT': P,
                    'LON': L,
                    'OHGT': H,
                    'EHGT': h,
                    'SE': SE,
                    'SN': SN,
                    'SU': SU
                }

    return vers, file, ref_frame, epoch, geoid, coord_types, coords
예제 #27
0
            if o < 0: o += 1
            #Read the Coordinates
            if l.find('Adjusted Coordinates') != -1:
                c = -5
                o = 1
            if c == 0 and l != '\n':
                stn = l[0:20].strip()
                results = l[25:].split()
                r_count = 0
                for ct in coord_types:
                    if ct == 'E': E = float(results[r_count])
                    if ct == 'N': N = float(results[r_count])
                    if ct == 'z': z = int(results[r_count])
                    if ct == 'P':
                        if angular_msr_type != 'dd':
                            P = hp2dec(float(results[r_count]))
                        else:
                            P = float(results[r_count])
                    if ct == 'L':
                        if angular_msr_type != 'dd':
                            L = hp2dec(float(results[r_count]))
                        else:
                            L = float(results[r_count])
                    if ct == 'H': H = float(results[r_count])
                    if ct == 'h': h = float(results[r_count])
                    if ct == 'X': X = float(results[r_count])
                    if ct == 'Y': Y = float(results[r_count])
                    if ct == 'Z': Z = float(results[r_count])

                    r_count += 1
예제 #28
0
#!/usr/bin/env python3

"""
Geoscience Australia - Python Geodesy Package
Geoid Module

In Development
"""

import numpy as np
from geodepy.convert import hp2dec


# Define test grid points
nvals = np.array([(hp2dec(-31.51), hp2dec(133.48), -8.806),
                  (hp2dec(-31.51), hp2dec(133.49), -8.743),
                  (hp2dec(-31.52), hp2dec(133.48), -8.870),
                  (hp2dec(-31.52), hp2dec(133.49), -8.805)])

lat = hp2dec(-31.515996736)
long = hp2dec(133.483540489)