cfdm.Data.todict

Data.todict(graph='cull', _force_mask_hardness=True, _force_to_memory=True, optimize_graph=None)[source]

Return a dictionary of the dask graph key/value pairs.

New in version (cfdm): 1.11.2.0

Parameters
graph: str or None

Specify the treatment to apply to the graph (not in-place) before converting to a dictionary. Must be one of:

  • 'cull'

    This is the default. Remove unnecessary tasks which do not contribute to the computed result, equivalent to applying dask.optimization.cull to the graph.

  • 'optimise'

    Apply all possible graph optimisations. These will include removal of unnecessary tasks (see 'cull'), and is equivalent to applying dask.optimize to the graph.

  • None

    Do not apply any optimisations.

New in version (cfdm): 1.12.0.0

_force_mask_hardness: bool, optional

If True (the default) then force the mask hardness of the returned Dask graph to be that given by the hardmask attribute. If False then the mask hardness may or may not be correct, depending on the nature of the stack of previously defined lazy operations.

Set to False if the intention is to just inspect the state of the Dask graph, or is to add to the returned Dask graph further operations to which can correctly manage the mask hardness.

_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 of previously defined lazy operations.

Set to False if the intention is to just inspect the state of the Dask graph, or is to add to the returned Dask graph further operations to which can handle any required conversion to data in memory.

optimize_graph: Deprecated at version 1.12.0.0

Use the graph parameter instead. Note that graph='optimise' is equivalent to the deprecated optimize_graph=True.

Returns
dict

The dictionary of the dask graph’s key/value pairs.

Examples

>>> d = cfdm.Data([1, 2, 3, 4], chunks=2)
>>> d.todict()
{('array-58934a19a81f97038351581dea42e32f', 0): array([1, 2]),
 ('array-58934a19a81f97038351581dea42e32f', 1): array([3, 4]),
 ('cfdm_harden_mask-23375a35009f4d3ec84b767640370152',
  0): <Task ('cfdm_harden_mask-23375a35009f4d3ec84b767640370152', 0) cfdm_harden_mask(...)>,
 ('cfdm_harden_mask-23375a35009f4d3ec84b767640370152',
  1): <Task ('cfdm_harden_mask-23375a35009f4d3ec84b767640370152', 1) cfdm_harden_mask(...)>}
>>> e = d[0]
>>> e.todict(graph=None)
{('array-58934a19a81f97038351581dea42e32f', 0): array([1, 2]),
 ('array-58934a19a81f97038351581dea42e32f', 1): array([3, 4]),
 ('getitem-4d1949dc1e18d336e215bc226cd7b109',
  0): <Task ('getitem-4d1949dc1e18d336e215bc226cd7b109', 0) getitem(...)>,
 ('cfdm_harden_mask-b57a3694b00d301421b9fc21db4cf24e',
  0): <Task ('cfdm_harden_mask-b57a3694b00d301421b9fc21db4cf24e', 0) cfdm_harden_mask(...)>}
>>> e.todict(graph='cull')
{('getitem-4d1949dc1e18d336e215bc226cd7b109',
  0): <Task ('getitem-4d1949dc1e18d336e215bc226cd7b109', 0) getitem(...)>,
 ('array-58934a19a81f97038351581dea42e32f', 0): array([1, 2]),
 ('cfdm_harden_mask-b57a3694b00d301421b9fc21db4cf24e',
  0): <Task ('cfdm_harden_mask-b57a3694b00d301421b9fc21db4cf24e', 0) cfdm_harden_mask(...)>}