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

Add support of colorbar #839

Merged
merged 5 commits into from
Feb 4, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion satpy/tests/test_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import numpy as np
import xarray as xr
from trollimage.colormap import greys

try:
from unittest import mock
Expand Down Expand Up @@ -584,7 +585,16 @@ def setUp(self):
'height': 30,
'bg': 'black',
'bg_opacity': 255,
'line': 'white'}}
'line': 'white'}},
{'scale': {
'colormap': greys,
'extend': False,
'width': 1670, 'height': 110,
'tick_marks': 5, 'minor_tick_marks': 1,
'cursor': [0, 0], 'bg':'white',
'title':'TEST TITLE OF SCALE',
'fontsize': 110, 'align': 'cc'
}}
]
}

Expand Down
27 changes: 25 additions & 2 deletions satpy/writers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def add_overlay(orig_img, area, coast_dir, color=None, width=None, resolution=No
return new_image


def add_text(orig, dc, img, text=None):
def add_text(orig, dc, img, text):
"""Add text to an image using the pydecorate package.

All the features of pydecorate's ``add_text`` are available.
Expand All @@ -301,7 +301,7 @@ def add_text(orig, dc, img, text=None):
return XRImage(new_data)


def add_logo(orig, dc, img, logo=None):
def add_logo(orig, dc, img, logo):
"""Add logos or other images to an image using the pydecorate package.

All the features of pydecorate's ``add_logo`` are available.
Expand All @@ -322,6 +322,27 @@ def add_logo(orig, dc, img, logo=None):
return XRImage(new_data)


def add_scale(orig, dc, img, scale):
"""Add scale to an image using the pydecorate package.

All the features of pydecorate's ``add_scale`` are available.
See documentation of :doc:`pydecorate:index` for more info.

"""
LOG.info("Add scale to image.")

dc.add_scale(**scale)

arr = da.from_array(np.array(img) / 255.0, chunks=CHUNK_SIZE)

new_data = xr.DataArray(arr, dims=['y', 'x', 'bands'],
coords={'y': orig.data.coords['y'],
'x': orig.data.coords['x'],
'bands': list(img.mode)},
attrs=orig.data.attrs)
return XRImage(new_data)


def add_decorate(orig, fill_value=None, **decorate):
"""Decorate an image with text and/or logos/images.

Expand Down Expand Up @@ -376,6 +397,8 @@ def add_decorate(orig, fill_value=None, **decorate):
img = add_logo(img, dc, img_orig, logo=dec['logo'])
elif 'text' in dec:
img = add_text(img, dc, img_orig, text=dec['text'])
elif 'scale' in dec:
img = add_scale(img, dc, img_orig, scale=dec['scale'])
return img


Expand Down