@@ -1100,8 +1100,8 @@ def _add_aux_coords(self, cube, cf_var_cube, dimension_names):
11001100 # Add CF-netCDF auxiliary coordinate variable references to the
11011101 # CF-netCDF data variable.
11021102 if auxiliary_coordinate_names :
1103- cf_var_cube . coordinates = ' ' .join (
1104- sorted ( auxiliary_coordinate_names ) )
1103+ coord_variable_names = ' ' .join (sorted ( auxiliary_coordinate_names ))
1104+ _setncattr ( cf_var_cube , 'coordinates' , coord_variable_names )
11051105
11061106 def _add_cell_measures (self , cube , cf_var_cube , dim_names ):
11071107 """
@@ -1135,8 +1135,8 @@ def _add_cell_measures(self, cube, cf_var_cube, dim_names):
11351135 # Add CF-netCDF cell measure variable references to the
11361136 # CF-netCDF data variable.
11371137 if cell_measure_names :
1138- cf_var_cube . cell_measures = ' ' .join (
1139- sorted ( cell_measure_names ) )
1138+ cm_var_names = ' ' .join (sorted ( cell_measure_names ))
1139+ _setncattr ( cf_var_cube , 'cell_measures' , cm_var_names )
11401140
11411141 def _add_dim_coords (self , cube , dimension_names ):
11421142 """
@@ -1225,7 +1225,7 @@ def _add_aux_factories(self, cube, cf_var_cube, dimension_names):
12251225 primary_coord )
12261226 cf_var = self ._dataset .variables [name ]
12271227 _setncattr (cf_var , 'standard_name' , std_name )
1228- cf_var . axis = 'Z'
1228+ _setncattr ( cf_var , ' axis' , 'Z' )
12291229 # Update the formula terms.
12301230 ft = formula_terms .split ()
12311231 ft = [name if t == cf_name else t for t in ft ]
@@ -1235,10 +1235,11 @@ def _add_aux_factories(self, cube, cf_var_cube, dimension_names):
12351235 # Update the associated cube variable.
12361236 coords = cf_var_cube .coordinates .split ()
12371237 coords = [name if c == cf_name else c for c in coords ]
1238- cf_var_cube .coordinates = ' ' .join (coords )
1238+ _setncattr (cf_var_cube , 'coordinates' ,
1239+ ' ' .join (coords ))
12391240 else :
12401241 _setncattr (cf_var , 'standard_name' , std_name )
1241- cf_var . axis = 'Z'
1242+ _setncattr ( cf_var , ' axis' , 'Z' )
12421243 _setncattr (cf_var , 'formula_terms' , formula_terms )
12431244
12441245 def _get_dim_names (self , cube ):
@@ -1382,7 +1383,7 @@ def _create_cf_bounds(self, coord, cf_var, cf_name):
13821383 # Create the bounds dimension with the appropriate extent.
13831384 self ._dataset .createDimension (bounds_dimension_name , n_bounds )
13841385
1385- cf_var . bounds = cf_name + '_bnds'
1386+ _setncattr ( cf_var , ' bounds' , cf_name + '_bnds' )
13861387 cf_var_bounds = self ._dataset .createVariable (
13871388 cf_var .bounds , bounds .dtype .newbyteorder ('=' ),
13881389 cf_var .dimensions + (bounds_dimension_name ,))
@@ -1481,7 +1482,7 @@ def _create_cf_cell_measure_variable(self, cube, dimension_names,
14811482 cf_var [:] = data
14821483
14831484 if cell_measure .units != 'unknown' :
1484- cf_var . units = str (cell_measure .units )
1485+ _setncattr ( cf_var , ' units' , str (cell_measure .units ) )
14851486
14861487 if cell_measure .standard_name is not None :
14871488 _setncattr (cf_var , 'standard_name' , cell_measure .standard_name )
@@ -1577,7 +1578,7 @@ def _create_cf_variable(self, cube, dimension_names, coord):
15771578 if coord in cf_coordinates :
15781579 axis = iris .util .guess_coord_axis (coord )
15791580 if axis is not None and axis .lower () in SPATIO_TEMPORAL_AXES :
1580- cf_var . axis = axis .upper ()
1581+ _setncattr ( cf_var , ' axis' , axis .upper () )
15811582
15821583 # Add the data to the CF-netCDF variable.
15831584 cf_var [:] = points
@@ -1589,7 +1590,7 @@ def _create_cf_variable(self, cube, dimension_names, coord):
15891590 standard_name , long_name , units = self ._cf_coord_identity (coord )
15901591
15911592 if units != 'unknown' :
1592- cf_var . units = units
1593+ _setncattr ( cf_var , ' units' , units )
15931594
15941595 if standard_name is not None :
15951596 _setncattr (cf_var , 'standard_name' , standard_name )
@@ -1801,7 +1802,7 @@ def add_ellipsoid(ellipsoid):
18011802 self ._coord_systems .append (cs )
18021803
18031804 # Refer to grid var
1804- cf_var_cube . grid_mapping = cs .grid_mapping_name
1805+ _setncattr ( cf_var_cube , ' grid_mapping' , cs .grid_mapping_name )
18051806
18061807 def _create_cf_data_variable (self , cube , dimension_names , local_keys = None ,
18071808 ** kwargs ):
0 commit comments