metradar 0.1.6__py3-none-any.whl → 0.1.8.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- metradar/__init__.py +4 -2
- metradar/config.py +53 -0
- metradar/core/__init__.py +9 -0
- metradar/{get_cross_section_from_pyart.py → core/get_cross_section.py} +5 -157
- metradar/{mosaic_merge.py → core/mosaic_merge.py} +3 -1
- metradar/{oa_dig_func.py → core/oa_dig_func.py} +83 -333
- metradar/graph/__init__.py +9 -0
- metradar/{mosaic_quickdraw.py → graph/draw_comp_mosaic.py} +71 -68
- metradar/{draw_mosaic_new.py → graph/draw_latlon_func.py} +177 -173
- metradar/graph/draw_radar_aws.py +212 -0
- metradar/{draw_radar_comp_func.py → graph/draw_radar_comp_func.py} +319 -248
- metradar/graph/parse_pal.py +157 -0
- metradar/io/__init__.py +9 -0
- metradar/{cnrad_level2.py → io/cnrad_level2.py} +45 -2
- metradar/{decode_fmt_pyart.py → io/decode_fmt_pyart.py} +20 -3
- metradar/{decode_pup_rose.py → io/decode_pup_rose.py} +241 -684
- metradar/{read_new_mosaic_func.py → io/read_new_mosaic_func.py} +30 -2
- metradar/io/read_swan.py +250 -0
- metradar/{rose_structer.py → io/rose_structer.py} +2 -0
- metradar/project/__init__.py +9 -0
- metradar/project/make_mosaic/__init__.py +9 -0
- metradar/project/make_mosaic/batch_draw_mosaic.py +32 -0
- metradar/{make_mosaic_mp_archive.py → project/make_mosaic/make_mosaic_func.py} +144 -175
- metradar/project/make_mosaic/make_mosaic_mp.ini +29 -0
- metradar/project/make_mosaic/make_mosaic_mp.py +70 -0
- metradar/project/make_vpr_aws/__init__.py +9 -0
- metradar/project/make_vpr_aws/construct_aws_refvpr_mainprog.ini +39 -0
- metradar/project/make_vpr_aws/construct_aws_refvpr_mainprog.py +565 -0
- metradar/project/make_vpr_aws/make_mosaic_20230731_daxing.ini +29 -0
- metradar/project/make_vpr_aws/make_mosaic_basefile.ini +29 -0
- metradar/project/nowcasting/__init__.py +9 -0
- metradar/project/nowcasting/nowcast_by_pysteps.py +214 -0
- metradar/{trans_nc_pgmb.py → project/nowcasting/trans_mosaic_pgmb.py} +19 -17
- metradar/project/qpe/Archive /346/250/241/345/274/217/350/257/264/346/230/216.txt" +2 -0
- metradar/project/qpe/__init__.py +9 -0
- metradar/project/qpe/archive_main_qpe_cfg.ini +91 -0
- metradar/project/qpe/do_s1.sh +6 -0
- metradar/project/qpe/do_s2.sh +6 -0
- metradar/project/qpe/do_s3.sh +6 -0
- metradar/project/qpe/do_s4.sh +6 -0
- metradar/project/qpe/do_s5.sh +6 -0
- metradar/project/qpe/exec_all.sh +11 -0
- metradar/project/qpe/get_rainrate_func.py +80 -0
- metradar/project/qpe/main_qpe_cfg.ini +85 -0
- metradar/project/qpe/s1_download_radar_region_cmadaas.py +123 -0
- metradar/project/qpe/s2_pre_process_single_radar.py +183 -0
- metradar/project/qpe/s3_trans_rainrate_to_qpe.py +499 -0
- metradar/project/qpe/s4_mosaic_qpe.py +523 -0
- metradar/project/qpe/s5_draw_qpe_mosaic.py +308 -0
- metradar/project/wind_retrieval/__init__.py +9 -0
- metradar/project/wind_retrieval/config_3dwind.ini +45 -0
- metradar/{main_pydda.py → project/wind_retrieval/main_pydda.py} +152 -149
- metradar/util/__init__.py +9 -0
- metradar/{comm_func.py → util/comm_func.py} +1 -41
- metradar/util/exceptions.py +50 -0
- metradar/util/geo_transforms_pyart.py +627 -0
- metradar/{get_tlogp_from_sharppy.py → util/get_tlogp_from_sharppy.py} +16 -5
- metradar/{parse_pal.py → util/parse_pal.py} +147 -147
- metradar/util/radar_common.py +16 -0
- metradar/{trans_new_mosaic_nc.py → util/trans_new_mosaic_nc.py} +1 -1
- metradar-0.1.8.2.dist-info/METADATA +90 -0
- metradar-0.1.8.2.dist-info/RECORD +69 -0
- {metradar-0.1.6.dist-info → metradar-0.1.8.2.dist-info}/WHEEL +1 -1
- metradar-0.1.8.2.dist-info/licenses/LICENSE +21 -0
- {metradar-0.1.6.dist-info → metradar-0.1.8.2.dist-info}/top_level.txt +0 -1
- cfg/config.py +0 -90
- metradar/grid.py +0 -281
- metradar/grid_data.py +0 -64
- metradar/oa_couhua.py +0 -166
- metradar/read_new_mosaic.py +0 -33
- metradar/retrieve_cmadaas.py +0 -3126
- metradar/retrieve_micaps_server.py +0 -2061
- metradar-0.1.6.dist-info/METADATA +0 -37
- metradar-0.1.6.dist-info/RECORD +0 -34
- /metradar/{pgmb_io.py → io/pgmb_io.py} +0 -0
- /metradar/{exceptions.py → project/make_vpr_aws/exceptions.py} +0 -0
- /metradar/{geo_transforms_pyart.py → project/make_vpr_aws/geo_transforms_pyart.py} +0 -0
- /metradar/{make_gif.py → util/make_gif.py} +0 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# _*_ coding: utf-8 _*_
|
|
1
2
|
'''
|
|
2
3
|
绘制雷达拼图
|
|
3
4
|
'''
|
|
@@ -7,7 +8,7 @@
|
|
|
7
8
|
import os
|
|
8
9
|
import matplotlib.pyplot as plt
|
|
9
10
|
import cartopy.crs as ccrs
|
|
10
|
-
from parse_pal import parse
|
|
11
|
+
from metradar.util.parse_pal import parse,parse_pro
|
|
11
12
|
import xarray as xr
|
|
12
13
|
import numpy as np
|
|
13
14
|
from matplotlib.transforms import offset_copy
|
|
@@ -16,88 +17,40 @@ from matplotlib.font_manager import FontProperties
|
|
|
16
17
|
import json
|
|
17
18
|
import matplotlib as mpl
|
|
18
19
|
import matplotlib
|
|
19
|
-
matplotlib.use('
|
|
20
|
-
|
|
20
|
+
matplotlib.use('agg')
|
|
21
|
+
|
|
21
22
|
from cartopy.io.shapereader import Reader
|
|
22
23
|
import pandas as pd
|
|
23
24
|
from multiprocessing import cpu_count, Pool,freeze_support
|
|
25
|
+
from metradar.config import CONFIG
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
g_fontfile='resources/fonts/msyhbd.ttc'
|
|
28
|
-
g_font_max = FontProperties(fname=g_fontfile, size=8)
|
|
29
|
-
g_font_mid = FontProperties(fname=g_fontfile, size=6)
|
|
30
|
-
g_font_min = FontProperties(fname=g_fontfile, size=4)
|
|
31
|
-
|
|
32
|
-
mpl.rcParams['font.size'] = 7
|
|
33
|
-
mpl.rcParams['font.weight'] = 'bold'
|
|
34
|
-
mpl.rcParams['font.family'] = 'Times'
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def add_gisinfo(ax,font=None):
|
|
38
|
-
city_file = 'resources/stations/2018年国家级地面气象站-2423.xlsx'
|
|
39
|
-
# city_file = '../common/resources/stations/cma_county_station_info.dat'# cma_city_station_info cma_national_station_info
|
|
40
|
-
|
|
41
|
-
if not os.path.exists(city_file):
|
|
42
|
-
print(city_file +' not exist!')
|
|
43
|
-
return False
|
|
27
|
+
# 资源文件路径
|
|
28
|
+
RESOURCES_PATH = CONFIG.get('SETTING','RESOURCES_PATH')
|
|
44
29
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
30
|
+
FONT_FILE = RESOURCES_PATH + '/fonts/YaHeiConsolasHybrid_1.12.ttf'
|
|
31
|
+
COLOR_PATH=RESOURCES_PATH + '/gr2_colors/'
|
|
32
|
+
MAP_PATH = RESOURCES_PATH + '/国省市县审图号(GS (2019) 3082号'
|
|
33
|
+
STATION_FILE = RESOURCES_PATH + '/stations/cma_city_station_info.dat'
|
|
49
34
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
for i in range(data.shape[0]):
|
|
54
|
-
lat_deg = int(data['纬度'][i]/10000)
|
|
55
|
-
lat_min = int(str(data['纬度'][i])[-4:-2])
|
|
56
|
-
lat_sec = int(str(data['纬度'][i])[-2::])
|
|
57
|
-
tmp_lat = lat_deg + lat_min/60 + lat_sec/3600
|
|
58
|
-
|
|
59
|
-
lon_deg = int(data['经度'][i]/10000)
|
|
60
|
-
lon_min = int(str(data['经度'][i])[-4:-2])
|
|
61
|
-
lon_sec = int(str(data['经度'][i])[-2::])
|
|
62
|
-
tmp_lon = lon_deg + lon_min/60 + lon_sec/3600
|
|
63
|
-
|
|
64
|
-
lat.append(tmp_lat)
|
|
65
|
-
lon.append(tmp_lon)
|
|
66
|
-
names.append(data['站名'][i])
|
|
35
|
+
g_font_max = FontProperties(fname= FONT_FILE, size=8)
|
|
36
|
+
g_font_mid = FontProperties(fname= FONT_FILE, size=6)
|
|
37
|
+
g_font_min = FontProperties(fname= FONT_FILE, size=4)
|
|
67
38
|
|
|
39
|
+
mpl.rcParams['font.size'] = 7
|
|
40
|
+
mpl.rcParams['font.weight'] = 'normal'
|
|
41
|
+
# mpl.rcParams['font.family'] = 'Times New Roman'
|
|
68
42
|
|
|
69
|
-
cities = pd.DataFrame(data={'name':names, 'lat':lat, 'lon':lon})
|
|
70
|
-
# draw station information
|
|
71
|
-
font = g_font_min
|
|
72
|
-
geodetic_transform = ccrs.Geodetic()._as_mpl_transform(ax)
|
|
73
|
-
for _, row in cities.iterrows():
|
|
74
|
-
text_transform = offset_copy(geodetic_transform, units='dots', x=-5)
|
|
75
|
-
ax.plot(row['lon'], row['lat'], marker='o', color=[0.2,0.2,0.2], linestyle='None',
|
|
76
|
-
markersize=2, alpha=0.8, transform=ccrs.PlateCarree())
|
|
77
|
-
ax.text(row['lon']-0.01, row['lat'], row['name'], clip_on=True, # city_name
|
|
78
|
-
verticalalignment='center', horizontalalignment='right',
|
|
79
|
-
transform=text_transform, fontproperties=font, color=[0.2,0.2,0.2],
|
|
80
|
-
path_effects=[path_effects.Stroke(linewidth=1, foreground=[1,1,1]),
|
|
81
|
-
path_effects.Normal()])
|
|
82
|
-
|
|
83
43
|
|
|
84
44
|
def draw_gisinfo(ax,font=None):
|
|
85
45
|
|
|
86
|
-
city_file =
|
|
46
|
+
city_file =STATION_FILE
|
|
87
47
|
|
|
88
48
|
if not os.path.exists(city_file):
|
|
89
49
|
print(city_file +' not exist!')
|
|
90
50
|
return False
|
|
91
51
|
|
|
92
52
|
cities = pd.read_csv(city_file, delimiter=r"\s+") # cma_city_station_info
|
|
93
|
-
|
|
94
|
-
# cities = pd.read_table(city_file,sep='\s+',header=None,names=['stanum','lat','lon','name','city','province']) # cma_county_station_info
|
|
95
|
-
# extract subregion
|
|
96
|
-
|
|
97
|
-
# targetprovince = '吉林省'
|
|
98
|
-
# flag1 = cities['province']==targetprovince
|
|
99
|
-
# cityname = np.unique(cities[flag1]['city'])
|
|
100
|
-
# cityname = np.unique(cities['city'])
|
|
53
|
+
|
|
101
54
|
cityname = np.unique(cities['city_name'])
|
|
102
55
|
names=[]
|
|
103
56
|
lat=[]
|
|
@@ -108,8 +61,7 @@ def draw_gisinfo(ax,font=None):
|
|
|
108
61
|
flag2 = curdata['city_name'] == name
|
|
109
62
|
tmp_lat = np.mean(curdata[flag2]['lat'])
|
|
110
63
|
tmp_lon = np.mean(curdata[flag2]['lon'])
|
|
111
|
-
|
|
112
|
-
# if name.find('蒙古') >0: name = name.strip(name[name.find('蒙古')::])
|
|
64
|
+
|
|
113
65
|
names.append(name)
|
|
114
66
|
lon.append(tmp_lon)
|
|
115
67
|
lat.append(tmp_lat)
|
|
@@ -157,7 +109,7 @@ def add_china_map_2cartopy(ax, facecolor='none',transform=None,name='province',
|
|
|
157
109
|
|
|
158
110
|
if name == 'county':
|
|
159
111
|
# 添加县边界
|
|
160
|
-
shpfile =
|
|
112
|
+
shpfile = MAP_PATH + os.sep + names[name] + ".shp"
|
|
161
113
|
ax.add_geometries(
|
|
162
114
|
Reader(shpfile).geometries(), transform,
|
|
163
115
|
path_effects=[path_effects.Stroke(linewidth=lw, foreground=[1,1,1]),path_effects.Normal()],
|
|
@@ -165,7 +117,7 @@ def add_china_map_2cartopy(ax, facecolor='none',transform=None,name='province',
|
|
|
165
117
|
|
|
166
118
|
if name == 'city':
|
|
167
119
|
# 添加市边界
|
|
168
|
-
shpfile =
|
|
120
|
+
shpfile = MAP_PATH + os.sep + names[name] + ".shp"
|
|
169
121
|
ax.add_geometries(
|
|
170
122
|
Reader(shpfile).geometries(), transform,
|
|
171
123
|
path_effects=[path_effects.Stroke(linewidth=lw+0.2, foreground=[1,1,1]),path_effects.Normal()],
|
|
@@ -173,22 +125,12 @@ def add_china_map_2cartopy(ax, facecolor='none',transform=None,name='province',
|
|
|
173
125
|
|
|
174
126
|
# 添加省边界
|
|
175
127
|
if name == 'province':
|
|
176
|
-
shpfile =
|
|
128
|
+
shpfile = MAP_PATH + os.sep + names[name] + ".shp"
|
|
177
129
|
ax.add_geometries(
|
|
178
130
|
Reader(shpfile).geometries(), transform,
|
|
179
131
|
path_effects=[path_effects.Stroke(linewidth=lw+0.5, foreground=[1,1,1]),path_effects.Normal()],
|
|
180
132
|
facecolor=facecolor, edgecolor=edgecolor, lw=lw+0.2, **kwargs)
|
|
181
133
|
|
|
182
|
-
def add_private_shp(ax,facecolor='none',transform=None,name='province',edgecolor='k', lw=0.8, **kwargs):
|
|
183
|
-
mappath = '/Users/wenjianzhu/Library/CloudStorage/OneDrive-个人/推广应用/GR2/吉林/地理信息/归档'
|
|
184
|
-
|
|
185
|
-
shpfile = mappath + os.sep + "jilin.shp"
|
|
186
|
-
|
|
187
|
-
ax.add_geometries(
|
|
188
|
-
Reader(shpfile).geometries(), transform,
|
|
189
|
-
path_effects=[path_effects.Stroke(linewidth=lw+0.2, foreground=[1,1,1]),path_effects.Normal()],
|
|
190
|
-
facecolor=facecolor, edgecolor=edgecolor, lw=lw-0.2, **kwargs)
|
|
191
|
-
|
|
192
134
|
def cm_precip():
|
|
193
135
|
"""
|
|
194
136
|
Standardized colormaps from National Weather Service
|
|
@@ -211,69 +153,123 @@ def cm_precip():
|
|
|
211
153
|
[0,109,44], [255,250,138], [255,204,79], [254,141,60], [252,78,42],
|
|
212
154
|
[214,26,28], [173,0,38], [112,0,38], [59,0,48], [76,0,115], [255,219,255]])
|
|
213
155
|
|
|
214
|
-
# Create a tuple for every color indicating the normalized
|
|
215
|
-
# position on the colormap and the assigned color.
|
|
216
|
-
# COLORS = []
|
|
217
|
-
# for i, n in enumerate(norm):
|
|
218
|
-
# COLORS.append((n, np.array(C[i])/255.))
|
|
219
|
-
|
|
220
|
-
# Create the colormap
|
|
221
|
-
# cmap = mpl.colors.LinearSegmentedColormap.from_list("precipitation", COLORS)
|
|
222
156
|
cmap, norm = mpl.colors.from_levels_and_colors(np.array(a), np.array(C)/255.0, extend='neither')
|
|
223
157
|
return cmap, norm
|
|
224
158
|
|
|
225
159
|
|
|
226
|
-
def
|
|
227
|
-
|
|
160
|
+
def draw_latlon(data,lat,lon,slat=None,nlat=None,wlon=None,elon=None,outpath=None,outname=None,tstr=None,
|
|
161
|
+
prefix_title='雷达组合反射率拼图 ',units='dBZ',add_title=False,badd_gis=True,badd_logo=True,
|
|
162
|
+
subtitle='',titlecolor='r',thred=None,cb_ratio=0.618,fig_size=[6,4],dpi=400,colorfile=None):
|
|
163
|
+
'''
|
|
164
|
+
该函数在绘制经纬度网格数据的核心函数
|
|
165
|
+
draw_latlon 的 Docstring
|
|
228
166
|
|
|
167
|
+
:param data: DataArray 类型,二维数组
|
|
168
|
+
:param lat: 数据的纬度列表,一维数组
|
|
169
|
+
:param lon: 数据的经度列表,一维数组
|
|
170
|
+
:param slat: 绘图南边界
|
|
171
|
+
:param nlat: 绘图北边界
|
|
172
|
+
:param wlon: 绘图西边界
|
|
173
|
+
:param elon: 绘图东边界
|
|
174
|
+
:param outpath: 图片保存路径
|
|
175
|
+
:param outname: 图片保存名称
|
|
176
|
+
:param tstr: 时间字符串,YYYYMMDDHHmmss格式
|
|
177
|
+
:param prefix_title: 标题前缀
|
|
178
|
+
:param units: 单位
|
|
179
|
+
:param add_title: 是否添加标题
|
|
180
|
+
:param badd_gis: 是否添加地理信息
|
|
181
|
+
:param badd_logo: 是否在左下角添加说明: Powered by metradar
|
|
182
|
+
:param subtitle: 标题后缀
|
|
183
|
+
:param titlecolor: 标题颜色
|
|
184
|
+
:param thred: 显示阈值,小于该阈值不显示
|
|
185
|
+
:param cb_ratio: 色标长度占Y轴长度的比例
|
|
186
|
+
:param fig_size: 图片画布尺寸,默认为[4,3]
|
|
187
|
+
:param dpi: 保存图片的分辨率
|
|
188
|
+
:param colorfile: 自定义配色文件路径,如果不提供则使用默认配色方案,色标文件必须是.pal格式,可以使用resources目录下的配色文件
|
|
189
|
+
'''
|
|
229
190
|
if units == 'dBZ':
|
|
230
|
-
|
|
191
|
+
if colorfile is not None:
|
|
192
|
+
var_cmap,norm = parse(colorfile)
|
|
193
|
+
else:
|
|
194
|
+
var_cmap,norm = parse(COLOR_PATH + '/BR_WDTB_Bright.pal')#BR_WDTB_Bright.pal default_BR_PUP2.pal BR_AVL_BroadcastNegatives.pal
|
|
231
195
|
elif units == 'mm':
|
|
232
|
-
|
|
196
|
+
if colorfile is not None:
|
|
197
|
+
var_cmap,norm = parse(colorfile)
|
|
198
|
+
else:
|
|
199
|
+
var_cmap,norm = cm_precip()
|
|
233
200
|
elif units == '%':
|
|
234
|
-
|
|
201
|
+
if colorfile is not None:
|
|
202
|
+
var_cmap,norm = parse(colorfile)
|
|
203
|
+
else:
|
|
204
|
+
var_cmap,norm = parse(COLOR_PATH + '/default_CC_ROSE.pal')
|
|
235
205
|
elif units == 'dB':
|
|
236
|
-
|
|
206
|
+
if colorfile is not None:
|
|
207
|
+
var_cmap,norm = parse(colorfile)
|
|
208
|
+
else:
|
|
209
|
+
var_cmap,norm = parse(COLOR_PATH + '/default_ZDR_ROSE.pal')
|
|
237
210
|
elif units == 'deg/km':
|
|
238
|
-
|
|
211
|
+
if colorfile is not None:
|
|
212
|
+
var_cmap,norm = parse(colorfile)
|
|
213
|
+
else:
|
|
214
|
+
var_cmap,norm = parse(COLOR_PATH + '/default_KDP_ROSE.pal')
|
|
239
215
|
elif units == 'cat':
|
|
240
|
-
|
|
216
|
+
if colorfile is not None:
|
|
217
|
+
var_cmap,norm = parse(colorfile)
|
|
218
|
+
else:
|
|
219
|
+
var_cmap,norm = parse(COLOR_PATH + '/default_HCAS.pal')
|
|
220
|
+
elif units == 'm/s':
|
|
221
|
+
if colorfile is not None:
|
|
222
|
+
var_cmap,norm = parse(colorfile)
|
|
223
|
+
else:
|
|
224
|
+
var_cmap,norm = parse(COLOR_PATH + '/default_BV_PUP2.pal')
|
|
225
|
+
elif units == 'kg/m2':
|
|
226
|
+
if colorfile is not None:
|
|
227
|
+
var_cmap,norm = parse(colorfile)
|
|
228
|
+
else:
|
|
229
|
+
var_cmap,norm = parse(COLOR_PATH + '/default_VIL.pal')
|
|
230
|
+
elif units == 'km':
|
|
231
|
+
if colorfile is not None:
|
|
232
|
+
var_cmap,norm = parse(colorfile)
|
|
233
|
+
else:
|
|
234
|
+
outdic = parse_pro(COLOR_PATH + '/default_ET_PUP.pal')
|
|
235
|
+
var_cmap,norm = outdic['cmap'],outdic['norm']
|
|
241
236
|
else:
|
|
242
237
|
pass
|
|
243
238
|
|
|
244
239
|
# newdata.data.shape[1],newdata.data.shape[0]
|
|
245
|
-
fig= plt.figure(figsize=
|
|
240
|
+
fig= plt.figure(figsize=fig_size,dpi=dpi,clear=True)
|
|
246
241
|
map_panel_axes = [0.1, 0.1, .8, .8]
|
|
247
|
-
|
|
248
|
-
# projs=ccrs.LambertConformal(central_longitude=(wlon + elon)/2,central_latitude=(slat + nlat)/2,standard_parallels=(20,50))
|
|
242
|
+
|
|
249
243
|
projs = ccrs.PlateCarree()
|
|
250
|
-
transforms = ccrs.PlateCarree()
|
|
251
244
|
|
|
252
245
|
ax = plt.axes(map_panel_axes, projection=projs)
|
|
253
|
-
|
|
246
|
+
# 如果slat,nlat,wlon,elon没有提供,则使用数据的范围
|
|
247
|
+
if slat is None:
|
|
248
|
+
slat = float(lat.min())
|
|
249
|
+
if nlat is None:
|
|
250
|
+
nlat = float(lat.max())
|
|
251
|
+
if wlon is None:
|
|
252
|
+
wlon = float(lon.min())
|
|
253
|
+
if elon is None:
|
|
254
|
+
elon = float(lon.max())
|
|
254
255
|
extent = [wlon, elon, slat, nlat]
|
|
255
|
-
ax.set_extent(extent, crs=
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
# try:
|
|
259
|
-
# request = TDT_Hillshade() # 地形阴影
|
|
260
|
-
# ax.add_image(request, 10) # level=10 缩放等
|
|
261
|
-
# except:
|
|
262
|
-
# pass
|
|
256
|
+
ax.set_extent(extent, crs=projs)
|
|
257
|
+
|
|
258
|
+
|
|
263
259
|
if not thred is None:
|
|
264
260
|
newdata = np.ma.masked_array(data, data < thred)
|
|
265
261
|
else:
|
|
266
262
|
newdata = data
|
|
267
263
|
grid_lat,grid_lon=np.meshgrid(lat,lon)
|
|
268
|
-
pcm = ax.pcolormesh(grid_lon,grid_lat,newdata.T,cmap=var_cmap,norm=norm,transform=
|
|
264
|
+
pcm = ax.pcolormesh(grid_lon,grid_lat,newdata.T,cmap=var_cmap,norm=norm,transform=projs)
|
|
269
265
|
|
|
270
|
-
# add_private_shp(ax)
|
|
271
266
|
|
|
272
267
|
# add_china_map_2cartopy(ax,name='county')
|
|
273
268
|
# add_china_map_2cartopy(ax,name='city')
|
|
274
269
|
add_china_map_2cartopy(ax,name='province',lw=0.5)
|
|
275
270
|
|
|
276
|
-
|
|
271
|
+
if badd_gis:
|
|
272
|
+
draw_gisinfo(ax)
|
|
277
273
|
|
|
278
274
|
|
|
279
275
|
# 添加地图网格
|
|
@@ -299,14 +295,20 @@ def draw_mosaic(data,lat,lon,slat=None,nlat=None,wlon=None,elon=None,outpath=Non
|
|
|
299
295
|
|
|
300
296
|
lb=ax.gridlines(draw_labels=True,x_inline=False, y_inline=False,xlocs=np.arange(int(wlon)-1,int(elon)+1,lon_step), ylocs=np.arange(int(slat)-1,int(nlat)+1,lat_step),
|
|
301
297
|
linewidth=0.1, color='k', alpha=0.8, linestyle='--')
|
|
298
|
+
|
|
299
|
+
# 在左下角添加一行字: Powered by metradar
|
|
300
|
+
if badd_logo:
|
|
301
|
+
textstr = 'Powered by metradar'
|
|
302
|
+
ax.text(0.01, 0.01, textstr, transform=ax.transAxes, fontsize=5, verticalalignment='bottom',
|
|
303
|
+
horizontalalignment='left', color='k', alpha=0.6, fontproperties=g_font_min)
|
|
302
304
|
# point_lat = 30.72
|
|
303
305
|
# point_lon = 108.57
|
|
304
306
|
# ax.plot(point_lon,point_lat,marker='o',color='r',markersize=4,transform=ccrs.PlateCarree())
|
|
305
307
|
lb.top_labels = None
|
|
306
308
|
lb.right_labels = None
|
|
307
309
|
lb.rotate_labels = False
|
|
308
|
-
|
|
309
|
-
titlestr1 = prefix_title + tstr[0:8] + 'T' + tstr[8:
|
|
310
|
+
|
|
311
|
+
titlestr1 = prefix_title + tstr[0:8] + 'T' + tstr[8:14] + ' UTC ' + subtitle
|
|
310
312
|
|
|
311
313
|
if add_title:
|
|
312
314
|
ax.set_title(titlestr1,fontproperties=g_font_mid,loc='left',verticalalignment='top',color=titlecolor)
|
|
@@ -320,33 +322,29 @@ def draw_mosaic(data,lat,lon,slat=None,nlat=None,wlon=None,elon=None,outpath=Non
|
|
|
320
322
|
plt.colorbar(mappable=pcm,cax=cb_ax,extend='both',ticks=np.arange(0,80,5))
|
|
321
323
|
else:
|
|
322
324
|
plt.colorbar(mappable=pcm,cax=cb_ax,extend='both')
|
|
323
|
-
cb_ax.text(1.8, 1.035, units, transform=cb_ax.transAxes,va="center", ha="center", font=
|
|
325
|
+
cb_ax.text(1.8, 1.035, units, transform=cb_ax.transAxes,va="center", ha="center", font=g_font_mid ) # 0.5,1.02
|
|
324
326
|
|
|
325
327
|
if units == 'cat':
|
|
326
328
|
cb_ax.set_yticklabels(['空','地物','晴空','干雪','湿雪','冰晶','霰','大雨滴','小到中雨','大雨','冰雹',],font=g_font_min)
|
|
327
329
|
|
|
328
330
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
# plt.subplots_adjust(top=1,bottom=0,left=0,right=1,hspace=0,wspace=0)
|
|
332
|
-
|
|
333
|
-
# data = np.ma.masked_array(newdata.data, newdata.data < 10)
|
|
334
|
-
# plt.pcolormesh(data,cmap=ref_cmap,norm=norm)
|
|
335
|
-
# plt.axis("off")
|
|
331
|
+
if not os.path.exists(outpath):
|
|
332
|
+
os.makedirs(outpath,exist_ok=True)
|
|
336
333
|
if os.path.exists(outpath):
|
|
337
334
|
if outname.endswith('.eps'):
|
|
338
335
|
plt.savefig(outpath + os.sep + outname, transparent=False, dpi=dpi,papertype='a4')
|
|
339
336
|
else:
|
|
340
337
|
fig.savefig(outpath + os.sep + outname, bbox_inches="tight",transparent=False, dpi=dpi,)
|
|
341
|
-
|
|
338
|
+
|
|
342
339
|
print(outpath + os.sep + outname + ' saved!')
|
|
343
|
-
|
|
344
|
-
# plt.show()
|
|
340
|
+
|
|
345
341
|
|
|
346
342
|
def draw_single(param):
|
|
347
343
|
filename = param['filename']
|
|
348
344
|
filepath = param['filepath']
|
|
349
345
|
outpath = param['outpath']
|
|
346
|
+
outname = param['outname']
|
|
347
|
+
tstr = param['timestr']
|
|
350
348
|
slat = param['slat']
|
|
351
349
|
nlat = param['nlat']
|
|
352
350
|
wlon = param['wlon']
|
|
@@ -355,67 +353,73 @@ def draw_single(param):
|
|
|
355
353
|
thred = param['thred']
|
|
356
354
|
|
|
357
355
|
|
|
358
|
-
outname = filename.replace('.nc','.png')
|
|
359
|
-
tstr = filename.split('.')[2] + filename.split('.')[3]
|
|
356
|
+
# outname = filename.replace('.nc','.png')
|
|
357
|
+
# tstr = filename.split('.')[2] + filename.split('.')[3]
|
|
360
358
|
data = xr.open_dataset(filepath + os.sep + filename)
|
|
361
359
|
try:
|
|
362
360
|
newdata = data.cref.sel(latitude=slice(slat,nlat),longitude=slice(wlon,elon))
|
|
363
|
-
|
|
361
|
+
draw_latlon(newdata,newdata.latitude.data,newdata.longitude.data,slat,nlat,wlon,elon,outpath,outname,tstr,dpi=dpi,thred=thred)
|
|
364
362
|
except:
|
|
365
363
|
newdata = data.cref.sel(lat=slice(slat,nlat),lon=slice(wlon,elon))
|
|
366
|
-
|
|
364
|
+
draw_latlon(newdata,newdata.lat.data,newdata.lon.data,slat,nlat,wlon,elon,outpath,outname,tstr,dpi=dpi,thred=thred)
|
|
367
365
|
|
|
368
366
|
|
|
369
367
|
|
|
370
368
|
|
|
371
369
|
if __name__ == "__main__":
|
|
372
370
|
freeze_support()
|
|
373
|
-
filepath = '/
|
|
374
|
-
|
|
375
|
-
outpath = '/
|
|
371
|
+
filepath = '/home/wjzhu/OneDrive/PythonCode/MyWork/metradar/testdata/mosaic_bin'
|
|
372
|
+
filename = 'ACHN_CREF_20210918_155000.BIN'
|
|
373
|
+
outpath = '/home/wjzhu/OneDrive/PythonCode/MyWork/metradar/output/pic'
|
|
376
374
|
|
|
377
375
|
if not os.path.exists(outpath):
|
|
378
376
|
os.makedirs(outpath)
|
|
377
|
+
# 单张图绘制
|
|
378
|
+
curparam=dict()
|
|
379
|
+
curparam['filepath'] = filepath
|
|
380
|
+
curparam['filename'] = filename
|
|
381
|
+
curparam['outpath'] = outpath
|
|
382
|
+
curparam['outname'] = filename + '.png'
|
|
383
|
+
curparam['timestr'] = filename.split('_')[2] + filename.split('_')[3].split('.')[0]
|
|
384
|
+
curparam['slat'] = 15
|
|
385
|
+
curparam['nlat'] = 55
|
|
386
|
+
curparam['wlon'] = 72
|
|
387
|
+
curparam['elon'] =140
|
|
388
|
+
curparam['dpi'] = 300
|
|
389
|
+
curparam['thred'] = 10
|
|
390
|
+
|
|
391
|
+
draw_single(curparam)
|
|
379
392
|
|
|
380
|
-
# curparam=dict()
|
|
381
|
-
# curparam['filepath'] = filepath
|
|
382
|
-
# curparam['filename'] = filename
|
|
383
|
-
# curparam['outpath'] = outpath
|
|
384
|
-
# curparam['slat'] = 33
|
|
385
|
-
# curparam['nlat'] = 37
|
|
386
|
-
# curparam['wlon'] = 109
|
|
387
|
-
# curparam['elon'] =117
|
|
388
|
-
# curparam['dpi'] = 600
|
|
389
|
-
# curparam['thred'] = 10
|
|
390
|
-
|
|
391
|
-
# draw_single(curparam)
|
|
392
|
-
|
|
393
393
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
pools
|
|
394
|
+
|
|
395
|
+
# 多进程批量绘制
|
|
396
|
+
# params=[]
|
|
397
|
+
# files = os.listdir(filepath)
|
|
398
|
+
# files = sorted(files)
|
|
399
|
+
# for filename in files:
|
|
400
|
+
# if filename.startswith('.') or filename.startswith('..'):
|
|
401
|
+
# continue
|
|
402
|
+
# # if filename.split('.')[3][2:4] != '00' and filename.split('.')[3][2:4] != '12' and filename.split('.')[3][2:4] != '30' and filename.split('.')[3][2:4] != '48':
|
|
403
|
+
# # continue
|
|
404
|
+
# curparam=dict()
|
|
405
|
+
# curparam['filepath'] = filepath
|
|
406
|
+
# curparam['filename'] = filename
|
|
407
|
+
# curparam['outname'] = filename + '.png'
|
|
408
|
+
# curparam['timestr'] = filename.split('_')[2] + filename.split('_')[3].split('.')[0]
|
|
409
|
+
# curparam['outpath'] = outpath
|
|
410
|
+
# curparam['slat'] = 28
|
|
411
|
+
# curparam['nlat'] = 32.5
|
|
412
|
+
# curparam['wlon'] = 105.5
|
|
413
|
+
# curparam['elon'] =110.5
|
|
414
|
+
# curparam['dpi'] = 300
|
|
415
|
+
# curparam['thred'] = 15
|
|
416
|
+
|
|
417
|
+
# params.append(curparam)
|
|
418
|
+
|
|
419
|
+
# MAXP = int(cpu_count()*0.8)
|
|
420
|
+
# pools = Pool(MAXP)
|
|
421
|
+
|
|
422
|
+
# pools.map(draw_single, params)
|
|
423
|
+
# pools.close()
|
|
424
|
+
# pools.join()
|
|
421
425
|
|