Description
from @eho-tacc's https://github.com/benbovy/xarray-simlab/issues/140#issuecomment-709586253
I think it would be really useful to expose variable metadata in the group (and generally across the package, but that's a different point)
Even though I haven't had any use case for this yet, accessing variable metadata from inside process class methods would probably make sense indeed. Right now xarray data structures are used for the model "outer" interface only, but I've been wondering if it would make sense to also leverage it inside models.
Since xsimlab.variable
attributes contain all the metadata needed to wrap their values as xarray variables in model inputs/outputs, nothing prevents doing the same in process classes too, i.e.,
@xs.process
class Foo:
bar = xsimlab.variable(...)
def initialize(self):
x = self.bar # self.bar returns a xarray.Variable or a xarray.DataArray object
We could probably look model-wise for xsimlab.index
variables to automatically populate xarray.DataArray
coordinates.
That said, I'm not sure if the example above should be the default behavior (this would be a breaking change). Maybe an option or flag exposed somewhere? I don't know where exactly... Or maybe an explicit function? E.g.,
@xs.process
class Foo:
bar = xsimlab.variable(...)
def initialize(self):
x = xsimlab.getattr_as_dataarray(self, 'bar')
I like the latter option, although it might be quite verbose if we want this as the default behavior.