|
21 | 21 | import numpy as np |
22 | 22 |
|
23 | 23 |
|
| 24 | +def validate_dict(o, name): |
| 25 | + """ |
| 26 | + Check that the given object is a dictionary. If not, raise TypeError. |
| 27 | +
|
| 28 | + :param o: The object to validate. |
| 29 | + :param str name: The name of the object to use in the error message. |
| 30 | + :return: None |
| 31 | + """ |
| 32 | + |
| 33 | + if not isinstance(o, dict): |
| 34 | + raise TypeError("{name} should be a dictionary (got {o})".format(name=name, o=repr(o))) |
| 35 | + |
| 36 | + |
24 | 37 | class NetCDFGroupDict(object): |
25 | 38 | def __init__(self, |
26 | 39 | dimensions=None, |
@@ -54,6 +67,10 @@ def __init__(self, |
54 | 67 | #w4.variables.keys() = ['temp'] |
55 | 68 | #w4.dimensions = {'lon':720,'lat':330,'time':300} |
56 | 69 | """ |
| 70 | + self._dimensions = None |
| 71 | + self._variables = None |
| 72 | + self._global_attributes = None |
| 73 | + |
57 | 74 | self.title = title |
58 | 75 | self.dimensions = dimensions or OrderedDict() |
59 | 76 | self.variables = variables or OrderedDict() |
@@ -83,6 +100,33 @@ def __add__(self, other): |
83 | 100 | self_copy.title = "{t1} + {t2}".format(t1=self.title, t2=other.title) |
84 | 101 | return self_copy |
85 | 102 |
|
| 103 | + @property |
| 104 | + def dimensions(self): |
| 105 | + return self._dimensions |
| 106 | + |
| 107 | + @dimensions.setter |
| 108 | + def dimensions(self, value): |
| 109 | + validate_dict(value, 'dimensions') |
| 110 | + self._dimensions = value |
| 111 | + |
| 112 | + @property |
| 113 | + def variables(self): |
| 114 | + return self._variables |
| 115 | + |
| 116 | + @variables.setter |
| 117 | + def variables(self, value): |
| 118 | + validate_dict(value, 'variables') |
| 119 | + self._variables = value |
| 120 | + |
| 121 | + @property |
| 122 | + def global_attributes(self): |
| 123 | + return self._global_attributes |
| 124 | + |
| 125 | + @global_attributes.setter |
| 126 | + def global_attributes(self, value): |
| 127 | + validate_dict(value, 'global_attributes') |
| 128 | + self._global_attributes = value |
| 129 | + |
86 | 130 | def is_dim_consistent(self): |
87 | 131 | """Check if the variable dictionary |
88 | 132 | is consistent with current dimensions""" |
|
0 commit comments