We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Given the process definitions below:
@xs.process class ConsumeDA: da = xs.variable(dims='x', intent='inout') def initialize(self): print(f"Is a DataArray: {isinstance(self.da, xr.DataArray)}") print(type(self.da)) @xs.process class InitDA: da = xs.foreign(ConsumeDA, 'da', intent='out') def initialize(self): self.da = xr.DataArray(data=range(5), dims='x')
We see expected behavior when instantiating an xr.DataArray within an upstream process:
xr.DataArray
model0 = xs.Model(dict( init=InitDA, use=ConsumeDA )) xs.create_setup( model=model0, clocks=dict(step=range(2)), input_vars=dict(), output_vars=dict() ).xsimlab.run(model=model0) # Is a DataArray: True # <class 'xarray.core.dataarray.DataArray'>
However, when the same variable is passed as an input, it is converted to a numpy.ndarray:
numpy.ndarray
model1 = xs.Model(dict( use=ConsumeDA )) xs.create_setup( model=model1, clocks=dict(step=range(2)), input_vars=dict( use__da=xr.DataArray(data=range(5), dims='x') ), output_vars=dict() ).xsimlab.run(model=model1) # Is a DataArray: False # <class 'numpy.ndarray'>
Is this expected behavior? If so, what is best practice for passing DataArrays as model inputs?
DataArray
The text was updated successfully, but these errors were encountered:
Yes it's expected behavior. Currently Xarray objects are used only for the model I/O interface.
I agree that using xarray DataArray or Variable inside process classes would be useful, though. I suggest that in #141.
Sorry, something went wrong.
Thanks for confirming, @benbovy.
For posterity: I worked around this by writing upstream "converter" processes that ingest np.ndarray or numbers.Number and output DataArrays.
np.ndarray
numbers.Number
No branches or pull requests
Given the process definitions below:
We see expected behavior when instantiating an
xr.DataArray
within an upstream process:However, when the same variable is passed as an input, it is converted to a
numpy.ndarray
:Is this expected behavior? If so, what is best practice for passing
DataArray
s as model inputs?Environment
The text was updated successfully, but these errors were encountered: