Python绘制GPM二级数据降水剖面图

"""
nlayer 80 Number of layers at the fixed heights of 0.00-0.25 km, 0.25-0.50 km, ..., 19.50-19.75 km, and 19.75-20.00 km.
"""
from pathlib import Path
from collections import namedtuple

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import matplotlib.cm as cm
import matplotlib.colors as mcolors
import cmaps
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
import xarray as xr
# 上一篇有介绍不做赘述
Point = namedtuple('Point', ['x', 'y'])
Pair = namedtuple('Pair', ['start', 'end'])


def region_mask(lon, lat, extents):
    '''返回用于索引经纬度方框内数据的Boolean数组.'''
    lonmin, lonmax, latmin, latmax = extents
    return (
        (lon >= lonmin) & (lon <= lonmax) &
        (lat >= latmin) & (lat <= latmax)
    )



def make_LH_cmap(levels):
    '''制作潜热的colormap.'''
    levels = np.asarray(levels)
    cmap = cmaps.BlueWhiteOrangeRed  # 可以调用NCL的颜色,想要什么颜色就 .+颜色名进行调用
    nbin = len(levels) - 1  # 两个数字之间分配一个颜色
    n_negative = np.count_nonzero(levels < 0)  # 不同数据大小进行分配
    n_positive = np.count_nonzero(levels > 0)
    colors = np.vstack([
        cmap(np.linspace(0, 0.5, n_negative)[:-1]),
        cmap(np.linspace(0.5, 1, n_positive))
    ])
    cmap = mcolors.ListedColormap(colors)  # 将colors全部选择,可选择截断一部分
    norm = mcolors.BoundaryNorm(levels, nbin)  # levels需要单调递增,bin表示映射颜色的数量
    return cmap, norm

def make_Rr_cmap(levels):
    '''制作降水的colormap.'''
    nbin = len(levels) - 1
    cmap = cm.get_cmap('jet', nbin)
    norm = mcolors.BoundaryNorm(levels, nbin)
    return cmap, norm


def get_line_label_pos(pair, space=0.5):
    '''根据两点连线计算起点旁边标签的位置.'''
    x0, y0 = pair.start
    x1, y1 = pair.end
    length = np.hypot(x1 - x0, y1 - y0)
    r = space / length
    x = (1 + r) * x0 - r * x1
    y = (1 + r) * y0 - r * y1
    return Point(x, y)


class CrossSectionGPM:
    '''
    对GPM二级产品求剖面的类.

   
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值