Skip to content
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

Closed
spencerahill opened this issue Nov 12, 2015 · 12 comments
Closed

Calc not working for AM3 due to 2-D lat/lon bound arrays #39

spencerahill opened this issue Nov 12, 2015 · 12 comments
Labels

Comments

@spencerahill
Copy link
Owner

Results of print(ds) added to Calc._add_grid_attributes immediately before return(ds):

<xray.Dataset>
Dimensions:     (bnds: 2, lat: 90, level: 23, lon: 144, pfull: 48, phalf: 49, time: 360)
Coordinates:
  * lat         (lat) float64 -89.0 -87.0 -85.0 -83.0 -81.0 -79.0 -77.0 ...
  * lon         (lon) float64 1.25 3.75 6.25 8.75 11.25 13.75 16.25 18.75 ...
  * bnds        (bnds) int64 0 1
  * time        (time) datetime64[ns] 1981-01-16T12:00:00 1981-02-15 ...
    lat_bounds  (lat, bnds) float64 -90.0 -88.0 -88.0 -86.0 -86.0 -84.0 ...
  * phalf       (phalf) float64 0.01 0.02697 0.05171 0.08895 0.1425 0.2207 ...
    sfc_area    (lon, bnds, lat) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    bk          (phalf) float64 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
  * pfull       (pfull) float64 0.01711 0.03801 0.06866 0.1136 0.1788 0.2744 ...
    land_mask   (lat, lon) float64 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 ...
    lon_bounds  (lon, bnds) float64 0.0 2.5 2.5 5.0 5.0 7.5 7.5 10.0 10.0 ...
    zsurf       (lat, lon) float64 2.851e+03 2.851e+03 2.851e+03 2.851e+03 ...
  * level       (level) float32 100000.0 92500.0 85000.0 77500.0 70000.0 ...
    pk          (phalf) float64 1.0 2.697 5.171 8.895 14.25 22.07 33.61 ...
Data variables:
    t_surf      (time, lat, lon) float64 243.8 243.7 243.7 243.6 243.5 243.4 ...
    average_DT  (time) timedelta64[ns] 31 days 28 days 31 days 30 days ...
    lat_bnds    (time, lat, bnds) float64 -90.0 -88.0 -88.0 -86.0 -86.0 ...
    lon_bnds    (time, lon, bnds) float64 0.0 2.5 2.5 5.0 5.0 7.5 7.5 10.0 ...
Attributes:

Note the presence of both lat_bnds and lon_bnds as variables and lat_bounds and lon_bounds as coordinates, and that the former pair incorrectly have time as their first coordinate.

This ultimately yields an error in the regional calculations:

/home/Spencer.Hill/py/main.py in <module>()
     43
     44 if __name__ == '__main__':
---> 45     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.pyc in compute(self)
    695                     data = full_ts
    696                 if 'reg' in specs:
--> 697                     reduced.update({reduc: self.region_calcs(data, func)})
    698                 else:
    699                     reduced.update({reduc: self._time_reduce(data, func)})

/home/Spencer.Hill/py/aospy/aospy/calc.pyc in region_calcs(self, arr, func, n)
    642             else:
    643                 method = getattr(reg, func)
--> 644                 data_out = method(arr, self.model[n])
    645             reg_dat.update({reg.name: data_out})
    646         return reg_dat

/home/Spencer.Hill/py/aospy/aospy/region.pyc in av(self, data, model)
     74     def av(self, data, model):
     75         """Time average of region-average time-series."""
---> 76         ts_ = self.ts(data, model)
     77         if 'year' not in ts_.coords:
     78             return ts_

/home/Spencer.Hill/py/aospy/aospy/region.pyc in ts(self, data, model)
     67         dims = ['lat', 'lon']
     68         coords = [data_masked.coords[c] for c in dims]
---> 69         sfc_area = data.sfc_area
     70         land_mask = data.land_mask
     71         weights = (self.mask_var(sfc_area)*land_mask).sum('lat').sum('lon')

/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'
@spencerkclark
Copy link
Collaborator

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 t_surf here I'd be happy to help. Without looking at the specific files themselves, these are my initial thoughts:

  • I would expect lat_bnds and lon_bnds to be variables in the Dataset at the point at which you printed things out. If they are present in the t_surf file, which I presume they are, then they will be read in within the call to xray.open_dataset. These will be stripped out the moment the t_surf attribute is selected from the Dataset. That said I would not expect them to have time as a coordinate; my feeling is that this must have something to do with the xray.concat call in a prior line, but without doing a proper test I can't be certain.
  • The fact that the sfc_area is throwing an AttributeError within Region suggests to me that the problem is still within the function to compute surface area itself. If you look at the coordinates, surface area is a function of lon, bnds, and lat. I think what's happening here is that since t_surf is not a function of bnds, the sfc_area attribute is getting stripped out when t_surf is selected from the Dataset. Thus it is not present at the time the DataArray gets to the code in Region. If we can fix Model.grid_sfc_area to handle 2D grid information (and return something sensible for the surface the area -- i.e. be a function of only lat and lon and not have zero values), then I think this issue will fix itself.

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 lat_bnds and lon_bnds in particular) it's probably not worth putting in.

@spencerahill
Copy link
Owner Author

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.

@spencerkclark
Copy link
Collaborator

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.


I would expect lat_bnds and lon_bnds to be variables in the Dataset at the point at which you printed things out. If they are present in the t_surf file, which I presume they are, then they will be read in within the call to xray.open_dataset. These will be stripped out the moment the t_surf attribute is selected from the Dataset. That said I would not expect them to have time as a coordinate; my feeling is that this must have something to do with the xray.concat call in a prior line, but without doing a proper test I can't be certain.

Yes, it's the way we call xray.concat that's causing the trouble here. A simple fix is to add the keyword argument data_vars='minimal'. This tells xray to not concatenate (but still retain) variables that are not functions of the dimensions being concatenated on (in this case time). See the following minimal example:

In [11]: import xray

In [12]: ROOT = '/archive/s1h/am3/am3clim_hurrell/gfdl.ncrc2-intel-prod-openmp/pp/atmos/ts/monthly/1yr/'

In [13]: y1 = xray.open_dataset('{}atmos.198201-198212.t_surf.nc'.format(ROOT), drop_variables=['nv', 'time_bounds'])

In [14]: y2 = xray.open_dataset('{}atmos.198301-198312.t_surf.nc'.format(ROOT), drop_variables=['nv', 'time_bounds'])

In [15]: y1_and_y2_full = xray.concat([y1, y2], dim='time')

In [16]: y1_and_y2_min = xray.concat([y1, y2], dim='time', data_vars='minimal')

In [17]: y1_and_y2_full
Out[17]:
<xray.Dataset>
Dimensions:     (bnds: 2, lat: 90, lon: 144, time: 24)
Coordinates:
  * lat         (lat) float64 -89.0 -87.0 -85.0 -83.0 -81.0 -79.0 -77.0 ...
  * lon         (lon) float64 1.25 3.75 6.25 8.75 11.25 13.75 16.25 18.75 ...
  * bnds        (bnds) int64 0 1
  * time        (time) datetime64[ns] 1982-01-16T12:00:00 1982-02-15 ...
Data variables:
    t_surf      (time, lat, lon) float64 244.2 244.1 244.0 243.9 243.8 243.7 ...
    average_T2  (time) datetime64[ns] 1982-02-01 1982-03-01 1982-04-01 ...
    lat_bnds    (time, lat, bnds) float64 -90.0 -88.0 -88.0 -86.0 -86.0 ...
    average_T1  (time) datetime64[ns] 1982-01-01 1982-02-01 1982-03-01 ...
    lon_bnds    (time, lon, bnds) float64 0.0 2.5 2.5 5.0 5.0 7.5 7.5 10.0 ...
    average_DT  (time) timedelta64[ns] 31 days 28 days 31 days 30 days ...
Attributes:
    filename: atmos.198201-198212.t_surf.nc
    title: am3clim_hurrell
    grid_type: mosaic
    grid_tile: 1
    comment: pressure level interpolator, version 3.0, precision=double
    history: fregrid --input_mosaic atmos_mosaic.nc --input_file 19820101.atmos_month --interp_method conserve_order2 --remap_file .fregrid_remap_file_144_by_90 --nlon 144 --nlat 90 --scalar_field (**please see the field list in this file**)
    code_version: $Name: fre-nctools-bronx-7 $

In [18]: y1_and_y2_min
Out[18]:
<xray.Dataset>
Dimensions:     (bnds: 2, lat: 90, lon: 144, time: 24)
Coordinates:
  * lat         (lat) float64 -89.0 -87.0 -85.0 -83.0 -81.0 -79.0 -77.0 ...
  * lon         (lon) float64 1.25 3.75 6.25 8.75 11.25 13.75 16.25 18.75 ...
  * bnds        (bnds) int64 0 1
  * time        (time) datetime64[ns] 1982-01-16T12:00:00 1982-02-15 ...
Data variables:
    lat_bnds    (lat, bnds) float64 -90.0 -88.0 -88.0 -86.0 -86.0 -84.0 ...
    lon_bnds    (lon, bnds) float64 0.0 2.5 2.5 5.0 5.0 7.5 7.5 10.0 10.0 ...
    t_surf      (time, lat, lon) float64 244.2 244.1 244.0 243.9 243.8 243.7 ...
    average_DT  (time) timedelta64[ns] 31 days 28 days 31 days 30 days ...
    average_T2  (time) datetime64[ns] 1982-02-01 1982-03-01 1982-04-01 ...
    average_T1  (time) datetime64[ns] 1982-01-01 1982-02-01 1982-03-01 ...
Attributes:
    filename: atmos.198201-198212.t_surf.nc
    title: am3clim_hurrell
    grid_type: mosaic
    grid_tile: 1
    comment: pressure level interpolator, version 3.0, precision=double
    history: fregrid --input_mosaic atmos_mosaic.nc --input_file 19820101.atmos_month --interp_method conserve_order2 --remap_file .fregrid_remap_file_144_by_90 --nlon 144 --nlat 90 --scalar_field (**please see the field list in this file**)
    code_version: $Name: fre-nctools-bronx-7 $

That being said, there is another issue at play here -- lat_bnds and lon_bnds are not coordinates (as they are in AM2) when they are read in, but variables. Thus within Run._add_grid_attributes they are ignored when the function looks for them within the Dataset at the Run level, so they are populated from the Model object, which explains why there are two sets of bounds in the Dataset you printed above (one dependent on time and the other not). If the Run._add_grid_attributes function were able to find the bounds they would be set as coordinates (and would no longer be variables); these coordinates would be also be (incorrectly) functions of time.

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 data_vars='minimal' argument to xray.concat and make sure that Run._add_grid_attributes looks in both the coordinates and the variables for grid information:

  • Change line 355 in Calc to ds_coord_name = set(names_ext).intersection(set(ds.coords) | set(ds.data_vars))
  • Change line 408 in Calc to ds = xray.concat(ds_chunks, dim=TIME_STR, data_vars='minimal')

@spencerahill
Copy link
Owner Author

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.

@spencerahill
Copy link
Owner Author

@spencerkclark Have you tried implementing your recommended fix, i.e. the changes to ds_coord_name and concat? I'm still getting errors that I can't immediately sort out. Possible, but I don't think its the case, that they're from the changes to surface area that I've implemented, so I want to double check with you. Here's my traceback for a calc of t_surf using AM3 monthly data:

/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

@spencerahill
Copy link
Owner Author

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.

@spencerahill
Copy link
Owner Author

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.

@spencerkclark
Copy link
Collaborator

Yes, that's fine. I haven't seen that kind of error thrown by xray before. Do you know what it means?

--> 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 time and phalf seem to be involved at this stage (here it seems we should be assigning a phalf DataArray to the key phalf within the Dataset).

Would it be possible for you to provide me a printout of what getattr(self.model[n], name_int) returns directly before this assignment statement is tried? That might help me determine if the issue is within Model or within Calc. Essentially I want to find out from where time is entering the problem here.

That said, I'm guessing you've tried this simple stuff already; what's causing you to think this is trickier than you thought?

@spencerahill
Copy link
Owner Author

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!

@spencerahill
Copy link
Owner Author

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 Model to the surface area computation, and its possible this problem comes from that new code. Might be something simple -- have run out of steam for now but wanted to document current status.

@spencerkclark
Copy link
Collaborator

When I run this updated surface area function on the coords from /archive/s1h/am3/am3clim_hurrell/gfdl.ncrc2-intel-prod-openmp/pp/atmos/ts/monthly/1yr/atmos.198001-198012.t_surf.nc
I still get something that is a function of bnds, as well as lon and lat. I think that if you fix things such that the surface area function in Model returns something that's only a function of lon and lat things will sort themselves out downstream (see the second bullet point in my first comment in this thread for a more detailed explanation).

@spencerahill
Copy link
Owner Author

Yes, you're right, the surface area method is not getting rid of the bounds coordinate. Working on that now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants