cf.Data.compute¶
- Data.compute(persist=None, _force_to_memory=True, _cache_elements=True)[source]¶
A view of the computed data.
In-place changes to the returned array might affect the underlying Dask array, depending on how the that Dask array has been defined.
The returned array has the same mask hardness and fill value as the data.
Compare with
array.Performance
computecauses all delayed operations to be computed.Added in version (cfdm): 1.11.2.0
See also
array,datetime_array,sparse_array,persist,cf.persist_data- Parameters:
- persist:
Noneorbool, optional Control the persistence of computed data. Persisting turns the underlying lazy dask array into an equivalent chunked dask array, but now with the results fully computed and cached memory. This can avoid the expense of re-reading the data from disk, or re-computing it, when the data is accessed on multiple occasions.
If persist is
None(the default) then the value of persist will be taken from thecf.persist_datafunction. If persist is True then the data is persisted, regardless of value returned bycf.persist_data. If persist is False then the data is not persisted, regardless of value returned bycf.persist_data.Added in version (cfdm): 1.13.1.0
- _force_to_memory:
bool, optional If True (the default) then force the data resulting from computing the returned Dask graph to be in memory. If False then the data resulting from computing the Dask graph may or may not be in memory, depending on the nature of the stack.
- _cache_elements:
bool, optional If True (the default) then create a cache of selected elements from the computed array in memory, if the type of the array allows it. See
cache_elementsfor details.Added in version (cfdm): 1.13.0.0
- persist:
- Returns:
An in-memory view of the data
Examples
>>> d = cf.Data([1, 2, 3.0], 'km') >>> d.compute() array([1., 2., 3.])
>>> from scipy.sparse import csr_array >>> d = cf.Data(csr_array((2, 3))) >>> d.compute() <2x3 sparse array of type '<class 'numpy.float64'>' with 0 stored elements in Compressed Sparse Row format> >>> d.array array([[0., 0., 0.], [0., 0., 0.]]) >>> d.compute().toarray() array([[0., 0., 0.], [0., 0., 0.]])
>>> f = cf.example_field(0) >>> cf.write(f, 'file.nc') >>> f = cf.read('file.nc')[0] >>> print(f.data.compute()) [[0.007 0.034 0.003 0.014 0.018 0.037 0.024 0.029] [0.023 0.036 0.045 0.062 0.046 0.073 0.006 0.066] [0.11 0.131 0.124 0.146 0.087 0.103 0.057 0.011] [0.029 0.059 0.039 0.07 0.058 0.072 0.009 0.017] [0.006 0.036 0.019 0.035 0.018 0.037 0.034 0.013]] >>> f.data.compute(_force_to_memory=False) <CF PyfiveArray(5, 8): file.nc, q(5, 8)>