Retrieving values from a variable

The framework of PyGeode is designed to work with data that is too large to fit in memory. That is to say, you don’t normally have the numerical values at hand. Instead, you work with a symbolic reference to the data, and build a sequence of operations that will be performed only when data is needed. Usually, this is when:

  • You are saving the variable to a file

  • You are generating a plot

  • You are calling an iterative routine such as EOF(), or some other complicated operation for which there is no efficient symbolic wrapper.

In the above routines, the logistics of retrieving the data is handled internally, so you only see the end result. There may be times, however, when you want to work with raw values. Perhaps you are using PyGeode in conjunction with some other packages which operate on numpy arrays. Or, perhaps you just feel more comfortable working with an array instead of some abstract data object. We won’t judge you. Just call Var.get() and you can do whatever you want with the data.

Var.get(pbar=None, **kwargs)[source]

Gets a raw numpy array containing the values of the variable.

Parameters
pbarboolean (optional)

If True, will display a progress bar while the data is being retrieved. This requires the python-progressbar package (not included with PyGeode).

**kwargskeyword arguments (optional)

One or more keyword arguments may be included to subset the variable before grabbing the data. See Var.__call__() for a similar method which uses this keyword subsetting.

Returns
outnumpy.ndarray

The requested values, as a numpy array.

Notes

Once you grab the data as a numpy array, you can no longer use the PyGeode functions to do further work on it directly. You can, however, use Var.__init__() to re-wrap your numpy array as a PyGeode Var. This may be useful if you want to do some very complicated operations on the data using the numpy interface as an intermediate step.

PyGeode variables can be huge! They can be larger than the available RAM in your computer, or even larger than your hard disk. Numpy arrays, on the other hand, need to fit in memory, so make sure you are only getting a reasonable piece of data at a time.

Examples

>>> from pygeode.tutorial import t1
>>> print(t1.Temp)
<Var 'Temp'>:
  Units: K  Shape:  (lat,lon)  (31,60)
  Axes:
    lat <Lat>      :  90 S to 90 N (31 values)
    lon <Lon>      :  0 E to 354 E (60 values)
  Attributes:
    {}
  Type:  Add_Var (dtype="float64")
>>> x = t1.Temp.get()
>>> print(x)
[[260.73262556 258.08759192 256.45287123 ... 265.01237988 265.01237988
  263.37765919]
 [261.22683172 258.75813366 257.23239435 ... 265.22126909 265.22126909
  263.69552978]
 [261.98265134 259.69028886 258.27353093 ... 265.69177175 265.69177175
  264.27501382]
 ...
 [261.98265134 264.27501382 265.69177175 ... 258.27353093 258.27353093
  259.69028886]
 [261.22683172 263.69552978 265.22126909 ... 257.23239435 257.23239435
  258.75813366]
 [260.73262556 263.37765919 265.01237988 ... 256.45287123 256.45287123
  258.08759192]]
Var.__getitem__(slices)[source]

Gets a raw numpy array containing a subset of values of the variable.

Parameters
sliceslist of slices
Returns
outnumpy.ndarray

The requested values, as a numpy array.

Examples

>>> from pygeode.tutorial import t1
>>> print(t1.Temp[:].shape)
(31, 60)
>>> print(t1.Temp[20:-6, ::12])
[[285.64721554 287.07380031 286.52889342 284.76553766 284.22063076]
 [281.09169696 282.80359869 282.14971042 280.03368351 279.37979523]
 [276.73945224 278.73667093 277.97380127 275.50510321 274.74223356]
 [272.82122084 275.10375648 274.23190545 271.41053624 270.5386852 ]
 [269.47711035 272.04496294 271.06413053 267.89009017 266.90925775]]
Var.load(pbar=True)[source]

Returns a version of this variable with all data loaded into memory.

Parameters
pbarboolean

If True, display a progress bar while loading data.

See Also:

Var class overview