Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete kdtree after saving cache #1227

Merged
merged 1 commit into from
Jun 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions satpy/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,8 @@ def save_neighbour_info(self, cache_dir, mask=None, **kwargs):
zarr_out.to_zarr(filename)

self._index_caches[mask_name] = cache
# Delete the kdtree, it's not needed anymore
self.resampler.delayed_kdtree = None

def _read_resampler_attrs(self):
"""Read certain attributes from the resampler for caching."""
Expand Down
5 changes: 4 additions & 1 deletion satpy/tests/test_resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class TestKDTreeResampler(unittest.TestCase):
@mock.patch('satpy.resample.zarr.open')
@mock.patch('satpy.resample.KDTreeResampler._create_cache_filename')
@mock.patch('pyresample.kd_tree.XArrayResamplerNN')
def test_kd_resampling(self, resampler, create_filename, zarr_open,
def test_kd_resampling(self, xr_resampler, create_filename, zarr_open,
xr_dset, cnc):
"""Test the kd resampler."""
import numpy as np
Expand All @@ -148,6 +148,7 @@ def test_kd_resampling(self, resampler, create_filename, zarr_open,
resampler = KDTreeResampler(source_swath, target_area)
resampler.precompute(
mask=da.arange(5, chunks=5).astype(np.bool), cache_dir='.')
xr_resampler.assert_called_once()
resampler.resampler.get_neighbour_info.assert_called()
# swath definitions should not be cached
self.assertFalse(len(mock_dset.to_zarr.mock_calls), 0)
Expand All @@ -173,6 +174,8 @@ def test_kd_resampling(self, resampler, create_filename, zarr_open,
nbcalls = len(resampler.resampler.get_neighbour_info.mock_calls)
# test reusing the resampler
zarr_open.side_effect = None
# The kdtree shouldn't be available after saving cache to disk
assert resampler.resampler.delayed_kdtree is None

class FakeZarr(dict):

Expand Down