GithubHelp home page GithubHelp logo

Comments (5)

dcherian avatar dcherian commented on August 18, 2024

One of the variables in ds2 is cftime (probably the bounds variable). It'll work if you call .load() on that variable.

from esmlab.

mnlevy1981 avatar mnlevy1981 commented on August 18, 2024

Changing the end of the call sequence to

ds2['time_bound'].load() # New call per comment above
ds2_ann = esmlab.resample(ds2, freq='ann')

gives a new error:

TypeError: unsupported operand type(s) for *: 'cftime._cftime.DatetimeNoLeap' and 'float'

Full traceback is

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-8-f0ede6cb0845> in <module>
      1 ds2['time_bound'].load()
----> 2 ds2_ann = esmlab.resample(ds2, freq='ann')
      3 ds2_ann

/glade/work/mlevy/codes/esmlab/esmlab/core.py in resample(dset, freq, weights, time_coord_name, method)
    778     else:
    779         ds = dset.esmlab.set_time(time_coord_name=time_coord_name).compute_ann_mean(
--> 780             weights=weights, method=method
    781         )
    782 

/glade/work/mlevy/miniconda3/envs/cesm2-marbl/lib/python3.7/contextlib.py in inner(*args, **kwds)
     72         def inner(*args, **kwds):
     73             with self._recreate_cm():
---> 74                 return func(*args, **kwds)
     75         return inner
     76 

/glade/work/mlevy/codes/esmlab/esmlab/core.py in compute_ann_mean(self, weights, method)
    554             return da_weighted_mean.where(mask)
    555 
--> 556         computed_dset = dset.apply(weighted_mean_arr, wgts=wgts)
    557 
    558         computed_dset = self.compute_resample_times(

/glade/work/mlevy/miniconda3/envs/cesm2-marbl/lib/python3.7/site-packages/xarray/core/dataset.py in apply(self, func, keep_attrs, args, **kwargs)
   4138         variables = {
   4139             k: maybe_wrap_array(v, func(v, *args, **kwargs))
-> 4140             for k, v in self.data_vars.items()
   4141         }
   4142         if keep_attrs is None:

/glade/work/mlevy/miniconda3/envs/cesm2-marbl/lib/python3.7/site-packages/xarray/core/dataset.py in <dictcomp>(.0)
   4138         variables = {
   4139             k: maybe_wrap_array(v, func(v, *args, **kwargs))
-> 4140             for k, v in self.data_vars.items()
   4141         }
   4142         if keep_attrs is None:

/glade/work/mlevy/codes/esmlab/esmlab/core.py in weighted_mean_arr(darr, wgts)
    545             )
    546             da_sum = (
--> 547                 (darr * wgts).resample({self.time_coord_name: 'A'}).sum(dim=self.time_coord_name)
    548             )
    549             ones_out = (

/glade/work/mlevy/miniconda3/envs/cesm2-marbl/lib/python3.7/site-packages/xarray/core/dataarray.py in func(self, other)
   2507             variable = (
   2508                 f(self.variable, other_variable)
-> 2509                 if not reflexive
   2510                 else f(other_variable, self.variable)
   2511             )

/glade/work/mlevy/miniconda3/envs/cesm2-marbl/lib/python3.7/site-packages/xarray/core/variable.py in func(self, other)
   1904                 new_data = (
   1905                     f(self_data, other_data)
-> 1906                     if not reflexive
   1907                     else f(other_data, self_data)
   1908                 )

TypeError: unsupported operand type(s) for *: 'cftime._cftime.DatetimeNoLeap' and 'float'

from esmlab.

andersy005 avatar andersy005 commented on August 18, 2024

The .load() call needs to be done internally (in esmlab). I don't remember the exact location in the source code, but a while ago, @dcherian showed @matt-long and I how to address this issue.

from esmlab.

klindsay28 avatar klindsay28 commented on August 18, 2024

@mnlevy1981, I got the unsupported operand... error from a mistake in PR #156.

Please check if PR #158 helps you out.

from esmlab.

mnlevy1981 avatar mnlevy1981 commented on August 18, 2024

Thanks @klindsay28, the branch in #158 did the trick! I didn't see any tickets for the NotImplementedError but didn't think to search the issues again after the error changed to TypeError: unsupported operand type(s).

Closing this issue because it seems like it will be resolved in an existing PR.

from esmlab.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.