def geo_mask(self): """Masking the space pixels from geometry info.""" cfac = np.uint32(self.proj_info['CFAC']) lfac = np.uint32(self.proj_info['LFAC']) coff = np.float32(self.proj_info['COFF']) loff = np.float32(self.proj_info['LOFF']) nlines = int(self.data_info['number_of_lines']) ncols = int(self.data_info['number_of_columns']) # count starts at 1 local_coff = 1 local_loff = (self.total_segments - self.segment_number) * nlines + 1 xmax, ymax = get_geostationary_angle_extent(self.area) pixel_cmax = np.rad2deg(xmax) * cfac * 1.0 / 2**16 pixel_lmax = np.rad2deg(ymax) * lfac * 1.0 / 2**16 def ellipse(line, col): return ((line / pixel_lmax) ** 2) + ((col / pixel_cmax) ** 2) <= 1 cols_idx = da.arange(-(coff - local_coff), ncols - (coff - local_coff), dtype=np.float, chunks=CHUNK_SIZE) lines_idx = da.arange(nlines - (loff - local_loff), -(loff - local_loff), -1, dtype=np.float, chunks=CHUNK_SIZE) return ellipse(lines_idx[:, None], cols_idx[None, :])
def test_get_geostationary_angle_extent(self): """Get max geostationary angles.""" geos_area = mock.MagicMock() geos_area.proj_dict = {'a': 6378169.00, 'b': 6356583.80, 'h': 35785831.00} expected = (0.15185342867090912, 0.15133555510297725) np.testing.assert_allclose(expected, hf.get_geostationary_angle_extent(geos_area)) geos_area.proj_dict = {'a': 1000.0, 'b': 1000.0, 'h': np.sqrt(2) * 1000.0 - 1000.0} expected = (np.deg2rad(45), np.deg2rad(45)) np.testing.assert_allclose(expected, hf.get_geostationary_angle_extent(geos_area))
def test_get_geostationary_angle_extent(self): """Get max geostationary angles.""" geos_area = mock.MagicMock() del geos_area.crs geos_area.proj_dict = { 'proj': 'geos', 'sweep': 'x', 'lon_0': -89.5, 'a': 6378169.00, 'b': 6356583.80, 'h': 35785831.00, 'units': 'm' } expected = (0.15185342867090912, 0.15133555510297725) np.testing.assert_allclose( expected, hf.get_geostationary_angle_extent(geos_area)) geos_area.proj_dict['a'] = 1000.0 geos_area.proj_dict['b'] = 1000.0 geos_area.proj_dict['h'] = np.sqrt(2) * 1000.0 - 1000.0 expected = (np.deg2rad(45), np.deg2rad(45)) np.testing.assert_allclose( expected, hf.get_geostationary_angle_extent(geos_area)) geos_area.proj_dict = { 'proj': 'geos', 'sweep': 'x', 'lon_0': -89.5, 'ellps': 'GRS80', 'h': 35785831.00, 'units': 'm' } expected = (0.15185277703584374, 0.15133971368991794) np.testing.assert_allclose( expected, hf.get_geostationary_angle_extent(geos_area))
def _get_area_def_uniform_sampling(self, lon0, channel): """Get area definition with uniform sampling""" logger.debug('Computing area definition') if lon0 is not None: # Define proj4 projection parameters proj_dict = { 'a': EQUATOR_RADIUS, 'b': POLE_RADIUS, 'lon_0': lon0, 'h': ALTITUDE, 'proj': 'geos', 'units': 'm' } # Calculate maximum scanning angles xmax, ymax = get_geostationary_angle_extent( namedtuple('area', ['proj_dict'])(proj_dict)) # Derive area extent using small angle approximation (maximum # scanning angle is ~8.6 degrees) llx, lly, urx, ury = ALTITUDE * np.array( [-xmax, -ymax, xmax, ymax]) area_extent = [llx, lly, urx, ury] # Original image is oversampled. Create pyresample area definition # with uniform sampling in N-S and E-W direction if self._is_vis(channel): sampling = SAMPLING_NS_VIS else: sampling = SAMPLING_NS_IR pix_size = ALTITUDE * sampling area_def = pyresample.geometry.AreaDefinition( area_id='goes_geos_uniform', name='{} geostationary projection (uniform sampling)'.format( self.platform_name), proj_id='goes_geos_uniform', proj_dict=proj_dict, x_size=np.rint((urx - llx) / pix_size).astype(int), y_size=np.rint((ury - lly) / pix_size).astype(int), area_extent=area_extent) return area_def else: return None