Skip to content

Commit

Permalink
Merge 1b127b7 into ec3cdb1
Browse files Browse the repository at this point in the history
  • Loading branch information
pnuu committed Feb 1, 2017
2 parents ec3cdb1 + 1b127b7 commit ef77912
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions mpop/projector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

0 comments on commit ef77912

Please sign in to comment.