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

Fix geotiff and png writers to save to a temporary directory #257

Merged
merged 3 commits into from
Apr 19, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ install:
- pip install behave
- pip install h5netcdf
- pip install python-hdf4
- "pip install --no-binary :all: netCDF4"
- 'pip install --no-binary :all: netCDF4'
- pip install gdal==1.10.0
- pip install scipy
- pip install rasterio
addons:
apt_packages:
- libgdal-dev
- libhdf5-serial-dev
- libhdf4-alt-dev
- netcdf-bin
- libnetcdf-dev
- cython
- libgdal-dev
- libhdf5-serial-dev
- libhdf4-alt-dev
- netcdf-bin
- libnetcdf-dev
- cython
script:
- coverage run --source=satpy setup.py test
- coverage run -a --source=satpy -m behave satpy/tests/features --tags=-download
Expand All @@ -36,14 +37,16 @@ after_success:
- codecov
deploy:
provider: pypi
user: Martin.Raspaud
user: dhoese
password:
secure: RuQzdaLTY4sryIzG8Hz1KWEsyYRxrLvbyfm7DurXDPcj2vsujRwJicNwBrJajIBkzZWwdmWE8db55BPWZwCsJtVUbE53vc742wSAcci2zzCgizSb/jjlDkwk1CE/PoMl4t3JsuIU6bklgw1Y1d4Xn4+BeZe8Blol5PD/FUovxfo=
secure: frK+0k1STeTM7SizRseP0qdTfOVz9ZMIra+3qEytPdxCLceXAH8LxPU16zj5rdNQxasF1hZ6rAd952fly+ypw2TEf5r2WnStrt7G5QlyE7VB6XGSDpIUxKF1FYccLvYs0/R6Y35MTEPqdM51PM5yEBjoY5b4tA3RF3fDq11cqc/SiWr6DgSLB1WJZULOdtCzBbfGbm5LyJ7yeNbISASSAwVvZTGWw7kJDgi0W5zxwEX82N5tBGbfKIu59qmxyj8FxmcrUwKZ4P3rQNg1kN1utzAB+PSf3GAVvbZfWJQuAKwMqpZgaV9lX0V7eUd/AxPobzEk9WyoNBMIdrSPej5BKWTDiYvaeRTOsggoUCSQJJA/SITEvkJgLWXoKKX2OWrM8RBUO4MoZJpPGXN42PRtMJkV2sx6ZigkpJlHdn39SsIRZX31zsfv8bBhclb70bt1Ts0fDd0rVdZAI6gMI+sgUePwEUn+XbWrvI0sMfDX3QsXDMV393RHgaIPxd+lRqUlYsNOxjsWpsbsvX55ePLxYHsNrv11KKyL/iGjGotVeVUO5D78qvfd4JrsUnMalQyZfW8NTEKa5Ebcs7gYJTwYEOTCQU12BkHOv1zFkjZG5RdGwkEvG3pykLhx+qDyYEd7pKB3TvhzLPqZPSrPxirwcoc0UzCc6ocYdzpqVuViFuk=
on:
tags: true
repo: pytroll/satpy
python: 3.6
distributions: "sdist bdist_wheel"
sudo: true
notifications:
slack:
rooms:
- pytroll:96mNSYSI1dBjGyzVXkBT6qFt#satpy
- pytroll:96mNSYSI1dBjGyzVXkBT6qFt#satpy
32 changes: 20 additions & 12 deletions satpy/tests/writer_tests/test_geotiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,29 @@ def test_simple_write(self):
"""Test basic writer operation."""
from satpy.writers.geotiff import GeoTIFFWriter
datasets = self._get_test_datasets()
w = GeoTIFFWriter()
w.save_datasets(datasets, base_dir=self.base_dir)
w = GeoTIFFWriter(base_dir=self.base_dir)
w.save_datasets(datasets)

def test_simple_delayed_write(self):
"""Test writing can be delayed."""
from dask.delayed import Delayed
import dask.array as da
from satpy.writers.geotiff import GeoTIFFWriter
datasets = self._get_test_datasets()
w = GeoTIFFWriter()
w = GeoTIFFWriter(base_dir=self.base_dir)
# when we switch to rio_save on XRImage then this will be sources
# and targets
res = w.save_datasets(datasets, compute=False, base_dir=self.base_dir)
self.assertIsInstance(res, Delayed)
res.compute()
res = w.save_datasets(datasets, compute=False)
# this will fail if rasterio isn't installed
self.assertIsInstance(res, tuple)
# two lists, sources and destinations
self.assertEqual(len(res), 2)
self.assertIsInstance(res[0], list)
self.assertIsInstance(res[1], list)
self.assertIsInstance(res[0][0], da.Array)
da.store(res[0], res[1])
for target in res[1]:
if hasattr(target, 'close'):
target.close()

def test_float_write(self):
"""Test that geotiffs can be written as floats.
Expand All @@ -98,11 +107,10 @@ def test_float_write(self):
"""
from satpy.writers.geotiff import GeoTIFFWriter
datasets = self._get_test_datasets()
w = GeoTIFFWriter()
w.save_datasets(datasets,
dtype=np.float32,
enhancement_config=False,
base_dir=self.base_dir)
w = GeoTIFFWriter(base_dir=self.base_dir,
enhancement_config=False,
dtype=np.float32)
w.save_datasets(datasets)


def suite():
Expand Down
17 changes: 15 additions & 2 deletions satpy/tests/writer_tests/test_simple_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@

class TestPillowWriter(unittest.TestCase):

def setUp(self):
"""Create temporary directory to save files to"""
import tempfile
self.base_dir = tempfile.mkdtemp()

def tearDown(self):
"""Remove the temporary directory created for a test"""
try:
import shutil
shutil.rmtree(self.base_dir, ignore_errors=True)
except OSError:
pass

def _get_test_datasets(self):
import xarray as xr
import dask.array as da
Expand All @@ -58,14 +71,14 @@ def test_init(self):
def test_simple_write(self):
from satpy.writers.simple_image import PillowWriter
datasets = self._get_test_datasets()
w = PillowWriter()
w = PillowWriter(base_dir=self.base_dir)
w.save_datasets(datasets)

def test_simple_delayed_write(self):
from dask.delayed import Delayed
from satpy.writers.simple_image import PillowWriter
datasets = self._get_test_datasets()
w = PillowWriter()
w = PillowWriter(base_dir=self.base_dir)
res = w.save_datasets(datasets, compute=False)
self.assertIsInstance(res, Delayed)
res.compute()
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
requires=h5py pyresample python2-numexpr pyhdf xarray dask h5netcdf
release=1
doc_files = doc/Makefile doc/source/*.rst doc/examples/*.py

[bdist_wheel]
universal=1