Hi,
Not sure this is still being supported, but I was thrilled to find your python implementation of the R package clhs as it's exceedingly useful in my current work. And R is painful for the uninitiated. I've tested the library by following your example (https://clhs-py.readthedocs.io/en/latest/notebooks/quickstart.html)
I've downloaded a stack of soil attributes from GEE (https://developers.google.com/earth-engine/datasets/catalog/CSIRO_SLGA) and used gdalwarp to cut out pixels outside my shapefile for all 18 layers and then used georasters to convert them to pandas.
My initial goal was to use the 18 layers (AWC, Total N and SOC for 0-5,5-15,15-30,30-60,60-100) separately, but when that didn't work I just took the mean of the 3 variables over the 0-100cm profile as a test. This also didn't work. Strangely I can't see any difference in our dataframes (after checking the xarray tutorial data), except mine will have discontinuities in x and y as some cells were cut as outside the shapefile. Example dataframe (dfOut) attached and code below.
num_sample=50
sampled=clhs.clhs(dfOut[['AWC_0-100','NTO_0-100', 'SOC_0-100']],
num_sample, max_iterations=1000)
clhs_sample=dfOut.iloc[sampled["sample_indices"]]
df_testing_clhs.csv
Error below (looks like nothing has been added to the continuous_objective_values object):
IndexError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_21692/2054753940.py in
4 # cLHS
5 sampled=clhs.clhs(dfOut[['AWC_0-100','NTO_0-100', 'SOC_0-100']],
----> 6 num_sample, max_iterations=1000)
7 clhs_sample=dfOut.iloc[sampled["sample_indices"]]
~\Anaconda3\envs\py3_geo\lib\site-packages\clhs\clhs.py in clhs(predictors, num_samples, good_mask, include, max_iterations, objective_func_limit, initial_temp, temp_decrease, cycle_length, p, weights, progress, random_state, **progress_kwargs)
746 previous_results["remaining_indices"],
747 previous_results["obj_continuous"],
--> 748 include)
749 x_continuous = continuous_predictors.iloc[sample_indices].copy()
750 x_categorical = categorical_predictors.iloc[sample_indices].copy()
~\Anaconda3\envs\py3_geo\lib\site-packages\clhs\clhs.py in resample(p, sampled_indices, remaining_indices, continuous_objective_values, include)
555 return resample_worst(
556 continuous_objective_values, sampled_indices, remaining_indices,
--> 557 include)
558
559
~\Anaconda3\envs\py3_geo\lib\site-packages\clhs\clhs.py in resample_worst(continuous_objective_values, sampled_indices, remaining_indices, include)
498 np.isin(new_sampled_indices, include_, assume_unique=True, invert=True)]
499 unique_obj_vals, inverse_indices = np.unique(
--> 500 continuous_objective_values[idx_not_included], return_inverse=True)
501 idx_worst = idx_not_included[
502 inverse_indices[(inverse_indices == unique_obj_vals.size - 1)]]
IndexError: index 0 is out of bounds for axis 0 with size 0
Thanks for your time
Ian