Exemplo n.º 1
0
    def test_get_lonlats(self):
        """Test get_lonlats on StackedAreaDefinition."""
        area3 = geometry.AreaDefinition(
            "area3", 'area3', "geosmsg", {
                'a': '6378169.0',
                'b': '6356583.8',
                'h': '35785831.0',
                'lon_0': '0.0',
                'proj': 'geos',
                'units': 'm'
            }, 5568, 464, (3738502.0095458371, 3251436.5796920112,
                           -1830246.0673044831, 2787374.2399544837))

        # transition
        area4 = geometry.AreaDefinition(
            "area4", 'area4', "geosmsg", {
                'a': '6378169.0',
                'b': '6356583.8',
                'h': '35785831.0',
                'lon_0': '0.0',
                'proj': 'geos',
                'units': 'm'
            }, 5568, 464, (5567747.7409681147, 2787374.2399544837,
                           -1000.3358822065015, 2323311.9002169576))

        final_area = geometry.StackedAreaDefinition(area3, area4)
        self.assertEqual(len(final_area.defs), 2)
        lons, lats = final_area.get_lonlats()
        lons0, lats0 = final_area.defs[0].get_lonlats()
        lons1, lats1 = final_area.defs[1].get_lonlats()
        np.testing.assert_allclose(lons[:464, :], lons0)
        np.testing.assert_allclose(lons[464:, :], lons1)
        np.testing.assert_allclose(lats[:464, :], lats0)
        np.testing.assert_allclose(lats[464:, :], lats1)
Exemplo n.º 2
0
    def get_area_def(self, dataset_id):
        """Get the area definition of the band.

        In general, image data from one window/area is available. For the HRV channel in FES mode, however,
        data from two windows ('Lower' and 'Upper') are available. Hence, we collect lists of area-extents
        and corresponding number of image lines/columns. In case of FES HRV data, two area definitions are
        computed, stacked and squeezed. For other cases, the lists will only have one entry each, from which
        a single area definition is computed.

        Note that the AreaDefinition area extents returned by this function for Native data will be slightly
        different compared to the area extents returned by the SEVIRI HRIT reader.
        This is due to slightly different pixel size values when calculated using the data available in the files. E.g.
        for the 3 km grid:

        ``Native: data15hd['ImageDescription']['ReferenceGridVIS_IR']['ColumnDirGridStep'] == 3000.4031658172607``
        ``HRIT:                            np.deg2rad(2.**16 / pdict['lfac']) * pdict['h'] == 3000.4032785810186``

        This results in the Native 3 km full-disk area extents being approx. 20 cm shorter in each direction.

        The method for calculating the area extents used by the HRIT reader (CFAC/LFAC mechanism) keeps the
        highest level of numeric precision and is used as reference by EUM. For this reason, the standard area
        definitions defined in the `areas.yaml` file correspond to the HRIT ones.

        """
        pdict = {}
        pdict['a'] = self.mda['projection_parameters']['a']
        pdict['b'] = self.mda['projection_parameters']['b']
        pdict['h'] = self.mda['projection_parameters']['h']
        pdict['ssp_lon'] = self.mda['projection_parameters']['ssp_longitude']

        area_naming_input_dict = {
            'platform_name': 'msg',
            'instrument_name': 'seviri',
            'resolution': int(dataset_id['resolution'])
        }
        area_naming = get_geos_area_naming({
            **area_naming_input_dict,
            **get_service_mode('seviri', pdict['ssp_lon'])
        })

        pdict['a_name'] = area_naming['area_id']
        pdict['a_desc'] = area_naming['description']
        pdict['p_id'] = ""

        area_extent = self.get_area_extent(dataset_id)
        areas = list()
        for aex, nlines, ncolumns in zip(area_extent['area_extent'],
                                         area_extent['nlines'],
                                         area_extent['ncolumns']):
            pdict['nlines'] = nlines
            pdict['ncols'] = ncolumns
            areas.append(get_area_definition(pdict, aex))

        if len(areas) == 2:
            area = geometry.StackedAreaDefinition(areas[0], areas[1])
            area = area.squeeze()
        else:
            area = areas[0]

        return area
Exemplo n.º 3
0
    def get_area_def(self, dataset_id):
        """Get the area definition of the band."""
        pdict = {}
        pdict['a'] = self.mda['projection_parameters']['a']
        pdict['b'] = self.mda['projection_parameters']['b']
        pdict['h'] = self.mda['projection_parameters']['h']
        pdict['ssp_lon'] = self.mda['projection_parameters']['ssp_longitude']

        if dataset_id['name'] == 'HRV':
            pdict['nlines'] = self.mda['hrv_number_of_lines']
            pdict['ncols'] = self.mda['hrv_number_of_columns']
            pdict['a_name'] = 'geos_seviri_hrv'
            pdict['a_desc'] = 'SEVIRI high resolution channel area'
            pdict['p_id'] = 'seviri_hrv'

            if self.mda['is_full_disk']:
                # handle full disk HRV data with two separated area definitions
                [
                    upper_area_extent, lower_area_extent, upper_nlines,
                    upper_ncols, lower_nlines, lower_ncols
                ] = self.get_area_extent(dataset_id)

                # upper area
                pdict[
                    'a_desc'] = 'SEVIRI high resolution channel, upper window'
                pdict['nlines'] = upper_nlines
                pdict['ncols'] = upper_ncols
                upper_area = get_area_definition(pdict, upper_area_extent)

                # lower area
                pdict[
                    'a_desc'] = 'SEVIRI high resolution channel, lower window'
                pdict['nlines'] = lower_nlines
                pdict['ncols'] = lower_ncols
                lower_area = get_area_definition(pdict, lower_area_extent)

                area = geometry.StackedAreaDefinition(lower_area, upper_area)
                area = area.squeeze()
            else:
                # if the HRV data is in a ROI, the HRV channel is delivered in one area
                area = get_area_definition(pdict,
                                           self.get_area_extent(dataset_id))

        else:
            pdict['nlines'] = self.mda['number_of_lines']
            pdict['ncols'] = self.mda['number_of_columns']
            pdict['a_name'] = 'geos_seviri_visir'
            pdict['a_desc'] = 'SEVIRI low resolution channel area'
            pdict['p_id'] = 'seviri_visir'

            area = get_area_definition(pdict, self.get_area_extent(dataset_id))

        return area
Exemplo n.º 4
0
    def get_area_def(self, dataset_id):
        """Get the area definition of the band.

        In general, image data from one window/area is available. For the HRV channel in FES mode, however,
        data from two windows ('Lower' and 'Upper') are available. Hence, we collect lists of area-extents
        and corresponding number of image lines/columns. In case of FES HRV data, two area definitions are
        computed, stacked and squeezed. For other cases, the lists will only have one entry each, from which
        a single area definition is computed.
        """
        pdict = {}
        pdict['a'] = self.mda['projection_parameters']['a']
        pdict['b'] = self.mda['projection_parameters']['b']
        pdict['h'] = self.mda['projection_parameters']['h']
        pdict['ssp_lon'] = self.mda['projection_parameters']['ssp_longitude']

        if dataset_id['name'] == 'HRV':
            res = 1.0
            pdict['p_id'] = 'seviri_hrv'
        else:
            res = 3.0
            pdict['p_id'] = 'seviri_visir'

        service_mode = get_service_mode(pdict['ssp_lon'])
        pdict['a_name'] = 'msg_seviri_%s_%.0fkm' % (service_mode['name'], res)
        pdict[
            'a_desc'] = 'SEVIRI %s area definition with %.0f km resolution' % (
                service_mode['desc'], res)

        area_extent = self.get_area_extent(dataset_id)
        areas = list()
        for aex, nlines, ncolumns in zip(area_extent['area_extent'],
                                         area_extent['nlines'],
                                         area_extent['ncolumns']):
            pdict['nlines'] = nlines
            pdict['ncols'] = ncolumns
            areas.append(get_area_definition(pdict, aex))

        if len(areas) == 2:
            area = geometry.StackedAreaDefinition(areas[0], areas[1])
            area = area.squeeze()
        else:
            area = areas[0]

        return area
Exemplo n.º 5
0
    def get_area_def(self, dsid):
        """Get the area definition of the band."""
        # Common parameters for both HRV and other channels
        nlines = int(self.mda['number_of_lines'])
        loff = np.float32(self.mda['loff'])
        pdict = {}
        pdict['cfac'] = np.int32(self.mda['cfac'])
        pdict['lfac'] = np.int32(self.mda['lfac'])
        pdict['coff'] = np.float32(self.mda['coff'])

        pdict['a'] = self.mda['projection_parameters']['a']
        pdict['b'] = self.mda['projection_parameters']['b']
        pdict['h'] = self.mda['projection_parameters']['h']
        pdict['ssp_lon'] = self.mda['projection_parameters']['SSP_longitude']

        pdict['nlines'] = nlines
        pdict['ncols'] = int(self.mda['number_of_columns'])
        if (self.prologue['ImageDescription']['Level15ImageProduction']
                         ['ImageProcDirection'] == 0):
            pdict['scandir'] = 'N2S'
        else:
            pdict['scandir'] = 'S2N'

        # Compute area definition for non-HRV channels:
        if dsid['name'] != 'HRV':
            pdict['loff'] = loff - nlines
            aex = self._get_area_extent(pdict)
            pdict['a_name'] = 'geosmsg'
            pdict['a_desc'] = 'MSG/SEVIRI low resolution channel area'
            pdict['p_id'] = 'msg_lowres'
            area = get_area_definition(pdict, aex)
            self.area = area
            return self.area

        segment_number = self.mda['segment_sequence_number']

        current_first_line = ((segment_number -
                               self.mda['planned_start_segment_number'])
                              * pdict['nlines'])

        # Or, if we are processing HRV:
        pdict['a_name'] = 'geosmsg_hrv'
        pdict['p_id'] = 'msg_hires'
        bounds = self.epilogue['ImageProductionStats']['ActualL15CoverageHRV'].copy()
        if self.fill_hrv:
            bounds['UpperEastColumnActual'] = 1
            bounds['UpperWestColumnActual'] = HRV_NUM_COLUMNS
            bounds['LowerEastColumnActual'] = 1
            bounds['LowerWestColumnActual'] = HRV_NUM_COLUMNS
            pdict['ncols'] = HRV_NUM_COLUMNS

        upper_south_line = bounds[
            'LowerNorthLineActual'] - current_first_line - 1
        upper_south_line = min(max(upper_south_line, 0), pdict['nlines'])
        lower_coff = (5566 - bounds['LowerEastColumnActual'] + 1)
        upper_coff = (5566 - bounds['UpperEastColumnActual'] + 1)

        # First we look at the lower window
        pdict['nlines'] = upper_south_line
        pdict['loff'] = loff - upper_south_line
        pdict['coff'] = lower_coff
        pdict['a_desc'] = 'MSG/SEVIRI high resolution channel, lower window'
        lower_area_extent = self._get_area_extent(pdict)
        lower_area = get_area_definition(pdict, lower_area_extent)

        # Now the upper window
        pdict['nlines'] = nlines - upper_south_line
        pdict['loff'] = loff - pdict['nlines'] - upper_south_line
        pdict['coff'] = upper_coff
        pdict['a_desc'] = 'MSG/SEVIRI high resolution channel, upper window'
        upper_area_extent = self._get_area_extent(pdict)
        upper_area = get_area_definition(pdict, upper_area_extent)

        area = geometry.StackedAreaDefinition(lower_area, upper_area)

        self.area = area.squeeze()
        return self.area
Exemplo n.º 6
0
    def get_area_def(self, dsid):
        """Get the area definition of the band."""
        if dsid.name != 'HRV':
            return super(HRITMSGFileHandler, self).get_area_def(dsid)

        cfac = np.int32(self.mda['cfac'])
        lfac = np.int32(self.mda['lfac'])
        loff = np.float32(self.mda['loff'])

        a = self.mda['projection_parameters']['a']
        b = self.mda['projection_parameters']['b']
        h = self.mda['projection_parameters']['h']
        lon_0 = self.mda['projection_parameters']['SSP_longitude']

        nlines = int(self.mda['number_of_lines'])
        ncols = int(self.mda['number_of_columns'])

        segment_number = self.mda['segment_sequence_number']

        current_first_line = (
            segment_number - self.mda['planned_start_segment_number']) * nlines
        bounds = self.epilogue['ImageProductionStats']['ActualL15CoverageHRV']

        upper_south_line = bounds[
            'LowerNorthLineActual'] - current_first_line - 1
        upper_south_line = min(max(upper_south_line, 0), nlines)

        lower_coff = (5566 - bounds['LowerEastColumnActual'] + 1)
        upper_coff = (5566 - bounds['UpperEastColumnActual'] + 1)

        lower_area_extent = self.get_area_extent(
            (upper_south_line, ncols), (loff, lower_coff), (lfac, cfac), h)

        upper_area_extent = self.get_area_extent(
            (nlines - upper_south_line, ncols),
            (loff - upper_south_line, upper_coff), (lfac, cfac), h)

        proj_dict = {
            'a': float(a),
            'b': float(b),
            'lon_0': float(lon_0),
            'h': float(h),
            'proj': 'geos',
            'units': 'm'
        }

        lower_area = geometry.AreaDefinition('some_area_name',
                                             "On-the-fly area", 'geosmsg',
                                             proj_dict, ncols,
                                             upper_south_line,
                                             lower_area_extent)

        upper_area = geometry.AreaDefinition('some_area_name',
                                             "On-the-fly area", 'geosmsg',
                                             proj_dict, ncols,
                                             nlines - upper_south_line,
                                             upper_area_extent)

        area = geometry.StackedAreaDefinition(lower_area, upper_area)

        self.area = area.squeeze()
        return area
Exemplo n.º 7
0
    def test_append(self):
        """Appending new definitions."""
        area1 = geometry.AreaDefinition(
            "area1", 'area1', "geosmsg", {
                'a': '6378169.0',
                'b': '6356583.8',
                'h': '35785831.0',
                'lon_0': '0.0',
                'proj': 'geos',
                'units': 'm'
            }, 5568, 464, (3738502.0095458371, 3715498.9194295374,
                           -1830246.0673044831, 3251436.5796920112))

        area2 = geometry.AreaDefinition(
            "area2", 'area2', "geosmsg", {
                'a': '6378169.0',
                'b': '6356583.8',
                'h': '35785831.0',
                'lon_0': '0.0',
                'proj': 'geos',
                'units': 'm'
            }, 5568, 464, (3738502.0095458371, 4179561.259167064,
                           -1830246.0673044831, 3715498.9194295374))

        adef = geometry.StackedAreaDefinition(area1, area2)
        self.assertEqual(len(adef.defs), 1)
        self.assertTupleEqual(adef.defs[0].area_extent,
                              (3738502.0095458371, 4179561.259167064,
                               -1830246.0673044831, 3251436.5796920112))

        # same

        area3 = geometry.AreaDefinition(
            "area3", 'area3', "geosmsg", {
                'a': '6378169.0',
                'b': '6356583.8',
                'h': '35785831.0',
                'lon_0': '0.0',
                'proj': 'geos',
                'units': 'm'
            }, 5568, 464, (3738502.0095458371, 3251436.5796920112,
                           -1830246.0673044831, 2787374.2399544837))
        adef.append(area3)
        self.assertEqual(len(adef.defs), 1)
        self.assertTupleEqual(adef.defs[0].area_extent,
                              (3738502.0095458371, 4179561.259167064,
                               -1830246.0673044831, 2787374.2399544837))

        self.assertIsInstance(adef.squeeze(), geometry.AreaDefinition)

        # transition
        area4 = geometry.AreaDefinition(
            "area4", 'area4', "geosmsg", {
                'a': '6378169.0',
                'b': '6356583.8',
                'h': '35785831.0',
                'lon_0': '0.0',
                'proj': 'geos',
                'units': 'm'
            }, 5568, 464, (5567747.7409681147, 2787374.2399544837,
                           -1000.3358822065015, 2323311.9002169576))

        adef.append(area4)
        self.assertEqual(len(adef.defs), 2)
        self.assertTupleEqual(adef.defs[-1].area_extent,
                              (5567747.7409681147, 2787374.2399544837,
                               -1000.3358822065015, 2323311.9002169576))

        self.assertEqual(adef.y_size, 4 * 464)
        self.assertIsInstance(adef.squeeze(), geometry.StackedAreaDefinition)

        adef2 = geometry.StackedAreaDefinition()
        self.assertEqual(len(adef2.defs), 0)

        adef2.append(adef)
        self.assertEqual(len(adef2.defs), 2)
        self.assertTupleEqual(adef2.defs[-1].area_extent,
                              (5567747.7409681147, 2787374.2399544837,
                               -1000.3358822065015, 2323311.9002169576))

        self.assertEqual(adef2.y_size, 4 * 464)