Skip to content

Commit

Permalink
notebooks_mod3
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiomarco25 committed Dec 18, 2024
1 parent 5ff3fef commit 237329e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 187 deletions.
30 changes: 26 additions & 4 deletions notebooks/spatialdata_tutorials/7_image_params.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
},
{
"cell_type": "code",
"execution_count": 66,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -137,6 +137,29 @@
"\n",
"# Example: Assuming `data_array` is your xArray DataArray with dims (channels, height, width)\n",
"def process_xarray(data_array, sigma=5, downsize_factor=0.1):\n",
" \"\"\"\n",
" Processes a 3D xarray by applying Gaussian smoothing and downscaling on each 2D slice.\n",
"\n",
" Parameters:\n",
" - data_array: xarray.DataArray\n",
" A 3D xarray where the first dimension represents slices, and the next two dimensions\n",
" represent 2D spatial data.\n",
" - sigma: float, optional (default=5)\n",
" The standard deviation for the Gaussian kernel used in smoothing.\n",
" - downsize_factor: float, optional (default=0.1)\n",
" The factor by which each 2D slice is resized during downscaling.\n",
"\n",
" Returns:\n",
" - smoothed_and_downsized: numpy.ndarray\n",
" A 3D numpy array with processed slices, where the first dimension corresponds to\n",
" the original slicing dimension, and the remaining dimensions are the downsized\n",
" 2D spatial data.\n",
"\n",
" Notes:\n",
" - The function loops through each slice of the input data, applies Gaussian smoothing,\n",
" downsizes the smoothed array, and stacks the results back into a single 3D array.\n",
" - Ensure that `data_array` has the correct shape and data types for processing.\n",
" \"\"\"\n",
" processed_slices = []\n",
" \n",
" for i in range(data_array.shape[0]): # Loop over the first dimension\n",
Expand All @@ -150,11 +173,10 @@
" \n",
" processed_slices.append(downscaled)\n",
" \n",
" smoothed_and_downsized=np.stack(processed_slices , axis=0)\n",
" # Stack back into an xArray\n",
" \n",
" smoothed_and_downsized = np.stack(processed_slices, axis=0)\n",
" return smoothed_and_downsized\n",
"\n",
"\n",
"# Example usage\n",
"# Assuming your xArray is named `image_array`\n",
"smoothed_and_downsized = process_xarray(imarray, sigma=5, downsize_factor=0.5)\n",
Expand Down
183 changes: 0 additions & 183 deletions notebooks/spatialdata_tutorials/9_sender_centric_analysis.ipynb

This file was deleted.

0 comments on commit 237329e

Please sign in to comment.