def test_generate_rolling_average_w_matrix_uniform_ufull(self): """ Test for function which generates a w matrix for a rolling average operation - one observation per scanline """ ################################################################################################################ # 1. Define input data ################################################################################################################ matchup_times = array([0.0, 1.0, 2.0, 3.0, 4.0]) scanline_time = 1.0 kernel_uncertainty = array([[1.0, 1.1, 1.2, 1.3, 1.4], [1.1, 1.2, 1.3, 1.4, 1.5], [1.2, 1.3, 1.4, 1.5, 1.6], [1.3, 1.4, 1.5, 1.6, 1.7], [1.4, 1.5, 1.6, 1.7, 1.8]]) ################################################################################################################ # 2. Define expected output ################################################################################################################ w_matrix_expected = array([[0.2, 0.2, 0.2, 0.2, 0.2, 0.0, 0.0, 0.0, 0.0], [0.0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.0, 0.0, 0.0], [0.0, 0.0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.0, 0.0], [0.0, 0.0, 0.0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.0], [0.0, 0.0, 0.0, 0.0, 0.2, 0.2, 0.2, 0.2, 0.2]]) u_matrix_expected = array([1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8]) ################################################################################################################ # 3. W matrix generation script ################################################################################################################ w_matrix_test, u_matrix_test = generate_rolling_average_w_matrix(matchup_times, scanline_time, kernel_uncertainty) w_matrix_test = w_matrix_test.toarray() ################################################################################################################ # 3. Compare output ################################################################################################################ # a. w matrix for row_test, row_expected in zip(w_matrix_test, w_matrix_expected): self.assertEquals(row_test.tolist(), row_expected.tolist()) # b. u matrix self.assertEquals(u_matrix_expected.tolist(), u_matrix_test.tolist())
def test_generate_rolling_average_w_matrix_unordered_uint(self): """ Test for function which generates a w matrix for a rolling average operation - match-ups not in time order """ ################################################################################################################ # 1. Define input data ################################################################################################################ matchup_times = array([102.0, 101.0, 100.0, 0.0, 104.0]) scanline_time = 1.0 kernel_uncertainty = 1.0 weights = array([0.2, 0.2, 0.2, 0.2, 0.2]) ################################################################################################################ # 2. Define expected output ################################################################################################################ w_matrix_expected = array([[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.2, 0.2, 0.2, 0.2, 0.0, 0.0, 0.0, 0.0], [0.2, 0.2, 0.2, 0.2, 0.2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2, 0.2, 0.2, 0.2, 0.2]]) u_matrix_expected = array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]) ################################################################################################################ # 3. W matrix generation script ################################################################################################################ w_matrix_test, u_matrix_test = generate_rolling_average_w_matrix(matchup_times, scanline_time, kernel_uncertainty, weights=weights) w_matrix_test = w_matrix_test.toarray() ################################################################################################################ # 3. Compare output ################################################################################################################ # a. w matrix for row_test, row_expected in zip(w_matrix_test, w_matrix_expected): self.assertEquals(row_test.tolist(), row_expected.tolist()) # b. u matrix self.assertEquals(u_matrix_expected.tolist(), u_matrix_test.tolist())
def return_w_matrix_variables_MW(time1, time2, scanline_time, uR1, uR2, weights, sensor_1_instrument, sensor_2_instrument): """ :type time1: numpy.ndarray :param time1: Matchup time for sensor 1 :type time2: numpy.ndarray :param time2: Matchup time for sensor 2 :type scanline_time: float :param scanline_time: time interval between consecutive scanlines :type uR1: float :param uR1: Random uncertainty for X1, first row :type uR2: float :param uR2: Random uncertainty for X1, first row :type sensor_1_name: str :param sensor_1_name: Sensor ID for match-up sensor 1 :type weights: numpy.ndarray :param weights: :return: :w_matrix_val: *numpy.ndarray* Concatenated array of non-zero elements of W matrices :w_matrix_row: *numpy.ndarray* Concatenated array of row indices of W matrices :w_matrix_col: *numpy.ndarray* Concatenated array of row indices of W matrices :w_matrix_nnz: *numpy.ndarray* Number of non-zeros elements per W matrix :u_matrix_row_count: *numpy.ndarray* Number of non-zero elements per u matrix :u_matrix_val: *numpy.ndarray* Concatenated array of u matrix non-zero values :w_matrix_use1: *numpy.ndarray* Mapping from X1 array column index to W :w_matrix_use2: *numpy.ndarray* Mapping from X2 array column index to W :u_matrix_use1: *numpy.ndarray* Mapping from X1 array column index to U :u_matrix_use2: *numpy.ndarray* Mapping from X2 array column index to U """ # 1. Generate lists of W matrices and uncertainty vectors # a. Build w and u matrix vectors for Sensor 2 w_matrix2, u_matrix20 = generate_rolling_average_w_matrix(time2, scanline_time, float(uR2[0]), weights=weights) w_matrices = [w_matrix2] u_matrix21 = ones(len(u_matrix20)) * uR2[1] u_matrix22 = ones(len(u_matrix20)) * uR2[2] u_matrices = [u_matrix20, u_matrix21, u_matrix22] # b. Build w matrix and uncertainty vectors for Sensor 1 (if not reference) if len(uR1) != 1: # a. Compute W data w_matrix1, u_matrix10 = generate_rolling_average_w_matrix( time1, scanline_time, float(uR1[0]), weights=weights) w_matrices = [w_matrix1, w_matrix2] u_matrix11 = ones(len(u_matrix20)) * uR1[1] u_matrix12 = ones(len(u_matrix20)) * uR1[2] u_matrices = [ u_matrix10, u_matrix11, u_matrix12, u_matrix20, u_matrix21, u_matrix22 ] # 2. Convert W matrices and uncertainty vector to input file variables w_matrix_val, w_matrix_row, w_matrix_col, w_matrix_nnz, \ u_matrix_row_count, u_matrix_val = return_w_matrix_variables(w_matrices, u_matrices) # 3. Assign type/use matrices if (sensor_1_instrument == "ref") and (sensor_2_instrument == "AMSUB"): w_matrix_use1 = array([0], dtype=int8) w_matrix_use2 = array([1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0], dtype=int8) u_matrix_use1 = array([0], dtype=int8) u_matrix_use2 = array([1, 2, 3, 3, 3, 3, 3, 3, 3, 0, 0], dtype=int8) if (sensor_1_instrument == "ref") and (sensor_2_instrument == "MHS"): w_matrix_use1 = array([0], dtype=int8) w_matrix_use2 = array([1, 1, 1, 1, 1, 1, 1, 0, 0], dtype=int8) u_matrix_use1 = array([0], dtype=int8) u_matrix_use2 = array([1, 2, 3, 3, 3, 3, 3, 0, 0], dtype=int8) if (sensor_1_instrument == "MHS") and (sensor_2_instrument == "MHS"): w_matrix_use1 = array([1, 1, 1, 1, 1, 1, 1, 0, 0], dtype=int8) w_matrix_use2 = array([2, 2, 2, 2, 2, 2, 2, 0, 0], dtype=int8) u_matrix_use1 = array([1, 2, 3, 3, 3, 3, 3, 0, 0], dtype=int8) u_matrix_use2 = array([4, 5, 6, 6, 6, 6, 6, 0, 0], dtype=int8) if (sensor_1_instrument == "AMSUB") and (sensor_2_instrument == "MHS"): w_matrix_use1 = array([1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0], dtype=int8) w_matrix_use2 = array([2, 2, 2, 2, 2, 2, 2, 0, 0], dtype=int8) u_matrix_use1 = array([1, 2, 3, 3, 3, 3, 3, 3, 3, 0, 0], dtype=int8) u_matrix_use2 = array([4, 5, 6, 6, 6, 6, 6, 0, 0], dtype=int8) if (sensor_1_instrument == "MHS") and (sensor_2_instrument == "AMSUB"): w_matrix_use1 = array([1, 1, 1, 1, 1, 1, 1, 0, 0], dtype=int8) w_matrix_use2 = array([2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0], dtype=int8) u_matrix_use1 = array([1, 2, 3, 3, 3, 3, 3, 0, 0], dtype=int8) u_matrix_use2 = array([4, 5, 6, 6, 6, 6, 6, 6, 6, 0, 0], dtype=int8) if (sensor_1_instrument == "AMSUB") and (sensor_2_instrument == "AMSUB"): w_matrix_use1 = array([1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0], dtype=int8) w_matrix_use2 = array([2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0], dtype=int8) u_matrix_use1 = array([1, 2, 3, 3, 3, 3, 3, 3, 3, 0, 0], dtype=int8) u_matrix_use2 = array([4, 5, 6, 6, 6, 6, 6, 6, 6, 0, 0], dtype=int8) return w_matrix_val, w_matrix_row, w_matrix_col, w_matrix_nnz,\ u_matrix_row_count, u_matrix_val, w_matrix_use1, w_matrix_use2, u_matrix_use1, u_matrix_use2
def return_w_matrices(u_C_S_sensor_1, u_C_ICT_sensor_1, u_C_S_sensor_2, u_C_ICT_sensor_2, time_sensor_1, width_sensor_1, time_sensor_2, width_sensor_2, m1): """ Return w matrices and uncertainty vectors for a match-up :type u_C_S_sensor_1: numpy.ndarray :param u_C_S_sensor_1: Scanline uncertainties for space counts for sensor 1 :type u_C_ICT_sensor_1: numpy.ndarray :param u_C_ICT_sensor_1: Scanline uncertainties for ICT counts for sensor 1 :type u_C_S_sensor_2: numpy.ndarray :param u_C_S_sensor_2: Scanline uncertainties for space counts for sensor 2 :type u_C_ICT_sensor_2: numpy.ndarray :param u_C_ICT_sensor_2: Scanline uncertainties for ICT counts for sensor 2 :type time_sensor_1: numpy.ndarray :param time_sensor_1: match-up time for sensor 1 :type width_sensor_1: float :param width_sensor_1: scanline time for sensor 1 :type time_sensor_2: numpy.ndarray :param time_sensor_2: match-up time for sensor 2 :type width_sensor_2: float :param width_sensor_2: scanline time for sensor 2 :type sensor_1_name: int :param sensor_1_name: sensor 1 ID :return: :W: *scipy.sparse.csr_matrix* weighting matrix :uncertainty_vector: *numpy.ndarray* scanline uncertainty vector """ # 1. Build w matrix and uncertainty vectors for Sensor 2 w_C_S_sensor_2, uncertainty_vector_S_sensor_2 = generate_rolling_average_w_matrix( time_sensor_2, width_sensor_2, u_C_S_sensor_2) _, uncertainty_vector_ICT_sensor_2 = generate_rolling_average_w_matrix( time_sensor_2, width_sensor_2, u_C_ICT_sensor_2) w_matrices = [w_C_S_sensor_2] uncertainty_vectors = [ uncertainty_vector_S_sensor_2, uncertainty_vector_ICT_sensor_2 ] # 2. Build w matrix and uncertainty vectors for Sensor 1 (if not reference) if m1 != 1: # a. Compute W data w_C_S_sensor_1, uncertainty_vector_S_sensor_1 = generate_rolling_average_w_matrix( time_sensor_1, width_sensor_1, u_C_S_sensor_1) _, uncertainty_vector_ICT_sensor_1 = generate_rolling_average_w_matrix( time_sensor_1, width_sensor_1, u_C_ICT_sensor_1) w_matrices = [w_C_S_sensor_1, w_C_S_sensor_2] uncertainty_vectors = [ uncertainty_vector_S_sensor_1, uncertainty_vector_ICT_sensor_1, uncertainty_vector_S_sensor_2, uncertainty_vector_ICT_sensor_2 ] return w_matrices, uncertainty_vectors