Skip to content
New issue

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

'ValueError: array of sample points is empty' with certain randomly generated coordinates #33

Open
zilch42 opened this issue Sep 4, 2024 · 4 comments

Comments

@zilch42
Copy link

zilch42 commented Sep 4, 2024

Hi there,

I'm having a weird issue where some sets of coordinates produce a ValueError and other sets of coordinates don't. I'm not exactly sure what the difference between these two coordinate examples is.

I've hard coded two examples of coordinates generated from np.random.rand() below. dummy_coords1 is an example that works, and dummy_coords2 is an example that does not. Both were produced by np.random.rand(12, 2)

datamapplot v0.3.0

import numpy as np
import datamapplot

dummy_labels = [['T1', 'Unlabelled', 'T1', 'T1', 'T2', 'T2', 'T2', 'T2', 'Unlabelled', 'Unlabelled', 'T2', 'T2'],
                ['T3', 'Unlabelled', 'T4', 'T4', 'T3', 'T3', 'T4', 'T5', 'Unlabelled', 'Unlabelled', 'T5', 'T5']]
dummy_label_array = np.array(dummy_labels)
dummy_hover = ['Text']*12

dummy_coords = np.random.rand(12, 2)

# works
dummy_coords1 = np.array([[0.36944978, 0.24840278],
       [0.05371874, 0.6797169 ],
       [0.73539839, 0.5694784 ],
       [0.37300726, 0.33794748],
       [0.09289142, 0.2358011 ],
       [0.95914631, 0.72673466],
       [0.67561212, 0.54775067],
       [0.54549458, 0.04819768],
       [0.88099899, 0.39860445],
       [0.26929064, 0.12571897],
       [0.84381725, 0.57393012],
       [0.74503466, 0.33412061]])

# doesn't work
dummy_coords2 = np.array([[0.90951533, 0.08958288],
       [0.98867221, 0.11019179],
       [0.01779863, 0.02374286],
       [0.80546908, 0.43450257],
       [0.09368194, 0.84672945],
       [0.89156692, 0.51185024],
       [0.68626036, 0.54685405],
       [0.94836897, 0.4673322 ],
       [0.98332563, 0.38787542],
       [0.32122166, 0.89713211],
       [0.00077888, 0.36843552],
       [0.0949498 , 0.40831818]])

datamapplot.create_interactive_plot(
    dummy_coords2, 
    *dummy_label_array, 
    hover_text=dummy_hover, 
    cluster_boundary_polygons=False
    )
{
	"name": "ValueError",
	"message": "array of sample points is empty",
	"stack": "---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[12], line 39
     25 # doesn't work
     26 dummy_coords2 = np.array([[0.90951533, 0.08958288],
     27        [0.98867221, 0.11019179],
     28        [0.01779863, 0.02374286],
   (...)
     36        [0.00077888, 0.36843552],
     37        [0.0949498 , 0.40831818]])
---> 39 datamapplot.create_interactive_plot(
     40     dummy_coords2, 
     41     *dummy_label_array, 
     42     hover_text=dummy_hover, 
     43     cluster_boundary_polygons=False
     44     )

File c:\\Users\\\[path]\\lib\\site-packages\\datamapplot\\create_plots.py:457, in create_interactive_plot(data_map_coords, hover_text, inline_data, noise_label, noise_color, color_label_text, label_wrap_width, label_color_map, width, height, darkmode, palette_hue_shift, palette_hue_radius_dependence, cmap, marker_size_array, marker_color_array, use_medoids, cluster_boundary_polygons, color_cluster_boundaries, polygon_alpha, *label_layers, **render_html_kwds)
    455 if label_color_map is None:
    456     if cmap is None:
--> 457         palette = palette_from_datamap(
    458             data_map_coords,
    459             label_dataframe[[\"x\", \"y\"]].values,
    460             hue_shift=palette_hue_shift,
    461             radius_weight_power=palette_hue_radius_dependence,
    462         )
    463     else:
    464         palette = palette_from_cmap_and_datamap(
    465             cmap,
    466             data_map_coords,
    467             label_dataframe[[\"x\", \"y\"]].values,
    468             radius_weight_power=palette_hue_radius_dependence,
    469         )

File c:\\Users\\[path]\\lib\\site-packages\\datamapplot\\palette_handling.py:65, in palette_from_datamap(umap_coords, label_locations, hue_shift, theta_range, radius_weight_power, min_lightness)
     58         chroma = (
     59             np.argsort(np.argsort(data_map_radii[r_mask])) / mask_size
     60         ) * 80 + 20
     61         lightness = (
     62             1.0 - (np.argsort(np.argsort(data_map_radii[r_mask])) / mask_size)
     63         ) * (80 - min_lightness) + min_lightness
     64         location_lightness.append(
---> 65             np.interp(
     66                 r,
     67                 np.sort(data_map_radii[r_mask]),
     68                 np.sort(lightness)[::-1],
     69             )
     70         )
     71         location_chroma.append(
     72             np.interp(r, np.sort(data_map_radii[r_mask]), np.sort(chroma))
     73         )
     74 else:

File c:\\Users\\[path]\\lib\\site-packages\
umpy\\lib\\function_base.py:1599, in interp(x, xp, fp, left, right, period)
   1596     xp = np.concatenate((xp[-1:]-period, xp, xp[0:1]+period))
   1597     fp = np.concatenate((fp[-1:], fp, fp[0:1]))
-> 1599 return interp_func(x, xp, fp, left, right)

ValueError: array of sample points is empty"
}
@lmcinnes
Copy link
Contributor

lmcinnes commented Sep 4, 2024

I have some guesses, but I'll actually have to try it out and see what exactly is the issue and how easy it will be to fix. I'm not sure when I'll have enough time to set aside to do debugging, but hopefully soon.

@rolandmueller
Copy link

I have the same error.

@pergamonster
Copy link
Contributor

@zilch42 thanks vm for such a helpful repro. I had exactly the same issue and was able to run using dummy_coords2 by widening the theta_range to np.pi/4 from np.pi/16. @lmcinnes is it helpful if i add the ability to set this as you can for
hue_shift=palette_hue_shift,
radius_weight_power=palette_hue_radius_dependence

@lmcinnes
Copy link
Contributor

lmcinnes commented Jan 8, 2025

It would probably be useful -- I would be happy to accept a PR if you can get it done.

pergamonster added a commit to pergamonster/datamapplot that referenced this issue Jan 8, 2025
…enerated coordinates TutteInstitute#33

Add theta_range option to allow less restrictive masking
lmcinnes added a commit that referenced this issue Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants