Closed rupsabasu2020 closed 3 years ago
The error occurs because you are submitting incorrect data to max_cluster_extent
. According to the documentation:
*y* --- a 1D field
A 1D field is a vector (i.e., a 1D array), but you have submitted a 2D array (3 x 1D fields) as the y
argument.
Try this and it should work:
y = rft1d.randn1d(1,101,20)
calc = rft1d.geom.ClusterMetricCalculator()
h = 1
x = calc.max_cluster_extent(y, h)
Incidentally, please consider using a higher value than 1
for the FWHM
argument in rft1d.randn1d
. This function simulates smooth fields, and cannot accurately model smoothness for extremely rough fields (FWHM < 3). If you want to use rough fields, use np.randn
instead, whose fields should be perfectly rough (within numerical tolerance).
Hi Todd,
Thanks very much for your quick answer.. I did indeed miss that in order to compute the upcrossing probabilities, it is essential to supply 1D vector as the input data. Sorry to have bothered you about this trivial issue ..
Regards, Rupsa
No problem! Others may encounter a similar problem, so it's good to have this report in the forum for future reference.
Hi ! As per a previous suggestion for rft1d for python3, I am now running- "from spm1d import rft1d". However, a further functionality for rft1d gives traceback error for the embedded function "bwlabel". More specifically, running the following example from the rft1d page:- ' y = rft1d.randn1d(3,101,1) calc= rft1d.geom.ClusterMetricCalculator() h = 1 x = calc.max_cluster_extent(y, h) '
results in the following traceback:- ' Traceback (most recent call last): File "first_study.py", line 23, in
x = calc.max_cluster_extent(y, h)
File "/Users/rupsabasu/Library/Python/3.8/lib/python/site-packages/rft1d/geom.py", line 299, in max_cluster_extent
return max( self.cluster_extents(y, u, interp, wrap) )
File "/Users/rupsabasu/Library/Python/3.8/lib/python/site-packages/rft1d/geom.py", line 220, in cluster_extents
L,n = bwlabel(y >= u, merge_wrapped=wrap)
File "/Users/rupsabasu/Library/Python/3.8/lib/python/site-packages/rft1d/geom.py", line 583, in bwlabel
if b[0]:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
'
Is there something that I am doing wrong here ? Could someone explain why the given example does not work?