# Buggy code
def __init__(
    self,
    semi_major_axis=None,
    semi_minor_axis=None,
    inverse_flattening=None,
    longitude_of_prime_meridian=0,
):
    """
    Creates a new GeogCS.

    Kwargs:

        * semi_major_axis              -  of ellipsoid in metres
        * semi_minor_axis              -  of ellipsoid in metres
        * inverse_flattening           -  of ellipsoid
        * longitude_of_prime_meridian  -  Can be used to specify the
                                          prime meridian on the ellipsoid
                                          in degrees. Default = 0.

    If just semi_major_axis is set, with no semi_minor_axis or
    inverse_flattening, then a perfect sphere is created from the given
    radius.

    If just two of semi_major_axis, semi_minor_axis, and
    inverse_flattening are given the missing element is calculated from the
    formula:
    :math:`flattening = (major - minor) / major`

    Currently, Iris will not allow over-specification (all three ellipsoid
    parameters).

    Examples::

        cs = GeogCS(6371229)
        pp_cs = GeogCS(iris.fileformats.pp.EARTH_RADIUS)
        airy1830 = GeogCS(semi_major_axis=6377563.396,
                          semi_minor_axis=6356256.909)
        airy1830 = GeogCS(semi_major_axis=6377563.396,
                          inverse_flattening=299.3249646)
        custom_cs = GeogCS(6400000, 6300000)

    """
    # No ellipsoid specified? (0 0 0)
    if (
        (semi_major_axis is None)
        and (semi_minor_axis is None)
        and (inverse_flattening is None)
    ):
        raise ValueError("No ellipsoid specified")

    # Ellipsoid over-specified? (1 1 1)
    if (
        (semi_major_axis is not None)
        and (semi_minor_axis is not None)
        and (inverse_flattening is not None)
    ):
        raise ValueError("Ellipsoid is overspecified")

    # Perfect sphere (semi_major_axis only)? (1 0 0)
    elif semi_major_axis is not None and (
        semi_minor_axis is None and inverse_flattening is None
    ):
        semi_minor_axis = semi_major_axis
        inverse_flattening = 0.0

    # Calculate semi_major_axis? (0 1 1)
    elif semi_major_axis is None and (
        semi_minor_axis is not None and inverse_flattening is not None
    ):
        semi_major_axis = -semi_minor_axis / (
            (1.0 - inverse_flattening) / inverse_flattening
        )

    # Calculate semi_minor_axis? (1 0 1)
    elif semi_minor_axis is None and (
        semi_major_axis is not None and inverse_flattening is not None
    ):
        semi_minor_axis = semi_major_axis - (
            (1.0 / inverse_flattening) * semi_major_axis
        )

    # Calculate inverse_flattening? (1 1 0)
    elif inverse_flattening is None and (
        semi_major_axis is not None and semi_minor_axis is not None
    ):
        if semi_major_axis == semi_minor_axis:
            inverse_flattening = 0.0
        else:
            inverse_flattening = 1.0 / (
                (semi_major_axis - semi_minor_axis) / semi_major_axis
            )

    # We didn't get enough to specify an ellipse.
    else:
        raise ValueError("Insufficient ellipsoid specification")

    #: Major radius of the ellipsoid in metres.
    self.semi_major_axis = float(semi_major_axis)

    #: Minor radius of the ellipsoid in metres.
    self.semi_minor_axis = float(semi_minor_axis)

    #: :math:`1/f` where :math:`f = (a-b)/a`
    self.inverse_flattening = float(inverse_flattening)

    #: Describes 'zero' on the ellipsoid in degrees.
    self.longitude_of_prime_meridian = float(longitude_of_prime_meridian)


# Traceback (TypeError)
iris.__version__
Out[25]: '2.3.0'

In [26]: c =  iris.load_cube('/our/own/local/directory/hierarchy/snw_EUR-11_ECMWF-ERAINT_evaluation_r1i1p1_CNRM-ALADIN63_v1_day_19790101-19801231.nc')

In [27]: c.coord('projection_x_coordinate')
Out[27]:
DimCoord(array([   0. ,   12.5,   25. ,   37.5,   50. ,   62.5,   75. ,   87.5,
100. ,  112.5,  125. ,  137.5,  150. ,  162.5,  175. ,  187.5,
##   8>< snip    8>< snip
5500. , 5512.5, 5525. , 5537.5, 5550. , 5562.5, 5575. , 5587.5,
5600. , 5612.5, 5625. , 5637.5, 5650. ]), standard_name='projection_x_coordinate', units=Unit('km'), long_name='x coordinate of projection', var_name='x', coord_system=LambertConformal(central_lat=49.5, central_lon=10.5, false_easting=None, false_northing=None, secant_latitudes=(49.5,), ellipsoid=None))

In [28]: iris.save(c,'c.nc')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-28-4160b1a355b0> in <module>
----> 1 iris.save(c,'c.nc')

~/.conda/envs/climix-devel-3/lib/python3.8/site-packages/iris/io/__init__.py in save(source, target, saver, **kwargs)
406     # Single cube?
407     if isinstance(source, iris.cube.Cube):
--> 408         saver(source, target, **kwargs)
409
410     # CubeList or sequence of cubes?

~/.conda/envs/climix-devel-3/lib/python3.8/site-packages/iris/fileformats/netcdf.py in save(cube, filename, netcdf_format, local_keys, unlimited_dimensions, zlib, complevel, shuffle, fletcher32, contiguous, chunksizes, endian, least_significant_digit, packing, fill_value)
2386         # Iterate through the cubelist.
2387         for cube, packspec, fill_value in zip(cubes, packspecs, fill_values):
-> 2388             sman.write(cube, local_keys, unlimited_dimensions, zlib, complevel,
2389                        shuffle, fletcher32, contiguous, chunksizes, endian,
2390                        least_significant_digit, packing=packspec,

~/.conda/envs/climix-devel-3/lib/python3.8/site-packages/iris/fileformats/netcdf.py in write(self, cube, local_keys, unlimited_dimensions, zlib, complevel, shuffle, fletcher32, contiguous, chunksizes, endian, least_significant_digit, packing, fill_value)
981
982         # Create the associated cube CF-netCDF data variable.
--> 983         cf_var_cube = self._create_cf_data_variable(
984             cube, dimension_names, local_keys, zlib=zlib, complevel=complevel,
985             shuffle=shuffle, fletcher32=fletcher32, contiguous=contiguous,

~/.conda/envs/climix-devel-3/lib/python3.8/site-packages/iris/fileformats/netcdf.py in _create_cf_data_variable(self, cube, dimension_names, local_keys, packing, fill_value, **kwargs)
2131
2132         # Create the CF-netCDF grid mapping.
-> 2133         self._create_cf_grid_mapping(cube, cf_var)
2134
2135         return cf_var

~/.conda/envs/climix-devel-3/lib/python3.8/site-packages/iris/fileformats/netcdf.py in _create_cf_grid_mapping(self, cube, cf_var_cube)
1848                     cf_var_grid.latitude_of_projection_origin = cs.central_lat
1849                     cf_var_grid.longitude_of_central_meridian = cs.central_lon
-> 1850                     cf_var_grid.false_easting = cs.false_easting
1851                     cf_var_grid.false_northing = cs.false_northing
1852

netCDF4/_netCDF4.pyx in netCDF4._netCDF4.Variable.__setattr__()

netCDF4/_netCDF4.pyx in netCDF4._netCDF4.Variable.setncattr()

netCDF4/_netCDF4.pyx in netCDF4._netCDF4._set_att()

TypeError: illegal data type for attribute b'false_easting', must be one of dict_keys(['S1', 'i1', 'u1', 'i2', 'u2', 'i4', 'u4', 'i8', 'u8', 'f4', 'f8']), got O


In [29]: !ncdump -h /our/own/local/directory/hierarchy/snw_EUR-11_ECMWF-ERAINT_evaluation_r1i1p1_CNRM-ALADIN63_v1_day_19790101-19801231.nc
netcdf snw_EUR-11_ECMWF-ERAINT_evaluation_r1i1p1_CNRM-ALADIN63_v1_day_19790101-19801231 {
dimensions:
y = 453 ;
x = 453 ;
nvertex = 4 ;
time = UNLIMITED ; // (731 currently)
axis_nbounds = 2 ;
variables:
double bounds_nav_lon(y, x, nvertex) ;
double bounds_nav_lat(y, x, nvertex) ;
double time(time) ;
time:axis = "T" ;
time:standard_name = "time" ;
time:long_name = "Time axis" ;
time:calendar = "gregorian" ;
time:units = "days since 1949-01-01 00:00:00" ;
time:time_origin = "1949-01-01 00:00:00" ;
time:bounds = "time_bounds" ;
double time_bounds(time, axis_nbounds) ;
float snw(time, y, x) ;
snw:standard_name = "surface_snow_amount" ;
snw:long_name = "Surface Snow Amount" ;
snw:units = "kg m-2" ;
snw:online_operation = "average" ;
snw:interval_operation = "450 s" ;
snw:interval_write = "1 d" ;
snw:cell_methods = "time: mean" ;
snw:_FillValue = 1.e+20f ;
snw:missing_value = 1.e+20f ;
snw:coordinates = "lon lat" ;
snw:grid_mapping = "Lambert_Conformal" ;
double lon(y, x) ;
lon:standard_name = "longitude" ;
lon:long_name = "Longitude" ;
lon:units = "degrees_east" ;
lon:bounds = "bounds_nav_lon" ;
double lat(y, x) ;
lat:standard_name = "latitude" ;
lat:long_name = "Latitude" ;
lat:units = "degrees_north" ;
lat:bounds = "bounds_nav_lat" ;
char Lambert_Conformal ;
Lambert_Conformal:latitude_of_projection_origin = 49.5f ;
Lambert_Conformal:standard_parallel = 49.5f ;
Lambert_Conformal:longitude_of_central_meridian = 10.5f ;
Lambert_Conformal:grid_mapping_name = "lambert_conformal_conic" ;
double x(x) ;
x:units = "km" ;
x:long_name = "x coordinate of projection" ;
x:standard_name = "projection_x_coordinate" ;
x:axis = "X" ;
double y(y) ;
y:units = "km" ;
y:long_name = "y coordinate of projection" ;
y:standard_name = "projection_y_coordinate" ;
y:axis = "Y" ;

// global attributes:
:description = "Created by xios" ;
:title = "Created by xios" ;
:Conventions = "CF-1.6" ;
:creation_date = "2018-09-28T16:13:44Z" ;
:name = "EUR-11_ECMWF-ERAINT_evaluation_r1i1p1_CNRM-ALADIN63_v1_day" ;
:institute_id = "CNRM" ;
:institution = "CNRM (Centre National de Recherches Meteorologiques, Toulouse 31057, France)" ;
:model_id = "CNRM-ALADIN63" ;
:experiment_id = "evaluation" ;
:experiment = "Evaluation run with reanalysis forcing" ;
:contact = "contact.aladin-cordex@meteo.fr" ;
:product = "output" ;
:Convention = "CF-1.6" ;
:driving_model_id = "ECMWF-ERAINT" ;
:driving_model_ensemble_member = "r1i1p1" ;
:driving_experiment_name = "evaluation" ;
:driving_experiment = "ERA-INTERIM, evaluation, r1i1p1" ;
:rcm_version_id = "v1" ;
:project_id = "CORDEX" ;
:CORDEX_domain = "EUR-11" ;
:references = "http://www.umr-cnrm.fr/spip.php?article125&amp;lang=en" ;
:comment = "CORDEX Europe EUR-11 CNRM-ALADIN 6.3 L91 ECMWF-ERAINT: EUC12v63-1.100. Reference : Daniel M., Lemonsu A., Déqué M., Somot S., Alias A., Masson V. (2018) Benefits of explicit urban parametrization in regional climate modelling to study climate and city interactions. Climate Dynamics, 1-20, doi:10.1007/s00382-018-4289-x" ;
:frequency = "day" ;
:tracking_id = "hdl:21.14103/0efca508-2ffb-420b-8093-fffe58a7ae75" ;
}

# Fixed code
def __init__(
    self,
    semi_major_axis=None,
    semi_minor_axis=None,
    inverse_flattening=None,
    longitude_of_prime_meridian=None,
):
    """
    Creates a new GeogCS.

    Kwargs:

    * semi_major_axis, semi_minor_axis:
        Axes of ellipsoid, in metres.  At least one must be given
        (see note below).

    * inverse_flattening:
        Can be omitted if both axes given (see note below).
        Defaults to 0.0 .

    * longitude_of_prime_meridian:
        Specifies the prime meridian on the ellipsoid, in degrees.
        Defaults to 0.0 .

    If just semi_major_axis is set, with no semi_minor_axis or
    inverse_flattening, then a perfect sphere is created from the given
    radius.

    If just two of semi_major_axis, semi_minor_axis, and
    inverse_flattening are given the missing element is calculated from the
    formula:
    :math:`flattening = (major - minor) / major`

    Currently, Iris will not allow over-specification (all three ellipsoid
    parameters).

    Examples::

        cs = GeogCS(6371229)
        pp_cs = GeogCS(iris.fileformats.pp.EARTH_RADIUS)
        airy1830 = GeogCS(semi_major_axis=6377563.396,
                          semi_minor_axis=6356256.909)
        airy1830 = GeogCS(semi_major_axis=6377563.396,
                          inverse_flattening=299.3249646)
        custom_cs = GeogCS(6400000, 6300000)

    """
    # No ellipsoid specified? (0 0 0)
    if (
        (semi_major_axis is None)
        and (semi_minor_axis is None)
        and (inverse_flattening is None)
    ):
        raise ValueError("No ellipsoid specified")

    # Ellipsoid over-specified? (1 1 1)
    if (
        (semi_major_axis is not None)
        and (semi_minor_axis is not None)
        and (inverse_flattening is not None)
    ):
        raise ValueError("Ellipsoid is overspecified")

    # Perfect sphere (semi_major_axis only)? (1 0 0)
    elif semi_major_axis is not None and (
        semi_minor_axis is None and inverse_flattening is None
    ):
        semi_minor_axis = semi_major_axis
        inverse_flattening = 0.0

    # Calculate semi_major_axis? (0 1 1)
    elif semi_major_axis is None and (
        semi_minor_axis is not None and inverse_flattening is not None
    ):
        semi_major_axis = -semi_minor_axis / (
            (1.0 - inverse_flattening) / inverse_flattening
        )

    # Calculate semi_minor_axis? (1 0 1)
    elif semi_minor_axis is None and (
        semi_major_axis is not None and inverse_flattening is not None
    ):
        semi_minor_axis = semi_major_axis - (
            (1.0 / inverse_flattening) * semi_major_axis
        )

    # Calculate inverse_flattening? (1 1 0)
    elif inverse_flattening is None and (
        semi_major_axis is not None and semi_minor_axis is not None
    ):
        if semi_major_axis == semi_minor_axis:
            inverse_flattening = 0.0
        else:
            inverse_flattening = 1.0 / (
                (semi_major_axis - semi_minor_axis) / semi_major_axis
            )

    # We didn't get enough to specify an ellipse.
    else:
        raise ValueError("Insufficient ellipsoid specification")

    #: Major radius of the ellipsoid in metres.
    self.semi_major_axis = float(semi_major_axis)

    #: Minor radius of the ellipsoid in metres.
    self.semi_minor_axis = float(semi_minor_axis)

    #: :math:`1/f` where :math:`f = (a-b)/a`.
    self.inverse_flattening = float(inverse_flattening)

    #: Describes 'zero' on the ellipsoid in degrees.
    self.longitude_of_prime_meridian = _arg_default(longitude_of_prime_meridian, 0)