Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions lib/iris/fileformats/_pyke_rules/fc_rules_cf.krb
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ fc_extras
import iris.coord_systems
import iris.fileformats.cf as cf
import iris.fileformats.netcdf
from iris.fileformats.netcdf import parse_cell_methods, UnknownCellMethodWarning
from iris.fileformats.netcdf import _get_cf_var_data, parse_cell_methods, UnknownCellMethodWarning
import iris.fileformats.pp as pp
import iris.exceptions
import iris.std_names
Expand Down Expand Up @@ -1712,25 +1712,16 @@ fc_extras
# Get units
attr_units = get_attr_units(cf_coord_var, attributes)

def cf_var_as_array(cf_var):
dtype = iris.fileformats.netcdf._get_actual_dtype(cf_var)
fill_value = getattr(cf_var.cf_data, '_FillValue',
netCDF4.default_fillvals[dtype.str[1:]])
proxy = iris.fileformats.netcdf.NetCDFDataProxy(
cf_var.shape, dtype, engine.filename,
cf_var.cf_name, fill_value)
return as_lazy_data(proxy)

# Get any coordinate point data.
if isinstance(cf_coord_var, cf.CFLabelVariable):
points_data = cf_coord_var.cf_label_data(cf_var)
else:
points_data = cf_var_as_array(cf_coord_var)
points_data = _get_cf_var_data(cf_coord_var, engine.filename)

# Get any coordinate bounds.
cf_bounds_var = get_cf_bounds_var(cf_coord_var)
if cf_bounds_var is not None:
bounds_data = cf_var_as_array(cf_bounds_var)
bounds_data = _get_cf_var_data(cf_bounds_var, engine.filename)

# Handle transposed bounds where the vertex dimension is not
# the last one. Test based on shape to support different
Expand Down Expand Up @@ -1783,16 +1774,7 @@ fc_extras
# Get units
attr_units = get_attr_units(cf_cm_attr, attributes)

def cf_var_as_array(cf_var):
dtype = cf_var.dtype
fill_value = getattr(cf_var.cf_data, '_FillValue',
netCDF4.default_fillvals[dtype.str[1:]])
proxy = iris.fileformats.netcdf.NetCDFDataProxy(
cf_var.shape, dtype, engine.filename,
cf_var.cf_name, fill_value)
return as_lazy_data(proxy)

data = cf_var_as_array(cf_cm_attr)
data = _get_cf_var_data(cf_cm_attr, engine.filename)

# Determine the name of the dimension/s shared between the CF-netCDF data variable
# and the coordinate being built.
Expand Down
15 changes: 12 additions & 3 deletions lib/iris/fileformats/netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,16 +501,25 @@ def _get_actual_dtype(cf_var):
return dummy_data.dtype


def _load_cube(engine, cf, cf_var, filename):
"""Create the cube associated with the CF-netCDF data variable."""
def _get_cf_var_data(cf_var, filename):
# Get lazy chunked data out of a cf variable.
dtype = _get_actual_dtype(cf_var)

# Create cube with deferred data, but no metadata
fill_value = getattr(cf_var.cf_data, '_FillValue',
netCDF4.default_fillvals[cf_var.dtype.str[1:]])
proxy = NetCDFDataProxy(cf_var.shape, dtype, filename, cf_var.cf_name,
fill_value)
data = as_lazy_data(proxy)
chunks = cf_var.cf_data.chunking()
# Chunks can be an iterable, None, or `'contiguous'`.
if chunks == 'contiguous':
chunks = None
return as_lazy_data(proxy, chunks=chunks)


def _load_cube(engine, cf, cf_var, filename):
"""Create the cube associated with the CF-netCDF data variable."""
data = _get_cf_var_data(cf_var, filename)
cube = iris.cube.Cube(data)

# Reset the pyke inference engine.
Expand Down