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

Add support of colorbar #839

merged 5 commits into from Feb 4, 2020

Conversation

zxdawn
Copy link
Member

@zxdawn zxdawn commented Jul 1, 2019

Add add_scale (plotting colorbar) to add_decorate.

@codecov
Copy link

codecov bot commented Jul 1, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@a7484fe). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #839   +/-   ##
=========================================
  Coverage          ?   86.77%           
=========================================
  Files             ?      179           
  Lines             ?    27305           
  Branches          ?        0           
=========================================
  Hits              ?    23694           
  Misses            ?     3611           
  Partials          ?        0

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a7484fe...a18ebbe. Read the comment docs.

@coveralls
Copy link

coveralls commented Jul 1, 2019

Coverage Status

Coverage increased (+0.004%) to 86.775% when pulling c208265 on zxdawn:add_scale into 3007391 on pytroll:master.

@djhoese
Copy link
Member

djhoese commented Aug 30, 2019

@zxdawn This still needs a test, right? Or does this not work for you?

@zxdawn
Copy link
Member Author

zxdawn commented Sep 2, 2019

@djhoese I remember it works when using it alone. Will test again after my field-work.

@zxdawn
Copy link
Member Author

zxdawn commented Oct 5, 2019

Finally, I tested this and here's the example and result:

Script

import os, sys, glob
from satpy.scene import Scene
from satpy.resample import get_area_def
from satpy.utils import debug_on
from trollimage.colormap import greys, rainbow
import aggdraw

#debug_on()
#os.environ['PPP_CONFIG_DIR'] = '/datadir2/anaconda/miniconda3/source_codes/satpy/satpy/etc/'

date = '20190807'
save_dir = '/xin/figures/FY4A/scale/'
save_path = save_dir + date + '/'

os.makedirs(save_path, exist_ok = True)

# read data as usual
scn = Scene(glob.glob('/public/home/zhangxin/bigdata/FY4A/L1/DISK/20190807/FY4A-_AGRI--_N_DISK_1047E_L1-_FDI-_MULT_NOM_20190807060000_20190807061459_4000M_V0001.HDF'), reader='agri_l1')
channel = 'ir_br'
scn.load([channel])
img = scn.resample('LEKIMA_1km')

# set the right width and height for colorbar
height, width = img[channel].shape
h_legend = int(height/30)
w_legend = int(width/2)

# set the corresponding colormap ticks range
greys.set_range(-40 , 30)
rainbow.set_range(-90, -40)
rainbow.reverse()

# save datasets with decorate: scale
img.save_datasets(base_dir = save_path, filename='FY4A_scale.png',
                     compute = True,
                     datasets = [channel],
                     writer = 'simple_image',
                     decorate={'decorate': [
                     {'scale': {'colormap': rainbow, 'extend': False,
                                'width': w_legend, 'height': h_legend,
                                'tick_marks': 5, 'minor_tick_marks': 1,
                                'cursor': [0, 0], 'bg':'white',
                                # title settings
                                'title':'Brightness Temperature ($^\circ$C)',
                                'fontsize': h_legend*100, 'align': 'cc',
                                }},
                     {'scale': {'colormap': greys, 'extend': False,
                                'width': w_legend, 'height': h_legend,
                                'cursor': [w_legend, 0]
                                }},
                        ]
                     }
                 )

Result

FY4A_scale

Issues

  1. I can't change the color of ticks and the background of label by "fill" = "white" in the scale.
  2. There's a bug in pydecorate and I submit a PR: Add "check for font object" in "title" section pydecorate#9

@mraspaud mraspaud added component:writers enhancement code enhancements, features, improvements labels Oct 14, 2019
Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Is there any test you could add ? For example in this class:

class TestOverlays(unittest.TestCase):

@zxdawn zxdawn marked this pull request as ready for review November 11, 2019 06:01
@zxdawn zxdawn requested a review from djhoese as a code owner November 11, 2019 06:01
satpy/writers/__init__.py Outdated Show resolved Hide resolved
Copy link
Member

@mraspaud mraspaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for finishing this up.

@mraspaud mraspaud merged commit 1c4c43c into pytroll:master Feb 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:writers enhancement code enhancements, features, improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants