mdarray 0.5.3-java → 0.5.4-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. data/README.md +325 -70
  2. data/doc/20130625 MDArray Internals.docx +0 -0
  3. data/lib/colt/colt.rb +2 -0
  4. data/lib/colt/matrix/colt_matrix.rb +365 -0
  5. data/lib/colt/matrix/matrix2D_floating_algebra.rb +325 -0
  6. data/lib/colt/matrix/matrix_hierarchy.rb +258 -0
  7. data/lib/mdarray.rb +54 -3
  8. data/lib/mdarray/access.rb +16 -0
  9. data/lib/mdarray/counter.rb +16 -0
  10. data/lib/mdarray/creation.rb +13 -1
  11. data/lib/mdarray/lazy_mdarray.rb +6 -2
  12. data/lib/mdarray/lazy_operators.rb +8 -0
  13. data/lib/mdarray/printing.rb +18 -3
  14. data/lib/mdarray/section.rb +101 -0
  15. data/lib/netcdf/attribute.rb +154 -0
  16. data/lib/netcdf/cdm_node.rb +71 -0
  17. data/lib/netcdf/dimension.rb +146 -0
  18. data/lib/netcdf/file.rb +253 -0
  19. data/lib/netcdf/file_writer.rb +474 -0
  20. data/lib/netcdf/group.rb +205 -0
  21. data/lib/netcdf/netcdf.rb +151 -0
  22. data/lib/netcdf/variable.rb +520 -0
  23. data/test/colt/test_complete.rb +1 -2
  24. data/test/colt/test_double_matrix2d.rb +186 -0
  25. data/test/colt/test_float_matrix2d.rb +171 -0
  26. data/test/colt/test_math.rb +21 -0
  27. data/test/colt/test_matrix.rb +172 -0
  28. data/test/complete.rb +9 -1
  29. data/test/env.rb +11 -1
  30. data/test/mdarray/test_complete.rb +2 -0
  31. data/test/mdarray/test_creation.rb +19 -28
  32. data/test/mdarray/test_non_numeric.rb +97 -0
  33. data/test/mdarray/test_sections.rb +94 -0
  34. data/test/mdarray/test_views.rb +23 -1
  35. data/test/netcdf/netcdfwriter.rb +197 -0
  36. data/test/netcdf/test_complete.rb +27 -0
  37. data/test/netcdf/test_netcdf.rb +331 -0
  38. data/test/netcdf/test_redefine.rb +120 -0
  39. data/vendor/incanter.jar +0 -0
  40. data/vendor/{netcdfAll-4.3.16.jar → netcdfAll-4.3.18.jar} +0 -0
  41. data/version.rb +1 -1
  42. metadata +44 -26
  43. data/vendor/parallelcolt-0.10.0.jar +0 -0
@@ -0,0 +1,71 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ ##########################################################################################
4
+ # Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
5
+ # and distribute this software and its documentation, without fee and without a signed
6
+ # licensing agreement, is hereby granted, provided that the above copyright notice, this
7
+ # paragraph and the following two paragraphs appear in all copies, modifications, and
8
+ # distributions.
9
+ #
10
+ # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
11
+ # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
12
+ # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
13
+ # POSSIBILITY OF SUCH DAMAGE.
14
+ #
15
+ # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
17
+ # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
18
+ # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
19
+ # OR MODIFICATIONS.
20
+ ##########################################################################################
21
+
22
+ class NetCDF
23
+
24
+ #=======================================================================================
25
+ # Define a superclass for all the CDM node classes: Group, Dimension, etc. Define the
26
+ # sort of the node CDMSort so that we can 1. do true switching on node type 2. avoid use
27
+ # of instanceof 3. Use container classes that have more than one kind of node
28
+ #
29
+ # Also move various common fields and methods to here.
30
+ #=======================================================================================
31
+
32
+ class CDMNode
33
+
34
+ attr_reader :netcdf_elmt
35
+
36
+ #------------------------------------------------------------------------------------
37
+ # Initializes a CDMNode with a java CDMNode
38
+ #------------------------------------------------------------------------------------
39
+
40
+ def initialize(netcdf_cdmnode)
41
+ @netcdf_elmt = netcdf_cdmnode
42
+ end
43
+
44
+ #------------------------------------------------------------------------------------
45
+ #
46
+ #------------------------------------------------------------------------------------
47
+
48
+ def get_full_name
49
+ @netcdf_elmt.getFullName()
50
+ end
51
+
52
+ alias :get_full_name_escaped :get_full_name
53
+
54
+ #------------------------------------------------------------------------------------
55
+ #
56
+ #------------------------------------------------------------------------------------
57
+
58
+ def get_short_name
59
+ @netcdf_elmt.getShortName()
60
+ end
61
+
62
+ alias :name :get_short_name
63
+
64
+ end
65
+
66
+ end
67
+
68
+ require_relative 'group'
69
+ require_relative 'dimension'
70
+ require_relative 'variable'
71
+ require_relative 'attribute'
@@ -0,0 +1,146 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ ##########################################################################################
4
+ # Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
5
+ # and distribute this software and its documentation, without fee and without a signed
6
+ # licensing agreement, is hereby granted, provided that the above copyright notice, this
7
+ # paragraph and the following two paragraphs appear in all copies, modifications, and
8
+ # distributions.
9
+ #
10
+ # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
11
+ # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
12
+ # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
13
+ # POSSIBILITY OF SUCH DAMAGE.
14
+ #
15
+ # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
17
+ # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
18
+ # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
19
+ # OR MODIFICATIONS.
20
+ ##########################################################################################
21
+
22
+ class NetCDF
23
+
24
+ #=======================================================================================
25
+ # A Dimension is used to define the array shape of a Variable. It may be shared among
26
+ # Variables, which provides a simple yet powerful way of associating Variables. When a
27
+ # Dimension is shared, it has a unique name within its Group. It may have a coordinate
28
+ # Variable, which gives each index a coordinate value. A private Dimension cannot have a
29
+ # coordinate Variable, so use shared dimensions with coordinates when possible. The
30
+ # Dimension length must be > 0, except for an unlimited dimension which may have
31
+ # length = 0, and a vlen Dimension has length = -1.
32
+ # Immutable if setImmutable() was called, except for an Unlimited Dimension, whose size
33
+ # can change.
34
+ #=======================================================================================
35
+
36
+ class Dimension < CDMNode
37
+
38
+ #------------------------------------------------------------------------------------
39
+ #
40
+ #------------------------------------------------------------------------------------
41
+
42
+ def get_length
43
+ @netcdf_elmt.getLength()
44
+ end
45
+
46
+ alias :length :get_length
47
+
48
+ #------------------------------------------------------------------------------------
49
+ #
50
+ #------------------------------------------------------------------------------------
51
+
52
+ def shared?
53
+ @netcdf_elmt.isShared()
54
+ end
55
+
56
+ #------------------------------------------------------------------------------------
57
+ #
58
+ #------------------------------------------------------------------------------------
59
+
60
+ def unlimited?
61
+ @netcdf_elmt.isUnlimited()
62
+ end
63
+
64
+ #------------------------------------------------------------------------------------
65
+ #
66
+ #------------------------------------------------------------------------------------
67
+
68
+ def variable_length?
69
+ @netcdf_elmt.isVariableLength()
70
+ end
71
+
72
+ #------------------------------------------------------------------------------------
73
+ #
74
+ #------------------------------------------------------------------------------------
75
+
76
+ def group
77
+ NetCDF::Group.new(@netcdf_elmt.getGroup())
78
+ end
79
+
80
+ end # Dimension
81
+
82
+ #=======================================================================================
83
+ #
84
+ #=======================================================================================
85
+
86
+ class DimensionWriter < Dimension
87
+
88
+ #------------------------------------------------------------------------------------
89
+ #
90
+ #------------------------------------------------------------------------------------
91
+
92
+ def set_immutable
93
+ @netcdf_elmt.setImmutable()
94
+ end
95
+
96
+ #------------------------------------------------------------------------------------
97
+ #
98
+ #------------------------------------------------------------------------------------
99
+
100
+ def length=(val)
101
+ @netcdf_elmt.setLength(val)
102
+ end
103
+
104
+ #------------------------------------------------------------------------------------
105
+ #
106
+ #------------------------------------------------------------------------------------
107
+
108
+ def name=(name)
109
+ @netcdf_elmt.setName(name)
110
+ end
111
+
112
+ #------------------------------------------------------------------------------------
113
+ #
114
+ #------------------------------------------------------------------------------------
115
+
116
+ def shared=(bool)
117
+ @netcdf_elmt.setShared(bool)
118
+ end
119
+
120
+ #------------------------------------------------------------------------------------
121
+ #
122
+ #------------------------------------------------------------------------------------
123
+
124
+ def unlimited=(bool)
125
+ @netcdf_elmt.setUnlimited(bool)
126
+ end
127
+
128
+ #------------------------------------------------------------------------------------
129
+ #
130
+ #------------------------------------------------------------------------------------
131
+
132
+ def variable_length=(bool)
133
+ @netcdf_elmt.setVariableLength(bool)
134
+ end
135
+
136
+ #------------------------------------------------------------------------------------
137
+ #
138
+ #------------------------------------------------------------------------------------
139
+
140
+ def group=(group)
141
+ @netcdf_elmt.setGroup(group.netcdf_elmt)
142
+ end
143
+
144
+ end # DimensionWriter
145
+
146
+ end # NetCDF
@@ -0,0 +1,253 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ ##########################################################################################
4
+ # Copyright © 2013 Rodrigo Botafogo. All Rights Reserved. Permission to use, copy, modify,
5
+ # and distribute this software and its documentation, without fee and without a signed
6
+ # licensing agreement, is hereby granted, provided that the above copyright notice, this
7
+ # paragraph and the following two paragraphs appear in all copies, modifications, and
8
+ # distributions.
9
+ #
10
+ # IN NO EVENT SHALL RODRIGO BOTAFOGO BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
11
+ # INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF
12
+ # THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF RODRIGO BOTAFOGO HAS BEEN ADVISED OF THE
13
+ # POSSIBILITY OF SUCH DAMAGE.
14
+ #
15
+ # RODRIGO BOTAFOGO SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
16
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
17
+ # SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS".
18
+ # RODRIGO BOTAFOGO HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
19
+ # OR MODIFICATIONS.
20
+ ##########################################################################################
21
+
22
+ require 'java'
23
+
24
+ #======================================================================================
25
+ #
26
+ #======================================================================================
27
+
28
+ class NetCDF
29
+
30
+ #=======================================================================================
31
+ # Parent File for the file hierarchy that includes File and FileWriter.
32
+ #=======================================================================================
33
+
34
+ class FileParent
35
+
36
+ attr_reader :home_dir
37
+ attr_reader :file_name
38
+ attr_reader :netcdf_elmt
39
+ attr_reader :outside_scope
40
+ attr_reader :root_group
41
+
42
+ #------------------------------------------------------------------------------------
43
+ # NetCDF File
44
+ #------------------------------------------------------------------------------------
45
+
46
+ def initialize(home_dir, name, outside_scope = nil)
47
+ @home_dir = home_dir
48
+ @file_name = "#{home_dir}/#{name}.nc"
49
+ @outside_scope = outside_scope
50
+ end
51
+
52
+ #------------------------------------------------------------------------------------
53
+ # Gets a list of all global attributes, i.e, all attributes in the root group
54
+ #------------------------------------------------------------------------------------
55
+
56
+ def global_attributes
57
+ @root_group.attributes
58
+ end
59
+
60
+ end # FileParent
61
+
62
+ #=======================================================================================
63
+ # Read-only scientific datasets that are accessible through the netCDF API. Immutable
64
+ # after setImmutable() is called. However, reading data is not thread-safe.
65
+ #=======================================================================================
66
+
67
+ class File < FileParent
68
+ include_package "ucar.nc2"
69
+
70
+ #------------------------------------------------------------------------------------
71
+ # Opens a file for reading
72
+ #------------------------------------------------------------------------------------
73
+
74
+ def open
75
+ @netcdf_elmt = NetcdfFile.open(@file_name)
76
+ @root_group = @netcdf_elmt.findGroup(nil)
77
+ end
78
+
79
+ #------------------------------------------------------------------------------------
80
+ # Find out if the file can be opened, but dont actually open it.
81
+ #------------------------------------------------------------------------------------
82
+
83
+ def can_open?
84
+ @netcdf_elmt.canOpen(@file_name)
85
+ end
86
+
87
+ #------------------------------------------------------------------------------------
88
+ # closes the file
89
+ #------------------------------------------------------------------------------------
90
+
91
+ def close
92
+ @netcdf_elmt.close()
93
+ end
94
+
95
+ #------------------------------------------------------------------------------------
96
+ # Completely empty the objects in the netcdf file.
97
+ #------------------------------------------------------------------------------------
98
+
99
+ def empty
100
+ @netcdf_elmt.empty()
101
+ end
102
+
103
+ #------------------------------------------------------------------------------------
104
+ # Find a Group, with the specified (full) name.
105
+ #------------------------------------------------------------------------------------
106
+
107
+ def find_group(name)
108
+ NetCDF::Group.new(@netcdf_elmt.findGroup(name))
109
+ end
110
+
111
+ #------------------------------------------------------------------------------------
112
+ # Find an attribute, with the specified (escaped full) name.
113
+ #------------------------------------------------------------------------------------
114
+
115
+ def find_attribute(name)
116
+ NetCDF::Attribute.new(@netcdf_elmt.findAttribute(name))
117
+ end
118
+
119
+ #------------------------------------------------------------------------------------
120
+ # Find an global attribute, with the specified (full) name.
121
+ #------------------------------------------------------------------------------------
122
+
123
+ def find_global_attribute(name, ignore_case = false)
124
+ if (ignore_case)
125
+ NetCDF::Attribute.new(@netcdf_elmt.findGlobalAttributeIgnoreCase(name))
126
+ else
127
+ NetCDF::Attribute.new(@netcdf_elmt.findGlobalAttribute(name))
128
+ end
129
+ end
130
+
131
+ #------------------------------------------------------------------------------------
132
+ # Finds a dimension by full name
133
+ #------------------------------------------------------------------------------------
134
+
135
+ def find_dimension(name)
136
+ NetCDF::Dimension.new(@netcdf_elmt.findDimension(name))
137
+ end
138
+
139
+ #------------------------------------------------------------------------------------
140
+ # Return the unlimited (record) dimension, or null if not exist. If there are
141
+ # multiple unlimited dimensions, it will return the first one.
142
+ # <tt>Returns:</tt> the unlimited Dimension, or null if none.
143
+ #------------------------------------------------------------------------------------
144
+
145
+ def find_unlimited_dimension
146
+ NetCDF::Dimension.new(@netcdf_elmt.getUnlimitedDimension())
147
+ end
148
+
149
+ # Don't know the difference between find and get methods on the original NetCDF API
150
+ alias :get_unlimited_dimension :find_unlimited_dimension
151
+
152
+
153
+ #------------------------------------------------------------------------------------
154
+ # Finds a variable by name
155
+ #------------------------------------------------------------------------------------
156
+
157
+ def find_variable(name)
158
+ NetCDF::Variable.new(@netcdf_elmt.findVariable(name))
159
+ end
160
+
161
+
162
+
163
+
164
+ #------------------------------------------------------------------------------------
165
+ # Outputs the data CDL to an output stream
166
+ # * TODO: allow writing to other output streams. Need to interface with java streams
167
+ # * <tt>strict</tt> if true, make it stricly CDL, otherwise, add a little extra info
168
+ #------------------------------------------------------------------------------------
169
+
170
+ def write_cdl(out = $stdout, strict = false)
171
+ @netcdf_elmt.writeCDL(out.to_outputstream, strict)
172
+ end
173
+
174
+ #------------------------------------------------------------------------------------
175
+ # Find all dimensions in the file
176
+ #------------------------------------------------------------------------------------
177
+
178
+ def detail_info
179
+ @netcdf_elmt.getDetailInfo()
180
+ end
181
+
182
+ #------------------------------------------------------------------------------------
183
+ # Get a human-readable description for this file type.
184
+ #------------------------------------------------------------------------------------
185
+
186
+ def file_type_description
187
+ @netcdf_elmt.getFileTypeDescription()
188
+ end
189
+
190
+ #------------------------------------------------------------------------------------
191
+ # Get the file type id for the underlying data source.
192
+ #------------------------------------------------------------------------------------
193
+
194
+ def file_type_id
195
+ @netcdf_elmt.getFileTypeId()
196
+ end
197
+
198
+ #------------------------------------------------------------------------------------
199
+ # Get the globally unique dataset identifier, if it exists.
200
+ #------------------------------------------------------------------------------------
201
+
202
+ def id
203
+ @netcdf_elmt.getId()
204
+ end
205
+
206
+ #------------------------------------------------------------------------------------
207
+ #
208
+ #------------------------------------------------------------------------------------
209
+
210
+ def last_modified
211
+ @netcdf_elmt.getLastModified()
212
+ end
213
+
214
+ #------------------------------------------------------------------------------------
215
+ # Get the NetcdfFile location.
216
+ #------------------------------------------------------------------------------------
217
+
218
+ def location
219
+ @netcdf_elmt.getLocation()
220
+ end
221
+
222
+ #------------------------------------------------------------------------------------
223
+ # Get the human-readable title, if it exists.
224
+ #------------------------------------------------------------------------------------
225
+
226
+ def title
227
+ @netcdf_elmt.getTitle()
228
+ end
229
+
230
+ #------------------------------------------------------------------------------------
231
+ # Get the human-readable title, if it exists.
232
+ #------------------------------------------------------------------------------------
233
+
234
+ def unlimited_dimension?
235
+ @netcdf_elmt.hasUnlimitedDimension()
236
+ end
237
+
238
+
239
+
240
+
241
+ #------------------------------------------------------------------------------------
242
+ # Find all dimensions in the file
243
+ #------------------------------------------------------------------------------------
244
+
245
+ def get_dimensions
246
+ @netcdf_elmt.getDimensions()
247
+ end
248
+
249
+ end # File
250
+
251
+ end # NetCDF
252
+
253
+ require_relative 'file_writer'