Exemplo n.º 1
0
    def read_band(self, key, info):
        """Read the data."""
        # Read data
        tic = datetime.now()
        with open(self.filename, "rb") as fp_:
            header = self._read_header(fp_)
            res = self._read_data(fp_, header)
        res = self._mask_invalid(data=res, header=header)
        self._header = header
        logger.debug("Reading time " + str(datetime.now() - tic))

        # Calibrate
        res = self.calibrate(res, key.calibration)

        # Get actual satellite position. For altitude use the ellipsoid radius at the SSP.
        actual_lon = float(self.nav_info['SSP_longitude'])
        actual_lat = float(self.nav_info['SSP_latitude'])
        re = get_earth_radius(lon=actual_lon, lat=actual_lat,
                              a=float(self.proj_info['earth_equatorial_radius'] * 1000),
                              b=float(self.proj_info['earth_polar_radius'] * 1000))
        actual_alt = float(self.nav_info['distance_earth_center_to_satellite']) * 1000 - re

        # Update metadata
        new_info = dict(
            units=info['units'],
            standard_name=info['standard_name'],
            wavelength=info['wavelength'],
            resolution='resolution',
            id=key,
            name=key.name,
            scheduled_time=self.scheduled_time,
            platform_name=self.platform_name,
            sensor=self.sensor,
            satellite_longitude=float(self.nav_info['SSP_longitude']),
            satellite_latitude=float(self.nav_info['SSP_latitude']),
            satellite_altitude=float(self.nav_info['distance_earth_center_to_satellite'] -
                                     self.proj_info['earth_equatorial_radius']) * 1000,
            orbital_parameters={
                'projection_longitude': float(self.proj_info['sub_lon']),
                'projection_latitude': 0.,
                'projection_altitude': float(self.proj_info['distance_from_earth_center'] -
                                             self.proj_info['earth_equatorial_radius']) * 1000,
                'satellite_actual_longitude': actual_lon,
                'satellite_actual_latitude': actual_lat,
                'satellite_actual_altitude': actual_alt,
                'nadir_longitude': float(self.nav_info['nadir_longitude']),
                'nadir_latitude': float(self.nav_info['nadir_latitude'])}
        )
        res = xr.DataArray(res, attrs=new_info, dims=['y', 'x'])

        # Mask space pixels
        if self.mask_space:
            res = self._mask_space(res)

        return res
Exemplo n.º 2
0
    def test_get_earth_radius(self):
        """Test earth radius computation."""
        a = 2.
        b = 1.

        def re(lat):
            """Compute ellipsoid radius at the given geodetic latitude.

            Reference: Capderou, M.: Handbook of Satellite Orbits, Equation (2.20).
            """
            lat = np.deg2rad(lat)
            e2 = 1 - b ** 2 / a ** 2
            n = a / np.sqrt(1 - e2*np.sin(lat)**2)
            return n * np.sqrt((1 - e2)**2 * np.sin(lat)**2 + np.cos(lat)**2)

        for lon in (0, 180, 270):
            self.assertEqual(hf.get_earth_radius(lon=lon, lat=0., a=a, b=b), a)
        for lat in (90, -90):
            self.assertEqual(hf.get_earth_radius(lon=0., lat=lat, a=a, b=b), b)
        self.assertTrue(np.isclose(hf.get_earth_radius(lon=123, lat=45., a=a, b=b), re(45.)))
Exemplo n.º 3
0
    def _get_metadata(self, key, ds_info):
        # Get actual satellite position. For altitude use the ellipsoid radius at the SSP.
        actual_lon = float(self.nav_info['SSP_longitude'])
        actual_lat = float(self.nav_info['SSP_latitude'])
        re = get_earth_radius(
            lon=actual_lon,
            lat=actual_lat,
            a=float(self.proj_info['earth_equatorial_radius'] * 1000),
            b=float(self.proj_info['earth_polar_radius'] * 1000))
        actual_alt = float(
            self.nav_info['distance_earth_center_to_satellite']) * 1000 - re

        if self._round_actual_position:
            actual_lon = round(actual_lon, 3)
            actual_lat = round(actual_lat, 2)
            actual_alt = round(actual_alt / 150) * 150  # to the nearest 150m

        # Update metadata
        new_info = dict(
            units=ds_info['units'],
            standard_name=ds_info['standard_name'],
            wavelength=ds_info['wavelength'],
            resolution='resolution',
            id=key,
            name=key['name'],
            platform_name=self.platform_name,
            sensor=self.sensor,
            time_parameters=dict(
                nominal_start_time=self.nominal_start_time,
                nominal_end_time=self.nominal_end_time,
                observation_start_time=self.observation_start_time,
                observation_end_time=self.observation_end_time,
            ),
            orbital_parameters={
                'projection_longitude':
                float(self.proj_info['sub_lon']),
                'projection_latitude':
                0.,
                'projection_altitude':
                float(self.proj_info['distance_from_earth_center'] -
                      self.proj_info['earth_equatorial_radius']) * 1000,
                'satellite_actual_longitude':
                actual_lon,
                'satellite_actual_latitude':
                actual_lat,
                'satellite_actual_altitude':
                actual_alt,
                'nadir_longitude':
                float(self.nav_info['nadir_longitude']),
                'nadir_latitude':
                float(self.nav_info['nadir_latitude']),
            },
        )
        return new_info