添加了两个脚本
纹理图片和色标图片单独生成脚本
This commit is contained in:
parent
451dd6683c
commit
f8516ff1a1
101
gmt-colorBar.sh
Executable file
101
gmt-colorBar.sh
Executable file
@ -0,0 +1,101 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# 包含GMT自带脚本文件 其中包含了一些有用的功能 比如获取网格文件的范围
|
||||||
|
. gmt_shell_functions.sh
|
||||||
|
# 包含dispOption脚本
|
||||||
|
. dispOptions
|
||||||
|
#GMT画一个色度条
|
||||||
|
# 初始化参数
|
||||||
|
data='null'
|
||||||
|
unit='m'
|
||||||
|
color='rainbow'
|
||||||
|
range='null'
|
||||||
|
overwriteRange='null'
|
||||||
|
overwrite=0
|
||||||
|
bartick="a" #色标轴标轴间隔 a表示自动
|
||||||
|
opFile=0
|
||||||
|
# 从命令行获取参数
|
||||||
|
while getopts "hi:r:u:c:v:o" arg
|
||||||
|
do
|
||||||
|
case $arg in
|
||||||
|
h)
|
||||||
|
dispTitle "${0##*/}" "plot a color bar using GMT script. The template accepts a grid (.nc .grid) file as input and outputs a .png and a .eps file. \
|
||||||
|
For further explanations, please look for GMT's manuscripts."
|
||||||
|
dispAuthorInfo "Yi Zhang (zhangyi.cugwuhan@gmail.com)"
|
||||||
|
dispUsage "${0##*/} -i<grid-data> [-r<xmin>/<xmax>/<ymin>/<ymax>] [-c<cpt-file>] [-o] [-u<unit>] [-v<bar-tick>]"
|
||||||
|
dispOptionShort "-i" "input grid file."
|
||||||
|
dispOptionShort "-r" "data range. The template will detect the input data range automatically, the use of this option will overwrite the range."
|
||||||
|
dispOptionShort "-c" "color cpt, The default is rainbow."
|
||||||
|
dispOptionShort "-o" "open file in finder, the default is using imgcat."
|
||||||
|
dispOptionShort "-u" "data unit. The default is meter."
|
||||||
|
dispOptionShort "-v" "intervals of color bar's labels. the script will set the intervals automatically if -v option is not set."
|
||||||
|
exit 0;;
|
||||||
|
i)
|
||||||
|
data=$OPTARG;;
|
||||||
|
u)
|
||||||
|
unit=$OPTARG;;
|
||||||
|
c)
|
||||||
|
color=$OPTARG;;
|
||||||
|
v)
|
||||||
|
bartick=$OPTARG;;
|
||||||
|
r)
|
||||||
|
overwrite=1
|
||||||
|
overwriteRange=$OPTARG;;
|
||||||
|
o)
|
||||||
|
opFile=1;;
|
||||||
|
v)
|
||||||
|
bartick=$OPTARG;;
|
||||||
|
?)
|
||||||
|
printf "error: unknow argument\nuse -h option to see help information\n"
|
||||||
|
exit 1;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
# 进行必要的参数检查
|
||||||
|
if [[ $data == "null" ]]; then
|
||||||
|
printf "error: no input file name\nuse -h option to see help information\n"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
# 初始化临时文件名
|
||||||
|
cptfile=user.cpt
|
||||||
|
psfile=${data%.*}.ps
|
||||||
|
jpgfile=${data%.*}.png
|
||||||
|
# 获取网格范围
|
||||||
|
if [[ $overwrite == 1 ]]; then
|
||||||
|
range=${overwriteRange}
|
||||||
|
else
|
||||||
|
range=$(gmt_get_gridregion ${data})
|
||||||
|
fi
|
||||||
|
# 设置绘图参数
|
||||||
|
gmt gmtset \
|
||||||
|
FONT_ANNOT_PRIMARY=7p,Times-Roman,black \
|
||||||
|
MAP_FRAME_PEN=thinnest,black \
|
||||||
|
MAP_TICK_LENGTH_PRIMARY=1p/0.5p \
|
||||||
|
MAP_TITLE_OFFSET=7p \
|
||||||
|
MAP_GRID_CROSS_SIZE_PRIMARY=2p \
|
||||||
|
FONT_LABEL=7p,Times-Roman,black \
|
||||||
|
MAP_FRAME_AXES=WeSnZ \
|
||||||
|
MAP_LABEL_OFFSET=2p \
|
||||||
|
MAP_ANNOT_OFFSET_PRIMARY=2.5p
|
||||||
|
|
||||||
|
gmt grd2cpt ${data} -C${color} -R${range} -Z -D > $cptfile
|
||||||
|
|
||||||
|
#-C${cptfile}+Uk 使用km(色标单位除1000
|
||||||
|
#如果unit等于km则在cptfile后面添加+Uk
|
||||||
|
if [[ ${unit} == 'km+Uk' ]]; then
|
||||||
|
gmt psscale -Dx1.6i/0.1i+w1.2i/0.07i+h -C${cptfile}+Uk -Bx${bartick} -By+l${unit} > $psfile
|
||||||
|
else
|
||||||
|
gmt psscale -Dx1.6i/0.1i+w1.2i/0.07i+h -C${cptfile} -Bx${bartick} -By+l${unit} > $psfile
|
||||||
|
fi
|
||||||
|
gmt psconvert $psfile -A -TEG -E500
|
||||||
|
# 删除临时文件 使用linux终端rm命令
|
||||||
|
rm $cptfile $psfile gmt.history gmt.conf
|
||||||
|
if [[ $plotgrad == 1 ]]; then
|
||||||
|
rm $gradfile
|
||||||
|
fi
|
||||||
|
if [[ $opFile == 1 ]]; then
|
||||||
|
# 打开图片文件 此命令使用MacOS终端open命令
|
||||||
|
open $jpgfile
|
||||||
|
else
|
||||||
|
# 在终端显示图像 此命令需要imgcat.sh脚本和iTerm终端
|
||||||
|
imgcat $jpgfile
|
||||||
|
fi
|
||||||
|
fi
|
96
gmtxy-texture.sh
Executable file
96
gmtxy-texture.sh
Executable file
@ -0,0 +1,96 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# 包含GMT自带脚本文件 其中包含了一些有用的功能 比如获取网格文件的范围
|
||||||
|
. gmt_shell_functions.sh
|
||||||
|
# 包含dispOption脚本
|
||||||
|
. dispOptions
|
||||||
|
#GMT绘制纹理图层,输入文件为网格文件
|
||||||
|
# 初始化参数
|
||||||
|
data='null'
|
||||||
|
gradData='null'
|
||||||
|
color='rainbow'
|
||||||
|
range='null'
|
||||||
|
overwriteRange='null'
|
||||||
|
overwrite=0
|
||||||
|
plotgrad=0
|
||||||
|
size='4i/2i'
|
||||||
|
opFile=0
|
||||||
|
# 从命令行获取参数
|
||||||
|
while getopts "hi:r:c:G:s:go" arg
|
||||||
|
do
|
||||||
|
case $arg in
|
||||||
|
h)
|
||||||
|
dispTitle "${0##*/}" "simple texture images plotting using GMT script. The template accepts a grid (.nc .grid) file as input and outputs a .png and a .eps file. \
|
||||||
|
For further explanations, please look for GMT's manuscripts."
|
||||||
|
dispAuthorInfo "Yi Zhang (zhangyi.cugwuhan@gmail.com)"
|
||||||
|
dispUsage "${0##*/} -i<grid-data> [-r<xmin>/<xmax>/<ymin>/<ymax>] [-c<cpt-file>] [-g] [-G<grad-data>] [-s<x-size>/<y-size>] [-o]"
|
||||||
|
dispOptionShort "-i" "input grid file."
|
||||||
|
dispOptionShort "-r" "data range. The template will detect the input data range automatically, the use of this option will overwrite the range."
|
||||||
|
dispOptionShort "-c" "color cpt, The default is rainbow."
|
||||||
|
dispOptionShort "-g" "use grdgradient. The default is false."
|
||||||
|
dispOptionShort "-G" "provide a different input grid data for the use of grdgradient. This should be used with the '-g' option at the same time."
|
||||||
|
dispOptionShort "-s" "specify the size ratio of the output files, the default is 4i/2i."
|
||||||
|
dispOptionShort "-o" "open file in finder, the default is using imgcat."
|
||||||
|
exit 0;;
|
||||||
|
i)
|
||||||
|
data=$OPTARG;;
|
||||||
|
c)
|
||||||
|
color=$OPTARG;;
|
||||||
|
r)
|
||||||
|
overwrite=1
|
||||||
|
overwriteRange=$OPTARG;;
|
||||||
|
g)
|
||||||
|
plotgrad=1;;
|
||||||
|
G)
|
||||||
|
gradData=$OPTARG;;
|
||||||
|
s)
|
||||||
|
size=$OPTARG;;
|
||||||
|
o)
|
||||||
|
opFile=1;;
|
||||||
|
?)
|
||||||
|
printf "error: unknow argument\nuse -h option to see help information\n"
|
||||||
|
exit 1;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
# 进行必要的参数检查
|
||||||
|
if [[ $data == "null" ]]; then
|
||||||
|
printf "error: no input file name\nuse -h option to see help information\n"
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
# 初始化临时文件名
|
||||||
|
cptfile=user.cpt
|
||||||
|
psfile=${data%.*}.ps
|
||||||
|
jpgfile=${data%.*}.png
|
||||||
|
# 获取网格范围
|
||||||
|
if [[ $overwrite == 1 ]]; then
|
||||||
|
range=${overwriteRange}
|
||||||
|
else
|
||||||
|
range=$(gmt_get_gridregion ${data})
|
||||||
|
fi
|
||||||
|
|
||||||
|
gmt grd2cpt ${data} -C${color} -R${range} -Z -D > $cptfile
|
||||||
|
if [[ $plotgrad == 1 ]]; then
|
||||||
|
gradfile=${data%.*}Grad.nc
|
||||||
|
if [[ $gradData == 'null' ]]; then
|
||||||
|
gmt grdgradient ${data} -G${gradfile} -Nt -A0/45
|
||||||
|
else
|
||||||
|
gmt grdgradient ${gradData} -G${gradfile} -Nt -A0/45
|
||||||
|
fi
|
||||||
|
gmt grdimage ${data} -R${range} -C${cptfile} -I${gradfile} -JX${size} -P > $psfile
|
||||||
|
else
|
||||||
|
gmt grdimage ${data} -R${range} -C${cptfile} -JX${size} -P > $psfile
|
||||||
|
fi
|
||||||
|
|
||||||
|
gmt psconvert $psfile -A -TEG -E500
|
||||||
|
# 删除临时文件 使用linux终端rm命令
|
||||||
|
rm $cptfile $psfile gmt.history
|
||||||
|
if [[ $plotgrad == 1 ]]; then
|
||||||
|
rm $gradfile
|
||||||
|
fi
|
||||||
|
if [[ $opFile == 1 ]]; then
|
||||||
|
# 打开图片文件 此命令使用MacOS终端open命令
|
||||||
|
open $jpgfile
|
||||||
|
else
|
||||||
|
# 在终端显示图像 此命令需要imgcat.sh脚本和iTerm终端
|
||||||
|
imgcat $jpgfile
|
||||||
|
fi
|
||||||
|
fi
|
Loading…
Reference in New Issue
Block a user