-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calc not working for AM3 due to 2-D lat/lon bound arrays #39
Comments
Have you figured out the source of these issues yet? If you can point me to the files that you were reading in as the source for
I'll also note that the way things stand now, surface area is still strictly calculated at the Model level. It's an easy change to allow computing it at the Run level, but until we address this issue (the time dependent |
Sure: /archive/s1h/am3/am3clim_hurrell/gfdl.ncrc2-intel-prod-openmp/pp/atmos/ts/monthly/1yr/atmos.198001-198012.t_surf.nc I haven't had a chance to dig into this much yet, so yes any help is welcome. |
Great, thanks. A disclaimer is that I have not worked with files of this structure before (i.e. the grid bounds being stored as vectors of tuples), but I think I've zeroed in on what's going on here.
Yes, it's the way we call
That being said, there is another issue at play here -- Computing the surface area is a separate issue to this bug; I think we can close this issue if we just make sure to add the |
Glad the solution seems to be this simple. I am in the process of implementing this right now -- fixing up the surface area method at the same time, since the problems with it also derive from how bound arrays are handled. |
@spencerkclark Have you tried implementing your recommended fix, i.e. the changes to /home/Spencer.Hill/py/main.py in <module>()
50
51 if __name__ == '__main__':
---> 52 calcs = aospy_user.main(mp)
/home/Spencer.Hill/py/aospy_user/aospy_user/main.pyc in main(main_params)
176 return
177 param_combos = cs.create_params_all_calcs()
--> 178 calcs = cs.create_calcs(param_combos, exec_calcs=True, print_table=True)
179 return calcs
/home/Spencer.Hill/py/aospy_user/aospy_user/main.pyc in create_calcs(self, param_combos, exec_calcs, print_table)
142 if exec_calcs:
143 try:
--> 144 calc.compute()
145 except:
146 raise
/home/Spencer.Hill/py/aospy/aospy/calc.py in compute(self)
648 # Load the input data from disk.
649 data_in = self._prep_data(self._get_all_data(self.start_date,
--> 650 self.end_date),
651 self.var.func_input_dtype)
652 # Compute only the needed timeseries.
/home/Spencer.Hill/py/aospy/aospy/calc.py in _get_all_data(self, start_date, end_date)
554 end_date, n),
555 self.var.func_input_dtype)
--> 556 for n, var in enumerate(self.variables)]
557
558 def _local_ts(self, *data_in):
/home/Spencer.Hill/py/aospy/aospy/calc.py in _get_input_data(self, var, start_date, end_date, n)
514 data = self._create_input_data_obj(var, start_date, end_date, n=n,
515 set_dt=set_dt,
--> 516 set_pfull=set_pfull)
517 # Force all data to be at full pressure levels, not half levels.
518 if self.dtype_in_vert == 'sigma' and var.def_vert == 'phalf':
/home/Spencer.Hill/py/aospy/aospy/calc.py in _create_input_data_obj(self, var, start_date, end_date, n, set_dt, set_pfull)
411 ds_chunks.append(test)
412 ds = xray.concat(ds_chunks, dim=TIME_STR, data_vars='minimal')
--> 413 ds = self._add_grid_attributes(ds, n)
414 for name in var.names:
415 try:
/home/Spencer.Hill/py/aospy/aospy/calc.py in _add_grid_attributes(self, ds, n)
371 # Bring in coord from model object if it exists.
372 if getattr(self.model[n], name_int, None) is not None:
--> 373 ds[name_int] = getattr(self.model[n], name_int)
374 ds = ds.set_coords(name_int)
375 if self.dtype_in_vert == 'pressure' and 'level' in ds.coords:
/home/s1h/anaconda/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):
/home/s1h/anaconda/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(),
/home/s1h/anaconda/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))
/home/s1h/anaconda/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
/home/s1h/anaconda/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)
/home/s1h/anaconda/lib/python2.7/site-packages/xray/core/dataset.pyc in _expand_variables(raw_variables, old_variables, compat)
140 for dim, coord in iteritems(var.coords):
141 if dim != name:
--> 142 add_variable(dim, coord.variable)
143 var = var.variable
144 add_variable(name, var)
/home/s1h/anaconda/lib/python2.7/site-packages/xray/core/dataset.pyc in add_variable(name, var)
130 raise ValueError('conflicting value for variable %s:\n'
131 'first value: %r\nsecond value: %r'
--> 132 % (name, variables[name], var))
133 if compat == 'broadcast_equals':
134 maybe_promote_or_replace(name, var)
ValueError: conflicting value for variable phalf:
first value: <xray.Variable (time: 120)>
array([2678400000000000, 2419200000000000, 2678400000000000,
2592000000000000, 2678400000000000, 2592000000000000,
2678400000000000, 2678400000000000, 2592000000000000,
2678400000000000, 2592000000000000, 2678400000000000,
2678400000000000, 2505600000000000, 2678400000000000,
2592000000000000, 2678400000000000, 2592000000000000,
2678400000000000, 2678400000000000, 2592000000000000,
2678400000000000, 2592000000000000, 2678400000000000,
2678400000000000, 2419200000000000, 2678400000000000,
2592000000000000, 2678400000000000, 2592000000000000,
2678400000000000, 2678400000000000, 2592000000000000,
2678400000000000, 2592000000000000, 2678400000000000,
2678400000000000, 2419200000000000, 2678400000000000,
2592000000000000, 2678400000000000, 2592000000000000,
2678400000000000, 2678400000000000, 2592000000000000,
2678400000000000, 2592000000000000, 2678400000000000,
2678400000000000, 2419200000000000, 2678400000000000,
2592000000000000, 2678400000000000, 2592000000000000,
2678400000000000, 2678400000000000, 2592000000000000,
2678400000000000, 2592000000000000, 2678400000000000,
2678400000000000, 2505600000000000, 2678400000000000,
2592000000000000, 2678400000000000, 2592000000000000,
2678400000000000, 2678400000000000, 2592000000000000,
2678400000000000, 2592000000000000, 2678400000000000,
2678400000000000, 2419200000000000, 2678400000000000,
2592000000000000, 2678400000000000, 2592000000000000,
2678400000000000, 2678400000000000, 2592000000000000,
2678400000000000, 2592000000000000, 2678400000000000,
2678400000000000, 2419200000000000, 2678400000000000,
2592000000000000, 2678400000000000, 2592000000000000,
2678400000000000, 2678400000000000, 2592000000000000,
2678400000000000, 2592000000000000, 2678400000000000,
2678400000000000, 2419200000000000, 2678400000000000,
2592000000000000, 2678400000000000, 2592000000000000,
2678400000000000, 2678400000000000, 2592000000000000,
2678400000000000, 2592000000000000, 2678400000000000,
2678400000000000, 2505600000000000, 2678400000000000,
2592000000000000, 2678400000000000, 2592000000000000,
2678400000000000, 2678400000000000, 2592000000000000,
2678400000000000, 2592000000000000, 2678400000000000], dtype='timedelta64[ns]')
Attributes:
long_name: Length of average period
second value: <xray.Coordinate 'phalf' (phalf: 49)>
array([ 1.00000000e-02, 2.69722000e-02, 5.17136000e-02,
8.89455000e-02, 1.42479000e-01, 2.20715700e-01,
3.36128300e-01, 5.04809600e-01, 7.47999300e-01,
1.09400550e+00, 1.58004600e+00, 2.25441080e+00,
3.17895600e+00, 4.43193500e+00, 6.11115580e+00,
8.33743920e+00, 1.12583405e+01, 1.50520759e+01,
1.99315829e+01, 2.61486254e+01, 3.39978420e+01,
4.38206240e+01, 5.60087014e+01, 7.10073115e+01,
8.93178242e+01, 1.11499702e+02, 1.38171684e+02,
1.70012093e+02, 2.07758186e+02, 2.52203387e+02,
3.04146456e+02, 3.63952255e+02, 4.30642962e+02,
5.01015122e+02, 5.70611348e+02, 6.35806353e+02,
6.94828646e+02, 7.47199253e+02, 7.93004419e+02,
8.32575026e+02, 8.66444320e+02, 8.95191787e+02,
9.19426071e+02, 9.39756026e+02, 9.56736463e+02,
9.70863393e+02, 9.82574798e+02, 9.92230000e+02,
1.00000000e+03])
Attributes:
long_name: ref half pressure level
units: mb
cartesian_axis: Z
positive: down |
Oh this might stem from the logic error in Model c.f. #38. I just noticed that the branch I'm on didn't have that fixed. Stay tuned. |
This is proving to be trickier than I thought to get working, and requiring more time than I can give it until at least after Wednesday. @spencerkclark Feel free to take a stab in the meantime if you'd like, but no worries otherwise, since this issue doesn't affect any of your stuff if I recall correctly. |
Yes, that's fine. I haven't seen that kind of error thrown by --> 373 ds[name_int] = getattr(self.model[n], name_int) Since the above line is what caused it within aospy, it seems like it must have something to do with assigning a DataArray from Model to the Dataset within Calc. It's puzzling why both Would it be possible for you to provide me a printout of what That said, I'm guessing you've tried this simple stuff already; what's causing you to think this is trickier than you thought? |
I just have a committee meeting on Wednesday that I'm scrambling to prep for (and that doesn't require any AM3 calculations)! After the better part of an hour, I wasn't making any headway, so I just need to come back to it after the meeting. And now I'm getting errors before I can even get to the print out you asked for. So just don't worry about this for now, we'll come back to it. Thanks! |
The latest on this...I uploaded a branch ( 54221fb ) with my most recent code. Calc is able to create the timeseries without error, but upon trying to perform a regional average the model sfc_area attribute is supposedly not there: ---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/home/Spencer.Hill/py/main2.py in <module>()
25
26 if __name__ == '__main__':
---> 27 calcs = aospy_user.main(mp, prompt_verify=True)
/home/Spencer.Hill/py/aospy_user/aospy_user/main.pyc in main(main_params, exec_calcs, print_table, prompt_verify)
179 param_combos = cs.create_params_all_calcs()
180 calcs = cs.create_calcs(param_combos, exec_calcs=exec_calcs,
--> 181 print_table=print_table)
182 return calcs
/home/Spencer.Hill/py/aospy_user/aospy_user/main.pyc in create_calcs(self, param_combos, exec_calcs, print_table)
143 if exec_calcs:
144 try:
--> 145 calc.compute()
146 except:
147 raise
/home/Spencer.Hill/py/aospy/aospy/calc.pyc in compute(self)
694 data = full_ts
695 if 'reg' in specs:
--> 696 reduced.update({reduc: self.region_calcs(data, func)})
697 else:
698 reduced.update({reduc: self._time_reduce(data, func)})
/home/Spencer.Hill/py/aospy/aospy/calc.pyc in region_calcs(self, arr, func, n)
641 else:
642 method = getattr(reg, func)
--> 643 data_out = method(arr)
644 reg_dat.update({reg.name: data_out})
645 return reg_dat
/home/Spencer.Hill/py/aospy/aospy/region.pyc in av(self, data)
76 def av(self, data):
77 """Time average of region-average time-series."""
---> 78 ts_ = self.ts(data)
79 if 'year' not in ts_.coords:
80 return ts_
/home/Spencer.Hill/py/aospy/aospy/region.pyc in ts(self, data)
68 """Create time-series of region-average data."""
69 data_masked = self.mask_var(data)
---> 70 sfc_area = data.sfc_area
71 land_mask = self._get_land_mask(data, self.do_land_mask)
72 weights = self._sum_over_lat_lon((self.mask_var(sfc_area)*land_mask))
/home/s1h/anaconda/lib/python2.7/site-packages/xray/core/common.pyc in __getattr__(self, name)
135 pass
136 raise AttributeError("%r object has no attribute %r" %
--> 137 (type(self).__name__, name))
138
139 def __dir__(self):
AttributeError: 'DataArray' object has no attribute 'sfc_area' I made some changes within |
When I run this updated surface area function on the coords from |
Yes, you're right, the surface area method is not getting rid of the bounds coordinate. Working on that now. Thanks! |
Results of
print(ds)
added toCalc._add_grid_attributes
immediately beforereturn(ds)
:Note the presence of both
lat_bnds
andlon_bnds
as variables andlat_bounds
andlon_bounds
as coordinates, and that the former pair incorrectly havetime
as their first coordinate.This ultimately yields an error in the regional calculations:
The text was updated successfully, but these errors were encountered: