Skip to content

Commit

Permalink
Add test to check that clip works as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
Trygve Aspenes committed Apr 11, 2019
1 parent c44b982 commit 08766cf
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions satpy/tests/writer_tests/test_mitiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,40 @@ def _get_test_one_dataset(self):
)
return ds1

def _get_test_dataset_with_bad_values(self, bands=3):
"""Helper function to create a single test dataset."""
import xarray as xr
import numpy as np
from datetime import datetime
from pyresample.geometry import AreaDefinition
from pyresample.utils import proj4_str_to_dict
area_def = AreaDefinition(
'test',
'test',
'test',
proj4_str_to_dict('+proj=stere +datum=WGS84 +ellps=WGS84 '
'+lon_0=0. +lat_0=90 +lat_ts=60 +units=km'),
100,
200,
(-1000., -1500., 1000., 1500.),
)

data = np.arange(-210, 790, 100).reshape((2, 5)) * 0.95
data /= 5.605
data[0, 0] = np.nan # need a nan value
data[0, 1] = 0. # Need a 0 value

rgb_data = np.stack([data, data, data])
ds1 = xr.DataArray(rgb_data,
dims=('bands', 'y', 'x'),
attrs={'name': 'test',
'start_time': datetime.utcnow(),
'platform_name': "TEST_PLATFORM_NAME",
'sensor': 'TEST_SENSOR_NAME',
'area': area_def,
'prerequisites': ['1', '2', '3']})
return ds1

def _get_test_dataset_calibration(self, bands=6):
"""Helper function to create a single test dataset."""
import xarray as xr
Expand Down Expand Up @@ -241,6 +275,25 @@ def test_save_dataset_with_calibration(self):
w = MITIFFWriter(filename=dataset.attrs['metadata_requirements']['file_pattern'], base_dir=self.base_dir)
w.save_dataset(dataset)

def test_save_dataset_with_bad_value(self):
"""Test basic writer operation."""
import os
import numpy as np
from libtiff import TIFF
from satpy.writers.mitiff import MITIFFWriter

expected = np.array([[0, 4, 1, 37, 73],
[110, 146, 183, 219, 255]])

dataset = self._get_test_dataset_with_bad_values()
w = MITIFFWriter(base_dir=self.base_dir)
w.save_dataset(dataset)
filename = "{:s}_{:%Y%m%d_%H%M%S}.mitiff".format(dataset.attrs['name'],
dataset.attrs['start_time'])
tif = TIFF.open(os.path.join(self.base_dir, filename))
for image in tif.iter_images():
np.testing.assert_allclose(image, expected, atol=1.e-6, rtol=0)


def suite():
"""The test suite for this writer's tests.
Expand Down

0 comments on commit 08766cf

Please sign in to comment.