Exemplo n.º 1
0
    def test_cal1_algorithm_01(self) -> None:
        """
        CAL1 algorithm test #01
        -----------------------
        """
        expected = TestDataLoader(self.expected_01, delim=' ')
        input_data = TestDataLoader(self.inputs_01, delim=' ')

        self.initialise_algorithm(input_data)
        waveform_shape = (self.chd.n_ku_pulses_burst, self.chd.n_samples_sar)
        wfm_i = np.reshape(input_data["wfm_cal_gain_uncorrected_i"], waveform_shape)
        wfm_q = np.reshape(input_data["wfm_cal_gain_uncorrected_q"], waveform_shape)
        waveform_input = wfm_i + 1j*wfm_q

        burst = L1AProcessingData(
            self.cst, self.chd,
            cal1_power=input_data['burst_power_cor_ku_l1a_echo_sar_ku'],
            cal1_phase=input_data['burst_phase_cor_ku_l1a_echo_sar_ku'],
            sig0_cal_ku=input_data['sig0_cal_ku_l1a_echo_sar_ku'],
            agc_ku=input_data['agc_ku_l1a_echo_sar_ku'],
            waveform_cor_sar=waveform_input
        )

        self.cal1_algorithm(burst)

        wfm_i = np.reshape(expected["wfm_gain_cal1_corrected_i"], waveform_shape)
        wfm_q = np.reshape(expected["wfm_gain_cal1_corrected_q"], waveform_shape)
        waveform_expected = wfm_i + 1j*wfm_q

        self.assertTrue(
            np.allclose(np.real(burst.waveform_cor_sar), np.real(waveform_expected))
        )
        self.assertTrue(
            np.allclose(np.imag(burst.waveform_cor_sar), np.imag(waveform_expected))
        )
Exemplo n.º 2
0
    def __call__(self, burst: L1AProcessingData) -> None:
        if self.cnf.flag_cal2_correction:
            pulses = np.ones((self.chd.n_ku_pulses_burst, 1))
            correction = burst.cal2_array[np.newaxis, :] * pulses

            wfm_fft = fftshift(fft(burst.waveform_cor_sar, self.chd.n_samples_sar, 1), 1)
            burst.waveform_cor_sar = ifft(ifftshift(wfm_fft / np.sqrt(correction), 1), self.chd.n_samples_sar, 1)
    def test_surface_location_algorithm_02(self):
        """
        surface location algorithm test 02
        ----------------------------------

        loads multiple input ISPs and one input surface location.
        expected result is for the surface location algorithm to
        determine that a new surface location should not yet be
        calculated
        """
        # load input data
        inputs = TestDataLoader(self.input_02, delim=' ')
        self.initialise_algorithm(inputs)

        # generate input packet objects
        isps = [
            L1AProcessingData(self.cst, self.chd, i,
                              time_sar_ku=time,
                              lat_sar_sat=inputs["lat_sar_sat"][i],
                              lon_sar_sat=inputs["lon_sar_sat"][i],
                              alt_sar_sat=inputs["alt_sar_sat"][i],
                              win_delay_sar_ku=inputs["win_delay_sar_ku"][i]) \
            for i, time in enumerate(inputs["time_sar_ku"])
            ]
        for packet in isps:
            packet.compute_location_sar_surf()

        # create prior surface location object
        surf = SurfaceData(self.cst, self.chd,
                           time_surf=inputs["time_surf"],
                           x_surf=inputs["x_surf"],
                           y_surf=inputs["y_surf"],
                           z_surf=inputs["z_surf"],
                           x_sat=inputs["x_sat"],
                           y_sat=inputs["y_sat"],
                           z_sat=inputs["z_sat"],
                           x_vel_sat=inputs["x_vel_sat"],
                           y_vel_sat=inputs["y_vel_sat"],
                           z_vel_sat=inputs["z_vel_sat"]
                           )
        surf.compute_surf_sat_vector()
        surf.compute_angular_azimuth_beam_resolution(
            inputs["pri_sar_pre_dat"]
        )

        # execute surface location algorithm
        new_surf = self.surface_location_algorithm([surf], isps)

        # confirm that no new surface is generated
        self.assertFalse(new_surf, msg="erroneously created new surface")
Exemplo n.º 4
0
    def test_sigma0_algorithm_01(self):
        input_data = TestDataLoader(self.inputs_01, delim=' ')
        expected = TestDataLoader(self.expected_01, delim=' ')

        self.initialise_algorithm(input_data)

        data_stack_size = input_data['data_stack_size']

        isps = []

        x_vel = input_data['x_vel_sat_sar']
        y_vel = input_data['y_vel_sat_sar']
        z_vel = input_data['z_vel_sat_sar']
        pri_sar = input_data['pri_sar_pre_dat']

        for stack_index in range(data_stack_size):
            packet = L1AProcessingData(self.cst,
                                       self.chd,
                                       x_vel_sat_sar=x_vel[stack_index],
                                       y_vel_sat_sar=y_vel[stack_index],
                                       z_vel_sat_sar=z_vel[stack_index],
                                       pri_sar_pre_dat=pri_sar[stack_index])
            isps.append(packet)

        working_loc = SurfaceData(self.cst,
                                  self.chd,
                                  data_stack_size=data_stack_size,
                                  range_sat_surf=input_data['range_sat_surf'],
                                  stack_bursts=np.asarray(isps))
        sig0_scale_factor = self.sigma0_algorithm(working_loc,
                                                  input_data['wv_length_ku'],
                                                  input_data['chirp_slope_ku'])
        self.assertAlmostEqual(
            expected['sigma0_scaling_factor'],
            sig0_scale_factor,
        )
Exemplo n.º 5
0
    def test_beam_angles_algorithm_02(self):
        """
        beam angles algorithm test #02
         -----------------------------
        """
        # load the expected data object
        expected = TestDataLoader(self.expected_02, delim=' ')

        # load the input data
        input_data = TestDataLoader(self.input_02, delim=' ')

        self.initialise_algorithm(input_data)
        # create surface location objects
        surfs = []

        for i, surf_num in enumerate(input_data["surface_counter"]):
            surf = SurfaceData(
                self.cst,
                self.chd,
                surf_num,
                time_surf=input_data["time_surf"][i],
                x_surf=input_data["x_surf"][i],
                y_surf=input_data["y_surf"][i],
                z_surf=input_data["z_surf"][i],
            )
            surfs.append(surf)

        # create packet object
        packet = L1AProcessingData(
            self.cst,
            self.chd,
            time_sar_ku=input_data["time_sar_ku"],
            x_sar_sat=input_data["x_sar_sat"],
            y_sar_sat=input_data["y_sar_sat"],
            z_sar_sat=input_data["z_sar_sat"],
            x_vel_sat_sar=input_data["x_vel_sat_sar"],
            y_vel_sat_sar=input_data["y_vel_sat_sar"],
            z_vel_sat_sar=input_data["z_vel_sat_sar"],
            pri_sar_pre_dat=input_data["pri_sar_pre_dat"])
        work_loc = input_data["working_surface_location_counter"]

        # execute beam angles algorithm
        self.beam_angles_algorithm(surfs, packet, work_loc)

        # confirm correct number of surfaces seen
        self.assertEqual(len(self.beam_angles_algorithm.surfaces_seen),
                         expected["surfaces_seen"])

        # confirm the working surface location is not seen
        self.assertFalse(self.beam_angles_algorithm.work_location_seen,
                         msg="working location erroneously seen")

        # check beam angles are correct
        self.assertTrue(np.allclose(self.beam_angles_algorithm.beam_angles,
                                    expected["beam_ang"]),
                        msg="Beam Angles values are not correct")

        # check surface indicies are correct
        self.assertTrue(np.array_equal(
            self.beam_angles_algorithm.surfaces_seen,
            expected["surf_loc_index"]),
                        msg="Surface Indicies are not correct")
Exemplo n.º 6
0
    def test_output(self):
        # load input and expected data
        data = TestDataLoader(self._input_data, delim=' ')

        # create L1BWriter
        writer = L1BWriter(chd=self.chd,
                           cnf=self.cnf,
                           cst=self.cst,
                           filename=self._output_fname)
        writer.open()

        # write outputs

        for i in range(data["count"]):
            burst = L1AProcessingData(
                cst=self.cst,
                chd=self.chd,
                seq_num=i,
                isp_coarse_time=data["isp_coarse_time"][i],
                isp_fine_time=data["isp_fine_time"][i],
                sral_fine_time=data["sral_fine_time"][i],
                flag_time_status=data["flag_time_status"][i],
                nav_bul_status=data["nav_bul_status"][i],
                nav_bul_source=data["nav_bul_source"][i],
                source_seq_count=data["source_seq_count"][i],
                oper_instr=data["oper_instr"][i],
                SAR_mode=data["SAR_mode"][i],
                cl_gain=data["cl_gain"][i],
                acq_stat=data["acq_stat"][i],
                dem_eeprom=data["dem_eeprom"][i],
                loss_track=data["loss_track"][i],
                h0_nav_dem=data["h0_nav_dem"][i],
                h0_applied=data["h0_applied"][i],
                cor2_nav_dem=data["cor2_nav_dem"][i],
                cor2_applied=data["cor2_applied"][i],
                dh0=data["dh0"][i],
                agccode_ku=data["agccode_ku"][i],
                int_path_cor_ku=data["int_path_cor_ku"][i],
                agc_ku=data["agc_ku"][i],
                sig0_cal_ku=data["sig0_cal_ku"][i],
                surf_type=data["surface_type"][i],
                uso_cor=data["uso_cor"][i])

            surf = SurfaceData(
                chd=self.chd,
                cst=self.cst,
                time_surf=data["time_surf"][i],
                prev_tai=0,
                prev_utc_secs=0,
                prev_utc_days=0,
                curr_day_length=60 * 60 * 24,
                gps_time_surf=data["gps_time_surf"][i],
                lat_surf=data["lat_surf"][i],
                lon_surf=data["lon_surf"][i],
                alt_sat=data["alt_sat"][i],
                alt_rate_sat=data["alt_rate_sat"][i],
                x_sat=data["x_sat"][i],
                y_sat=data["y_sat"][i],
                z_sat=data["z_sat"][i],
                x_vel_sat=data["x_vel_sat"][i],
                y_vel_sat=data["y_vel_sat"][i],
                z_vel_sat=data["z_vel_sat"][i],
                sigma0_scaling_factor=data["sigma0_scaling_factor"][i],
                data_stack_size=data["data_stack_size"][i],
                stack_std=data["stack_std"][i],
                stack_skewness=data["stack_skewness"][i],
                stack_kurtosis=data["stack_kurtosis"][i],
                look_angles_surf=data["beam_angles_surf"],
                waveform_multilooked=data["waveform_multilooked"][i] * np.ones(
                    (256)),
                stack_max=data["stack_max"][i],
                closest_burst_index=0,
                stack_bursts=[burst],
                win_delay_surf=data["win_delay_surf"][i])
            writer.write_record(surf)

        # close writer
        writer.close()

        # open output file
        output = nc.Dataset(self._output_fname)

        # compare to expected values
        expected = TestDataLoader(self._expected_data, delim=' ')

        for i in range(expected["count"]):

            self.assertAlmostEqual(output.variables["time_l1b_echo_sar_ku"][i],
                                   expected["time_l1b_echo_sar_ku"][i])
            self.assertAlmostEqual(
                output.variables["UTC_day_l1b_echo_sar_ku"][i],
                expected["UTC_day_l1b_echo_sar_ku"][i])
            self.assertAlmostEqual(
                output.variables["UTC_sec_l1b_echo_sar_ku"][i],
                expected["UTC_sec_l1b_echo_sar_ku"][i])
            # 630719981 is the time-delta between GPS & UTC
            self.assertAlmostEqual(
                output.variables["GPS_time_l1b_echo_sar_ku"][i],
                expected["GPS_time_l1b_echo_sar_ku"][i] + 630719981)
            # these are limited to 6 places because of errors caused
            # by all the conversions from rads to deg & back again
            self.assertAlmostEqual(output.variables["lat_l1b_echo_sar_ku"][i],
                                   degrees(expected["lat_l1b_echo_sar_ku"][i]),
                                   places=6)
            self.assertAlmostEqual(output.variables["lon_l1b_echo_sar_ku"][i],
                                   degrees(expected["lon_l1b_echo_sar_ku"][i]),
                                   places=6)
            self.assertAlmostEqual(
                output.variables["orb_alt_rate_l1b_echo_sar_ku"][i],
                expected["orb_alt_rate_l1b_echo_sar_ku"][i])
            self.assertAlmostEqual(
                output.variables["x_pos_l1b_echo_sar_ku"][i],
                expected["x_pos_l1b_echo_sar_ku"][i])
            self.assertAlmostEqual(
                output.variables["y_pos_l1b_echo_sar_ku"][i],
                expected["y_pos_l1b_echo_sar_ku"][i])
            self.assertAlmostEqual(
                output.variables["z_pos_l1b_echo_sar_ku"][i],
                expected["z_pos_l1b_echo_sar_ku"][i])
            self.assertAlmostEqual(
                output.variables["x_vel_l1b_echo_sar_ku"][i],
                expected["x_vel_l1b_echo_sar_ku"][i])
            self.assertAlmostEqual(
                output.variables["y_vel_l1b_echo_sar_ku"][i],
                expected["y_vel_l1b_echo_sar_ku"][i])
            self.assertAlmostEqual(
                output.variables["z_vel_l1b_echo_sar_ku"][i],
                expected["z_vel_l1b_echo_sar_ku"][i])
            self.assertAlmostEqual(
                output.variables["surf_type_l1b_echo_sar_ku"][i],
                expected["surf_type_l1b_echo_sar_ku"][i])
            self.assertAlmostEqual(
                output.variables["scale_factor_ku_l1b_echo_sar_ku"][i],
                expected["scale_factor_ku_l1b_echo_sar_ku"][i])
            self.assertAlmostEqual(
                output.variables["nb_stack_l1b_echo_sar_ku"][i],
                expected["nb_stack_l1b_echo_sar_ku"][i])
            self.assertAlmostEqual(
                output.variables["stdev_stack_l1b_echo_sar_ku"][i],
                expected["stdev_stack_l1b_echo_sar_ku"][i])
            self.assertAlmostEqual(
                output.variables["skew_stack_l1b_echo_sar_ku"][i],
                expected["skew_stack_l1b_echo_sar_ku"][i])
            self.assertAlmostEqual(
                output.variables["kurt_stack_l1b_echo_sar_ku"][i],
                expected["kurt_stack_l1b_echo_sar_ku"][i])
            # TODO: multi-dimension arrays
            # self.assertAlmostEqual(
            #     output.variables["beam_ang_l1b_echo_sar_ku"][i],
            #     expected["beam_ang_l1b_echo_sar_ku"][i]
            # )
            for j in range(256):
                self.assertAlmostEqual(
                    output.variables["i2q2_meas_ku_l1b_echo_sar_ku"][i, j],
                    expected["i2q2_meas_ku_l1b_echo_sar_ku"][i],
                    places=3)
Exemplo n.º 7
0
    def test_stacking_algorithm_01(self):
        """
        stack_gathering algorithm test 01
        --------------------------
        """

        input_data = TestDataLoader(self.inputs_01, delim=' ')
        expected = TestDataLoader(self.expected_01, delim=' ')

        self.initialise_algorithm(input_data)

        all_stack_size = input_data["all_stack_size"]

        input_beam_angles_list = np.reshape(
            input_data["beam_angles_list"],
            (all_stack_size, self.chd.n_ku_pulses_burst))
        isps = []

        for stack_index in range(all_stack_size):
            beams_focused = np.zeros(
                (self.chd.n_ku_pulses_burst, self.chd.n_samples_sar))
            pid = PacketPid.echo_sar if input_data['isp_pid'][
                stack_index] == 7 else PacketPid.echo_rmc
            packet = L1AProcessingData(
                self.cst,
                self.chd,
                stack_index,
                t0_sar=input_data["T0_sar"][stack_index],
                doppler_angle_sar_sat=input_data["doppler_angle_sar_sat"]
                [stack_index],
                pitch_sar=input_data["pitch_sar"][stack_index],
                beam_angles_list=input_beam_angles_list[stack_index, :],
                beams_focused=beams_focused,
                isp_pid=pid)
            isps.append(packet)

        working_loc = SurfaceData(self.cst, self.chd, stack_all_bursts=isps)
        for beam_index in input_data["stack_all_beam_indexes"]:
            working_loc.add_stack_beam_index(beam_index, 0, 0)

        self.stacking_algorithm(working_loc)

        self.assertEqual(self.stacking_algorithm.data_stack_size,
                         expected["data_stack_size"])
        self.assertEqual(self.stacking_algorithm.surface_type,
                         SurfaceType(expected["surface_type"]))

        # beam_angles_surf
        self.assertTrue(np.allclose(self.stacking_algorithm.beam_angles_surf,
                                    expected["beam_angles_surf"]),
                        msg="beam_angles_surf do not match expected values")
        # t0_surf
        self.assertTrue(np.allclose(self.stacking_algorithm.t0_surf,
                                    expected["t0_surf"]),
                        msg="t0_surf do not match expected values")
        # doppler_angles_surf
        self.assertTrue(np.allclose(
            self.stacking_algorithm.doppler_angles_surf,
            expected["doppler_angles_surf"]),
                        msg="doppler_angles_surf do not match expected values")
        # look_angles_surf
        self.assertTrue(np.allclose(self.stacking_algorithm.look_angles_surf,
                                    expected["look_angles_surf"]),
                        msg="look_angles_surf do not match expected values")
        # pointing_angles_surf
        self.assertTrue(
            np.allclose(self.stacking_algorithm.pointing_angles_surf,
                        expected["pointing_angles_surf"]),
            msg="pointing_angles_surf do not match expected values")
Exemplo n.º 8
0
    def test_azimuth_processing_algorithm_01(self):
        """
        azimuth processing algorithm test 01
        ------------------------------------

        tests the azimuth processing algorithm approximate method
        """
        expected = TestDataLoader(self.expected_01, delim=' ')
        input_data = TestDataLoader(self.inputs_01, delim=' ')
        self.initialise_algorithm(input_data)

        # construct complex waveform
        waveform_shape = (self.chd.n_ku_pulses_burst, self.chd.n_samples_sar)
        wfm_i = np.reshape(input_data["wfm_cor_sar_i"], waveform_shape)
        wfm_q = np.reshape(input_data["wfm_cor_sar_q"], waveform_shape)
        wv_len = input_data["wv_length_ku"]

        # create input packet
        packet = L1AProcessingData(
            self.cst, self.chd,
            time_sar_ku=input_data["time_sar_ku"],
            x_vel_sat_sar=input_data["x_vel_sat_sar"],
            y_vel_sat_sar=input_data["y_vel_sat_sar"],
            z_vel_sat_sar=input_data["z_vel_sat_sar"],
            pri_sar_pre_dat=input_data["pri_sar_pre_dat"],
            beam_angles_list=input_data["beam_angles_list"],
            waveform_cor_sar=wfm_i+1j*wfm_q
        )
        # compute beam angles trend for packet
        packet.calculate_beam_angles_trend(
            input_data["beam_angles_list_size_previous_burst"],
            input_data["beam_angles_trend_previous_burst"]
        )

        # execute azimuth processing algorithm
        self.azimuth_processing_algorithm(packet, wv_len)

        beams_focused = self.azimuth_processing_algorithm.beams_focused

        # construct focused beams waveform
        wfm_i = np.reshape(expected["beams_focused_i"], waveform_shape)
        wfm_q = np.reshape(expected["beams_focused_q"], waveform_shape)

        for pulse_index in range(self.chd.n_ku_pulses_burst):
            for sample_index in range(self.chd.n_samples_sar):

                pos = "\nstack: {}/{}, sample: {}/{}".format(
                    pulse_index, self.chd.n_ku_pulses_burst,
                    sample_index, self.chd.n_samples_sar
                )

                expected_val = wfm_i[pulse_index, sample_index]
                actual_val = beams_focused[pulse_index, sample_index].real

                if expected_val == 0:
                    self.assertEqual(
                        expected_val,
                        actual_val,
                        msg=pos
                    )
                else:
                    rel_err = abs((expected_val - actual_val) / expected_val)
                    self.assertLess(rel_err, 2e-10, msg=pos)

                expected_val = wfm_q[pulse_index, sample_index]
                actual_val = beams_focused[pulse_index, sample_index].imag

                if expected_val == 0:
                    self.assertEqual(
                        expected_val,
                        actual_val,
                        msg=pos
                    )
                else:
                    rel_err = abs((expected_val - actual_val) / expected_val)
                    self.assertLess(rel_err, 2e-10, msg=pos)
    def test_surface_location_algorithm_01(self):
        """
        surface location algorithm test 01
        ----------------------------------

        loads an input packet and passes it as an initial
        item to the surface location algorithm.

        expected result is for the algorithm to create
        an initial surface location. Values of this
        location are validated.
        """
        # load expected data
        expected_data = TestDataLoader(self.expected_01, delim=' ')
        # load input data
        packet = TestDataLoader(self.input_01, delim=' ')

        self.initialise_algorithm(packet)

        # create packet object
        isps = [
            L1AProcessingData(
                self.cst, self.chd,
                time_sar_ku=packet["time_sar_ku"],
                lat_sar_sat=packet["lat_sar_sat"],
                lon_sar_sat=packet["lon_sar_sat"],
                alt_sar_sat=packet["alt_sar_sat"],
                win_delay_sar_ku=packet["win_delay_sar_ku"],
                x_sar_sat=0,
                y_sar_sat=0,
                z_sar_sat=0,
                alt_rate_sat_sar=0,
                roll_sar=0,
                pitch_sar=0,
                yaw_sar=0,
                x_vel_sat_sar=0,
                y_vel_sat_sar=0,
                z_vel_sat_sar=0,
                days=packet["time_sar_ku"] // self.cst.sec_in_day,
                seconds=packet["time_sar_ku"] % self.cst.sec_in_day
            )
        ]

        # execute surface location algorithm
        new_surf = self.surface_location_algorithm([], isps)

        # confirm new surface is created
        self.assertTrue(new_surf, msg="failed to create new surface")

        # retreive & validate surface properties
        surf = self.surface_location_algorithm.get_surface()

        self.assertAlmostEqual(surf["time_surf"], expected_data["time_surf"])

        self.assertAlmostEqual(surf["x_surf"], expected_data["x_surf"])
        self.assertAlmostEqual(surf["y_surf"], expected_data["y_surf"])
        self.assertAlmostEqual(surf["z_surf"], expected_data["z_surf"])

        self.assertAlmostEqual(surf["lat_surf"], expected_data["lat_surf"])
        self.assertAlmostEqual(surf["lon_surf"], expected_data["lon_surf"])
        self.assertAlmostEqual(surf["alt_surf"], expected_data["alt_surf"])
    def test_surface_location_algorithm_03(self):
        """
        surface location algorithm test 03
        ----------------------------------

        loads multiple input ISPs and one input surface location.
        expected result is for the surface location algorithm to
        generate a new surface location. The attributes of this
        new surface location are then validated against the expected
        values.
        """
        # load the expected data
        expected_data = TestDataLoader(self.expected_03, delim=' ')

        # load the input data
        inputs = TestDataLoader(self.input_03, delim=' ')

        self.initialise_algorithm(inputs)

        # create all input packet objects
        isps = [
            L1AProcessingData(self.cst, self.chd, i,
                              time_sar_ku=time,
                              lat_sar_sat=inputs["lat_sar_sat"][i],
                              lon_sar_sat=inputs["lon_sar_sat"][i],
                              alt_sar_sat=inputs["alt_sar_sat"][i],
                              win_delay_sar_ku=inputs["win_delay_sar_ku"][i],
                              x_sar_sat=0,
                              y_sar_sat=0,
                              z_sar_sat=0,
                              alt_rate_sat_sar=0,
                              roll_sar=0,
                              pitch_sar=0,
                              yaw_sar=0,
                              x_vel_sat_sar=0,
                              y_vel_sat_sar=0,
                              z_vel_sat_sar=0,
                              days=inputs["time_sar_ku"] // self.cst.sec_in_day,
                              seconds=inputs["time_sar_ku"] % self.cst.sec_in_day) \
            for i, time in enumerate(inputs["time_sar_ku"])
            ]
        # calculate surface position for each packet
        for packet in isps:
            packet.compute_location_sar_surf()

        # create the prior surface location object
        surf = SurfaceData(self.cst, self.chd,
                           time_surf=inputs["time_surf"],
                           x_surf=inputs["x_surf"],
                           y_surf=inputs["y_surf"],
                           z_surf=inputs["z_surf"],
                           x_sat=inputs["x_sat"],
                           y_sat=inputs["y_sat"],
                           z_sat=inputs["z_sat"],
                           x_vel_sat=inputs["x_vel_sat"],
                           y_vel_sat=inputs["y_vel_sat"],
                           z_vel_sat=inputs["z_vel_sat"]
                           )
        # compute properties of the surface location
        surf.compute_surf_sat_vector()
        surf.compute_angular_azimuth_beam_resolution(
            inputs["pri_sar_pre_dat"]
        )

        # execute the surface location algorithm
        new_surf = self.surface_location_algorithm([surf], isps)

        # confirm new surface has been created
        self.assertTrue(new_surf, msg="failed to create new surface")

        # retreive properties of the surface location
        surf = self.surface_location_algorithm.get_surface()

        # validate properties
        self.assertAlmostEqual(surf["time_surf"], expected_data["time_surf"])

        self.assertAlmostEqual(surf["x_surf"], expected_data["x_surf"], delta=1e-5)
        self.assertAlmostEqual(surf["y_surf"], expected_data["y_surf"], delta=1e-5)
        self.assertAlmostEqual(surf["z_surf"], expected_data["z_surf"], delta=1e-5)

        self.assertAlmostEqual(surf["lat_surf"], expected_data["lat_surf"], delta=1e-12)
        self.assertAlmostEqual(surf["lon_surf"], expected_data["lon_surf"], delta=1e-12)
        self.assertAlmostEqual(surf["alt_surf"], expected_data["alt_surf"], delta=1e-4)
Exemplo n.º 11
0
 def __getitem__(self, index: int) -> L1AProcessingData:
     # convert scale factor to linear value
     # scale_factor = pow(10, (-self.get_value(L1AVariables.scale_factor_ku_l1a_echo_sar_ku, index) / 20.))
     scale_factor = 20 * log10(
         self.get_value(L1AVariables.scale_factor_ku_l1a_echo_sar_ku,
                        index))
     # construct waveform
     waveform = scale_factor * (
         self.get_value(L1AVariables.i_meas_ku_l1a_echo_sar_ku, index) +
         1j * self.get_value(L1AVariables.q_meas_ku_l1a_echo_sar_ku, index))
     packet = L1AProcessingData(
         self.cst,
         self.chd,
         index,
         isp_pid=PacketPid.echo_sar,
         time_sar_ku=self.get_value(L1AVariables.time_l1a_echo_sar_ku,
                                    index),
         isp_coarse_time=self.get_value(
             L1AVariables.isp_coarse_time_l1a_echo_sar_ku, index),
         isp_fine_time=self.get_value(
             L1AVariables.isp_fine_time_l1a_echo_sar_ku, index),
         sral_fine_time=self.get_value(
             L1AVariables.sral_fine_time_l1a_echo_sar_ku, index),
         days=self.get_value(L1AVariables.UTC_day_l1a_echo_sar_ku, index),
         seconds=self.get_value(L1AVariables.UTC_sec_l1a_echo_sar_ku,
                                index),
         inst_id_sar_isp=0,
         pri_sar_pre_dat=self.chd.pri_sar,
         ambiguity_order_sar=0,
         burst_sar_ku=self.get_value(
             L1AVariables.burst_count_prod_l1a_echo_sar_ku, index),
         lat_sar_sat=radians(
             self.get_value(L1AVariables.lat_l1a_echo_sar_ku, index)),
         lon_sar_sat=radians(
             self.get_value(L1AVariables.lon_l1a_echo_sar_ku, index)),
         alt_sar_sat=self.get_value(L1AVariables.alt_l1a_echo_sar_ku,
                                    index),
         alt_rate_sat_sar=self.get_value(
             L1AVariables.orb_alt_rate_l1a_echo_sar_ku, index),
         x_vel_sat_sar=self.get_value(L1AVariables.x_vel_l1a_echo_sar_ku,
                                      index),
         y_vel_sat_sar=self.get_value(L1AVariables.y_vel_l1a_echo_sar_ku,
                                      index),
         z_vel_sat_sar=self.get_value(L1AVariables.z_vel_l1a_echo_sar_ku,
                                      index),
         roll_sar=radians(
             self.get_value(
                 L1AVariables.roll_sral_mispointing_l1a_echo_sar_ku,
                 index)),
         pitch_sar=radians(
             self.get_value(
                 L1AVariables.pitch_sral_mispointing_l1a_echo_sar_ku,
                 index)),
         yaw_sar=radians(
             self.get_value(
                 L1AVariables.yaw_sral_mispointing_l1a_echo_sar_ku, index)),
         h0_sar=self.get_value(L1AVariables.h0_applied_l1a_echo_sar_ku,
                               index),
         t0_sar=self.chd.
         t0_nom,  # * (1. + 2. * self.uso_cor_l1a_echo_sar_ku[index] / self.cst.c),
         cor2_sar=self.get_value(L1AVariables.cor2_applied_l1a_echo_sar_ku,
                                 index),
         win_delay_sar_ku=self.get_value(
             L1AVariables.range_ku_l1a_echo_sar_ku, index) * 2 / self.cst.c,
         x_sar_sat=self.get_value(L1AVariables.x_pos_l1a_echo_sar_ku,
                                  index),
         y_sar_sat=self.get_value(L1AVariables.y_pos_l1a_echo_sar_ku,
                                  index),
         z_sar_sat=self.get_value(L1AVariables.z_pos_l1a_echo_sar_ku,
                                  index),
         waveform_cor_sar=waveform,
         beams_focused=None,
         flag_time_status=self.get_value(
             L1AVariables.flag_time_status_l1a_echo_sar_ku, index),
         nav_bul_status=self.get_value(
             L1AVariables.nav_bul_status_l1a_echo_sar_ku, index),
         nav_bul_source=self.get_value(
             L1AVariables.nav_bul_source_l1a_echo_sar_ku, index),
         source_seq_count=self.get_value(
             L1AVariables.seq_count_l1a_echo_sar_ku, index),
         oper_instr=self.get_value(L1AVariables.oper_instr_l1a_echo_sar_ku,
                                   index),
         SAR_mode=self.get_value(L1AVariables.SAR_mode_l1a_echo_sar_ku,
                                 index),
         cl_gain=self.get_value(L1AVariables.cl_gain_l1a_echo_sar_ku,
                                index),
         acq_stat=self.get_value(L1AVariables.acq_stat_l1a_echo_sar_ku,
                                 index),
         dem_eeprom=self.get_value(L1AVariables.dem_eeprom_l1a_echo_sar_ku,
                                   index),
         loss_track=self.get_value(L1AVariables.loss_track_l1a_echo_sar_ku,
                                   index),
         h0_nav_dem=self.get_value(L1AVariables.h0_nav_dem_l1a_echo_sar_ku,
                                   index),
         h0_applied=self.get_value(L1AVariables.h0_applied_l1a_echo_sar_ku,
                                   index),
         cor2_nav_dem=self.get_value(
             L1AVariables.cor2_nav_dem_l1a_echo_sar_ku, index),
         cor2_applied=self.get_value(
             L1AVariables.cor2_applied_l1a_echo_sar_ku, index),
         dh0=self.get_value(L1AVariables.dh0_l1a_echo_sar_ku, index),
         agccode_ku=self.get_value(L1AVariables.agccode_ku_l1a_echo_sar_ku,
                                   index),
         range_ku=self.get_value(L1AVariables.range_ku_l1a_echo_sar_ku,
                                 index),
         int_path_cor_ku=self.get_value(
             L1AVariables.int_path_cor_ku_l1a_echo_sar_ku, index),
         agc_ku=self.get_value(L1AVariables.agc_ku_l1a_echo_sar_ku, index),
         sig0_cal_ku=self.get_value(
             L1AVariables.sig0_cal_ku_l1a_echo_sar_ku, index))
     packet.compute_location_sar_surf()
     packet.compute_doppler_angle()
     return packet
Exemplo n.º 12
0
    def test_output(self):
        # load input and expected data
        data = TestDataLoader(
            self._input_data, delim=' '
        )

        # create L1BSWriter
        writer = L1BSWriter(
            chd=self.chd, cnf=self.cnf, cst=self.cst,
            filename=self._output_fname
        )
        writer.open()

        # write outputs
        # stack_data = np.reshape(
        #     data["beams_range_compr_iq"], (data["count"], 240, 256)
        # )
        a, b = np.meshgrid(
            np.linspace(-10, 10, 256),
            np.linspace(-5, 5, 240)
        )
        stack_data = a + 1j * b

        for i in range(data["count"]):
            burst = L1AProcessingData(
                cst=self.cst,
                chd=self.chd,
                seq_num=i,
            )
            surf = SurfaceData(
                chd=self.chd,
                cst=self.cst,
                time_surf=data["time_surf"][i],
                prev_tai=0,
                prev_utc_secs=0,
                prev_utc_days=0,
                curr_day_length=60 * 60 * 24,
                lat_surf=data["lat_surf"][i],
                lon_surf=data["lon_surf"][i],
                surface_type=SurfaceType(data["surface_type"][i] % 3),
                alt_sat=data["alt_sat"][i],
                alt_rate_sat=data["alt_rate_sat"][i],
                x_sat=data["x_sat"][i],
                y_sat=data["y_sat"][i],
                z_sat=data["z_sat"][i],
                x_vel_sat=data["x_vel_sat"][i],
                y_vel_sat=data["y_vel_sat"][i],
                z_vel_sat=data["z_vel_sat"][i],
                x_surf=data["x_surf"][i],
                y_surf=data["y_surf"][i],
                z_surf=data["z_surf"][i],
                roll_sat=data["roll_sat"][i],
                pitch_sat=data["pitch_sat"][i],
                yaw_sat=data["yaw_sat"][i],
                waveform_multilooked=data["waveform_multilooked"][i] * np.ones((256)),
                stack_std=data["stack_std"][i],
                stack_skewness=data["stack_skewness"][i],
                stack_kurtosis=data["stack_kurtosis"][i],
                beams_range_compr_iq=stack_data * data["beams_range_compr_iq"][i],
                win_delay_surf=data["win_delay_surf"][i],
                closest_burst_index=0,
                stack_bursts=[burst]
            )
            writer.write_record(surf)

        # close writer
        writer.close()

        # open output file
        output = nc.Dataset(self._output_fname)

        # compare to expected values
        expected = TestDataLoader(
            self._expected_data, delim=' '
        )

        for i in range(expected["count"]):
            self.assertAlmostEqual(
                output.variables["time_l1bs_echo_sar_ku"][i],
                expected["time_l1bs_echo_sar_ku"][i]
            )
            self.assertAlmostEqual(
                output.variables["UTC_day_l1bs_echo_sar_ku"][i],
                expected["UTC_day_l1bs_echo_sar_ku"][i]
            )
            self.assertAlmostEqual(
                output.variables["UTC_sec_l1bs_echo_sar_ku"][i],
                expected["UTC_sec_l1bs_echo_sar_ku"][i]
            )
            self.assertAlmostEqual(
                output.variables["lat_l1bs_echo_sar_ku"][i],
                degrees(expected["lat_l1bs_echo_sar_ku"][i]),
                places=6
            )
            self.assertAlmostEqual(
                output.variables["lon_l1bs_echo_sar_ku"][i],
                degrees(expected["lon_l1bs_echo_sar_ku"][i]),
                places=6
            )
            self.assertAlmostEqual(
                output.variables["surf_type_l1bs_echo_sar_ku"][i],
                expected["surf_type_l1bs_echo_sar_ku"][i]
            )
            self.assertAlmostEqual(
                output.variables["orb_alt_rate_l1bs_echo_sar_ku"][i],
                expected["orb_alt_rate_l1bs_echo_sar_ku"][i]
            )
            self.assertAlmostEqual(
                output.variables["x_pos_l1bs_echo_sar_ku"][i],
                expected["x_pos_l1bs_echo_sar_ku"][i]
            )
            self.assertAlmostEqual(
                output.variables["y_pos_l1bs_echo_sar_ku"][i],
                expected["y_pos_l1bs_echo_sar_ku"][i]
            )
            self.assertAlmostEqual(
                output.variables["z_pos_l1bs_echo_sar_ku"][i],
                expected["z_pos_l1bs_echo_sar_ku"][i]
            )
            self.assertAlmostEqual(
                output.variables["x_vel_l1bs_echo_sar_ku"][i],
                expected["x_vel_l1bs_echo_sar_ku"][i]
            )
            self.assertAlmostEqual(
                output.variables["y_vel_l1bs_echo_sar_ku"][i],
                expected["y_vel_l1bs_echo_sar_ku"][i]
            )
            self.assertAlmostEqual(
                output.variables["z_vel_l1bs_echo_sar_ku"][i],
                expected["z_vel_l1bs_echo_sar_ku"][i]
            )
            self.assertAlmostEqual(
                output.variables["meas_x_pos_l1bs_echo_sar_ku"][i],
                expected["meas_x_pos_l1bs_echo_sar_ku"][i]
            )
            self.assertAlmostEqual(
                output.variables["meas_y_pos_l1bs_echo_sar_ku"][i],
                expected["meas_y_pos_l1bs_echo_sar_ku"][i]
            )
            self.assertAlmostEqual(
                output.variables["meas_z_pos_l1bs_echo_sar_ku"][i],
                expected["meas_z_pos_l1bs_echo_sar_ku"][i]
            )
            self.assertAlmostEqual(
                output.variables["stdev_stack_l1bs_echo_sar_ku"][i],
                expected["stdev_stack_l1bs_echo_sar_ku"][i]
            )
            self.assertAlmostEqual(
                output.variables["skew_stack_l1bs_echo_sar_ku"][i],
                expected["skew_stack_l1bs_echo_sar_ku"][i]
            )
            self.assertAlmostEqual(
                output.variables["kurt_stack_l1bs_echo_sar_ku"][i],
                expected["kurt_stack_l1bs_echo_sar_ku"][i]
            )
            for j in range(256):
                self.assertAlmostEqual(
                    output.variables["i2q2_meas_ku_l1bs_echo_sar_ku"][i, j],
                    expected["i2q2_meas_ku_l1bs_echo_sar_ku"][i]
                )
                for k in range(240):
                    self.assertAlmostEqual(
                        output.variables["i_echoes_ku_l1bs_echo_sar_ku"][i, j, k],
                        expected["i_echoes_ku_l1bs_echo_sar_ku"][i] * stack_data[k, j].real
                    )
                    self.assertAlmostEqual(
                        output.variables["q_echoes_ku_l1bs_echo_sar_ku"][i, j, k],
                        expected["q_echoes_ku_l1bs_echo_sar_ku"][i] * stack_data[j, k].imag
                    )
    def _geometry_corrections_algorithm_tests(self, input_data, expected):
        self.initialize_algorithm(input_data)
        # create stack of ISPs
        isps = []

        stack_size = input_data["data_stack_size"]
        for stack_index in range(stack_size):
            packet = L1AProcessingData(
                self.cst, self.chd,
                x_vel_sat_sar=input_data["x_vel_sat_sar"][stack_index],
                y_vel_sat_sar=input_data["y_vel_sat_sar"][stack_index],
                z_vel_sat_sar=input_data["z_vel_sat_sar"][stack_index],
                x_sar_sat=input_data["x_sar_sat"][stack_index],
                y_sar_sat=input_data["y_sar_sat"][stack_index],
                z_sar_sat=input_data["z_sar_sat"][stack_index],
                win_delay_sar_ku=input_data["win_delay_sar_ku"][stack_index]
            )
            isps.append(packet)

        # create working surface location
        beams_surf = np.reshape(
            input_data["beams_surf"],
            (stack_size, self.chd.n_samples_sar)
        )

        working_loc = SurfaceData(
            self.cst, self.chd,
            stack_bursts=isps,
            data_stack_size=stack_size,
            win_delay_surf=input_data["win_delay_surf"],
            x_surf=input_data["x_surf"],
            y_surf=input_data["y_surf"],
            z_surf=input_data["z_surf"],
            beam_angles_surf=input_data["beam_angles_surf"],
            t0_surf=input_data["T0_surf"],
            beams_surf=beams_surf
        )


        # TODO: add window delay alignment method selection
        self.geometry_corrections_algorithm(working_loc, input_data["wv_length_ku"])

        self.assertTrue(
            np.allclose(
                self.geometry_corrections_algorithm.doppler_corrections,
                expected["doppler_corrections"]
            ),
            msg="Doppler corrections do not match"
        )
        self.assertTrue(
            np.allclose(
                self.geometry_corrections_algorithm.range_sat_surf,
                expected["range_sat_surf"]
            ),
            msg="Range Sat Surf does not match"
        )
        self.assertTrue(
            np.allclose(
                self.geometry_corrections_algorithm.slant_range_corrections,
                expected["slant_range_corrections"], atol=1e-8
            ),
            msg="Slant Range Corrections do not match"
        )
        self.assertTrue(
            np.allclose(
                self.geometry_corrections_algorithm.win_delay_corrections,
                expected["win_delay_corrections"]
            ),
            msg="window delay corrections do not match"
        )
        flat_corr = np.ravel(self.geometry_corrections_algorithm.beams_geo_corr)
        components = zip(np.real(flat_corr), np.imag(flat_corr))

        for index, (i, q) in enumerate(components):
            expected_i = expected["beams_geo_corr_i"][index]
            expected_q = expected["beams_geo_corr_q"][index]

            if expected_i == 0:
                self.assertEqual(
                    expected_i, i
                )
            else:
                rel_err = abs((expected_i - i) / expected_i)
                self.assertLess(rel_err, 2e-4)

            if expected_q == 0:
                self.assertEqual(
                    expected_q, q
                )
            else:
                rel_err = abs((expected_q - q) / expected_q)
                self.assertLess(rel_err, 2e-4)
Exemplo n.º 14
0
    def test_surface_location_algorithm_04(self):
        """
        surface location algorithm test 04
        ----------------------------------

        loads multiple input ISPs and two input surface locations.
        expected result is for the surface location algorithm to
        generate a new surface location and focus the position of the previous
        one towards the target position. The attributes of these
        surface locations are then validated against the expected
        values.
        """
        # load the expected data
        expected_data = TestDataLoader(self.expected_04, delim=' ')

        # load the input data
        inputs = TestDataLoader(self.inputs_04, delim=' ')

        self.initialise_algorithm(inputs)

        # create all input packet objects
        isps = [
            L1AProcessingData(self.cst, self.chd, i,
                              time_sar_ku=time,
                              lat_sar_sat=inputs["lat_sar_sat"][i],
                              lon_sar_sat=inputs["lon_sar_sat"][i],
                              alt_sar_sat=inputs["alt_sar_sat"][i],
                              win_delay_sar_ku=inputs["win_delay_sar_ku"][i],
                              x_sar_sat=inputs["x_sar_sat"][i],
                              y_sar_sat=inputs["y_sar_sat"][i],
                              z_sar_sat=inputs["z_sar_sat"][i],
                              alt_rate_sat_sar=0,
                              roll_sar=inputs["roll_sar"][i],
                              pitch_sar=inputs["pitch_sar"][i],
                              yaw_sar=inputs["yaw_sar"][i],
                              x_vel_sat_sar=inputs["x_vel_sat_sar"][i],
                              y_vel_sat_sar=inputs["y_vel_sat_sar"][i],
                              z_vel_sat_sar=inputs["z_vel_sat_sar"][i],
                              days=inputs["time_sar_ku"] // self.cst.sec_in_day,
                              seconds=inputs["time_sar_ku"] % self.cst.sec_in_day) \
            for i, time in enumerate(inputs["time_sar_ku"])
            ]
        # calculate surface position for each packet
        for packet in isps:
            packet.compute_location_sar_surf()

        surfs = []
        # create the prior surface location object
        for i, time in enumerate(inputs["time_surf"]):
            surf = SurfaceData(
                self.cst, self.chd,
                time_surf=time,
                x_surf=inputs["x_surf"][i],
                y_surf=inputs["y_surf"][i],
                z_surf=inputs["z_surf"][i],
                lat_surf=inputs["lat_surf"][i],
                lon_surf=inputs["lon_surf"][i],
                alt_surf=inputs["alt_surf"][i],
                x_sat=inputs["x_sat"][i],
                y_sat=inputs["y_sat"][i],
                z_sat=inputs["z_sat"][i],
                lat_sat=inputs["lat_sat"][i],
                lon_sat=inputs["lon_sat"][i],
                alt_sat=inputs["alt_sat"][i],
                x_vel_sat=inputs["x_vel_sat"][i],
                y_vel_sat=inputs["y_vel_sat"][i],
                z_vel_sat=inputs["z_vel_sat"][i],
                focus_target_distance=inputs["focus_target_distance"][i],
                win_delay_surf=inputs["win_delay_surf"][i]
            )
            surf.compute_surf_sat_vector()
            surf.compute_angular_azimuth_beam_resolution(
                inputs["pri_sar_pre_dat"][i]
            )
            surfs.append(surf)

        # execute the surface location algorithm
        new_surf = self.surface_location_algorithm(surfs, isps)

        # confirm new surface has been created
        self.assertTrue(new_surf, msg="failed to create new surface")

        # retreive properties of the surface location
        surf = surfs[1]

        # validate properties
        self.assertAlmostEqual(surf.time_surf, expected_data["time_surf"])

        self.assertAlmostEqual(surf.x_surf, expected_data["x_surf"], delta=1e-5)
        self.assertAlmostEqual(surf.y_surf, expected_data["y_surf"], delta=1e-5)
        self.assertAlmostEqual(surf.z_surf, expected_data["z_surf"], delta=1e-5)

        self.assertAlmostEqual(surf.lat_surf, expected_data["lat_surf"], delta=1e-12)
        self.assertAlmostEqual(surf.lon_surf, expected_data["lon_surf"], delta=1e-12)
        self.assertAlmostEqual(surf.alt_surf, expected_data["alt_surf"], delta=1e-4)

        self.assertAlmostEqual(surf.win_delay_surf, expected_data["win_delay_surf"])