figure_draw_py

python绘图

环境配置与IDE配置

  • python环境安装可通过直接下载或者通过包管理器anaconda下载,这里更推荐使用anaconda可以搭建多个不同版本的python环境且彼此不受影响,两种方法下载后均会自动配置好环境变量,不需要下一步操作。后续介绍主要围绕anaconda+vscode的配置来介绍。
  • conda创建环境需要打开anaconda prompt来创建,常用的conda命令如下
    • conda env list 列出目前已有的环境
    • conda create -n env_name python=3.x.x 创建名称为env_name版本为3.x.x的python环境
    • conda activate env_name 进入env_name的环境 deactivate 退出环境
    • 在进入某一环境后可以通过conda install xxx来下载不同的包,原理与pip相同
  • IDE使用vscode,下载好后在任意一个目录下创建python文件后,在右下角选择已经创建好的conda环境即可

    常用包

  1. numpy 数据处理包,主要使用其中创建空数组或是对数组进行布尔逻辑索引等操作
  2. matplotlib python中绘图最主要的包
  3. xarray 可以读取.nc等带有表头格式的文件
  4. cartopy 主要进行地图绘制的包
  5. netCDF4 可以读取nc格式文件并将读取出来的文件转换为ndarray即numpy数组
  6. scipy 包含许多统计变量的计算函数
  7. h5py 读取HDF格式文件,读取后变为Dataset格式,通过提取变量变为ndarray
  8. shapefile 与shp文件相关的地图绘制

绘图基本流程与常用函数

以绘制GPM降水资料在甘肃的分布为例

  1. 读取数据
    import h5py
    file = 'path_to_GPM_file'
    Dataset = h5py.File(file)
    lon = Dataset['/Grid/lon'][:] #不同的二进制文件中变量关键词不同,变量组关系不同,可使用ncdump -h 先查看文件变量组在读取
    lat = Dataset['/Grid/lat'][:] #这里使用[:]是为了只将变量中的数据取出,而不包含变量的头信息等
    prec = Dataset['Grid/precipitationCal'][:]/2 #由于GPM是逐半小时的降雨率
    prec = prec[0,:,:].transpose() #由于GPM资料是time*lon*lat,需要转化为lat*lon再绘图
  2. 控制数据区域

由于GPM数据为全球范围,直接整体处理对内存与运行速度负载较大,可以通过python中numpy的特性MaskedArray与shp文件来限定其范围

import numpy as np
import shapefile as shp
mark = np.zeros((150,200),dtype=bool) #创建一个布尔形式与数据大小相符的数组
shp_file = shp.Reader('Gansu.shp')
rec = shp_file.shapeRecords()
for r in rec:
    poly = r.shape    #.shape属性一般需要通过迭代内部才能取到
for i in range(0,len(lon)):
    for j in range(0,len(lat)): #通过便利格点,来确定其是否在给定的shp文件范围内部
        if geometry.Point([lon[i],lat[j]]).within(geometry.shape(poly)):
            mark[j,i] = True # 根据shp文件结构不同,需要调整poly的结构,如这里使用的是甘肃省界shp文件,内部仅有一个多边形

到这里,mark数组就变为了在甘肃省内部为True,外部为False的一个标记数组,之后将经纬度网格点以及降水数据网格点取mark,即可绘制图像。这是python中较为常用的一个特性

  1. 绘图
  • 主要用到matplotlib下的pyplot包,需要在画图时将图中出现的字体改为新罗马

    from matplotlib import pyplot as plt #引入pyplot库
    import matplotlib as mpl
    mpl.rcParams['font.family'] = 'sans-serif'
    mpl.rcParams['font.sans-serif'] = ['Times New Roman']
    mpl.rcParams['axes.unicode_minus'] = False
    mpl.rcParams['mathtext.fontset'] = 'stix'
  • 主要的画图函数有

    plt.plot(x = ,y = ,color = ,linestyle = ) #折线图 可指定线条颜色,线条形式(实线 solid、虚线 dashed...)
    plt.contourf(x = , y = , z = , cmap = ) #填色图 z为每个格点上对应的值,注意,这里的xy必须为网格点数据,即不能是单一的xy一维序列,而是网格坐标,cmap可以修改填色所使用的colorbar
    import matplotlib.colors as mcolors
    clevs = [0,0.1,2,5,15,30,50]
    cdict = ['#00000000','#A9F090','#40B73F','#63B7FF','#0000FE','#FF00FC','#850042']
    prec_cmap = mcolors.ListedColormap(cdict)
    norm = mpl.colors.BoundaryNorm(clevs,prec_cmap.N) #可以使用这种方式自定义cmap,同样可以在scatter图中使用
    plt.scatter(x = , y = , c = , cmap = ,...) #注意,scatter中的xy与countourf不同,需为一维长度相等的数组,不可为二维网格
    plt.contour() #等值线图 同contourf
    plt.bar(x = , height = , width = ) #直方图 可以指定宽度或是高度随x而变化 
  • 绘图流程

可以通过plt直接调用几个函数直接进行绘制,或是通过

fig = plt.figure(figsize=(12,8))
ax = fig.addsubplot(111,projection = xxx) #这里的111是指一幅图,可以通过指定该参数来绘制组图如
ax1 = fig.addsubplot(2,2,1) # 此时添加了一副2*2的子图,并指定当前绘图区域在第一幅,即左上图,按照左到右,上到下排序
....
# 在绘图结束后,可以调用
plt.savefig(fanme = , dpi = , Orientation = , format = ) # 参数包括文件保存地址与文件名,文件清晰度(如保存位图可忽略),图片方向,图片格式
# 或是
plt.show() # 在弹出的对话框中选择保存的形式
  • 常用绘图工具函数
  1. 经纬度显示转化
from matplotlib.ticker import FuncFormatter
def to_latitude(temp, position):
    return '%1.0f'%(temp) + '°N'
def to_longtitude(temp,position): #通过占位符替换坐标轴显示形式,同理可以改写百分数
    return '%1.0f'%(temp)+ '°E'

需要在主函数,即绘图调用处加上,同理,改写百分制显示时只需要改写y轴显示形式即可

x_fomatter = FuncFormatter(to_longtitude)
y_fomatter = FuncFormatter(to_latitude)
plt.gca().yaxis.set_major_formatter(y_fomatter)
plt.gca().xaxis.set_major_formatter(x_fomatter)

LES

SGS turbulent using 3D Smagorinsky-Lilly closure

era5 initializing WRF

References

  1. How to run the WRF model using ERA5 (on model levels) as initial and boundary conditions
  2. Grib to Netcdf conversion
  3. Download ERA-Interim data
  4. 气象家园

Summarization

  1. Download
  2. Preprocess
  3. Automation
  4. Geogrid
  5. Ungrib
  6. Produce additional intermediate files
  7. Metgrid

Download

ERA5 data were downloaded as described in How to download ERA5 data via the ECMWF Web API
Here I’m attaching scripts to download surface and model data:

if you want to use analysis and one hour resolution, all you need to change are data, area and target. Otherwise, you should change as needed.

This is a little different from downloading ERA-Interim data. ERA-Interim includes Geopotential and Land-sea mask in invariant field. ERA5 includes them in surface dataset. So, we just need to download surface data and model level data.

Surface data (GetERA5-sfc.py)

from ecmwfapi import ECMWFDataServer
server = ECMWFDataServer()
server.retrieve({
    'class':'ea',
    'dataset':'era5',
    'area':'Nort/West/Sout/East',
    'date':'DATE1/to/DATE2',
    'expver':'1',
    'levtype':'sfc',
    'param':'msl/skt/2t/10u/10v/2d/z/lsm/sst/ci/sd/stl1/stl2/stl3/stl4/swvl1/swvl2/swvl3/swvl4',  
    'stream':'oper',
    'time':'00:00:00/01:00:00/02:00:00/03:00:00/04:00:00/05:00:00/06:00:00/07:00:00/08:00:00/09:00:00/10:00:00/11:00:00/12:00:00/13:00:00/14:00:00/15:00:00/16:00:00/17:00:00/18:00:00/19:00:00/20:00:00/21:00:00/22:00:00/23:00:00',
    'type':'an',
    'target':'ERA5-DATE1-DATE2-sfc.grb',
    'grid':"0.25/0.25",
})

Model level data (GetERA5-ml.py)

from ecmwfapi import ECMWFDataServer
server = ECMWFDataServer()
server.retrieve({
    'class':'ea',
    'dataset':'era5',
    'area':'Nort/West/Sout/East',
    'date':'DATE1/to/DATE2',
    'expver':'1',
    'levelist': '1/to/137',
    'levtype':'ml',
    'param':'129/130/131/132/133/152',
    'stream':'oper',
    'time':'00:00:00/01:00:00/02:00:00/03:00:00/04:00:00/05:00:00/06:00:00/07:00:00/08:00:00/09:00:00/10:00:00/11:00:00/12:00:00/13:00:00/14:00:00/15:00:00/16:00:00/17:00:00/18:00:00/19:00:00/20:00:00/21:00:00/22:00:00/23:00:00',
    'type':'an',
    'target':'ERA5-DATE1-DATE2-ml.grb',
    'grid':'0.25/0.25',
})

Preprocess

Install eccodes or grib_api according to ECMWF.

If you choose grib_api, you must install the new version of grib_api. Otherwise, you will get this error when using grib_set (e.g. grib_api Version 1.12.3):

GRIB_API ERROR   :  Key "numberOfVerticalCoordinateValues": Trying to encode value of 276 but the maximum allowable value is 255 (number of bits=8)

GRIB_API ERROR   :  unable to set NV=276 as long (Encoding invalid)
GRIB_API ERROR   :  grib_set_values[0] deletePV (1) failed: Key/value not found
GRIB_API ERROR   :  grib_set_values[1] edition (1) failed: Encoding invalid

Preprocess surface data (optional)

echo 'write "[centre]_[dataDate]_[dataType]_[levelType]_[step].grib[edition]";' > split.rule  
grib_filter split.rule your/surface_data/name

Preprocess model level data (necessary)

grib_set -s deletePV=1,edition=1 your/model_level_data/name your/model_level_data/name.grib1
grib_filter split.rule your/model_level_data/name.grib1

Finally, you will get these files (the structure of filename is
[centre]_[dataDate]_[dataType]_[levelType]_[step].grib[edition]):

|– ecmf_20150531_an_ml_0.grib1
|– ecmf_20150531_an_sfc_0.grib1
|– ecmf_20150601_an_ml_0.grib1
|– ecmf_20150601_an_sfc_0.grib1

Link_grib.csh all these files in your preprocessing working directory.

Automation script (Download + Preprocess)

You can automate the script rather than change elements one by one (as suggested by Conor).

#!/bin/bash -l

CODEDIR=/nuist/u/home/yinyan/xin/scratch/data/ERA5/code
DATADIR=/nuist/u/home/yinyan/xin/scratch/data/ERA5/data

# Set your python environment
export PATH=~/xin/work/anaconda3/bin:$PATH
source activate root

cd $CODEDIR

DATE1=20170419
DATE2=20170420
Nort=90
West=0
Sout=-30
East=180

YY1=`echo $DATE1 | cut -c1-4`
MM1=`echo $DATE1 | cut -c5-6`
DD1=`echo $DATE1 | cut -c7-8`

YY2=`echo $DATE2 | cut -c1-4`
MM2=`echo $DATE2 | cut -c5-6`
DD2=`echo $DATE2 | cut -c7-8`

sed -e "s/DATE1/${DATE1}/g;s/DATE2/${DATE2}/g;s/Nort/${Nort}/g;s/West/${West}/g;s/Sout/${Sout}/g;s/East/${East}/g;" GetERA5-sfc.py > GetERA5-${DATE1}-${DATE2}-sfc.py

python GetERA5-${DATE1}-${DATE2}-sfc.py

sed -e "s/DATE1/${DATE1}/g;s/DATE2/${DATE2}/g;s/Nort/${Nort}/g;s/West/${West}/g;s/Sout/${Sout}/g;s/East/${East}/g;" GetERA5-ml.py > GetERA5-${DATE1}-${DATE2}-ml.py

python GetERA5-${DATE1}-${DATE2}-ml.py

mkdir -p ${DATADIR}/$YY1

mv ERA5-${DATE1}-${DATE2}-sfc.grb ERA5-${DATE1}-${DATE2}-ml.grb ${DATADIR}/$YY1/

cd ${DATADIR}/$YY1/

echo 'write "[centre]_[dataDate]_[dataType]_[levelType]_[step].grib[edition]";' > split.rule
grib_filter split.rule ERA5-${DATE1}-${DATE2}-sfc.grb
grib_set -s deletePV=1,edition=1 ERA5-${DATE1}-${DATE2}-ml.grb ERA5-${DATE1}-${DATE2}-ml.grib1
grib_filter split.rule ERA5-${DATE1}-${DATE2}-ml.grib1

# If you want to delete original files, you can uncomment the following line.
# rm *grb

exit 0

Geogrid

run geogrid.exe as usual

Ungrib

run ungrib.exe by using the following Vtable (as suggested by valerio):

GRIB | Level| Level| Level| metgrid | metgrid | metgrid                 |
Code | Code |  1 |  2 | Name   | Units  | Description               |
-----+------+------+------+----------+----------+------------------------------------------+  
 130 | 109 |  * |   | TT    | K    | Temperature               |
 131 | 109 |  * |   | UU    | m s-1  | U                    |
 132 | 109 |  * |   | VV    | m s-1  | V                    |
 133 | 109 |  * |   | SPECHUMD | kg kg-1 | Specific humidity            |
 152 | 109 |  * |   | LOGSFP  | Pa    | Log surface pressure           |
 157 | 109 |  * |   | RHUM   | %    | Relative humidity            |
 129 | 1  |  0 |   | SOILGEO | m    |                     |
   | 1  |  0 |   | SOILHGT | m    | Terrain field of source analysis     |   
 165 | 1  |  0 |   | UU    | m s-1  | U                    | At 10 m   
 166 | 1  |  0 |   | VV    | m s-1  | V                    | At 10 m   
 167 | 1  |  0 |   | TT    | K    | Temperature               | At 2 m   
 168 | 1  |  0 |   | DEWPT  | K    |                     | At 2 m   
   | 1  |  0 |   | RH    | %    | Relative Humidity at 2 m         | At 2 m   
 172 | 1  |  0 |   | LANDSEA | 0/1 Flag | Land/Sea flag              |
 134 | 1  |  0 |   | PSFC   | Pa    | Surface Pressure             |
 134 | 109 |  1 |   | PSFCH  | Pa    |                     |
 151 | 1  |  0 |   | PMSL   | Pa    | Sea-level Pressure            |
 235 | 1  |  0 |   | SKINTEMP | K    | Sea-Surface Temperature         |
 31 | 1  |  0 |   | SEAICE  | 0/1 Flag | Sea-Ice-Flag               |
 34 | 1  |  0 |   | SST   | K    | Sea-Surface Temperature         |
 141 | 1  |  0 |   | SNOW_EC | m    |                     |
   | 1  |  0 |   | SNOW   | kg m-2  |Water Equivalent of Accumulated Snow Depth|  
 139 | 112 |  0 |  7 | ST000007 | K    | T of 0-7 cm ground layer         |
 170 | 112 |  7 | 28 | ST007028 | K    | T of 7-28 cm ground layer        |
 183 | 112 | 28 | 100 | ST028100 | K    | T of 28-100 cm ground layer       |
 236 | 112 | 100 | 255 | ST100255 | K    | T of 100-255 cm ground layer       |
 39 | 112 |  0 |  7 | SM000007 | fraction | Soil moisture of 0-7 cm ground layer   |   
 40 | 112 |  7 | 28 | SM007028 | fraction | Soil moisture of 7-28 cm ground layer  |   
 41 | 112 | 28 | 100 | SM028100 | fraction | Soil moisture of 28-100 cm ground layer |   
 42 | 112 | 100 | 255 | SM100255 | fraction | Soil moisture of 100-255 cm ground layer |   
-----+------+------+------+----------+----------+------------------------------------------+

Produce additional intermediate files

Create the following ecmwf_coeffs table (named ecmwf_coeffs) and run */WPS/util/calc_ecmwf_p.exe:

0 0.000000 0.00000000  
1 2.000365 0.00000000  
2 3.102241 0.00000000  
3 4.666084 0.00000000  
4 6.827977 0.00000000  
5 9.746966 0.00000000  
6 13.605424 0.00000000  
7 18.608931 0.00000000  
8 24.985718 0.00000000  
9 32.985710 0.00000000  
10 42.879242 0.00000000  
11 54.955463 0.00000000  
12 69.520576 0.00000000  
13 86.895882 0.00000000  
14 107.415741 0.00000000  
15 131.425507 0.00000000  
16 159.279404 0.00000000  
17 191.338562 0.00000000  
18 227.968948 0.00000000  
19 269.539581 0.00000000  
20 316.420746 0.00000000  
21 368.982361 0.00000000  
22 427.592499 0.00000000  
23 492.616028 0.00000000  
24 564.413452 0.00000000  
25 643.339905 0.00000000  
26 729.744141 0.00000000  
27 823.967834 0.00000000  
28 926.344910 0.00000000  
29 1037.201172 0.00000000  
30 1156.853638 0.00000000  
31 1285.610352 0.00000000  
32 1423.770142 0.00000000  
33 1571.622925 0.00000000  
34 1729.448975 0.00000000  
35 1897.519287 0.00000000  
36 2076.095947 0.00000000  
37 2265.431641 0.00000000  
38 2465.770508 0.00000000  
39 2677.348145 0.00000000  
40 2900.391357 0.00000000  
41 3135.119385 0.00000000  
42 3381.743652 0.00000000  
43 3640.468262 0.00000000  
44 3911.490479 0.00000000  
45 4194.930664 0.00000000  
46 4490.817383 0.00000000  
47 4799.149414 0.00000000  
48 5119.895020 0.00000000  
49 5452.990723 0.00000000  
50 5798.344727 0.00000000  
51 6156.074219 0.00000000  
52 6526.946777 0.00000000  
53 6911.870605 0.00000000  
54 7311.869141 0.00000000  
55 7727.412109 0.00000700  
56 8159.354004 0.00002400  
57 8608.525391 0.00005900  
58 9076.400391 0.00011200  
59 9562.682617 0.00019900  
60 10065.978516 0.00034000  
61 10584.631836 0.00056200  
62 11116.662109 0.00089000  
63 11660.067383 0.00135300  
64 12211.547852 0.00199200  
65 12766.873047 0.00285700  
66 13324.668945 0.00397100  
67 13881.331055 0.00537800  
68 14432.139648 0.00713300  
69 14975.615234 0.00926100  
70 15508.256836 0.01180600  
71 16026.115234 0.01481600  
72 16527.322266 0.01831800  
73 17008.789062 0.02235500  
74 17467.613281 0.02696400  
75 17901.621094 0.03217600  
76 18308.433594 0.03802600  
77 18685.718750 0.04454800  
78 19031.289062 0.05177300  
79 19343.511719 0.05972800  
80 19620.042969 0.06844800  
81 19859.390625 0.07795800  
82 20059.931641 0.08828600  
83 20219.664062 0.09946200  
84 20337.863281 0.11150500  
85 20412.308594 0.12444800  
86 20442.078125 0.13831300  
87 20425.718750 0.15312500  
88 20361.816406 0.16891000  
89 20249.511719 0.18568900  
90 20087.085938 0.20349100  
91 19874.025391 0.22233300  
92 19608.572266 0.24224400  
93 19290.226562 0.26324200  
94 18917.460938 0.28535400  
95 18489.707031 0.30859800  
96 18006.925781 0.33293900  
97 17471.839844 0.35825400  
98 16888.687500 0.38436300  
99 16262.046875 0.41112500  
100 15596.695312 0.43839100  
101 14898.453125 0.46600300  
102 14173.324219 0.49380000  
103 13427.769531 0.52161900  
104 12668.257812 0.54930100  
105 11901.339844 0.57669200  
106 11133.304688 0.60364800  
107 10370.175781 0.63003600  
108 9617.515625 0.65573600  
109 8880.453125 0.68064300  
110 8163.375000 0.70466900  
111 7470.343750 0.72773900  
112 6804.421875 0.74979700  
113 6168.531250 0.77079800  
114 5564.382812 0.79071700  
115 4993.796875 0.80953600  
116 4457.375000 0.82725600  
117 3955.960938 0.84388100  
118 3489.234375 0.85943200  
119 3057.265625 0.87392900  
120 2659.140625 0.88740800  
121 2294.242188 0.89990000  
122 1961.500000 0.91144800  
123 1659.476562 0.92209600  
124 1387.546875 0.93188100  
125 1143.250000 0.94086000  
126 926.507812 0.94906400  
127 734.992188 0.95655000  
128 568.062500 0.96335200  
129 424.414062 0.96951300  
130 302.476562 0.97507800  
131 202.484375 0.98007200  
132 122.101562 0.98454200  
133 62.781250 0.98850000  
134 22.835938 0.99198400  
135 3.757813 0.99500300  
136 0.000000 0.99763000  
137 0.000000 1.00000000

Metgrid

Edit namelist.wps like this:

&ungrib
out_format = 'WPS',
prefix = 'FILE',
/

&metgrid
fg_name = 'FILE','PRES'
io_form_metgrid = 2,

If you just run metgrid.exe, you’ll get these warnings:

WARNING: Entry in METGRID.TBL not found for field ST100255. Default options will be used for this field!
WARNING: Entry in METGRID.TBL not found for field SM100255. Default options will be used for this field!
WARNING: Entry in METGRID.TBL not found for field LOGSFP. Default options will be used for this field!

You can edit METGRID.TBL to set interpolation method of ST100255 SM100255 and LOGSFP:

========================================
name=ST
        z_dim_name=num_st_layers
        derived=yes
        ....
# ELSE IF
        fill_lev =   7 : ST000007(200100)
        fill_lev =  28 : ST007028(200100)
        fill_lev = 100 : ST028100(200100)
        fill_lev = 255 : ST100255(200100)
        ....
========================================
name=SM
        z_dim_name=num_sm_layers
        derived=yes
        ....
# ELSE IF
        fill_lev =   7 : SM000007(200100)
        fill_lev =  28 : SM007028(200100)
        fill_lev = 100 : SM028100(200100)
        fill_lev = 255 : SM100255(200100)
        ....
....
....
========================================
name=SM100255
        interp_option=sixteen_pt+four_pt+wt_average_4pt+wt_average_16pt+search
        masked=water
        interp_mask=LANDSEA(0)
        missing_value=-1.E30
        fill_missing=1.
        flag_in_output=FLAG_SM100255
========================================
....
....
========================================
name=ST100255
        interp_option=sixteen_pt+four_pt+wt_average_4pt+wt_average_16pt+search
        masked=water
        interp_mask=LANDSEA(0)
        missing_value=-1.E30
        fill_missing=285.
        flag_in_output=FLAG_ST100255
========================================
....
....
========================================
name=LOGSFP
        interp_option=four_pt+average_4pt
        fill_lev=200100:PSFC(200100.)
        flag_in_output=FLAG_LOGSFP
========================================

Run metgrid.exe with the modified METGRID.TBL.ARW table.

Note of mozbc

If you’re using MOZART in WRF-Chem, then you need to change LOGSFP field in met* files to PSFC:

$ for i in met*; do ncap2 -s 'PSFC=exp(LOGSFP)' "$i" "$i"_tmp; done
After checking tmp files:
$ rename nc_tmp nc *.nc_tmp

namelist_wrf_parameter

WRF中namelist参数化方案选项说明

&physics

mp_physics 微物理参数化方案 (加粗数字代表选项编号)

  • Kessler scheme 暖雨(无冰)方案,一般用在理想云模型中 1
  • Purdue Lin scheme 有冰、雪和霰过程,适合真实数据高分辨率模拟 2
  • WRF Single-Moment 3-calss cheme 适用于中尺度网格带有冰雪过程的简单高效方案 3
  • WRF Single-Moment 5-class scheme 较上一方案稍微复杂,允许混合相过程和过冷水 4
  • Eta microphysics 一个带有诊断性混合相过程的简单方案,细网格使用5粗网格使用95
  • WRF Single-Moment 6-class scheme 带有冰雪和霰过程适用于高分辨率的模拟 6
  • Goddard microphysics scheme 带有冰雪和霰过程适用于高分辨模拟 7
  • New Thompson scheme 带有冰雪和霰过程,添加了降水集中度。8
  • Milbrandt-Yau Double-Moment 7-class scheme 使用包括了冰雹和霰的不同类别

py in met

写在前面

这篇博客主要记录在使用python进行气象数据处理/绘制中的一些问题
np.meshgrid(lon_grid,lat_grid) 可以将经纬度转换为对应的坐标点
xarray.Dataarray 具有标签属性(例如lat,lon)
numpy.array不具有标签属性

GPM

数据介绍

GPM数据分为两类

  1. 观测后4小时与十四小时的逐半小时0.1x0.1资料
  2. 观测后3.5月后的逐月0.1x0.1资料

数据处理

  1. 将观测资料进行质量控制,筛除缺测,通过时间对缺测全天的数据索引进行标记,之后将GPM资料做相同处理,进行相关系数等的计算
  2. 论文中讲述顺序要由大到小,由总体到局部

脚本留档

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import MultipleLocator
from matplotlib.ticker import FuncFormatter
import os
import cartopy.crs as ccrs
from cartopy.io.shapereader import Reader
import cartopy.feature as cfeat
import xarray as xr
import matplotlib as mpl
import h5py
from scipy import interpolate as ip
import shapefile
from matplotlib.path import Path
from matplotlib.patches import PathPatch
mpl.rcParams['font.family'] = 'sans-serif'
mpl.rcParams['font.sans-serif'] = ['Times New Roman']
mpl.rcParams['axes.unicode_minus'] = False
def to_latitude(temp, position):
    return '%1.0f'%(temp) + '°N'
def to_longtitude(temp,position):
    return '%1.0f'%(temp)+ '°E'
def to_time(temp,position):
    if temp < 10:
        return '0'+'%1.0f'%(temp)+':00'
    return '%1.0f'%(temp)+':00'         ##转换坐标轴
def countLine(file_path): 
    count = -1
    for count,line in enumerate(open(file_path,'r')):
        pass
        count += 1
    return count


def shp2clip(originfig, ax, shpfile, regionlist):  #白化函数 将contour在shp区域外转为白色
    sf = shapefile.Reader(shpfile)
    vertices = []
    codes = []
    for shape_rec in sf.shapeRecords():
        region_name = shape_rec.record[0] #是否是[0]得自行分析自己的shp文件
        if region_name in regionlist: 
            pts = shape_rec.shape.points
            prt = list(shape_rec.shape.parts) + [len(pts)]
            for i in range(len(prt) - 1):
                for j in range(prt[i], prt[i+1]):
                    vertices.append((pts[j][0], pts[j][1]))
                codes += [Path.MOVETO]
                codes += [Path.LINETO] * (prt[i+1] - prt[i] -2)
                codes += [Path.CLOSEPOLY]
            clip = Path(vertices, codes)
            clip = PathPatch(clip, transform=ax.transData)
    for contour in originfig.collections:
        contour.set_clip_path(clip)

    return clip
##shp2clip(tt,ax,sy,['辽宁省'])

bash

Debug

环境配置

  1. 在windows下vscode中配置git bash时要注意默认的终端选项中git bash中间的空格,会导致vscode不识别。同时在1.75.1版本的vscode中修改默认终端的选项为terminal.integrated.defaultProfile.windows

WRF学习

debug

1

在运行 ./geogrid.exe 出现cannot open shared object file:libifport.so.5 No such file or directory,通过在环境变量中增加寻找动态链接库方法解决未果,通过搜索发现有人说在适用intel编译器(或ia32),应该总输入 source /opt/intel/bin/compilervars.sh intel64

2

Fortran学习

baisc语法

基本构成

fortran程序由一组程序单元组成,每个包含一个主程序,语法如下

program program_name
implicit none
end program program_name

命名以及字符集

与C语言所包含的ASCII字符集基本相同,标识符即变量名称不区分大小写,且第一个字符必须是字母

关键字

https://wenku.baidu.com/view/08bea464cfbff121dd36a32d7375a417866fc109.html

数据类型

分为了5种包括整数,浮点数,复杂数,布尔类型,字符类型

  1. 整数(integer)与C语言中的int类似,仅保存整数
  2. 浮点数(real)默认类型为双精度浮点数,可通过kind函数对其以及整数进行精度控制,对整数是控制其所占字节大小,通过huge函数可以得到某一整数变量的最大值。通过数字后加d0来声明数字为双精度实数
  3. 复杂类型(complex)用于存储复数,赋值有两种方式,无论输入参数如何,其实部和虚部均为单精度
complex :: cx
cx = (1.0 , 2.0) ! cx = 1+2i
cx = cmplx(2.0 , 1.0) ! cx = 2+i
  1. 字符类型(character)用于存储字符串,通过len声明其长度
character(len = 10) :: name !声明了一个长度为40,名称为name的字符串
  1. 逻辑类型(logical)用于存储逻辑布尔值

  2. 对常量的声明,通过使用parameter关键字

integer , parameter :: const = 1
  1. 动态数组(Dynamic Arrays)编译时大小未知,执行时已知,通过allocatable来声明动态数组,必须声明数组的维度,通过allocate函数,随后可以通过deallocate来释放内存

算术运算符

基本的数学运算符以及关系运算符(== , >=…)与C基本相同,逻辑运算符与ncl相同,在含有等于的运算符多了一个v(如.eq.变为了.eqv.)

条件语句

与C类似,不同的是switch case 变为了 select case

循环语句

使用do或者do while来控制循环,循环可以嵌套,且存在内部声明的变量为局部变量,使用exit来退出循环,cycle作用类似于continue

函数

  1. 通过subroutine关键字来声明函数也称为子程序,在主函数中通过call来调用,fortran中函数的返回值较为特殊,在subroutine声明的函数中需要将返回值也作为函数参数声明,bingqie

  2. 通过function声明,需要注意在主函数中声明函数与函数类型,且结果返回值以函数名为结果,即返回 函数名=expression,同时函数中需要对参数进行声明时加上intent(in)关键字,并且此时参数为局部变量,变量不可修改,声明intent(out)变量不可为函数参数,但可以修改且可向外输送;intent(inout)既可以作为参数同时也可作为输出的结果,效果等同不声明intent,一般来说,在函数中其优势为局部变量,intent应该总为in,如果要使用其他的intent则应该使用subroutine热不是function

2021年总结

回顾这一年确实发生了许多事情,但最值得回味的还是准备考试的那段时间,尽管相比真正的刻苦努力的人还是有所差距,但也是尽力而为了,希望来年能得到一个好的结果。也很感激这大半年身边人的支持,唯一美中不足就是。。

data augmentation

(1)将图像从左向右翻转
(2)将图像从上到下翻转
(3)对角翻转图像
(4)调整图像亮度,最大delta设置为0.4
(5)调整图像对比度,将比例从0.8调至1.2
(6)调整图像色相,将最大差值设置为0.5
(7)调整图像饱和度,将比例从0.8设置为1.2
(8)将图像旋转90度、180度和270度。

batch,epoch,iteration

  1. batch size:简单来说,batch size就是每次训练向模型中传入的数据量的多少,过小的话会导致梯度不明显,模型下降速度慢,过大的话尽管速度会更快但会导致需要更多的epoch来获得更好的结果,与batch本身的节约内存空间的目的相悖,因此需要选择一个合适的batch大小来进行训练。

  2. iteration:意思为迭代,一个iteration等于将batch size中的数据迭代一遍

  3. epoch:意思为周期,一个周期相当于将样本中的所有数据遍历一遍。例如样本数量为1000,batch size为10,那么就需要100此iteration来完成一个epoch。