Last active
November 12, 2015 10:22
-
-
Save jfburkhart/7ea19ac88568f583c18d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [15]: em1 | |
Out[15]: | |
<xray.Dataset> | |
Dimensions: (lat: 720, lon: 1440, time: 4) | |
Coordinates: | |
* lat (lat) float32 89.875 89.625 89.375 89.125 88.875 88.625 ... | |
* lon (lon) float32 -179.875 -179.625 -179.375 -179.125 -178.875 ... | |
* time (time) datetime64[ns] 2004-08-01 2004-08-02 2004-08-03 2004-08-04 | |
Data variables: | |
emissions (time, lat, lon) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... | |
Attributes: | |
ndays: 4 | |
In [16]: em2 | |
Out[16]: | |
<xray.Dataset> | |
Dimensions: (lat: 360, lon: 720, time: 180) | |
Coordinates: | |
* lat (lat) float64 -89.75 -89.25 -88.75 -88.25 -87.75 -87.25 ... | |
* lon (lon) float64 -179.8 -179.2 -178.8 -178.2 -177.8 -177.2 ... | |
* time (time) datetime64[ns] 1993-01-31 1993-02-28 1993-03-31 ... | |
Data variables: | |
emissions (time, lat, lon) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... | |
Attributes: | |
len_p: 180 | |
In [17]: em1['parts'] = em1.emissions / em1.emissions.sum() | |
In [18]: em1 | |
Out[18]: | |
<xray.Dataset> | |
Dimensions: (lat: 720, lon: 1440, time: 4) | |
Coordinates: | |
* lat (lat) float32 89.875 89.625 89.375 89.125 88.875 88.625 ... | |
* lon (lon) float32 -179.875 -179.625 -179.375 -179.125 -178.875 ... | |
* time (time) datetime64[ns] 2004-08-01 2004-08-02 2004-08-03 2004-08-04 | |
Data variables: | |
emissions (time, lat, lon) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... | |
parts (time, lat, lon) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ... | |
Attributes: | |
ndays: 4 | |
In [19]: em2['parts'] = em2.emissions / em2.emissions.sum() | |
--------------------------------------------------------------------------- | |
ValueError Traceback (most recent call last) | |
<ipython-input-19-61a0025c91ba> in <module>() | |
----> 1 em2['parts'] = em2.emissions / em2.emissions.sum() | |
/opt/anaconda/envs/py2/lib/python2.7/site-packages/xray/core/dataset.pyc in __setitem__(self, key, value) | |
635 raise NotImplementedError('cannot yet use a dictionary as a key ' | |
636 'to set Dataset values') | |
--> 637 self.update({key: value}) | |
638 | |
639 def __delitem__(self, key): | |
/opt/anaconda/envs/py2/lib/python2.7/site-packages/xray/core/dataset.pyc in update(self, other, inplace) | |
1418 """ | |
1419 return self.merge( | |
-> 1420 other, inplace=inplace, overwrite_vars=list(other), join='left') | |
1421 | |
1422 def merge(self, other, inplace=False, overwrite_vars=set(), | |
/opt/anaconda/envs/py2/lib/python2.7/site-packages/xray/core/dataset.pyc in merge(self, other, inplace, overwrite_vars, compat, join) | |
1477 | |
1478 replace_vars, new_vars, new_coord_names = merge( | |
-> 1479 self, other, overwrite_vars, compat=compat, join=join) | |
1480 | |
1481 newly_coords = new_coord_names & (set(self) - set(self.coords)) | |
/opt/anaconda/envs/py2/lib/python2.7/site-packages/xray/core/dataset.pyc in _merge_dict(self, other, overwrite_vars, compat, join) | |
202 other.update(zip(alignable, aligned[1:])) | |
203 | |
--> 204 return _merge_expand(aligned_self, other, overwrite_vars, compat) | |
205 | |
206 | |
/opt/anaconda/envs/py2/lib/python2.7/site-packages/xray/core/dataset.pyc in _merge_expand(aligned_self, other, overwrite_vars, compat) | |
174 possible_conflicts = dict((k, v) for k, v in aligned_self._variables.items() | |
175 if k not in overwrite_vars) | |
--> 176 new_vars, new_coord_names = _expand_variables(other, possible_conflicts, compat) | |
177 replace_vars = aligned_self._variables.copy() | |
178 replace_vars.update(new_vars) | |
/opt/anaconda/envs/py2/lib/python2.7/site-packages/xray/core/dataset.pyc in _expand_variables(raw_variables, old_variables, compat) | |
142 add_variable(dim, coord.variable) | |
143 var = var.variable | |
--> 144 add_variable(name, var) | |
145 | |
146 return new_variables, new_coord_names | |
/opt/anaconda/envs/py2/lib/python2.7/site-packages/xray/core/dataset.pyc in add_variable(name, var) | |
122 | |
123 def add_variable(name, var): | |
--> 124 var = _as_dataset_variable(name, var) | |
125 if name not in variables: | |
126 variables[name] = var | |
/opt/anaconda/envs/py2/lib/python2.7/site-packages/xray/core/dataset.pyc in _as_dataset_variable(name, var) | |
66 """ | |
67 try: | |
---> 68 var = as_variable(var, key=name) | |
69 except TypeError: | |
70 raise TypeError('Dataset variables must be an array or a tuple of ' | |
/opt/anaconda/envs/py2/lib/python2.7/site-packages/xray/core/variable.pyc in as_variable(obj, key, strict) | |
49 obj = Variable(obj.name, obj) | |
50 elif key is not None: | |
---> 51 obj = Variable(key, obj) | |
52 else: | |
53 raise TypeError('cannot infer Variable dimensions') | |
/opt/anaconda/envs/py2/lib/python2.7/site-packages/xray/core/variable.pyc in __init__(self, dims, data, attrs, encoding, fastpath) | |
194 """ | |
195 self._data = _as_compatible_data(data, fastpath=fastpath) | |
--> 196 self._dims = self._parse_dimensions(dims) | |
197 self._attrs = None | |
198 self._encoding = None | |
/opt/anaconda/envs/py2/lib/python2.7/site-packages/xray/core/variable.pyc in _parse_dimensions(self, dims) | |
302 raise ValueError('dimensions %s must have the same length as the ' | |
303 'number of data dimensions, ndim=%s' | |
--> 304 % (dims, self.ndim)) | |
305 return dims | |
305 return dims | |
306 | |
ValueError: dimensions ('parts',) must have the same length as the number of data dimensions, ndim=3 | |
In [20]: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment