From 72edec6209d8dcebf4f57f09f7de6189896f9ed9 Mon Sep 17 00:00:00 2001 From: Martin Raspaud Date: Thu, 7 Nov 2019 11:16:48 +0100 Subject: [PATCH] Fix `grid` argument handling in overlaying --- satpy/tests/test_writers.py | 24 ++++++++++++++++++++++++ satpy/writers/__init__.py | 11 ++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/satpy/tests/test_writers.py b/satpy/tests/test_writers.py index f1459a5644..2b8e6a7391 100644 --- a/satpy/tests/test_writers.py +++ b/satpy/tests/test_writers.py @@ -20,6 +20,7 @@ import errno import shutil import unittest +import warnings import numpy as np import xarray as xr @@ -622,6 +623,29 @@ def test_add_overlay_basic_rgb(self): pil_args, pil_kwargs, fun_args, fun_kwargs) ContourWriterAGG.assert_called_with(coast_dir) + # test legacy call + + grid = {'minor_is_tick': True} + color = 'red' + expected_overlays = {'coasts': {'outline': color, 'width': 0.5, 'level': 1}, + 'borders': {'outline': color, 'width': 0.5, 'level': 1}, + 'grid': grid} + with warnings.catch_warnings(record=True) as wns: + warnings.simplefilter("always") + new_img = add_overlay(self.orig_rgb_img, self.area_def, coast_dir, + color=color, grid=grid, fill_value=0) + assert len(wns) == 1 + assert issubclass(wns[0].category, DeprecationWarning) + assert "deprecated" in str(wns[0].message) + + pil_args = None + pil_kwargs = {'fill_value': 0} + fun_args = (self.orig_rgb_img.data.area, ContourWriterAGG.return_value, expected_overlays) + fun_kwargs = None + apply_pil.assert_called_with(_burn_overlay, self.orig_rgb_img.mode, + pil_args, pil_kwargs, fun_args, fun_kwargs) + ContourWriterAGG.assert_called_with(coast_dir) + def test_add_overlay_basic_l(self): """Test basic add_overlay usage with L data.""" from satpy.writers import add_overlay diff --git a/satpy/writers/__init__.py b/satpy/writers/__init__.py index 0ac6546ecf..afb319d8e4 100644 --- a/satpy/writers/__init__.py +++ b/satpy/writers/__init__.py @@ -265,11 +265,12 @@ def add_overlay(orig_img, area, coast_dir, color=None, width=None, resolution=No level_borders = 1 overlays.setdefault('borders', {}).setdefault('level', level_borders) - if grid is not None and 'major_lonlat' in grid and grid['major_lonlat']: - major_lonlat = grid.pop('major_lonlat') - minor_lonlat = grid.pop('minor_lonlat', major_lonlat) - grid_params = {'Dlonlat': major_lonlat, 'dlonlat': minor_lonlat} - for key, val in grid_params.items(): + if grid is not None: + if 'major_lonlat' in grid and grid['major_lonlat']: + major_lonlat = grid.pop('major_lonlat') + minor_lonlat = grid.pop('minor_lonlat', major_lonlat) + grid.update({'Dlonlat': major_lonlat, 'dlonlat': minor_lonlat}) + for key, val in grid.items(): overlays.setdefault('grid', {}).setdefault(key, val) cw_ = ContourWriterAGG(coast_dir)