SpatialQuery.spatial_query.find_patterns_grid
- spatial_query.find_patterns_grid(max_dist=20, min_size=0, min_support=0.5, if_display=True, figsize=(10, 5), return_cellID=False, return_grid=False)[source]
Create a grid and use it to find surrounding patterns in spatial data.
- Parameters:
max_dist (float, default=20) – Maximum distance to consider a cell as a neighbor. Also used as grid spacing.
min_size (int, default=0) – Minimum neighborhood size for each grid point to consider.
min_support (float, default=0.5) – Threshold of frequency to consider a pattern as a frequent pattern.
if_display (bool, default=True) – Display the grid points with nearby frequent patterns if if_display=True.
figsize (tuple, default=(10, 5)) – Tuple of figure size for the display plot.
return_cellID (bool, default=False) – Indicate whether return cell IDs for each frequent pattern within the neighborhood of grid points. By default do not return cell ID.
return_grid (bool, default=False) – Indicate whether return the grid points. By default, do not return grid points. If True, will return a tuple (fp_df, grid).
- Returns:
- If return_grid=False (default):
- pd.DataFrame with frequent pattern results. Columns include:
itemsets: frozenset of cell types in the frequent pattern
support: frequency of the pattern (proportion of grid points with this pattern)
neighbor_id: set of cell indices belonging to the pattern (only if return_cellID=True)
- If return_grid=True:
- Tuple containing:
pd.DataFrame: frequent pattern results as described above
np.ndarray: grid points coordinates of shape (n_grid_points, 2)
- Return type:
Union[pd.DataFrame, Tuple[pd.DataFrame, np.ndarray]]