Previous Up Next

gpv備忘録

gpvは、GPhysライブラリに付属のコマンドラインツール gpview を私的に建て増し改造したものである。今のところ非公開。

独自に追加した機能が多くなってきたので、自分用備忘録として、ここにまとめる。

gpvという名前は、コマンド入力を簡単にするために gpview から iew をとったもの。

気象庁のデータ形式GPVと同じ名前だが、無関係である。# 名前がかぶってしまった...

REQUIRED LIBRARIES

USAGE

The first command form is

gpv gturl1 gturl2 gturl3 ... (options)

where the format of the gturl is

filepath@varname(,dimname=pos1(:pos2(:thinning_intv))(,dimname=...))

The second command form is

gpv gtfile1 gtfile2 ... --var url (options)

where the format of the url is

varname(,dimname=pos1(:pos2(:thinning_intv))(,dimname=...))

TIPS(gpviewでも使える小技)

独自に追加した機能

GPV CLASS

新たにクラスGPVを定義し、コマンドラインから実行できるgpvの機能を、rubyスクリプトのなかで使用できるようにした。 任意のrubyスクリプト内で

require "/Users/hiroki/RubyScripts/gpv"

などとすることで、使用可能となる。

Methods

new

GPVクラスのインスタンスを作成する。

a = GPV.new

作成したGPVクラスのオブジェクトは、そのなかで、オプション設定(rangeなど)を保持する(インスタンス変数として保持される)。

main(gpary=nil,string=nil,window=0)

gpvを実行する。引数は全て省略可能で、省略時の動作は、コマンドラインでgpvを実行した場合と同じ。返り値は処理された結果のGPhysオブジェクトのArray。

GPV.new.main # 単に実行するだけ
a = GPV.new 
gpa = a.main # 演算結果を返り値として取得できる
a.main(gpa,"--mean time") # 任意のArray of GPhysを与えられる

set_options(string=nil)

string で与えたオプションを設定する。省略時はARGVを読んで設定する。

その他

main から呼ぶために、機能別に幾つかメソッドを定義しているが、mainを通さずに個別に使って正常に動作するかは未確認。

OPTIONS

* は独自に追加したオプションを表す。使用時に * は不要。
<abc> は必須項目。[a|b|c]は選択項目。(abc)は省略可能項目。

GLOBAL OPTIONS

--help

print this message.

--var <url>

set the variable name and slicing parameters.

--vf*

use variable whose name is included in the filename.

--pry*

start pry after drawing the first figure.

--auto_pry*

automatically execute the given scripts like as in pry after drawing the first figure.

--silent*

start pry after drawing the first figure and automatically exec the given command.

--list*

execute gplist instead.

--read_csv* <num>

read csv file.
the first column is used for the axis and the other columns are used for data values.
<num> specifies how many data columns you want to read.

--read_fits*

read fits format image. automatically added if file extension is .fits. variable name must be given by number usually 1. (e.g., file.fits@1)

--calendar360*, --calendar365*

set this option if the calendar type is "360_day calendar" or "365_day calendar". Usually, calendar type will be automatically directed.

--set_missing_value* (<float>)

replace the missing values to given value and validate then. default value is 0.0.

--invalidation* <Float or Range>

invalidate the given value or range.

--join*

join muliple gturls along with an axis whose values are continual across the gturls and are not duplicate.

--extend_backward_along* <dim>,<len>[,<value>]

extend backward the object along <dim>-axis for <len> numbers with <value>.

--thinning* <dim>

set data thinning.

--nothinning* <dim>

prevent auto data thinning.

--parallel* <dim>

use parallel.

--cyclic_extension* <dim:num>[,<dim:num>

extend the data along <dim> with <num> grid(s) cyclically. e.g., –cyclic_extension x:4,y:4.

ANALYSIS OPTIONS

--mean <dim>

mean along axis <dim>.

--stddev <dim>

standard deviation along axis <dim>.

--max* <dim>

max values along axis <dim>.

--min* <dim>

min values along axis <dim>.

--eddy <dim>

deviation from mean along axis <dim>.

--sum* <dim>

sum along axis <dim>.

--integrate* <dim>

integration along axis <dim>.

--diff

calculate the difference of two variables.
you must provide two gturls whose size and dimension are same.

--operation <math_func>

operation of the specified math function on the data.
<math_func> should be a math function with one argument such as log10, sqrt, sin, etc.

--add*

calculate the sum of multiple variables.
you must provide two or more gturls whose size and dimension are same.

--divide*

calculate 1st gturl / 2nd gturl.
you must provide two gturls whose size and dimension are same.

--srot*

calculate rotation on sphere (with Earth radius) with 1st gturl and 2nd gturl.

--sdiv*

calculate divergence on sphere (with Earth radius) with 1st gturl and 2nd gturl.

--HKE*

calculate horizontal kinetic energy with 1st gturl and 2nd gturl.

--running_mean*, --rm* <dim,span(,skip)>

calculate the running mean along <dim> with a window of <span>.
multiple dims are not supported.
if integer <skip> is given, the date thinning is performed to the running mean.
for example, --rm t,12,12 to monthly data gives annual mean series (one value per year).

--global_mean*, --gm*

calculate the global mean considering the weight along latitude.
dims of longitude and latitude must be the 1st and 2nd dims, respectivly.

--ensemble_mean*, --em* (<num>)

calculate the ensemble mean.
you must provide two or more gturls whose size and dimension are same.
if <num> is given, ensemble mean will be calculated for each <num> gturls. if "concat" is given for <num>, provided gturls are concatenated along new dimension "member".

--derivative* <dim>

calculate the derivative alog axis <dim>.
GPhys.threepoint_O2nd_deriv is used.

--lowpass*, --lp* <dim>,<wn>

apply lowpass filter to <dim>-th dimension with wavenumber <wn> using fft.
i.e., this cut off the wavenumbers greater than <wn>.
<dim> must be integer. dimname is not supported yet.

--highpass*, --hp* <dim>,<wn>

apply highpass filter to <dim>-th dimension with wavenumber <wn> using fft.
i.e., this cut off the wavenumbers less than <wn>.
<dim> must be integer 0, 1, 2, or 3. dimnames and wn > 3 are not supported yet.

--power_spectra*, --ps* <dim(,any)>

calculate power spectra using fft along <dim>-th dimension.
by default, wavenumber is used for axis.
if any argument is given after comma, wavelength or period is used for axis.

--cut* dimname=pos1(:pos2(:thinning_intv))(,dimname=...)

apply cut, slice, and/or thinning after mathmatical operation.

--histogram* (any)

draw 1D histogram.
options "--int -n" and "--range xmin:xmax[,ymin:ymax]" can be used to set bins number and range.
options "--exch", "--title", and "--overplot n" also can be used.
if any argument is given, histogram are shown in percentage (%) not in numbers.

--radius* <radius>

set planetary radius.

--Omega* <Omega>

set planetary rotation rate in s−1 unit.

--composite* <dim,span,skip>

if <skip> is not given or zero, calculate mean with interval <span>.
i.e., --composite time,12 calculates mean of each month from monthly mean data.
if <skip> is given, calculate composite mean for dimension <dim>.
with length <span> with intercval of <skip>.
i.e., --composite time,3,9 calculates mean for time=0,1,2,12,13,14,24,...
this can be used to calculate seasonal mean such as DJF from mounthly mean data.

--split_axis* <dim,span,(newaxisname)>

split the <dim> axis with <span>.
for example, --split_axis time,12 applied to monthly data splits the time axis to year and month axis. name of the new axis can be given by [newaxisname]

--flip_data* <dim(,dim,..)>

flip (turn over) the data and axis of <dim>th dimension.
<dim> must by given by integer(s).

--interpolate_pole*

extend the latitude axis to have grid points on each pole (-90/+90 deg), and interpolate the pole values by mean of values on surrounding grid points.
this assumes the data has lon and lat in its first and second dimension, respectivly.

--normalize* [ |mean|float]

normalize data by initial (when no arg.) or mean or given value when data is one-dimension. normalization for other data is not implemented yet.

--regrid* [8-640]

interpolate to the Gausian latitude and cooresponding longitude.
number of lat-grid points is required and available numbers are
8, 16, 32, 64, 94, 96, 120, 128, 160, 240, 256, 320, 480, 640.

--sig2p <gturl of PS>

transform sigma coordinate to pressure coordinate. gturl of surface pressure must be given.

--set_assoc_coords <gturl>

set <gturl> as an associate coordinate.

--interpolate <args>

interpolate after operations.
<args> can be axis_name=90 or axis_name=[0,90,180,270] or axis_name=0:360:4 for example.
1) axis_name=90 style gives interpolation at the location and rank shrinks.
2) axis_name=[0,90,180,270] style gives interpolation for multiple location and use then as an axis.
3) axis_name=0:360:4 style similar to (2) but 0:360:4 means from 0 to 360 with separation of (360-0)/4.
multiple interpolation is not supported yet.

--extrapolation

enable extrapolation, when using --interpolate option.

--addingup <dim>[,<dim>,...]

adding up values along <dim>; i.e., val[i] = val[0..i].sum

--sht

use spherical_harmonics_next module for srot, sdiv.

--offset* <float>

offset the data by <float>.

--ES*

calculate Horizontal Kinetic Energy Spectra from U given as 1st gturl and V given as 2nd gturl.

--zonal_shift* <speed at equator in m/s>

shift entire field zonally as it is advected by the solid body rotation of <speed at equator in m/s>.

DRAWING OPTIONS

--wsn [1-4]

this is for dcl-5*. use --file for dcl-6*. set work staion number. each number represent output device:
1 : X window.
2 : PS file. (named dcl.ps)
3 : Tcl/Tk file.
4 : GTK Windows (depend on dcl-5.3)

--file* [png|eps|svg|pdf](,filename)

draw in file with given format. available formats are png, eps, and pdf.
putting comma and file name set the name of output file. (default: dcl)
this is for dcl-6*. use --wsn for dcl-5*.

--size* <num>

set the size factor of x-window (default: 1.25).

--clrmap [1-78 or filename]

set colormap to draw tone/contour. filename of DCL colormap is also acceptable.

--itr [1-4,5-7,10-15,20-23,30-33]

set axis scale. default is 1.
1 : linear scale for x/y axis
2 : linear scale for x , log scale for y axis
3 : log scale for x , linear scale for y axis
4 : log scale for x/y axis

--similar <simfac,vxoff,vyoff>

(for 5<=itr<=7) set similarity parameters which are fed in DCL.grssim.

--map_axis <uxc,uyc,rot>

(for 10<=itr<=33) set mapping parameters which are fed in DCL.umpcnt.

--map_radius <radius>

(for itr>=20) set clipping radius (degree) around the tangential point. Deafault=90.

--xcoord <xcoord>

name of x-coordinate (use for associate coordinates)

--ycoord <ycoord>

name of y-coordinate (use for associate coordinates)

--title <title>

set title of figure

--subtitle <subtitle>

set subtitle, which locates just below the title.

--noetitle

do not print title. equivalent to –title ""

--aspect <aspect>

set aspect ratio of Viewport. default is 2.0.

--noannotate

not draw annotations.

--animate, --anim <dim>

plot animation along <dim>. <dim> must be name of dimension.

--alternate, --Ga

enable to backing store.

--nowait, --Gw

not wait for any actions if animate

--reverse, --Gr

plot animation reversible if animate

--smooth, --Gaw

equal to --anlternate--nowait

--exch

exchange(transpose) x/y axis.

--m, --map <map_type>

plot map. itr number must be set. this option is neglect if itr number is 1-4.
abailable map type is coast_world, border_world, plate_world, state_usa, coast_japan, pref_japan.

--time_ax [nil|false|h|ymd]

specify type of calendar-type time axis
nil (=> auto slection)
false (=> do not use the time axis even if the units of the axis is a time one with since field)
"h" (=> like nil, but always use the hour-resolving datetime_ax method in dclext_datetime_ax.rb)
"ymd" (=> like "h" but for y-m-d type using DCL.uc[xy]acl)

--xx:yyyy=value

specify Dennou Club Library internal variable.
’xx’ is a package name prefix of DCL (eg. sg=>sgpack).
’yy’ is a variable name of DCL.
’value’ is a value of the DCL variable.

--sldiv* <[y|t],m,n>

split the drawing window into multiple panel.
argument should be provied in DCL.sldiv form.
e.g., --sldiv y,2,2 make 2x2 window.

--title_array* <title1,title2,...>

set multiple titles given as --title_array hoge,foo,bar; this gives the title "hoge" to the 1st figure, "foo" to the 2nd one, and "bar" to the 3rd one.

--linearline* <arg>

draw linear line expressed bay <arg>.
<arg> should be "x=<value>", "y=<value>", "x=y", or "y=x", where <value> is integer or float.
multiple lines can be drawn by setting multiple args separated by comma, such as "x=0,y=0".
ymd type expression is acceptable eg., y2000m1d1.
line index and type can be set by "i=num" and "t=num"; this must be written before expression of lines.
For example "–linearline i=22,t=3,y=0" draws y=0 line with index = 22 and type = 3.

--miscindex* <num>

set line index (color and width) of title, label, frame, etc.

--nocolor*

draw without color.

--nolabels*

draw without any labels.

--fact* <num>

factor for text size.

--lwf* <num>

factor for line width on PDF.

--textbox* <text>(,<num>,[l|c])

draw textbox, legends, and/or color bar in frame #<num>.

--xint* <xlabelint[:division]>

set x-axis’ label-tickmark interval and number of number of division between two label-tickmarks e.g., --xint 10:5 draws label interval with 10 and sub-tickmark interval of 2 (=10/5).

--yint* <ylabelint[:division]>

same as –xint but for y-axis.

LINE/MARK OPTIONS

--line

make line plot forced. (about first 1D)

--mark

make mark plot forced. (about first 1D)

--index

set DCL line index, which set the color/thickness of the line primitive. please see DCL documents.

--index_array* <num,num,...>

set DCL index of multiple lines.

--type

set line type.

--range <min:max>

set min/max value for line plot. min or max must be set.

--overplot

set number of lines on each figure. lines are distinguished with color.
use with --nocolor option if you want to distinguish lines by line type.

--overplot_color, --Opc

multiple lines are distinguished with color rather than line type.
(same as --overplot.)

--right_axis*

use with "--overplot 2" and draw 2nd y-axis in right side for 2nd gturl.
range of 2nd y-axis can be specified by --range left_min1:left_max,right_min:right_max.

--overplot_rm* <span>

overplot the running mean with thick line. running mean span is required.

--overplot_stddev*

overplot the mean +/- stddev (like errorbars); this must be used with "--mean" option.

--fill*

fill regions between plotted line and zero (or min or max) line.
if histogram, fill the boxes.

--xrange*

set x-axis range for line plot.

--yrange*

set y-axis range for line plot.

--step*

make line plot to step shape.

--zerocenter*

set y-axis center in line plot figure to zero.

--nolegend*

do not show legend.

--axis_options* <var1=val1,var2=val2,...>

set some axis options of USPACK (i.e., xoff/yoff, xfac/yfac, dxt/dyt, dxl/dyl).

CONTOUR/TONE OPTIONS

--shade

make contour and tone plot.

--noshade

make contour plot, without tone.

--nocont

make tone plot, without contour.

--range <min:max>

set min/max value for contour/tone plot. min or max must be set.

--crange <min:max>

set min/max value for contour plot. this is more dominant than --range

--srange <min:max>

set min/max value for tone plot. this is more dominant than --interval/int

--irange* <min:max>

same as --srange but tone regions of (-infinity, min] and [max to +infinity) are added.
use with --int option is recommended.

--interval,--int <num>

set interval value for contour/tone plot.
set the number of lines if you set negative value.

--cint <num>

set interval value for contour plot. this is more dominant than --interval/int

--sint <num>

set interval value for tone plot. this is more dominant than --interval/int.

--levels <num,...>

set values of contour/tone levels.

--clevels <num,...>

set values of contour levels.

--slevels <num,...>

set tone of contour levels.

--patterns <num,...>

set each patterns for tone plot.

--tone [a|e|f|b|c]

set tone subroutine
a (=> tone routine is selected automatically depending on the datasize)
e (=> DCL.uetone is used)
f (=> DCL.uetonf is used)
b (=> DCL.uetonb is used)
c (=> DCL.uetonc is used)

--nocolorbar

do not draw color bar

--nozero

do not draw zero contour

--udsfmt <strings>

change contour label format. see UDCNTR/DCL manual for the format.

--ocean*, --land*

mask data with ocean/land info, https://www.ncl.ucar.edu/Applications/Data/cdf/landsea.nc.
you need to download landsea.nc and place it on correct dir.

--clr_range* <range>

set color map range. maximum range is 10:99. default is 15:94.

--fullcolor* ([1|2])

draw full color figure. if arg is 1 or omitted, 1 gturl is drawn as tone diagram. if 2 is given, you need to provide 2 gturls. 1st one is used for color (hue) and 2nd one is used for brightness (value). --range xmin:xmax,ymin:ymax can be used.

--xmean*

draw line plot of mean along x-axis of the tone/contour plot on the right side.

--ymean*

draw line plot of mean along y-axis of the tone/contour plot below.

--maskshading* [gturl,maskval,ipat]

draw a mask for values less than or equal to maskval (optional; defalult is 0) with given gturl (optional; default is same as previouslt drawn GPhys) by ipat pattern number (optional; defalult is 1025).

--bothsides*

draw bothsides of the planet when itr = 30.

MULTI VARS OPTIONS

--scatter* (<xtitle,ytitle>)

make scatter plot with provided 2 gturls.
1st and 2nd gturls will be used for x- and y-axes, respectively.
titles of x- and y- axes can be specified by arguments xtitle,ytitle (optional) range of each axis can be specified by option --range [xmin:xmax,ymin:ymax] format.

--color_scatter* (<xtitle,ytitle>)

make color scatter plot with provided 3 gturls.
1st and 2nd gturls are used for x- and y-axes, respectively.
3rd gturl is used for color of marks.
titles of x- and y- axes can be specified by arguments xtitle,ytitle (optional).
range of each axis and color can be specified by option --range [xmin:xmax,ymin:ymax,zmin:zmax] format

--cot*

contour over tone. draw tone with 1st gturl and overplot contour with 2nd gturl.

--histogram2D*

draw 2D histogram with two gtulrs. if any argument is given, histogram are shown in percentage (%) not in numbers.
options "--int -n" and "--range xmin:xmax[,ymin:ymax]" can be used to set bins number and range.
options "--sint [-]n" and "--srange xmin:xmax" can be used to set tone interval[number] and range.
options "--exch" and "--title" also can be used.

--rmap* <dim>

draw 2D map of correaltion between 1st and 2nd gturls along <dim> axis.
<dim> can be axis name (string) or dimension number (integer), but only one axis is acceptable.

--mvo* <math operation>

Apply mathematical operation for multiple gturls.
In <math operation>, "x" indicates the 1st gturl, "y" the 2nd, "z" the 3rd, "u" the 4th, "v" the 5th, and "w"the 6th.
gturls more than 6 cannot be used, and this cannot be used repeatedly.

  gpv file.nc@{Uwind,Vwind} --mvo "(x*x + y*y)/2"
  

--vector*

draw a vector plot.
When 2 gturls are given, 1st one and 2nd one are used for x- and y-components of the vectors.
When 3 or 4 gturls are given, 2nd one and 3rd one are used for x- and y-components of the vectors, and tone of 1st one and counter of 4th one are overlaid.
If the 1st dim is lon or lat and the 2nd dim is not lon or lat, vectors are scaled by the geometry aspect ratio.

--vfact* <factor>

use with --vector to change the size of the vector by <factor>.

--vkeep*

use with --vector to keep the size of unit vector as that of the first plot.

--vint* <xint>(,yint)

use with --vector to set the intervals of grid points to draw vectors.

OUTPUT OPTIONS

--nc* (<outfilename>)

output operated GPhys object as NetCDF file. output file name can be specified.
Default name is "out.nc". cannot used with "--anim".
When multiple variables are open, they are stored in one file if possible.

--nc4* (<outfilename>)

output operated GPhys object as NetCDF ver 4 file with compression.
output file name can be specified. Default name is "out.nc". cannot used with "--anim".
When multiple variables are open, they are stored in one file if possible.
Need longer time to write out but smaller file will be made.

--nc4a* (<outfilename>)

output operated GPhys object continually with along time dim, as NetCDF ver 4 file with compression.

--rename* <varname>

rename the output variable name and "long_name" by <varname>.

--long_name* <longname>

rename the output "long_name" of the variable by <longname>.

--unit* <unit>

reset the unit of the operated variable by <unit>.

--axis_units_name* <axdim:unit[:axname:operation]>[,axdim:unit:axname:operation]

change unit (and name) of axis.
multiple axes can be given as

 --axis_units_name ax0:deg:lon,ax2:km:height:/1000   
  

for example. mathematical operation can be applied to the axis values.

--output_assoc_coords*

use with –nc4 or –nc to output associate coordinate as netcdf file.

--replace_axis* <axN:val1,val2,val3,...>

replace the value of the axis <axN> (N is 0, 1, 2,...) with given Array [val1, val2, val3, val4,...]

--csv* (<outfilename>)

output operated GPhys object as CSV file. operated GPhys object must be one dimensional. output file name can be specified. Default name is "out.csv".
if used with "--anim", GPhys object for last shown figure is outputted.

--nodraw*

do not draw any figures.

--crop*

crop (trim) output png or pdf files. this should be used with --noannotate option.

--ntype* <type>

convert type of values. <type> should be "sfloat", "float", etc.

--gif*

output gif animation. this must be used with –anim and –file png options.

--mp4* (<frame rate>)

output mp4 animation. frame rate can be given. this must be used with –anim and –file png options.


Previous Up Next