def pad_hrv_data(self, res): """Add empty pixels around the HRV.""" logger.debug('Padding HRV data to full disk') nlines = int(self.mda['number_of_lines']) 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) data_list = list() if upper_south_line > 0: # we have some of the lower window data_lower = pad_data_horizontally(res[:upper_south_line, :].data, (upper_south_line, HRV_NUM_COLUMNS), bounds['LowerEastColumnActual'], bounds['LowerWestColumnActual']) data_list.append(data_lower) if upper_south_line < nlines: # we have some of the upper window data_upper = pad_data_horizontally(res[upper_south_line:, :].data, (nlines - upper_south_line, HRV_NUM_COLUMNS), bounds['UpperEastColumnActual'], bounds['UpperWestColumnActual']) data_list.append(data_upper) return xr.DataArray(da.vstack(data_list), dims=('y', 'x'), attrs=res.attrs.copy())
def test_pad_data_horizontally_bad_shape(self): """Test the error handling for the horizontal hrv padding.""" data = xr.DataArray(data=np.zeros((1, 10)), dims=('y', 'x')) east_bound = 5 west_bound = 10 final_size = (1, 20) with self.assertRaises(IndexError): pad_data_horizontally(data, final_size, east_bound, west_bound)
def test_pad_data_horizontally(): """Test the horizontal hrv padding.""" data = xr.DataArray(data=np.zeros((1, 10)), dims=('y', 'x')) east_bound = 4 west_bound = 13 final_size = (1, 20) res = pad_data_horizontally(data, final_size, east_bound, west_bound) expected = np.array([[np.nan, np.nan, np.nan, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan]]) np.testing.assert_equal(res, expected)
def pad_data(self, dataset): """Pad data to full disk with empty pixels.""" logger.debug('Padding data to full disk') data_list = [] for south_bound, north_bound, east_bound, west_bound in zip( *self._img_bounds.values()): nlines = north_bound - south_bound + 1 data = self._extract_data_to_pad(dataset, south_bound, north_bound) padded_data = pad_data_horizontally(data, (nlines, self._final_shape[1]), east_bound, west_bound) data_list.append(padded_data) padded_data = da.vstack(data_list) # If we're dealing with RSS or ROI data, we also need to pad vertically in order to form a full disk array if not self._is_full_disk: padded_data = pad_data_vertically(padded_data, self._final_shape, south_bound, north_bound) return xr.DataArray(padded_data, dims=('y', 'x'), attrs=dataset.attrs.copy())