-
Notifications
You must be signed in to change notification settings - Fork 285
/
simple_image.py
67 lines (56 loc) · 2.76 KB
/
simple_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2015-2019 Satpy developers
#
# This file is part of satpy.
#
# satpy is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# satpy is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# satpy. If not, see <http://www.gnu.org/licenses/>.
"""Generic PIL/Pillow image format writer."""
import logging
from satpy.writers import ImageWriter
LOG = logging.getLogger(__name__)
class PillowWriter(ImageWriter):
"""Generic PIL image format writer."""
def __init__(self, **kwargs):
"""Initialize image writer plugin."""
ImageWriter.__init__(
self,
default_config_filename="writers/simple_image.yaml",
**kwargs)
def save_image(self, img, filename=None, compute=True, **kwargs):
"""Save Image object to a given ``filename``.
Args:
img (trollimage.xrimage.XRImage): Image object to save to disk.
filename (str): Optionally specify the filename to save this
dataset to. It may include string formatting
patterns that will be filled in by dataset
attributes.
compute (bool): If `True` (default), compute and save the dataset.
If `False` return either a `dask.delayed.Delayed`
object or tuple of (source, target). See the
return values below for more information.
**kwargs: Keyword arguments to pass to the images `save` method.
Returns:
Value returned depends on `compute`. If `compute` is `True` then
the return value is the result of computing a
`dask.delayed.Delayed` object or running `dask.array.store`. If
`compute` is `False` then the returned value is either a
`dask.delayed.Delayed` object that can be computed using
`delayed.compute()` or a tuple of (source, target) that should be
passed to `dask.array.store`. If target is provided the the caller
is responsible for calling `target.close()` if the target has
this method.
"""
filename = filename or self.get_filename(**img.data.attrs)
LOG.debug("Saving to image: %s", filename)
return img.save(filename, compute=compute, **kwargs)