diff --git a/mpop/projector.py b/mpop/projector.py index f64f240e..9c98d966 100644 --- a/mpop/projector.py +++ b/mpop/projector.py @@ -105,9 +105,9 @@ def __init__(self, in_area, out_area, radius=10000, nprocs=1): if (mode is not None and - mode not in ["quick", "nearest", "ewa"]): - raise ValueError( - "Projector mode must be 'nearest', 'quick' or 'ewa'") + mode not in ["quick", "nearest", "ewa", "bilinear"]): + raise ValueError("Projector mode must be one of 'nearest', " + "'quick', 'ewa', 'bilinear'") self.area_file = get_area_file() @@ -227,6 +227,20 @@ def __init__(self, in_area, out_area, self._cache['ewa_cols'] = cols self._cache['ewa_rows'] = rows + elif self.mode == "bilinear": + from pyresample.bilinear import get_bil_info + + bilinear_t, bilinear_s, input_idxs, idx_arr = \ + get_bil_info(self.in_area, self.out_area, + self.radius, neighbours=32, + nprocs=nprocs, masked=False) + + self._cache = {} + self._cache['bilinear_s'] = bilinear_s + self._cache['bilinear_t'] = bilinear_t + self._cache['input_idxs'] = input_idxs + self._cache['idx_arr'] = idx_arr + def save(self, resave=False): """Save the precomputation to disk, and overwrite existing file in case *resave* is true. @@ -282,4 +296,21 @@ def project_array(self, data): self.out_area, data, rows_per_scan=rows_per_scan) + elif self.mode == "bilinear": + from pyresample.bilinear import get_sample_from_bil_info + + if not 'bilinear_t' in self._cache: + self._cache['bilinear_t'] = self._file_cache['bilinear_t'] + self._cache['bilinear_s'] = self._file_cache['bilinear_s'] + self._cache['input_idxs'] = self._file_cache['input_idxs'] + self._cache['idx_arr'] = self._file_cache['idx_arr'] + + res = get_sample_from_bil_info(data.ravel(), + self._cache['bilinear_t'], + self._cache['bilinear_s'], + self._cache['input_idxs'], + self._cache['idx_arr'], + output_shape=self.out_area.shape) + res = np.ma.masked_invalid(res) + return res