[docs]defget_X_Y_grid(adata:Optional[AnnData]=None,genes:Optional[List]=None,X:Optional[np.ndarray]=None,Y:Optional[np.ndarray]=None,grid_num:List=[50,50,50],)->Tuple[np.ndarray,np.ndarray,np.ndarray,np.ndarray]:"""Prepare the X (spatial coordinates), Y (gene expression) and grid points for the kernel or deep model. Args: adata: AnnData object that contains spatial (numpy.ndarray) in the `obsm` attribute. genes: Gene list whose interpolate expression across space needs to learned. If Y is provided, genes will only be used to retrive the gene annotation info. X: The spatial coordinates of each data point. Y: The gene expression of the corresponding data point. grid_num: Number of grid to generate. Default is 50 for each dimension. Must be non-negative. Returns: X: spatial coordinates. Y: gene expression of the associated spatial coordinates. Grid: grid points formed with the input spatial coordinates. grid_in_hull: A list of booleans indicates whether the current grid points is within the convex hull formed by the input data points. """lm.main_info("Learn a continuous mapping from space to gene expression pattern")X,Y=adata.obsm["spatial"]ifXisNoneelseX,adata[:,genes].XifYisNoneelseY# Generate gridlm.main_info("Generate grid...")min_vec,max_vec=(X.min(0),X.max(0),)min_vec=min_vec-0.01*np.abs(max_vec-min_vec)max_vec=max_vec+0.01*np.abs(max_vec-min_vec)Grid_list=np.meshgrid(*[np.linspace(i,j,k)fori,j,kinzip(min_vec,max_vec,grid_num)])Grid=np.array([i.flatten()foriinGrid_list]).Tlm.main_info("Creating a Convex Hull...")hull,_=polyhull(X[:,0],X[:,1],X[:,2])lm.main_info("Identify grid points within the Convex Hull...")grid_in_hull=in_hull(Grid,hull.points[hull.vertices,:])returnX,Y,Grid,grid_in_hull