Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Sample usage

Richard Hattersley edited this page Aug 30, 2013 · 1 revision

In-memory mean of large dataset

When the result of data-reduction (e.g. mean) is small enough to hold in memory then one can simply request the answer as a NumPy array.

import biggus
import netCDF4

src_var = netCDF4.Dataset('/path/to/my/data.nc').variables['my_var']
array = biggus.ArrayAdapter(src_var)
mean_array = biggus.mean(array)
mean = mean_array.ndarray()

Disk-based mean of very large dataset

When the result of data-reduction (e.g. mean) is still too big to hold in memory then one can request the answer is "piped" to persistent storage.

import biggus
import netCDF4

src_var = netCDF4.Dataset('/path/to/my/data.nc').variables['my_var']
array = biggus.ArrayAdapter(src_var)
mean_array = biggus.mean(array)

target_dataset = netCDF4.Dataset('/path/to/my/result.nc', mode='a')
target_var = target_dataset.create_variable('my_result', mean_array.dtype, ('t', 'y', 'x'))
biggus.save(mean_array, target_var)
Clone this wiki locally