hdf5 0.2.2 → 0.3.0

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 (6) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +2 -2
  3. data/VERSION +1 -1
  4. data/hdf5.gemspec +4 -4
  5. data/lib/hdf5.rb +40 -1
  6. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f87349d9ad32fe5bf91ee2b354e422a33d58c6dd
4
- data.tar.gz: 123edc76244a070d15879c517833db299541840a
3
+ metadata.gz: 0ff1af6e7836f2531fbadc9744c5d35825c7b9ae
4
+ data.tar.gz: df8346f1e5fce5df73518e961e7a5aa45ef41327
5
5
  SHA512:
6
- metadata.gz: 54ecfe442aff612125759e3011bbfb5c30aeec7efc644de3254d4fcdf21079cead05966a2db3500740f471cd69d075b9bb60bb671b01192b7d66c16e2408a203
7
- data.tar.gz: 352c2115bd2e5e6383a050a12ab6bca2db9a4a1c9b9fa70aeb54f057f6ecbcbe1dbb599a53297a2d027079fd64f1e4ab5845528d43869a597a43bcfb6936f64e
6
+ metadata.gz: f388ab35ef657c5912817f79f3731b47db30ff7b2042562c5369a767653c4b756bad53aa738270e8ae152093026233e876dac11d9709c1ad6a406de53be8cc4c
7
+ data.tar.gz: 0fec9ef227844f49831910167ae9c2773468d71ea9c273717f3a05a45183c023d56ecbd091afd873dcfe05eda4fb4633b8371ae88b13cbb4d5e631e6ce767955
data/Rakefile CHANGED
@@ -17,8 +17,8 @@ Jeweler::Tasks.new do |gem|
17
17
  gem.name = "hdf5"
18
18
  gem.homepage = "http://github.com/edmundhighcock/hdf5"
19
19
  gem.license = "GPLv3"
20
- gem.summary = %Q{A ruby wrapper to the HDF5 data library. Currently read only.}
21
- gem.description = %Q{A ruby wrapper to the HDF5 data library. Currently read only.}
20
+ gem.summary = %Q{A ruby wrapper to the HDF5 data library. Currently can only read existing HDF5 files.}
21
+ gem.description = %Q{A ruby wrapper to the HDF5 data library. Currently can only read HDF5 files.}
22
22
  gem.email = "edmundhighcock@users.sourceforge.net"
23
23
  gem.authors = ["Edmund Highcock"]
24
24
  gem.files.exclude 'test/**/*'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.3.0
data/hdf5.gemspec CHANGED
@@ -2,18 +2,18 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: hdf5 0.2.2 ruby lib
5
+ # stub: hdf5 0.3.0 ruby lib
6
6
  # stub: ext/hdf5/extconf.rb
7
7
 
8
8
  Gem::Specification.new do |s|
9
9
  s.name = "hdf5"
10
- s.version = "0.2.2"
10
+ s.version = "0.3.0"
11
11
 
12
12
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
13
13
  s.require_paths = ["lib"]
14
14
  s.authors = ["Edmund Highcock"]
15
15
  s.date = "2014-07-23"
16
- s.description = "A ruby wrapper to the HDF5 data library. Currently read only."
16
+ s.description = "A ruby wrapper to the HDF5 data library. Currently can only read HDF5 files."
17
17
  s.email = "edmundhighcock@users.sourceforge.net"
18
18
  s.extensions = ["ext/hdf5/extconf.rb"]
19
19
  s.extra_rdoc_files = [
@@ -35,7 +35,7 @@ Gem::Specification.new do |s|
35
35
  s.homepage = "http://github.com/edmundhighcock/hdf5"
36
36
  s.licenses = ["GPLv3"]
37
37
  s.rubygems_version = "2.2.2"
38
- s.summary = "A ruby wrapper to the HDF5 data library. Currently read only."
38
+ s.summary = "A ruby wrapper to the HDF5 data library. Currently can only read existing HDF5 files."
39
39
 
40
40
  if s.respond_to? :specification_version then
41
41
  s.specification_version = 4
data/lib/hdf5.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'ffi'
2
+ require 'narray'
2
3
  class NArray
3
4
  # Returns an FFI::Pointer which points to the location
4
5
  # of the actual data array in memory.
@@ -195,21 +196,51 @@ module Hdf5
195
196
  # scope in the future for writing custom closures for reading in more
196
197
  # complex datatypes.
197
198
  def narray_all
198
- narr = NArray.send(narray_type, *dataspace.dims)
199
+ narr = NArray.send(narray_type, *dataspace.dims.reverse) # Note narray is fortran-style column major
199
200
  basic_read(@id, datatype.id, 0, 0, 0, narr.ffi_pointer)
200
201
  narr
201
202
  end
203
+ # Create an NArray of the appropriate type and size and a subsection of
204
+ # the dataset into it. start_indexes and end_indexes should be arrays
205
+ # of size ndims. start_indexes should contain the (zero-based) offset
206
+ # of the start of the read, and end_indexes should contain the offset of
207
+ # the end of the read. Each element of end_indexes can either be a zero
208
+ # based positive offset, or a negative offset where -1 corresponds to the
209
+ # end of the dataset dimension. This function will not work for complicated
210
+ # datatypes (basically only works for ints, floats and complexes, where a datatype
211
+ # composed of two floats is assumed to be a complex). There is
212
+ # scope in the future for writing custom closures for reading in more
213
+ # complex datatypes.
214
+ # As an example, consider a two-dimensional 6x10 dataset.
215
+ # dataset.narray_read([0,0], [-1,-1]) # would read the whole of the dataset
216
+ # dataset.narray_read([0,0], [5,9]) # would read the whole of the dataset
217
+ # dataset.narray_read([0,0], [2,-1]) # would read half the dataset
218
+ # dataset.narray_read([0,0], [-4,-1]) # would read the same half of the dataset
219
+ # dataset.narray_read([2,4], [2,4]) # would read one element of the dataset
220
+ def narray_simple_read(start_indexes, end_indexes)
221
+ nd = dataspace.ndims
222
+ raise ArgumentError.new("start_indexes and end_indexes must be of size ndims") unless start_indexes.size == nd and end_indexes.size == nd
223
+ szs = dataspace.dims
224
+ counts = end_indexes.zip(start_indexes.zip(szs)).map{|ei, (si, sz)| ei < 0 ? ei + sz - si + 1 : ei - si + 1}
225
+ dtspce = H5Dataspace.create_simple(counts)
226
+ dtspce.offset_simple(start_indexes)
227
+ narr = NArray.send(narray_type, *dtspce.dims.reverse) # Note narray is fortran-style column major
228
+ basic_read(@id, datatype.id, 0, dtspce.id, 0, narr.ffi_pointer)
229
+ narr
230
+ end
202
231
  #def array
203
232
  #end
204
233
  end
205
234
  # Object for wrapping an HD5 dataspace, which contains
206
235
  # information about the dimensions and size of the dataset
207
236
  class H5Dataspace
237
+ attr_reader :id
208
238
  extend FFI::Library
209
239
  ffi_lib H5Library.library_path
210
240
  attach_function :basic_get_simple_extent_ndims, :H5Sget_simple_extent_ndims, [H5Types.hid_t], :int
211
241
  attach_function :basic_get_simple_extent_dims, :H5Sget_simple_extent_dims, [H5Types.hid_t, :pointer, :pointer], :int
212
242
  attach_function :basic_create_simple, :H5Screate_simple, [:int, :pointer, :pointer], H5Types.hid_t
243
+ attach_function :basic_offset_simple, :H5Soffset_simple, [H5Types.hid_t, :pointer], H5Types.herr_t
213
244
  # Create a new HDF5 dataspace with the given current and maximum
214
245
  # dimensions. If maximum_dims is omitted it is set to current_dims.
215
246
  # Returns an H5Dataspace object wrapping the dataspace
@@ -240,12 +271,20 @@ module Hdf5
240
271
  return [basic_dims, basic_maxdims]
241
272
  end
242
273
  private :basic_dims_maxdims
274
+ # Get the size of the dataspace
243
275
  def dims
244
276
  basic_dims_maxdims[0].get_array_of_int64(0, ndims)
245
277
  end
278
+ # Get the maximum size of the dataspace
246
279
  def maxdims
247
280
  basic_dims_maxdims[1].get_array_of_int64(0, ndims)
248
281
  end
282
+ # Set the offset of the dataspace. offsets should be an ndims-sized array
283
+ # of zero-based integer offsets.
284
+ def offset_simple(offsets)
285
+ raise ArgumentError.new("offsets should have ndims elements") unless offsets.size == ndims
286
+ basic_offset_simple(@id, offsets.ffi_mem_pointer_hsize_t)
287
+ end
249
288
  end
250
289
  # Object for wrapping an HD5 datatype, which contains
251
290
  # information about the type and makeup of an individual element
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hdf5
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edmund Highcock
@@ -136,7 +136,8 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- description: A ruby wrapper to the HDF5 data library. Currently read only.
139
+ description: A ruby wrapper to the HDF5 data library. Currently can only read HDF5
140
+ files.
140
141
  email: edmundhighcock@users.sourceforge.net
141
142
  executables: []
142
143
  extensions:
@@ -178,5 +179,6 @@ rubyforge_project:
178
179
  rubygems_version: 2.2.2
179
180
  signing_key:
180
181
  specification_version: 4
181
- summary: A ruby wrapper to the HDF5 data library. Currently read only.
182
+ summary: A ruby wrapper to the HDF5 data library. Currently can only read existing
183
+ HDF5 files.
182
184
  test_files: []