Skip to content

Commit

Permalink
Adding a plugin for working around SciTools/iris#2927
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanwp committed Dec 19, 2017
1 parent a3c5f69 commit 4f40954
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions hadgem_unknown_vars.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
__author__ = 'watson-parris'
from cis.data_io.products.HadGEM import HadGEM_PP


class HadGEM_unknown_vars(HadGEM_PP):

def get_variable_names(self, filenames, data_type=None):
import iris
import cf_units as unit
from cis.utils import single_warnings_only
# Removes warnings and prepares for future Iris change
iris.FUTURE.netcdf_promote = True

variables = []

# Filter the warnings so that they only appear once - otherwise you get lots of repeated warnings
with single_warnings_only():
cubes = iris.load(filenames)

for cube in cubes:
is_time_lat_lon_pressure_altitude_or_has_only_1_point = True
for dim in cube.dim_coords:
units = dim.units
if dim.points.size > 1 and \
not units.is_time() and \
not units.is_time_reference() and \
not units.is_vertical() and \
not units.is_convertible(unit.Unit('degrees')):
is_time_lat_lon_pressure_altitude_or_has_only_1_point = False
break
if is_time_lat_lon_pressure_altitude_or_has_only_1_point:
name = cube.var_name or cube.name()
if name == 'unknown' and 'STASH' in cube.attributes:
name = '{}'.format(cube.attributes['STASH'])
variables.append(name)

return set(variables)

0 comments on commit 4f40954

Please sign in to comment.