gphys 1.5.2 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +134 -48
- data/LICENSE.txt +1 -1
- data/bin/gpprint +61 -8
- data/bin/gpview +13 -2
- data/ext/numru/gphys/dim_op.c +217 -0
- data/gphys.gemspec +2 -3
- data/lib/numru/dclext.rb +13 -4
- data/lib/numru/ggraph.rb +45 -19
- data/lib/numru/gphys/axis.rb +29 -2
- data/lib/numru/gphys/gphys.rb +26 -1
- data/lib/numru/gphys/gphys_dim_op.rb +87 -6
- data/lib/numru/gphys/gphys_netcdf_io.rb +1 -0
- data/lib/numru/gphys/grads_gridded.rb +6 -3
- data/lib/numru/gphys/version.rb +1 -1
- metadata +4 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13c32ab65077429fc0f5c4799d6986e2cb672dfa
|
4
|
+
data.tar.gz: b6cd30441caba1b246ae90b6ae9b8f090364cbce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc75b8a323b972ace9a8b0beb53fbedf8165409d9613f655bfaf08090c751fa8c4b594f09d51c53b8592a4c9b3be85e32447792cb78bf3ab7f94772aea3d78b2
|
7
|
+
data.tar.gz: c25b9805785e96f88ecf47e37855169cc4efecc29520d3df74da9385d57c811bd5de44c8f684fdcdc9cf5657972e69338c6699e906a90099f040d517ba5b9725
|
data/ChangeLog
CHANGED
@@ -1,3 +1,113 @@
|
|
1
|
+
2018-01-26 Takeshi Horinouchi
|
2
|
+
updated the years
|
3
|
+
|
4
|
+
M LICENSE.txt
|
5
|
+
|
6
|
+
2018-01-26 Takeshi Horinouchi
|
7
|
+
To release ver.1.5.3
|
8
|
+
|
9
|
+
M lib/numru/gphys/version.rb
|
10
|
+
|
11
|
+
2018-01-26 Takeshi Horinouchi
|
12
|
+
regression_line : added options annot_cor and annot_r2
|
13
|
+
|
14
|
+
M lib/numru/ggraph.rb
|
15
|
+
|
16
|
+
2018-01-26 Takeshi Horinouchi
|
17
|
+
Changed to use first2Dreally & first1Dreally where appropriate
|
18
|
+
|
19
|
+
M lib/numru/ggraph.rb
|
20
|
+
|
21
|
+
2018-01-26 Takeshi Horinouchi
|
22
|
+
Added new mehotds: firstNDreally, first1Dreally, first2Dreally etc
|
23
|
+
|
24
|
+
M lib/numru/gphys/gphys.rb
|
25
|
+
|
26
|
+
2018-01-26 Takeshi Horinouchi
|
27
|
+
Made the following methods class methods of GPhys (in addition to being private methods as before): c_running_mean, c_running_mean_2D, c_bin_mean, c_bin_sum
|
28
|
+
|
29
|
+
M ext/numru/gphys/dim_op.c
|
30
|
+
|
31
|
+
2017-12-25 Takeshi Horinouchi
|
32
|
+
bug fix
|
33
|
+
|
34
|
+
M lib/numru/gphys/gphys_dim_op.rb
|
35
|
+
|
36
|
+
2017-12-23 Takeshi Horinouchi
|
37
|
+
write_grid: To handle (avoid) multiple output of associated coordinates
|
38
|
+
|
39
|
+
M lib/numru/gphys/gphys_netcdf_io.rb
|
40
|
+
|
41
|
+
2017-12-23 Takeshi Horinouchi
|
42
|
+
modified: lib/numru/gphys/gphys_netcdf_io.rb
|
43
|
+
runnin_mean : Changed the default boundary condition to nil (automatic selection among BC_SIMPLE & BC_CYCLIC)
|
44
|
+
|
45
|
+
M lib/numru/gphys/gphys_dim_op.rb
|
46
|
+
|
47
|
+
2017-12-14 Takeshi Horinouchi
|
48
|
+
Merge branch 'master' of dennou-k.gfd-dennou.org:/GFD_Dennou_Club/ftp/arch/ruby/products/gphys/git_repos/gphys
|
49
|
+
|
50
|
+
2017-12-14 Takeshi Horinouchi
|
51
|
+
added a new method GPhys#running_mean_2D, which is good for data with missing.
|
52
|
+
|
53
|
+
M ext/numru/gphys/dim_op.c
|
54
|
+
M lib/numru/gphys/gphys_dim_op.rb
|
55
|
+
|
56
|
+
2017-12-14 Takeshi Horinouchi
|
57
|
+
bug fix
|
58
|
+
|
59
|
+
M lib/numru/gphys/axis.rb
|
60
|
+
|
61
|
+
2017-12-14 Takeshi Horinouchi
|
62
|
+
updated gemspec file
|
63
|
+
|
64
|
+
M gphys.gemspec
|
65
|
+
|
66
|
+
2017-07-15 Satoki Tsujino
|
67
|
+
bug fix (bi and bj in lib/numru/gphys/grads_gridded.rb).
|
68
|
+
|
69
|
+
M lib/numru/gphys/grads_gridded.rb
|
70
|
+
|
71
|
+
2017-07-14 Takeshi Horinouchi
|
72
|
+
bug fix (thanks to dvdvlop emails from Tsujino&Otobe san on 2017-0714)
|
73
|
+
|
74
|
+
M lib/numru/gphys/grads_gridded.rb
|
75
|
+
|
76
|
+
2017-07-07 Takeshi Horinouchi
|
77
|
+
Merge remote-tracking branch 'origin/master'
|
78
|
+
|
79
|
+
2017-07-07 Takeshi Horinouchi
|
80
|
+
bug fix
|
81
|
+
|
82
|
+
M lib/numru/dclext.rb
|
83
|
+
|
84
|
+
2017-06-07 takepiro
|
85
|
+
* bin/gpview: int option bug fixed.
|
86
|
+
* bin/gpprint: options added.
|
87
|
+
|
88
|
+
M bin/gpprint
|
89
|
+
M bin/gpview
|
90
|
+
|
91
|
+
2017-05-20 Takeshi Horinouchi
|
92
|
+
further update
|
93
|
+
|
94
|
+
M lib/numru/dclext.rb
|
95
|
+
|
96
|
+
2017-05-16 Takeshi Horinouchi
|
97
|
+
Added a new method Axis#nearest_index
|
98
|
+
|
99
|
+
M lib/numru/gphys/axis.rb
|
100
|
+
|
101
|
+
2017-05-16 Takeshi Horinouchi
|
102
|
+
complement to the previous commit
|
103
|
+
|
104
|
+
M lib/numru/dclext.rb
|
105
|
+
|
106
|
+
2017-05-07 Takeshi Horinouchi
|
107
|
+
DCLExt::ue_linear_levels : added handling of NaN
|
108
|
+
|
109
|
+
M lib/numru/dclext.rb
|
110
|
+
|
1
111
|
2017-04-17 Takeshi Horinouchi
|
2
112
|
1.5.1 --> 1.5.2
|
3
113
|
|
@@ -137,8 +247,7 @@ M ext/numru/gphys/ext_init.c
|
|
137
247
|
2016-06-08 Takeshi Horinouchi
|
138
248
|
file renamed (git mv)
|
139
249
|
|
140
|
-
|
141
|
-
A ext/numru/gphys/quad_mesh_sample.c
|
250
|
+
R100 ext/numru/gphys/mesh_resample.c ext/numru/gphys/quad_mesh_sample.c
|
142
251
|
|
143
252
|
2016-06-08 Takeshi Horinouchi
|
144
253
|
created an efficient quadrilateral mesh resampler
|
@@ -403,18 +512,12 @@ move extension files to ext/numru/gphys/
|
|
403
512
|
|
404
513
|
extension files should be located in "ext/" directory.
|
405
514
|
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
A ext/numru/gphys/multibitIO.c
|
413
|
-
D ext_coord.c
|
414
|
-
D ext_init.c
|
415
|
-
D extconf.rb
|
416
|
-
D interpo.c
|
417
|
-
D multibitIO.c
|
515
|
+
R100 dim_op.c ext/numru/gphys/dim_op.c
|
516
|
+
R100 ext_coord.c ext/numru/gphys/ext_coord.c
|
517
|
+
R100 ext_init.c ext/numru/gphys/ext_init.c
|
518
|
+
R100 extconf.rb ext/numru/gphys/extconf.rb
|
519
|
+
R100 interpo.c ext/numru/gphys/interpo.c
|
520
|
+
R100 multibitIO.c ext/numru/gphys/multibitIO.c
|
418
521
|
|
419
522
|
2015-03-10 Shin-ichi Takehiro
|
420
523
|
bin/gpview: History removes from the output of --help
|
@@ -920,14 +1023,10 @@ M lib/numru/gphys/grid.rb
|
|
920
1023
|
2014-05-06 Takeshi Horinouchi
|
921
1024
|
Moved old tests (which do not use unit test) from test/ to test_old/
|
922
1025
|
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
A test_old/eof_slp.rb
|
928
|
-
A test_old/mltbit.dat
|
929
|
-
A test_old/test_ep_flux.rb
|
930
|
-
A test_old/test_multibitIO.rb
|
1026
|
+
R100 test/eof_slp.rb test_old/eof_slp.rb
|
1027
|
+
R100 test/mltbit.dat test_old/mltbit.dat
|
1028
|
+
R100 test/test_ep_flux.rb test_old/test_ep_flux.rb
|
1029
|
+
R100 test/test_multibitIO.rb test_old/test_multibitIO.rb
|
931
1030
|
|
932
1031
|
2014-05-06 Takeshi Horinouchi
|
933
1032
|
Unit test for Axis class
|
@@ -1042,16 +1141,11 @@ Revert "the extention library is moved into ext/"
|
|
1042
1141
|
|
1043
1142
|
This reverts commit 9c59f9b4131150bfbc3d7a3087af8c8f1df90c47.
|
1044
1143
|
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
A ext_coord.c
|
1051
|
-
A ext_init.c
|
1052
|
-
A extconf.rb
|
1053
|
-
A interpo.c
|
1054
|
-
A multibitIO.c
|
1144
|
+
R100 ext/ext_coord.c ext_coord.c
|
1145
|
+
R100 ext/ext_init.c ext_init.c
|
1146
|
+
R100 ext/extconf.rb extconf.rb
|
1147
|
+
R100 ext/interpo.c interpo.c
|
1148
|
+
R100 ext/multibitIO.c multibitIO.c
|
1055
1149
|
|
1056
1150
|
2013-04-15 Takeshi Horinouchi
|
1057
1151
|
Revert "Updated extconf.rb; added $vendorarchdir to the search path etc."
|
@@ -1076,16 +1170,11 @@ M .gitignore
|
|
1076
1170
|
2013-03-28 Takeshi Horinouchi
|
1077
1171
|
the extention library is moved into ext/
|
1078
1172
|
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
D ext_coord.c
|
1085
|
-
D ext_init.c
|
1086
|
-
D extconf.rb
|
1087
|
-
D interpo.c
|
1088
|
-
D multibitIO.c
|
1173
|
+
R100 ext_coord.c ext/ext_coord.c
|
1174
|
+
R100 ext_init.c ext/ext_init.c
|
1175
|
+
R100 extconf.rb ext/extconf.rb
|
1176
|
+
R100 interpo.c ext/interpo.c
|
1177
|
+
R100 multibitIO.c ext/multibitIO.c
|
1089
1178
|
|
1090
1179
|
2013-03-27 Takeshi Horinouchi
|
1091
1180
|
(test) deleted the dummy file
|
@@ -1100,8 +1189,7 @@ A tmp.txt
|
|
1100
1189
|
2013-03-27 Takeshi Horinouchi
|
1101
1190
|
Renamed the current ChangeLog to back up.
|
1102
1191
|
|
1103
|
-
|
1104
|
-
D ChangeLog
|
1192
|
+
R100 ChangeLog .ChangeLog.until201303
|
1105
1193
|
|
1106
1194
|
2013-03-27 Takeshi Horinouchi
|
1107
1195
|
Registered files (patterns) to ignore in the repository
|
@@ -4001,8 +4089,7 @@ M lib/numru/vizshot.rb
|
|
4001
4089
|
2006-08-31 horinout
|
4002
4090
|
* lib/numru/vizshot.rb <-- lib/numru/easyviz.rb : renamed
|
4003
4091
|
|
4004
|
-
|
4005
|
-
A lib/numru/vizshot.rb
|
4092
|
+
R096 lib/numru/easyviz.rb lib/numru/vizshot.rb
|
4006
4093
|
|
4007
4094
|
2006-08-31 horinout
|
4008
4095
|
* support dump_code_and_data
|
@@ -6179,8 +6266,7 @@ Mon Jan 10 2005 T Horinouchi (partly < D Tsukahara)
|
|
6179
6266
|
M ChangeLog
|
6180
6267
|
A bin/gpprint
|
6181
6268
|
A bin/gpview
|
6182
|
-
|
6183
|
-
A bin/grads2nc_with_gphys
|
6269
|
+
R084 bin/grads2nc.rb bin/grads2nc_with_gphys
|
6184
6270
|
D bin/install.rb
|
6185
6271
|
M install.rb
|
6186
6272
|
|
data/LICENSE.txt
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
GPhys is copyrighted free software by Takeshi Horinouchi and
|
2
2
|
GFD Dennou Club (http://www.gfd-dennou.org/).
|
3
3
|
|
4
|
-
Copyright 2003-
|
4
|
+
Copyright 2003-2018 (C) Takeshi Horinouchi and GFD Dennou Club
|
5
5
|
(http://www.gfd-dennou.org/) All rights reserved.
|
6
6
|
|
7
7
|
Redistribution and use in source and binary forms, with or without
|
data/bin/gpprint
CHANGED
@@ -14,18 +14,29 @@ texts with line feeding to avoid long lines and are made to stdout.
|
|
14
14
|
|
15
15
|
= USAGE
|
16
16
|
|
17
|
-
% gpprint url
|
17
|
+
% gpprint [options] url
|
18
18
|
|
19
19
|
where the format of the url is
|
20
20
|
|
21
21
|
path[@|/]varname[,dimname=pos1[:pos2[:thinning_intv]][,dimname=...]]
|
22
22
|
|
23
|
+
= OPTIONS
|
24
|
+
|
25
|
+
:-h, --help
|
26
|
+
print this message.
|
27
|
+
:-l, --long
|
28
|
+
print with "%f".
|
29
|
+
:-e, --exp
|
30
|
+
print with "%e".
|
31
|
+
:-f format, --fmt format
|
32
|
+
set print format.
|
33
|
+
|
23
34
|
= EXAMPLES
|
24
35
|
|
25
36
|
% gpprint data.nc@temp
|
26
|
-
% gpprint data.nc@temp,lon=135.0
|
27
|
-
% gpprint data.nc@temp,lon=130:150,lat=0
|
28
|
-
% gpprint data.nc@temp,lon=130:150,lat=0:90:2
|
37
|
+
% gpprint -l data.nc@temp,lon=135.0
|
38
|
+
% gpprint -e data.nc@temp,lon=130:150,lat=0
|
39
|
+
% gpprint -f " %10.3f," data.nc@temp,lon=130:150,lat=0:90:2
|
29
40
|
|
30
41
|
= HISTORY
|
31
42
|
|
@@ -36,6 +47,7 @@ where the format of the url is
|
|
36
47
|
2005/08/23 S Takehiro (common methods to gp* command moved to gpcommon.rb)
|
37
48
|
2010/03/10 Y SASAKI (change help block into RD format)
|
38
49
|
2012/02/19 S Takehiro (description for gturl format updated)
|
50
|
+
2017/04/02 S Takehiro (options added)
|
39
51
|
|
40
52
|
=end
|
41
53
|
##################################################
|
@@ -44,15 +56,56 @@ require "numru/gphys"
|
|
44
56
|
require "numru/gphys/gpcommon"
|
45
57
|
include NumRu
|
46
58
|
|
47
|
-
|
59
|
+
require "getoptlong"
|
60
|
+
|
61
|
+
#---------------------- Option Configuration ----------------------
|
62
|
+
parser = GetoptLong.new(
|
63
|
+
["--exp", "-e", GetoptLong::NO_ARGUMENT ],
|
64
|
+
["--long", "-l", GetoptLong::NO_ARGUMENT ],
|
65
|
+
["--fmt", "-f", GetoptLong::REQUIRED_ARGUMENT],
|
66
|
+
["--help", "-h", GetoptLong::NO_ARGUMENT ])
|
67
|
+
begin
|
68
|
+
parser.each{|opt, arg|
|
69
|
+
case opt
|
70
|
+
when "--exp" then eval "$OPT_exp=true"
|
71
|
+
when "--long" then eval "$OPT_long=true"
|
72
|
+
when "--fmt" then eval "$OPT_fmt='#{arg}'"
|
73
|
+
when "--help" then eval "$OPT_help=true"
|
74
|
+
else
|
75
|
+
raise "must not happen"
|
76
|
+
end
|
77
|
+
}
|
78
|
+
rescue GetoptLong::AmbigousOption, GetoptLong::InvalidOption,
|
79
|
+
GetoptLong::MissingArgument,
|
80
|
+
GetoptLong::NeedlessArgument => err
|
81
|
+
help
|
82
|
+
$srderr.puts err.message
|
83
|
+
exit 1
|
84
|
+
end
|
85
|
+
|
86
|
+
#------------------------ Help message ------------------------
|
87
|
+
if $OPT_help then
|
88
|
+
help
|
89
|
+
exit(0)
|
90
|
+
end
|
48
91
|
|
49
|
-
|
92
|
+
#------------------------ Help message ------------------------
|
50
93
|
gturl = ARGV[0]
|
51
94
|
gp = GPhys::IO.open_gturl(gturl)
|
52
95
|
|
53
|
-
new_line_int =
|
96
|
+
new_line_int = 5
|
97
|
+
|
54
98
|
first_dim_len = (gp.shape[0]||1)
|
55
|
-
|
99
|
+
if $OPT_fmt then
|
100
|
+
fmt=$OPT_fmt
|
101
|
+
elsif $OPT_exp then
|
102
|
+
fmt=" %e,"
|
103
|
+
elsif $OPT_long then
|
104
|
+
fmt=" %f,"
|
105
|
+
else
|
106
|
+
fmt=" %g,"
|
107
|
+
end
|
108
|
+
|
56
109
|
i = 1
|
57
110
|
gp.val.each do |v|
|
58
111
|
printf(fmt,v)
|
data/bin/gpview
CHANGED
@@ -317,6 +317,7 @@ For multiple GPhys variables,
|
|
317
317
|
# 2015/03/10 S Takehiro (History removes from the output of --help option)
|
318
318
|
# 2015/09/05 Y O Takahashi && S Takehiro (add option --delay)
|
319
319
|
# 2015/09/06 Y O Takahashi && S Takehiro (defalt wsn number changed)
|
320
|
+
# 2017/06/07 S Takehiro (int option bug fix)
|
320
321
|
#
|
321
322
|
#################################################
|
322
323
|
require "getoptlong" # for option_parse
|
@@ -397,13 +398,23 @@ def draw_setup
|
|
397
398
|
min_range, max_range = __split_range($OPT_range)
|
398
399
|
min_crange, max_crange = __split_range($OPT_crange)
|
399
400
|
min_srange, max_srange = __split_range($OPT_srange)
|
401
|
+
if ( $OPT_cint || $OPT_interval || $OPT_int )
|
402
|
+
cont_interval = ( $OPT_cint || $OPT_interval || $OPT_int ).to_f
|
403
|
+
else
|
404
|
+
cont_interval = nil
|
405
|
+
end
|
406
|
+
if ( $OPT_sint || $OPT_interval || $OPT_int )
|
407
|
+
tone_interval = ( $OPT_sint || $OPT_interval || $OPT_int ).to_f
|
408
|
+
else
|
409
|
+
tone_interval = nil
|
410
|
+
end
|
400
411
|
GGraph.set_linear_contour_options(
|
401
|
-
'int' =>
|
412
|
+
'int' => cont_interval,
|
402
413
|
'min' => ( min_crange || min_range ),
|
403
414
|
'max' => ( max_crange || max_range )
|
404
415
|
)
|
405
416
|
GGraph.set_linear_tone_options(
|
406
|
-
'int' =>
|
417
|
+
'int' => tone_interval,
|
407
418
|
'min' => ( min_srange || min_range ),
|
408
419
|
'max' => ( max_srange || max_range )
|
409
420
|
)
|
data/ext/numru/gphys/dim_op.c
CHANGED
@@ -31,6 +31,9 @@ enum bc_type {
|
|
31
31
|
#define ID3z(i,j,k) ((i) + (j)*n0 + (k)*n0*nz)
|
32
32
|
#define ID3c(i,j,k) ((i) + (j)*n0 + (k)*n0*nc)
|
33
33
|
#define ID2(i,j) ((i) + (j)*n0)
|
34
|
+
#define ID5(i,j,k,l,m) ((i) + (j)*ni + (k)*ni*nd1 + (l)*ni*nd1*no1 + (m)*ni*nd1*no1*nd2)
|
35
|
+
#define NMax(i,j) ( (i) >= (j) ? (i) : (j) )
|
36
|
+
#define NMin(i,j) ( (i) <= (j) ? (i) : (j) )
|
34
37
|
|
35
38
|
static int
|
36
39
|
convol_result_length(na_shape_t n1, na_shape_t wlen, int ibc)
|
@@ -410,6 +413,215 @@ running_mean(int argc, VALUE *argv, VALUE self)
|
|
410
413
|
return vo;
|
411
414
|
}
|
412
415
|
|
416
|
+
/* Running tile (2D) mean for data with missing.
|
417
|
+
(if no missing, you can just run the 1D running mean twice.)
|
418
|
+
*/
|
419
|
+
static void
|
420
|
+
running_mean_2D_miss(zi, ni,nd1,no1,nd2,no2,
|
421
|
+
with_w1, w1, wlen1, ibc1, with_w2, w2, wlen2, ibc2,
|
422
|
+
zmiss, nminvalid, zo)
|
423
|
+
// IN
|
424
|
+
double *zi;
|
425
|
+
na_shape_t ni,nd1,no1,nd2,no2; /* treated as 5D array (inner => outer) */
|
426
|
+
int with_w1, with_w2;
|
427
|
+
double *w1, *w2;
|
428
|
+
na_shape_t wlen1, wlen2;
|
429
|
+
int ibc1, ibc2;
|
430
|
+
double zmiss;
|
431
|
+
int nminvalid;
|
432
|
+
// OUT
|
433
|
+
double *zo; // must have been set to 0 everywhere
|
434
|
+
{
|
435
|
+
na_shape_t i,j1,k1,j2,k2,m1,m2, jj1, jj2;
|
436
|
+
na_shape_t mstr1, mend1, mstr2, mend2;
|
437
|
+
na_shape_t wlhs1, wlhs2;
|
438
|
+
double wsum, wv;
|
439
|
+
int nm;
|
440
|
+
|
441
|
+
wlhs1 = (wlen1 - 1)/2; // e.g. 7->3, 6->2
|
442
|
+
wlhs2 = (wlen2 - 1)/2; // e.g. 7->3, 6->2
|
443
|
+
|
444
|
+
// < weighted running mean >
|
445
|
+
|
446
|
+
if ( !( ibc1 == BC_SIMPLE || ibc1 == BC_CYCLIC ) ) {
|
447
|
+
rb_raise(rb_eArgError,"Undefined boundary condision(1st D) (%d)", ibc1);
|
448
|
+
}
|
449
|
+
if ( !( ibc2 == BC_SIMPLE || ibc2 == BC_CYCLIC ) ) {
|
450
|
+
rb_raise(rb_eArgError,"Undefined boundary condision(2nd D) (%d)", ibc2);
|
451
|
+
}
|
452
|
+
|
453
|
+
for (k2=0; k2<no2; k2++) {
|
454
|
+
for (j2=0; j2<nd2; j2++) {
|
455
|
+
for (k1=0; k1<no1; k1++) {
|
456
|
+
for (j1=0; j1<nd1; j1++) {
|
457
|
+
for (i=0; i<ni; i++) {
|
458
|
+
wsum = 0.0;
|
459
|
+
nm = 0;
|
460
|
+
if (ibc1==BC_SIMPLE) {
|
461
|
+
mstr1 = NMax(0,wlhs1-j1);
|
462
|
+
mend1 = NMin(wlen1,nd1+wlhs1-j1);
|
463
|
+
} else { /* BC_CYCLIC */
|
464
|
+
mstr1 = 0;
|
465
|
+
mend1 = wlen1;
|
466
|
+
}
|
467
|
+
if (ibc2==BC_SIMPLE) {
|
468
|
+
mstr2 = NMax(0,wlhs2-j2);
|
469
|
+
mend2 = NMin(wlen2,nd2+wlhs2-j2);
|
470
|
+
} else { /* BC_CYCLIC */
|
471
|
+
mstr2 = 0;
|
472
|
+
mend2 = wlen2;
|
473
|
+
}
|
474
|
+
for (m2=mstr2; m2<mend2; m2++) {
|
475
|
+
for (m1=mstr1; m1<mend1; m1++) {
|
476
|
+
jj2 = j2-wlhs2+m2;
|
477
|
+
jj1 = j1-wlhs1+m1;
|
478
|
+
if (ibc1==BC_CYCLIC) {
|
479
|
+
if ( jj1 < 0 ) {
|
480
|
+
jj1 += nd1;
|
481
|
+
} else {
|
482
|
+
jj1 %= nd1;
|
483
|
+
}
|
484
|
+
}
|
485
|
+
if (ibc2==BC_CYCLIC) {
|
486
|
+
if ( jj2 < 0 ) {
|
487
|
+
jj2 += nd2;
|
488
|
+
} else {
|
489
|
+
jj2 %= nd2;
|
490
|
+
}
|
491
|
+
}
|
492
|
+
if ( zi[ID5(i,jj1,k1,jj2,k2)] != zmiss ) {
|
493
|
+
wv = 1.0;
|
494
|
+
if(with_w1){ wv *= w1[m1]; }
|
495
|
+
if(with_w2){ wv *= w2[m2]; }
|
496
|
+
zo[ID5(i,j1,k1,j2,k2)] +=
|
497
|
+
wv*zi[ID5(i,jj1,k1,jj2,k2)];
|
498
|
+
wsum += wv;
|
499
|
+
nm++;
|
500
|
+
}
|
501
|
+
}
|
502
|
+
}
|
503
|
+
if (nm >= nminvalid) {
|
504
|
+
zo[ID5(i,j1,k1,j2,k2)] /= wsum;
|
505
|
+
} else {
|
506
|
+
zo[ID5(i,j1,k1,j2,k2)] = zmiss;
|
507
|
+
}
|
508
|
+
}
|
509
|
+
}
|
510
|
+
}
|
511
|
+
}
|
512
|
+
}
|
513
|
+
}
|
514
|
+
|
515
|
+
// driver of running_mean_2D_miss
|
516
|
+
// (no-missing version is not needed)
|
517
|
+
//
|
518
|
+
static VALUE
|
519
|
+
running_mean_2D(obj, vi, dim1, len_or_wgt1, bc1, dim2, len_or_wgt2, bc2,
|
520
|
+
missv, nminvalid)
|
521
|
+
VALUE obj;
|
522
|
+
VALUE vi; // input NArray
|
523
|
+
VALUE dim1; // Integer
|
524
|
+
VALUE len_or_wgt1; // weight 1D NArray or Integer (length of uniform wgt)
|
525
|
+
VALUE bc1 ; // boundary condition (Integer)
|
526
|
+
VALUE dim2; // Integer
|
527
|
+
VALUE len_or_wgt2; // weight 1D NArray or Integer (length of uniform wgt)
|
528
|
+
VALUE bc2 ; // boundary condition (Integer)
|
529
|
+
VALUE missv; // missing value in vi
|
530
|
+
VALUE nminvalid; // miminum count of non-missing vales
|
531
|
+
{
|
532
|
+
struct NARRAY *na;
|
533
|
+
VALUE wgt;
|
534
|
+
na_shape_t *shi, wlen1, wlen2;
|
535
|
+
int with_w1, with_w2;
|
536
|
+
na_shape_t ni,nd1,no1,nd2,no2;
|
537
|
+
double *zi, *w1, *w2, zmiss;
|
538
|
+
int d1, d2, i, rank, ibc1, ibc2;
|
539
|
+
VALUE vo;
|
540
|
+
na_shape_t *sho, n1o;
|
541
|
+
int nminvalid_; // miminum count of non-missing vales
|
542
|
+
double *zo;
|
543
|
+
|
544
|
+
// < process arguments >
|
545
|
+
|
546
|
+
if (!IsNArray(vi)) { rb_raise(rb_eArgError,"1st arg must be a NArray"); }
|
547
|
+
vi = na_cast_object(vi, NA_DFLOAT);
|
548
|
+
rank = NA_RANK(vi);
|
549
|
+
if (rank < 2) { rb_raise(rb_eArgError,"rank 1st arg must be >= 2"); }
|
550
|
+
zi = NA_PTR_TYPE(vi, double *);
|
551
|
+
GetNArray(vi, na);
|
552
|
+
shi = na->shape;
|
553
|
+
|
554
|
+
d1 = NUM2INT( dim1 );
|
555
|
+
d2 = NUM2INT( dim2 );
|
556
|
+
nminvalid_ = NUM2INT( nminvalid );
|
557
|
+
|
558
|
+
if (d1 >= d2) { rb_raise(rb_eArgError,"d1 < d2 is required"); }
|
559
|
+
if (d2 >= rank) { rb_raise(rb_eArgError,"d2 must be < rank"); }
|
560
|
+
|
561
|
+
with_w1 = IsNArray(len_or_wgt1);
|
562
|
+
if (with_w1) {
|
563
|
+
wgt = len_or_wgt1;
|
564
|
+
if (NA_RANK(wgt)!=1){rb_raise(rb_eArgError,"wgt1 must be a 1D NArray");}
|
565
|
+
wgt = na_cast_object(wgt, NA_DFLOAT);
|
566
|
+
wlen1 = NA_TOTAL(wgt);
|
567
|
+
w1 = NA_PTR_TYPE(wgt, double *);
|
568
|
+
} else {
|
569
|
+
wlen1 = NUM2INT( len_or_wgt1 );
|
570
|
+
w1 == NULL; /* will not be used */
|
571
|
+
}
|
572
|
+
|
573
|
+
with_w2 = IsNArray(len_or_wgt2);
|
574
|
+
if (with_w2) {
|
575
|
+
wgt = len_or_wgt2;
|
576
|
+
if (NA_RANK(wgt)!=1){rb_raise(rb_eArgError,"wgt2 must be a 1D NArray");}
|
577
|
+
wgt = na_cast_object(wgt, NA_DFLOAT);
|
578
|
+
wlen2 = NA_TOTAL(wgt);
|
579
|
+
w2 = NA_PTR_TYPE(wgt, double *);
|
580
|
+
} else {
|
581
|
+
wlen2 = NUM2INT( len_or_wgt2 );
|
582
|
+
w2 == NULL; /* will not be used */
|
583
|
+
}
|
584
|
+
|
585
|
+
ibc1 = NUM2INT( bc1 );
|
586
|
+
ibc2 = NUM2INT( bc2 );
|
587
|
+
|
588
|
+
zmiss = NUM2DBL(missv);
|
589
|
+
|
590
|
+
|
591
|
+
// < shape as 5D >
|
592
|
+
|
593
|
+
nd1 = shi[d1]; // length of the dim to filter
|
594
|
+
if (wlen1 >= nd1) {rb_raise(rb_eArgError,"filter len >= len of the dim1");}
|
595
|
+
nd2 = shi[d2]; // length of the dim to filter
|
596
|
+
if (wlen2 >= nd1) {rb_raise(rb_eArgError,"filter len >= len of the dim2");}
|
597
|
+
|
598
|
+
ni = no1 = no2 = 1;
|
599
|
+
for (i=0; i<d1; i++) {
|
600
|
+
ni *= shi[i]; // total lengths of dims before d
|
601
|
+
}
|
602
|
+
for (i=d1+1; i<d2; i++) {
|
603
|
+
no1 *= shi[i]; // total lengths of dims after d
|
604
|
+
}
|
605
|
+
for (i=d2+1; i<rank; i++) {
|
606
|
+
no2 *= shi[i]; // total lengths of dims after d
|
607
|
+
}
|
608
|
+
|
609
|
+
// < initialize the NArray to ruturn >
|
610
|
+
|
611
|
+
sho = shi; // Limited to shape conserved cases
|
612
|
+
vo = na_make_object(NA_DFLOAT, rank, sho, cNArray);
|
613
|
+
GetNArray(vo, na);
|
614
|
+
na_clear_data(na);
|
615
|
+
zo = NA_PTR_TYPE(vo, double *);
|
616
|
+
|
617
|
+
// < do the job >
|
618
|
+
running_mean_2D_miss(zi, ni,nd1,no1,nd2,no2,
|
619
|
+
with_w1, w1, wlen1, ibc1, with_w2, w2, wlen2, ibc2,
|
620
|
+
zmiss, nminvalid_, zo);
|
621
|
+
|
622
|
+
return vo;
|
623
|
+
}
|
624
|
+
|
413
625
|
static void
|
414
626
|
bin_mean_nomiss(zi,n0,n1,n2, len, zo)
|
415
627
|
// IN
|
@@ -1209,10 +1421,15 @@ init_gphys_dim_op()
|
|
1209
1421
|
|
1210
1422
|
cGPhys = rb_define_class_under(mNumRu, "GPhys", rb_cObject);
|
1211
1423
|
rb_define_private_method(cGPhys, "c_running_mean", running_mean, -1);
|
1424
|
+
rb_define_private_method(cGPhys, "c_running_mean_2D", running_mean_2D, 9);
|
1425
|
+
rb_define_singleton_method(cGPhys, "c_running_mean", running_mean, -1);
|
1426
|
+
rb_define_singleton_method(cGPhys, "c_running_mean_2D", running_mean_2D, 9);
|
1212
1427
|
|
1213
1428
|
cVArray = rb_define_class_under(mNumRu, "VArray", rb_cObject);
|
1214
1429
|
rb_define_private_method(cVArray, "c_bin_mean", bin_mean, -1);
|
1215
1430
|
rb_define_private_method(cVArray, "c_bin_sum", bin_sum, -1);
|
1431
|
+
rb_define_singleton_method(cGPhys, "c_bin_mean", bin_mean, -1);
|
1432
|
+
rb_define_singleton_method(cGPhys, "c_bin_sum", bin_sum, -1);
|
1216
1433
|
|
1217
1434
|
rb_define_private_method(cVArray, "c_cum_sum", cum_sum, 2);
|
1218
1435
|
rb_define_singleton_method(cGPhys, "c_cell_integ_irreg",
|
data/gphys.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.test_files = spec.files.grep(%r{^(test|test_old|sample|testdata)/})
|
27
27
|
spec.extensions << "ext/numru/gphys/extconf.rb"
|
28
28
|
|
29
|
-
spec.post_install_message = "Thanks for installing! You can add extra libraries (i.e., ruby-lapack, rb-
|
29
|
+
spec.post_install_message = "Thanks for installing! You can add extra libraries (i.e., ruby-lapack, rb-gsl) to enjoy powerful calculating and handling datasets."
|
30
30
|
|
31
31
|
spec.required_ruby_version = Gem::Requirement.new(">= 1.8")
|
32
32
|
|
@@ -37,8 +37,7 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.add_runtime_dependency(%q<ruby-netcdf>, [">= 0.6.6"])
|
38
38
|
spec.add_runtime_dependency(%q<ruby-dcl>, [">= 1.6.1"])
|
39
39
|
spec.add_runtime_dependency(%q<ruby-fftw3>, [">= 0.3"])
|
40
|
-
#spec.add_runtime_dependency(%q<gsl>, [">= 1.14"])
|
41
|
-
spec.add_runtime_dependency(%q<rb-gsl>, [">= 1.14"])
|
40
|
+
#spec.add_runtime_dependency(%q<rb-gsl>, [">= 1.14"])
|
42
41
|
#spec.add_runtime_dependency(%q<ruby-lapack>, [">= 1.5"])
|
43
42
|
#spec.add_development_dependency(%q<rb-grib>, [">= 0.2.0"])
|
44
43
|
end
|
data/lib/numru/dclext.rb
CHANGED
@@ -927,6 +927,11 @@ module NumRu
|
|
927
927
|
# * inf_max false: no extension, true: extend to +infty, nil: same
|
928
928
|
# but for max is replaced by +infty, rather than extending
|
929
929
|
def ue_linear_levels(min, max, dx, lbound=false, inf_min=false, inf_max=false)
|
930
|
+
|
931
|
+
if !min || ( min.is_a?(Float) && min.nan? )|| !max || ( max.is_a?(Float) && max.nan? )
|
932
|
+
return [0.0]
|
933
|
+
end
|
934
|
+
|
930
935
|
if dx > 0
|
931
936
|
dz = dx.to_f
|
932
937
|
else
|
@@ -1219,7 +1224,8 @@ module NumRu
|
|
1219
1224
|
# draw frame, tick lines, and labels
|
1220
1225
|
if fmt
|
1221
1226
|
cfmt_bk = DCL::uyqfmt
|
1222
|
-
DCL::uysfmt(fmt)
|
1227
|
+
#DCL::uysfmt(fmt)
|
1228
|
+
DCL::uspset('cyfmt',fmt)
|
1223
1229
|
end
|
1224
1230
|
|
1225
1231
|
DCL::usyaxs(axside)
|
@@ -1232,14 +1238,16 @@ module NumRu
|
|
1232
1238
|
DCL::uxaxdv("b",1,index) if !inf0
|
1233
1239
|
DCL::uxaxdv("t",1,index) if !inf1
|
1234
1240
|
|
1235
|
-
DCL::uysfmt(cfmt_bk) if fmt
|
1241
|
+
#DCL::uysfmt(cfmt_bk) if fmt
|
1242
|
+
DCL::uspset('cyfmt',cfmt_bk) if fmt
|
1236
1243
|
|
1237
1244
|
else ## landscape ##
|
1238
1245
|
|
1239
1246
|
# draw frame, tick lines, and labels
|
1240
1247
|
if fmt
|
1241
1248
|
cfmt_bk = DCL::uxqfmt
|
1242
|
-
DCL::uxsfmt(fmt)
|
1249
|
+
#DCL::uxsfmt(fmt)
|
1250
|
+
DCL::uspset('cxfmt',fmt)
|
1243
1251
|
end
|
1244
1252
|
|
1245
1253
|
DCL::usxaxs(axside)
|
@@ -1252,7 +1260,8 @@ module NumRu
|
|
1252
1260
|
DCL::uyaxdv("l",1,index) if !inf0
|
1253
1261
|
DCL::uyaxdv("r",1,index) if !inf1
|
1254
1262
|
|
1255
|
-
DCL::uxsfmt(cfmt_bk) if fmt
|
1263
|
+
#DCL::uxsfmt(cfmt_bk) if fmt
|
1264
|
+
DCL::uspset('cxfmt',cfmt_bk) if fmt
|
1256
1265
|
end
|
1257
1266
|
|
1258
1267
|
DCLExt.color_bar_title_units(vxmin, vxmax, vymin, vymax, portrait, voff,
|
data/lib/numru/ggraph.rb
CHANGED
@@ -47,7 +47,7 @@ require "numru/dclext"
|
|
47
47
|
* ((<next_map>))
|
48
48
|
Set the option values effective only in the next call of ((<map>))
|
49
49
|
* ((<line>))
|
50
|
-
Plot a poly-line by selecting the first dimension
|
50
|
+
Plot a poly-line by selecting the first dimension
|
51
51
|
if (({gphys})) is more than 2D.
|
52
52
|
* ((<set_line>))
|
53
53
|
Change the default option values for ((<line>)).
|
@@ -66,7 +66,7 @@ require "numru/dclext"
|
|
66
66
|
* ((<tone_and_contour>))
|
67
67
|
Calls ((<tone>)) and ((<contour>)) successively.
|
68
68
|
* ((<contour>))
|
69
|
-
Contour plot by selecting the first 2 dimensions
|
69
|
+
Contour plot by selecting the first 2 dimensions
|
70
70
|
if (({gphys})) is more than 3D.
|
71
71
|
* ((<set_contour>))
|
72
72
|
Set options for contour in general.
|
@@ -84,7 +84,7 @@ require "numru/dclext"
|
|
84
84
|
is effective only for the next call of ((<contour>)).
|
85
85
|
* ((<tone>))
|
86
86
|
Color tone or shading by selecting the first 2 dimensions
|
87
|
-
|
87
|
+
if (({gphys})) is more than 3D.
|
88
88
|
* ((<color_bar >)) Color bar
|
89
89
|
* ((<set_tone_levels>))
|
90
90
|
Set tone levels for ((<tone>)) explicitly by values.
|
@@ -511,7 +511,7 @@ library if you like.
|
|
511
511
|
* see ((<map>)).
|
512
512
|
|
513
513
|
---line(gphys, newframe=true, options=nil)
|
514
|
-
Plot a poly-line by selecting the first dimension
|
514
|
+
Plot a poly-line by selecting the first dimension
|
515
515
|
if (({gphys})) is more than 2D.
|
516
516
|
|
517
517
|
ARGUMENTS
|
@@ -742,7 +742,7 @@ library if you like.
|
|
742
742
|
* Requires numru-misc-0.0.6 or later.
|
743
743
|
|
744
744
|
---contour(gphys, newframe=true, options=nil)
|
745
|
-
Contour plot by selecting the first 2 dimensions
|
745
|
+
Contour plot by selecting the first 2 dimensions
|
746
746
|
if (({gphys})) is more than 3D.
|
747
747
|
|
748
748
|
Contour levels are determined as follows:
|
@@ -858,7 +858,7 @@ library if you like.
|
|
858
858
|
|
859
859
|
---tone(gphys, newframe=true, options=nil)
|
860
860
|
Color tone or shading by selecting the first 2 dimensions
|
861
|
-
|
861
|
+
if (({gphys})) is more than 3D.
|
862
862
|
|
863
863
|
Tone levels are determined as follows:
|
864
864
|
* Tone levels are set in this method if not set by
|
@@ -1905,7 +1905,7 @@ module NumRu
|
|
1905
1905
|
['mean', nil, 'An Array to be pathed to the GPhys#mean method to take mean of the data before plotting (order applied: slice -> cut -> mean)']
|
1906
1906
|
)
|
1907
1907
|
|
1908
|
-
def data_prep_2D(gps, newframe, opts)
|
1908
|
+
def data_prep_2D(gps, newframe, opts, len1ok: false)
|
1909
1909
|
opend_here = []
|
1910
1910
|
gps.collect!{|gp|
|
1911
1911
|
if gp.is_a?(String)
|
@@ -1921,7 +1921,11 @@ module NumRu
|
|
1921
1921
|
end
|
1922
1922
|
end
|
1923
1923
|
gp = gp.mean(*opts['mean']) if opts['mean']
|
1924
|
-
|
1924
|
+
if len1ok
|
1925
|
+
gp = gp.first2D
|
1926
|
+
else
|
1927
|
+
gp = gp.first2Dreally
|
1928
|
+
end
|
1925
1929
|
gp = gp.transpose(1,0) if opts['transpose'] || opts['exchange']
|
1926
1930
|
if opts['xintv'] || opts['yintv']
|
1927
1931
|
gp = gp.copy
|
@@ -1981,7 +1985,7 @@ module NumRu
|
|
1981
1985
|
[xd, yd, closer, *gps]
|
1982
1986
|
end
|
1983
1987
|
|
1984
|
-
def data_prep_1D(gphys, opts)
|
1988
|
+
def data_prep_1D(gphys, opts, len1ok: false)
|
1985
1989
|
gp = gphys
|
1986
1990
|
if gp.is_a?(String)
|
1987
1991
|
gp = GPhys::IO.str2gphys(gp)
|
@@ -1998,7 +2002,11 @@ module NumRu
|
|
1998
2002
|
end
|
1999
2003
|
end
|
2000
2004
|
gp = gp.mean(*opts['mean']) if opts['mean']
|
2001
|
-
|
2005
|
+
if len1ok
|
2006
|
+
gp = gp.first1D
|
2007
|
+
else
|
2008
|
+
gp = gp.first1Dreally
|
2009
|
+
end
|
2002
2010
|
window = ( @@next_fig['window'] if @@next_fig ) || @@fig['window']
|
2003
2011
|
window = ( window ? window.dup : [nil, nil, nil, nil])
|
2004
2012
|
max = opts['max']; min = opts['min']
|
@@ -2016,7 +2024,7 @@ module NumRu
|
|
2016
2024
|
[xd, yd, closer, gp, window]
|
2017
2025
|
end
|
2018
2026
|
|
2019
|
-
def data_prep_1D2(fx, fy, opts)
|
2027
|
+
def data_prep_1D2(fx, fy, opts, len1ok: false)
|
2020
2028
|
gpx = fx
|
2021
2029
|
gpy = fy
|
2022
2030
|
to_close = Array.new
|
@@ -2043,18 +2051,26 @@ module NumRu
|
|
2043
2051
|
end
|
2044
2052
|
end
|
2045
2053
|
gpx = gpx.mean(*opts['mean']) if opts['mean']
|
2046
|
-
|
2054
|
+
if len1ok
|
2055
|
+
gpx = gpx.first1D
|
2056
|
+
else
|
2057
|
+
gpx = gpx.first1Dreally
|
2058
|
+
end
|
2047
2059
|
|
2048
2060
|
gpy = gpy[*opts['slice']] if opts['slice']
|
2049
2061
|
if (cut = opts['cut']) # substitution, not ==
|
2050
2062
|
if cut.is_a?(Array)
|
2051
2063
|
gpy = gpy.cut(*cut)
|
2052
2064
|
else
|
2053
|
-
gpy = gpy.cut(cut)
|
2065
|
+
gpy = gpy.cut(cut)
|
2054
2066
|
end
|
2055
2067
|
end
|
2056
2068
|
gpy = gpy.mean(*opts['mean']) if opts['mean']
|
2057
|
-
|
2069
|
+
if len1ok
|
2070
|
+
gpy = gpy.first1D
|
2071
|
+
else
|
2072
|
+
gpy = gpy.first1Dreally
|
2073
|
+
end
|
2058
2074
|
|
2059
2075
|
[gpx, gpy, closer]
|
2060
2076
|
end
|
@@ -2256,7 +2272,7 @@ module NumRu
|
|
2256
2272
|
@@next_mark = nil
|
2257
2273
|
end
|
2258
2274
|
opts = @@mark_options.interpret(options)
|
2259
|
-
x, y, closer, gp, window = data_prep_1D(gphys, opts)
|
2275
|
+
x, y, closer, gp, window = data_prep_1D(gphys, opts, len1ok: true)
|
2260
2276
|
if newframe
|
2261
2277
|
fig(x, y, {'window'=>window})
|
2262
2278
|
axes_or_map_and_ttl(gp, opts, x, y)
|
@@ -3230,6 +3246,8 @@ module NumRu
|
|
3230
3246
|
['x_given_y', false, 'If false (default), regress y for given x. If true, x given y.'],
|
3231
3247
|
['annot_slope', nil, 'Whether to show the slope on the right margin. nil: show when itr=1,4, do not show when itr=2,3; true: show; false: not show'],
|
3232
3248
|
['annot_intercept', false, '[Meaningful only when itr=1 (linear scaling plot)] if true, show the intercept on the right margin'],
|
3249
|
+
['annot_cor', false, 'Whether to show correlation coefficient on the right margin.'],
|
3250
|
+
['annot_r2', false, 'Whether to show squared correlation coefficient on the right margin.'],
|
3233
3251
|
['limit', false, 'If true, regression line is shown only over the range between max and min of the independent variable. If false, regression line is written over the whole range of the independent variable'],
|
3234
3252
|
['clip', true, "If true, use DCL's clipping not to show the line outside the viewport"],
|
3235
3253
|
['index', 1, 'line index'],
|
@@ -3289,7 +3307,7 @@ module NumRu
|
|
3289
3307
|
xr = NArray.sfloat(2) # --> x ends of the regression line
|
3290
3308
|
yr = NArray.sfloat(2) # --> y ends of the regression line
|
3291
3309
|
if y_given_x
|
3292
|
-
a,b = linear_regression(xs,ys)
|
3310
|
+
a,b,r2 = linear_regression(xs,ys)
|
3293
3311
|
if opts["limit"]
|
3294
3312
|
xr[0] = x.min
|
3295
3313
|
xr[1] = x.max
|
@@ -3300,7 +3318,7 @@ module NumRu
|
|
3300
3318
|
yrs = a + b*xrs
|
3301
3319
|
yr = !ylog ? yrs : NMath::exp(yrs)
|
3302
3320
|
else
|
3303
|
-
a,b = linear_regression(ys,xs)
|
3321
|
+
a,b,r2 = linear_regression(ys,xs)
|
3304
3322
|
if opts["limit"]
|
3305
3323
|
yr[0] = y.min
|
3306
3324
|
yr[1] = y.max
|
@@ -3318,6 +3336,8 @@ module NumRu
|
|
3318
3336
|
|
3319
3337
|
ai = opts['annot_intercept'] || opts['annot_intercept'].nil? && itr==1
|
3320
3338
|
as = opts['annot_slope'] || opts['annot_slope'].nil? && (itr==1 or itr==4)
|
3339
|
+
ac = opts['annot_cor']
|
3340
|
+
ar2 = opts['annot_r2']
|
3321
3341
|
if as && ai
|
3322
3342
|
if y_given_x
|
3323
3343
|
annot = ["regr y=a+bx:",
|
@@ -3326,6 +3346,8 @@ module NumRu
|
|
3326
3346
|
annot = ["regr x=a+by:",
|
3327
3347
|
" a=#{DCL.chval('A',a)}", " b=#{DCL.chval('A',b)}"]
|
3328
3348
|
end
|
3349
|
+
annot.push(sprintf("r=%-.3g",Math.sqrt(r2))) if ac
|
3350
|
+
annot.push(sprintf("r2=%-.3g",r2)) if ar2
|
3329
3351
|
annotate(annot, @@nannot)
|
3330
3352
|
elsif as
|
3331
3353
|
if y_given_x
|
@@ -3333,10 +3355,12 @@ module NumRu
|
|
3333
3355
|
else
|
3334
3356
|
annot = ["regress x given y:", " x(y) slope: #{DCL.chval('A',b)}"]
|
3335
3357
|
end
|
3358
|
+
annot.push(sprintf("r=%-.3g",Math.sqrt(r2))) if ac
|
3359
|
+
annot.push(sprintf("r2=%-.3g",r2)) if ar2
|
3336
3360
|
annotate(annot, @@nannot)
|
3337
3361
|
end
|
3338
3362
|
|
3339
|
-
[a,b]
|
3363
|
+
[a,b,r2]
|
3340
3364
|
end
|
3341
3365
|
end
|
3342
3366
|
|
@@ -3347,7 +3371,9 @@ module NumRu
|
|
3347
3371
|
my = y.mean
|
3348
3372
|
b = cxy/cxx
|
3349
3373
|
a = my - b*mx
|
3350
|
-
|
3374
|
+
cyy, ndiv = NMMath.covariance(y,y)
|
3375
|
+
r2 = cxy/Math.sqrt(cxx*cyy)
|
3376
|
+
[a,b,r2]
|
3351
3377
|
end
|
3352
3378
|
|
3353
3379
|
def linear_reg_slope_error(x,y,a,b)
|
data/lib/numru/gphys/axis.rb
CHANGED
@@ -600,7 +600,7 @@ module NumRu
|
|
600
600
|
self
|
601
601
|
end
|
602
602
|
def get_aux(name)
|
603
|
-
@aux[name]
|
603
|
+
@aux && @aux[name]
|
604
604
|
end
|
605
605
|
def aux_names
|
606
606
|
@aux ? @aux.keys : []
|
@@ -890,7 +890,25 @@ module NumRu
|
|
890
890
|
end
|
891
891
|
private :_cut_
|
892
892
|
|
893
|
-
|
893
|
+
# Find index nearest to loc
|
894
|
+
#
|
895
|
+
# * loc (Numeric, Date, DateTime)
|
896
|
+
#
|
897
|
+
# Return value: the index (Integer)
|
898
|
+
def nearest_index(loc)
|
899
|
+
if loc.class <= Date
|
900
|
+
loc = UNumeric.from_date(loc,pos.units,self.pos.get_att('calendar')).val
|
901
|
+
end
|
902
|
+
ax = self.pos.val
|
903
|
+
if cyclic_extendible?
|
904
|
+
dx, base = _cyclic_dx(ax-loc, modulo)
|
905
|
+
else
|
906
|
+
dx = (ax-loc).abs
|
907
|
+
end
|
908
|
+
idx = _minloc_(dx)
|
909
|
+
end
|
910
|
+
|
911
|
+
def _minloc_(a) # private to be used in nearest_index (for cut etc)
|
894
912
|
# Developper's MEMO: Such a method should be supported in NArray
|
895
913
|
minloc = 0 # initialization
|
896
914
|
for i in 0...(a.length-1) # here, do not assume monotonic
|
@@ -1158,7 +1176,16 @@ if $0 == __FILE__
|
|
1158
1176
|
|
1159
1177
|
p "## test join (cell)"
|
1160
1178
|
axcel_c2 = Axis.new(true).set_cell(xc+10,xb+10)
|
1179
|
+
axcel_c2.set_aux('aux1',xc*10)
|
1161
1180
|
axcel_c2.set_pos_to_center
|
1162
1181
|
jax = Axis.join([axcel_c,axcel_c2])
|
1163
1182
|
p jax, jax.name, jax.pos.val.to_a, jax.cell_bounds.val.to_a
|
1183
|
+
|
1184
|
+
p "## test neaest index"
|
1185
|
+
loc = 1.1
|
1186
|
+
p axpt, loc, axpt.nearest_index(loc)
|
1187
|
+
xc.put_att("modulo",[10.0])
|
1188
|
+
axpt_cyc = Axis.new().set_pos(xc)
|
1189
|
+
loc = -8.5
|
1190
|
+
p axpt_cyc, axpt_cyc.modulo, loc, axpt.nearest_index(loc)
|
1164
1191
|
end
|
data/lib/numru/gphys/gphys.rb
CHANGED
@@ -805,7 +805,7 @@ module NumRu
|
|
805
805
|
## For graphics -->
|
806
806
|
def first3D
|
807
807
|
raise "rank less than 3" if rank < 3
|
808
|
-
self[true,true,*([0]*(rank-3))]
|
808
|
+
self[true,true,true,*([0]*(rank-3))]
|
809
809
|
end
|
810
810
|
def first2D
|
811
811
|
raise "rank less than 2" if rank < 2
|
@@ -815,6 +815,31 @@ module NumRu
|
|
815
815
|
raise "rank less than 1" if rank < 1
|
816
816
|
self[true,*([0]*(rank-1))]
|
817
817
|
end
|
818
|
+
def firstNDreally(nd)
|
819
|
+
sh = shape_current
|
820
|
+
n = 0
|
821
|
+
sel = sh.map do |len|
|
822
|
+
if len > 1 && n < nd
|
823
|
+
n += 1
|
824
|
+
true
|
825
|
+
else
|
826
|
+
0
|
827
|
+
end
|
828
|
+
end
|
829
|
+
if n<nd
|
830
|
+
raise "Invalid shape #{sh} (not really #{nd}D or greater): # of dims with len>1 is fewer than #{nd}"
|
831
|
+
end
|
832
|
+
self[*sel]
|
833
|
+
end
|
834
|
+
def first3Dreally
|
835
|
+
firstNDreally(3)
|
836
|
+
end
|
837
|
+
def first2Dreally
|
838
|
+
firstNDreally(2)
|
839
|
+
end
|
840
|
+
def first1Dreally
|
841
|
+
firstNDreally(1)
|
842
|
+
end
|
818
843
|
## <-- For graphics
|
819
844
|
|
820
845
|
def coerce(other)
|
@@ -20,15 +20,16 @@ module NumRu
|
|
20
20
|
# * len_or_wgt : If Integer, specifies the length; if 1D NArray,
|
21
21
|
# specifies the weight (e.g., NArray[1.0, 2.0, 1.0] for
|
22
22
|
# the 1-2-1 smooting)
|
23
|
-
# * bc (Integer; optional) :
|
24
|
-
# *
|
23
|
+
# * bc (Integer; optional) : Specify one of the following:
|
24
|
+
# * nil (default) : choose BC_SIMPLE or BC_CYCLIC automatically
|
25
|
+
# * GPhys::BC_SIMPLE : Averaging is truncated at the boundaries
|
25
26
|
# (the number of grid points used is reduced near the boundaries).
|
26
27
|
# The shape of the object is conserved.
|
27
28
|
# * GPhys::BC_CYCLIC : Cyclic boundary condition. Shape conserved.
|
28
29
|
# * GPhys::BC_TRIM : Grids near the boundaries are trimmed to
|
29
30
|
# secure the number of grid points to average.
|
30
31
|
# Shape not conserved; length along the dim is reduced by (len-1).
|
31
|
-
# * nminvalid (Integer; optional;
|
32
|
+
# * nminvalid (Integer; optional; default=1):
|
32
33
|
# This parameter is used only when the data have missing.
|
33
34
|
# Minimum number of grid points needed for averaging.
|
34
35
|
# Must be from 1 to len.
|
@@ -40,15 +41,23 @@ module NumRu
|
|
40
41
|
# * If the length of the running mean is even number, fewer
|
41
42
|
# grid points are used from the "left" side; e.g.,
|
42
43
|
# If len is 6, result[2] is a mean over self[0]..self[5].
|
43
|
-
# * Regardless the na_type of self, double is used for
|
44
|
+
# * Regardless the na_type of self, double is used for averaging, so:
|
44
45
|
# * This method does not support complex numbers.
|
45
46
|
#
|
46
|
-
def running_mean(dim, len_or_wgt=nil, bc=
|
47
|
+
def running_mean(dim, len_or_wgt=nil, bc=nil, nminvalid=1)
|
47
48
|
|
48
49
|
#< process arguments >
|
49
50
|
|
50
51
|
dim = dim_index(dim) # to handle String or negative specification
|
51
52
|
|
53
|
+
if bc.nil?
|
54
|
+
if axis(dim).cyclic_extendible?
|
55
|
+
bc=BC_CYCLIC
|
56
|
+
else
|
57
|
+
bc=BC_SIMPLE
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
52
61
|
case len_or_wgt
|
53
62
|
when nil
|
54
63
|
raise ArgumentError, "You need to specify the length (Integer) or the weight (1D NArray) as the 2nd argument"
|
@@ -95,6 +104,78 @@ module NumRu
|
|
95
104
|
|
96
105
|
end
|
97
106
|
|
107
|
+
# Running mean along two dimensions (with optional weight specification).
|
108
|
+
#
|
109
|
+
# This method would be needed for data with missing. If the data
|
110
|
+
# has no missing, you should apply running_mean consecutively
|
111
|
+
# along the two dimensions you want, which will be faster and efficient.
|
112
|
+
#
|
113
|
+
# However, if the data have missing, the results are not the same.
|
114
|
+
# That's why this method is needed.
|
115
|
+
#
|
116
|
+
# ARGUMENTS
|
117
|
+
# * dim1 (Integer or String) : a dimension to apply the running mean
|
118
|
+
# * dim2 (Integer or String) : another dimension to apply the running mean
|
119
|
+
# (dim1 must be smaller than dim2)
|
120
|
+
# * len_or_wgt1 : If Integer, specifies the length of running mean for dim1.
|
121
|
+
# If 1D NArray, it specifies the weight (e.g., NArray[1.0, 2.0, 1.0] for
|
122
|
+
# the 1-2-1 smoothing)
|
123
|
+
# * len_or_wgt2 : as len_or_wgt1 but for dim2.
|
124
|
+
# * bc1 (Integer or nil; optional) : Specify one of the following for dim1:
|
125
|
+
# * nil : choose BC_SIMPLE or BC_CYCLIC automatically
|
126
|
+
# * GPhys::BC_SIMPLE : Averaging is truncated at the boundaries
|
127
|
+
# (the number of grid points used is reduced near the boundaries).
|
128
|
+
# The shape of the object is conserved.
|
129
|
+
# * GPhys::BC_CYCLIC : Cyclic boundary condition. Shape conserved.
|
130
|
+
# * bc2 : as bc1 but for dim2.
|
131
|
+
# * nminvalid (Integer; optional; default=1):
|
132
|
+
# Minimum number of grid points needed to define the running mean
|
133
|
+
# (it is the number of valid data in the 2-dimensional tile).
|
134
|
+
#
|
135
|
+
def running_mean_2D(dim1, dim2, len_or_wgt1, len_or_wgt2,
|
136
|
+
bc1=nil, bc2=nil,
|
137
|
+
nminvalid=1)
|
138
|
+
|
139
|
+
dim1 = dim_index(dim1) # to handle String or negative specification
|
140
|
+
dim2 = dim_index(dim2) # to handle String or negative specification
|
141
|
+
|
142
|
+
if bc1.nil?
|
143
|
+
if axis(dim1).cyclic_extendible?
|
144
|
+
bc1=BC_CYCLIC
|
145
|
+
else
|
146
|
+
bc1=BC_SIMPLE
|
147
|
+
end
|
148
|
+
end
|
149
|
+
if bc2.nil?
|
150
|
+
if axis(dim2).cyclic_extendible?
|
151
|
+
bc2=BC_CYCLIC
|
152
|
+
else
|
153
|
+
bc2=BC_SIMPLE
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
vi = self.val
|
158
|
+
if vi.is_a?(NArray)
|
159
|
+
# Just for convenience.
|
160
|
+
self.running_mean(dim1, len_or_wgt1, bc1, nminvalid).running_mean(dim2, len_or_wgt2, bc2, nminvalid)
|
161
|
+
end
|
162
|
+
|
163
|
+
if (vi.typecode > NArray::DFLOAT)
|
164
|
+
raise("This method supports only real or integer data")
|
165
|
+
end
|
166
|
+
if vi.is_a?(NArrayMiss)
|
167
|
+
vi, missval = nam2na_missval(vi)
|
168
|
+
vo = c_running_mean_2D(vi, dim1,len_or_wgt1,bc1, dim2,len_or_wgt2,bc2,
|
169
|
+
missval, nminvalid)
|
170
|
+
vo = NArrayMiss.to_nam(vo, vo.ne(missval) )
|
171
|
+
else
|
172
|
+
raise("This method accepts only data with missing. If not, you should apply running_mean twice for dim1 & dim2, respectively")
|
173
|
+
end
|
174
|
+
|
175
|
+
vvo = VArray.new( vo, self.data, self.name ) # Inherit name & attrs
|
176
|
+
GPhys.new( self.grid, vvo )
|
177
|
+
end
|
178
|
+
|
98
179
|
# Binning along a dimension (mean)
|
99
180
|
#
|
100
181
|
# The values are averaged every "len" grids; unlike running_mean
|
@@ -199,7 +280,7 @@ module NumRu
|
|
199
280
|
acs = Array.new
|
200
281
|
assoccoordnames.each do |nm|
|
201
282
|
ac = assoc_coord_gphys(nm)
|
202
|
-
acs.push(ac) if !ac.
|
283
|
+
acs.push(ac) if !ac.axnames.include?(dimname)
|
203
284
|
end
|
204
285
|
newgrid.set_assoc_coords(acs) if acs.length > 0
|
205
286
|
end
|
@@ -428,6 +428,7 @@ module NumRu
|
|
428
428
|
newaxes.push( newax )
|
429
429
|
}
|
430
430
|
if acnms = grid_or_gphys.assoccoordnames
|
431
|
+
(nms = file.var_names) and acnms -= nms
|
431
432
|
acnms.each{|nm|
|
432
433
|
acgp = grid_or_gphys.assoc_coord_gphys(nm)
|
433
434
|
VArrayNetCDF.write(file, acgp.data, nil, acgp.axnames)
|
@@ -919,7 +919,7 @@ EOS
|
|
919
919
|
|
920
920
|
imax, jmax = isize.to_i, jsize.to_i
|
921
921
|
dx, dy = dx.to_f, dy.to_f
|
922
|
-
bi, bj =
|
922
|
+
bi, bj = iref.to_f-1.0, jref.to_f-1.0
|
923
923
|
by, bx = latref.to_f, lonref.to_f
|
924
924
|
sy,sx = struelat.to_f, slon.to_f
|
925
925
|
sy2, = ntruelat.to_f
|
@@ -932,8 +932,11 @@ EOS
|
|
932
932
|
unless sx.abs < 180
|
933
933
|
raise "parameter for standard is invalid"
|
934
934
|
end
|
935
|
-
|
936
|
-
raise "
|
935
|
+
if sy.abs > 90
|
936
|
+
raise "Invalid PDEF (in control file): |struelat|>90"
|
937
|
+
end
|
938
|
+
if sy2.abs > 90
|
939
|
+
raise "Invalid PDEF (in control file): |ntruelat|>90"
|
937
940
|
end
|
938
941
|
bx = bx*PI/180
|
939
942
|
by = by*PI/180
|
data/lib/numru/gphys/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gphys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takeshi Horinouchi
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date:
|
15
|
+
date: 2018-01-26 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: narray
|
@@ -112,20 +112,6 @@ dependencies:
|
|
112
112
|
- - ">="
|
113
113
|
- !ruby/object:Gem::Version
|
114
114
|
version: '0.3'
|
115
|
-
- !ruby/object:Gem::Dependency
|
116
|
-
name: rb-gsl
|
117
|
-
requirement: !ruby/object:Gem::Requirement
|
118
|
-
requirements:
|
119
|
-
- - ">="
|
120
|
-
- !ruby/object:Gem::Version
|
121
|
-
version: '1.14'
|
122
|
-
type: :runtime
|
123
|
-
prerelease: false
|
124
|
-
version_requirements: !ruby/object:Gem::Requirement
|
125
|
-
requirements:
|
126
|
-
- - ">="
|
127
|
-
- !ruby/object:Gem::Version
|
128
|
-
version: '1.14'
|
129
115
|
description: Comprehensive library for self-descriptive gridded physical data (in
|
130
116
|
NetCDF, GrADS, or on memory) with graphics. This version works with Ruby 2.0.
|
131
117
|
email:
|
@@ -642,7 +628,7 @@ licenses:
|
|
642
628
|
- BSD-2-Clause
|
643
629
|
metadata: {}
|
644
630
|
post_install_message: Thanks for installing! You can add extra libraries (i.e., ruby-lapack,
|
645
|
-
rb-
|
631
|
+
rb-gsl) to enjoy powerful calculating and handling datasets.
|
646
632
|
rdoc_options: []
|
647
633
|
require_paths:
|
648
634
|
- ext
|
@@ -659,7 +645,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
659
645
|
version: '0'
|
660
646
|
requirements: []
|
661
647
|
rubyforge_project:
|
662
|
-
rubygems_version: 2.2.
|
648
|
+
rubygems_version: 2.5.2.1
|
663
649
|
signing_key:
|
664
650
|
specification_version: 4
|
665
651
|
summary: A multi-purpose class to handle Gridded Physical quantities
|