Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Operation pearson_correlation_scalar() fails #746

Closed
forman opened this issue Sep 18, 2018 · 2 comments
Closed

Operation pearson_correlation_scalar() fails #746

forman opened this issue Sep 18, 2018 · 2 comments
Assignees

Comments

@forman
Copy link
Member

forman commented Sep 18, 2018

What went wrong

Job: Executing operation "pearson_correlation_scalar"
Message: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Code: -32003
Method: set_workspace_resource
Exception: ValueError

Traceback (most recent call last):
  File "C:\Users\Norman\IdeaProjects\ccitools\cate\cate\util\web\jsonrpchandler.py", line 209, in send_service_method_result
    result = future.result()
  File "C:\Users\Norman\Miniconda3\envs\cate-env\lib\concurrent\futures\_base.py", line 425, in result
    return self.__get_result()
  File "C:\Users\Norman\Miniconda3\envs\cate-env\lib\concurrent\futures\_base.py", line 384, in __get_result
    raise self._exception
  File "C:\Users\Norman\Miniconda3\envs\cate-env\lib\concurrent\futures\thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Users\Norman\IdeaProjects\ccitools\cate\cate\util\web\jsonrpchandler.py", line 306, in call_service_method
    result = method(*method_params, monitor=monitor)
  File "C:\Users\Norman\IdeaProjects\ccitools\cate\cate\webapi\websocket.py", line 291, in set_workspace_resource
    monitor=monitor)
  File "C:\Users\Norman\IdeaProjects\ccitools\cate\cate\core\wsmanag.py", line 317, in set_workspace_resource
    workspace.execute_workflow(res_name=res_name, monitor=monitor)
  File "C:\Users\Norman\IdeaProjects\ccitools\cate\cate\core\workspace.py", line 652, in execute_workflow
    self.workflow.invoke_steps(steps, context=self._new_context(), monitor=monitor)
  File "C:\Users\Norman\IdeaProjects\ccitools\cate\cate\core\workflow.py", line 632, in invoke_steps
    step.invoke(context=context, monitor=monitor.child(work=1))
  File "C:\Users\Norman\IdeaProjects\ccitools\cate\cate\core\workflow.py", line 318, in invoke
    self._invoke_impl(_new_context(context, step=self), monitor=monitor)
  File "C:\Users\Norman\IdeaProjects\ccitools\cate\cate\core\workflow.py", line 980, in _invoke_impl
    return_value = self._op(monitor=monitor, **input_values)
  File "C:\Users\Norman\IdeaProjects\ccitools\cate\cate\core\op.py", line 216, in _call_
    return_value = self._wrapped_op(**input_values)
  File "C:\Users\Norman\IdeaProjects\ccitools\cate\cate\ops\correlation.py", line 110, in pearson_correlation_scalar
    cc, pv = pearsonr(array_x.values, array_y.values)
  File "C:\Users\Norman\Miniconda3\envs\cate-env\lib\site-packages\scipy\stats\stats.py", line 3025, in pearsonr
    r = max(min(r, 1.0), -1.0)
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Steps to reproduce the problem

import cate.ops

# Step 1
ds_1 = cate.ops.open_dataset(ds_id="local.CLOUD_07")

# Step 2
ds_2 = cate.ops.open_dataset(ds_id="local.OZONE_07")

# Step 3
res_1 = cate.ops.subset_spatial(ds=ds_1, region="POLYGON ((-0.42315899263257606 55.341677536612686, 16.859251257286218 55.341677536612686, 16.85925125728622 43.167691806188735, -0.42315899263257617 43.167691806188735, -0.42315899263257606 55.341677536612686))")

# Step 4
res_2 = cate.ops.subset_spatial(ds=ds_2, region="POLYGON ((-0.42315899263257606 55.341677536612686, 16.859251257286218 55.341677536612686, 16.85925125728622 43.167691806188735, -0.42315899263257617 43.167691806188735, -0.42315899263257606 55.341677536612686))")

# Step 5
res_3 = cate.ops.select_var(ds=res_1, var="cc_total")

# Step 6
res_4 = cate.ops.select_var(ds=res_2, var="cc_total, O3_du_tot")

# Step 7
res_5 = cate.ops.coregister(ds_master=res_3, ds_slave=res_4)

# Step 8
res_6 = cate.ops.pearson_correlation_scalar(ds_x=res_3, ds_y=res_5, var_x="cc_total", var_y="O3_du_tot")

Specifications

Cate 2.0.0.dev19 (in dev)

@forman
Copy link
Member Author

forman commented Sep 20, 2018

Hi @JanisGailis , could you please have a look into this today?

@JanisGailis
Copy link
Member

JanisGailis commented Sep 20, 2018

@forman Sorry, no, tomorrow afternoon as soonest.

EDIT: Looking at the stack trace again, I have an idea. I'll try to find time today, if I'm right, it shouldn't take too long.

JanisGailis pushed a commit that referenced this issue Sep 27, 2018
pearson_correlation_scalar now works with N-D data variables, by using
xr.stack to flatten them. This should work well with Dask.

Closes #746
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants