Пример #1
0
    def test_uv_size(self):

        #URL = 'http://testbedapps-dev.sura.org/thredds/dodsC/alldata/Estuarine_Hypoxia/noaa/cbofs2/synoptic/Output_Avg/ocean_avg_synoptic_seg22.nc'
        URL = os.path.join(data_path, "ocean_avg_synoptic_seg22.nc")

        # Call the uv_to_rho to calculate the resulting complex numbers on the
        # rho grid.
        uv_rho = rm.uv_to_rho(URL)

        # Manually calculate the two complex numbers for (rho) blocks.
        # The RHO blocks are (101,101) and (101,102) in this case
        nc = netCDF4.Dataset(URL)
        u = nc.variables['u'][0,0,:,:]
        v = nc.variables['v'][0,0,:,:]

        # This is what we have.
        #  ---------------------------------
        #  rho | u | rho | u | rho | u | rho
        #  ---------------------------------
        #   v  |   | {v} |   | {v} |   |  v
        #  ---------------------------------
        #  rho |{u}|(rho)|{u}|(rho)|{u}| rho
        #  ---------------------------------
        #   v  |   | {v} |   | {v} |   |  v
        #  ---------------------------------
        #  rho | u | rho | u | rho | u | rho
        #  ---------------------------------

        left_rho_u = 0.5 * (u[101,100] + u[101,101])
        left_rho_v = 0.5 * (v[100,101] + v[101,101])

        right_rho_u = 0.5 * (u[101,101] + u[101,102])
        right_rho_v = 0.5 * (v[100,102] + v[101,102])

        # Turn into a numpy array of complex numbers
        U = np.vectorize(complex)(np.array([left_rho_u,right_rho_u]), np.array(left_rho_v,right_rho_v))

        # Grab angles at the (rho) points
        angles = nc.variables['angle'][101,101:103]

        # And rotate by those angles
        U = rm.rotate_complex_by_angle(U,angles)

        left_rho  = U[0]
        right_rho = U[1]

        #print
        #print "Manual Left (101,101): " + str(left_rho)
        #print "Method Left (101,101): " + str(uv_rho[101,101])
        #print
        #print "Manual Right (101,102): " + str(right_rho)
        #print "Method Right (101,102): " + str(uv_rho[101,102])

        assert left_rho == uv_rho[101,101]
Пример #2
0
    def test_uv_size(self):
        #URL = 'http://testbedapps-dev.sura.org/thredds/dodsC/alldata/Estuarine_Hypoxia/noaa/cbofs2/synoptic/Output_Avg/ocean_avg_synoptic_seg22.nc'
        URL = os.path.join(self.data_path, "ocean_avg_synoptic_seg22.nc")

        # Call the uv_to_rho to calculate the resulting complex numbers on the
        # rho grid.
        uv_rho = rm.uv_to_rho(URL)

        # Manually calculate the two complex numbers for (rho) blocks.
        # The RHO blocks are (101,101) and (101,102) in this case
        nc = netCDF4.Dataset(URL)
        u = nc.variables['u'][0, 0, :, :]
        v = nc.variables['v'][0, 0, :, :]

        # This is what we have.
        #  ---------------------------------
        #  rho | u | rho | u | rho | u | rho
        #  ---------------------------------
        #   v  |   | {v} |   | {v} |   |  v
        #  ---------------------------------
        #  rho |{u}|(rho)|{u}|(rho)|{u}| rho
        #  ---------------------------------
        #   v  |   | {v} |   | {v} |   |  v
        #  ---------------------------------
        #  rho | u | rho | u | rho | u | rho
        #  ---------------------------------

        left_rho_u = 0.5 * (u[101, 100] + u[101, 101])
        left_rho_v = 0.5 * (v[100, 101] + v[101, 101])

        right_rho_u = 0.5 * (u[101, 101] + u[101, 102])
        right_rho_v = 0.5 * (v[100, 102] + v[101, 102])

        # Turn into a numpy array of complex numbers
        U = np.vectorize(complex)(np.array([left_rho_u, right_rho_u]),
                                  np.array(left_rho_v, right_rho_v))

        # Grab angles at the (rho) points
        angles = nc.variables['angle'][101, 101:103]

        # And rotate by those angles
        U = rm.rotate_complex_by_angle(U, angles)

        left_rho = U[0]
        right_rho = U[1]

        #print
        #print "Manual Left (101,101): " + str(left_rho)
        #print "Method Left (101,101): " + str(uv_rho[101,101])
        #print
        #print "Manual Right (101,102): " + str(right_rho)
        #print "Method Right (101,102): " + str(uv_rho[101,102])

        assert left_rho == uv_rho[101, 101]
Пример #3
0
    def test_angle_rotation(self):
        points = np.vectorize(complex)([-0.018,-0.013],[0.013,0.012])
        angles = np.array([-0.7,-0.3])
        r = rm.rotate_complex_by_angle(points,angles)

        # (-0.018+0.013j) * e^(sqrt(-1) * -0.7) = (-0.00539233+0.02153887j)
        # (-0.013+0.012j) * e^(sqrt(-1) * -0.3) = (-0.00887313+0.01530580j)

        result_test = np.array([-0.00539233+0.02153887j, -0.00887313+0.01530580j ], dtype=complex)

        assert np.allclose(r,result_test)