ASFOpenSARlab/opensarlab-notebooks

Lab2-SurfaceWaterExtentMapping.ipynb - ValueError: output array is read-only

Closed this issue · 1 comments

Hello,

I ran the Lab2-SurfaceWaterExtentMapping.ipynb with the 'do_PP = True' (cell 38) to enable the Fuzzy logic post-processing. However, there was an error message in cell 39 saying that 'ValueError: output array is read-only. The log messages are below here. Did I do something that I am not supposed to do?

Thank you.


/home/jovyan/.local/envs/hydrosar/lib/python3.9/site-packages/numpy/lib/function_base.py:4691: UserWarning: Warning: 'partition' will ignore the 'mask' of the MaskedArray.
arr.partition(

ValueError Traceback (most recent call last)
Cell In [40], line 109
107 ## HAND upper and lower fuzzy threshold calculation
108 maskedarray = np.ma.masked_where(maskimage==0, hand_interp)
--> 109 ma2 = np.ma.masked_where(maskedarray > np.percentile(maskedarray, 90), maskedarray)
110 hand_lowerlimit = np.ma.median(np.ma.masked_invalid(ma2))
111 hand_upperlimit = hand_lowerlimit + (np.ma.std(np.ma.masked_invalid(ma2)) + 3.5)*np.ma.std(np.ma.masked_invalid(ma2))

File <array_function internals>:180, in percentile(*args, **kwargs)

File ~/.local/envs/hydrosar/lib/python3.9/site-packages/numpy/lib/function_base.py:4166, in percentile(a, q, axis, out, overwrite_input, method, keepdims, interpolation)
4164 if not _quantile_is_valid(q):
4165 raise ValueError("Percentiles must be in the range [0, 100]")
-> 4166 return _quantile_unchecked(
4167 a, q, axis, out, overwrite_input, method, keepdims)

File ~/.local/envs/hydrosar/lib/python3.9/site-packages/numpy/lib/function_base.py:4424, in _quantile_unchecked(a, q, axis, out, overwrite_input, method, keepdims)
4416 def _quantile_unchecked(a,
4417 q,
4418 axis=None,
(...)
4421 method="linear",
4422 keepdims=False):
4423 """Assumes that q is in [0, 1], and is an ndarray"""
-> 4424 r, k = _ureduce(a,
4425 func=_quantile_ureduce_func,
4426 q=q,
4427 axis=axis,
4428 out=out,
4429 overwrite_input=overwrite_input,
4430 method=method)
4431 if keepdims:
4432 return r.reshape(q.shape + k)

File ~/.local/envs/hydrosar/lib/python3.9/site-packages/numpy/lib/function_base.py:3725, in _ureduce(a, func, **kwargs)
3722 else:
3723 keepdim = (1,) * a.ndim
-> 3725 r = func(a, **kwargs)
3726 return r, keepdim

File ~/.local/envs/hydrosar/lib/python3.9/site-packages/numpy/lib/function_base.py:4593, in _quantile_ureduce_func(a, q, axis, out, overwrite_input, method)
4591 else:
4592 arr = a.copy()
-> 4593 result = _quantile(arr,
4594 quantiles=q,
4595 axis=axis,
4596 method=method,
4597 out=out)
4598 return result

File ~/.local/envs/hydrosar/lib/python3.9/site-packages/numpy/lib/function_base.py:4710, in _quantile(arr, quantiles, axis, method, out)
4708 result_shape = virtual_indexes.shape + (1,) * (arr.ndim - 1)
4709 gamma = gamma.reshape(result_shape)
-> 4710 result = _lerp(previous,
4711 next,
4712 gamma,
4713 out=out)
4714 if np.any(slices_having_nans):
4715 if result.ndim == 0 and out is None:
4716 # can't write to a scalar

File ~/.local/envs/hydrosar/lib/python3.9/site-packages/numpy/lib/function_base.py:4530, in _lerp(a, b, t, out)
4528 # asanyarray is a stop-gap until gh-13105
4529 lerp_interpolation = asanyarray(add(a, diff_b_a * t, out=out))
-> 4530 subtract(b, diff_b_a * (1 - t), out=lerp_interpolation, where=t >= 0.5)
4531 if lerp_interpolation.ndim == 0 and out is None:
4532 lerp_interpolation = lerp_interpolation[()] # unpack 0d arrays

ValueError: output array is read-only

Hello,

I just found an update in the '/ProcessOwnData/HYDRO30Workflow-v1.ipynb' on 'correct fuzzy logic code' by Alex-Lewandowski.

ma2 = np.ma.masked_where(maskedarray > np.percentile(maskedarray.data, 90), maskedarray)

I applied this one on line 109 by adding the '.data'. The error seems to be disappeared.

Thank you.