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

JNB: Blacken notebooks #180

Merged
merged 5 commits into from Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 10 additions & 5 deletions .pre-commit-config.yaml
Expand Up @@ -10,6 +10,16 @@ repos:
- id: rst-inline-touching-normal
types: [text]

- repo: https://github.com/kynan/nbstripout
rev: 0.4.0
hooks:
- id: nbstripout

- repo: https://github.com/dfm/black_nbconvert
rev: dcd7789
hooks:
- id: black_nbconvert

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.3.0
hooks:
Expand All @@ -30,8 +40,3 @@ repos:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
exclude: \.(html|svg)$

- repo: https://github.com/kynan/nbstripout
rev: 0.4.0
hooks:
- id: nbstripout
53 changes: 31 additions & 22 deletions examples/Basic usage.ipynb
Expand Up @@ -39,8 +39,9 @@
"source": [
"# Import our plotting toolbox, and enable options for embedded notebook figures\n",
"import holoviews as hv\n",
"\n",
"%load_ext holoviews.ipython\n",
"%output widgets='embed'"
"%output widgets=\"embed\""
]
},
{
Expand All @@ -58,7 +59,7 @@
"\n",
"Images can be defined as a folder with tiff stacks:\n",
"```python\n",
"images = 'folder'\n",
"images = \"folder\"\n",
"```\n",
"Where each tiff stack in the folder is a trial with several frames.\n",
"\n",
Expand All @@ -71,8 +72,8 @@
"\n",
"If the ROIs were defined using ImageJ use ImageJ's export function to save them in a zip. Then, indicate the locations as a list:\n",
"```python\n",
"rois = 'rois.zip' # for a single set of rois across images\n",
"rois = ['rois1.zip', 'rois2.zip', ...] # for a roiset for each image\n",
"rois = \"rois.zip\" # for a single set of rois across images\n",
"rois = [\"rois1.zip\", \"rois2.zip\", ...] # for a roiset for each image\n",
"```\n",
"Defining a different roiset per image can be useful if you need to adjust for motion drift for example.\n",
"\n",
Expand All @@ -86,15 +87,15 @@
"outputs": [],
"source": [
"# Define image and ROI locations\n",
"images_location = 'exampleData/20150529'\n",
"rois_location = 'exampleData/20150429.zip'\n",
"images_location = \"exampleData/20150529\"\n",
"rois_location = \"exampleData/20150429.zip\"\n",
"\n",
"# Define the folder where FISSA's outputs will be stored, so they can be\n",
"# quickly reloaded in the future without having to recompute them.\n",
"# Make sure to use a different folder for each experiment.\n",
"# This argument is optional; if it is not provided, FISSA will not save its\n",
"# results for later use.\n",
"output_folder = 'fissa_example'\n",
"output_folder = \"fissa_example\"\n",
"\n",
"experiment = fissa.Experiment(images_location, rois_location, output_folder)"
]
Expand Down Expand Up @@ -212,8 +213,9 @@
"c = 2\n",
"t = 1\n",
"\n",
"(hv.Curve(experiment.raw[c][t][0, :], label='Raw')\n",
" * hv.Curve(experiment.result[c, t][0, :], label='Decontaminated')\n",
"(\n",
" hv.Curve(experiment.raw[c][t][0, :], label=\"Raw\")\n",
" * hv.Curve(experiment.result[c, t][0, :], label=\"Decontaminated\")\n",
")"
]
},
Expand Down Expand Up @@ -249,8 +251,9 @@
"c = 2\n",
"t = 1\n",
"\n",
"(hv.Curve(experiment.deltaf_raw[c][t], label='Raw', vdims=['df/f0']) *\n",
" hv.Curve(experiment.deltaf_result[c, t][0, :], label='Decontaminated')\n",
"(\n",
" hv.Curve(experiment.deltaf_raw[c][t], label=\"Raw\", vdims=[\"df/f0\"])\n",
" * hv.Curve(experiment.deltaf_result[c, t][0, :], label=\"Decontaminated\")\n",
")"
]
},
Expand Down Expand Up @@ -285,10 +288,10 @@
"```octave\n",
"ROIs.cell0.trial0{1} % polygon for the ROI\n",
"ROIs.cell0.trial0{2} % polygon for first neuropil subregion\n",
"result.cell0.trial0(1,:) % final extracted cell signal\n",
"result.cell0.trial0(2,:) % contaminating signal\n",
"raw.cell0.trial0(1,:) % raw measured celll signal\n",
"raw.cell0.trial0(2,:) % raw signal from first neuropil subregion\n",
"result.cell0.trial0(1, :) % final extracted cell signal\n",
"result.cell0.trial0(2, :) % contaminating signal\n",
"raw.cell0.trial0(1, :) % raw measured celll signal\n",
"raw.cell0.trial0(2, :) % raw signal from first neuropil subregion\n",
"```"
]
},
Expand Down Expand Up @@ -382,12 +385,12 @@
"\n",
"t = trial_of_interest\n",
"\n",
"plt.imshow(experiment.means[t], cmap='gray')\n",
"plt.imshow(experiment.means[t], cmap=\"gray\")\n",
"for roi_poly in experiment.roi_polys:\n",
" # Plot border around cells\n",
" # plt.plot(roi_poly[t][0][0][:, 1], roi_poly[t][0][0][:, 0], ':c')\n",
" # plt.plot(roi_poly[t][0][0][:, 1], roi_poly[t][0][0][:, 0], \":c\")\n",
" # Fill cells with partially-transparent shaded area\n",
" plt.fill(roi_poly[t][0][0][:, 1], roi_poly[t][0][0][:, 0], ':r', alpha=0.2)\n",
" plt.fill(roi_poly[t][0][0][:, 1], roi_poly[t][0][0][:, 0], \":r\", alpha=0.2)\n",
"plt.show()"
]
},
Expand Down Expand Up @@ -436,7 +439,8 @@
" rois_location,\n",
" output_folder,\n",
" nRegions=nRegions,\n",
" expansion=expansion,alpha=alpha,\n",
" expansion=expansion,\n",
" alpha=alpha,\n",
" ncores_preparation=ncores_preparation,\n",
" ncores_separation=ncores_separation,\n",
")\n",
Expand Down Expand Up @@ -469,8 +473,9 @@
"c = 2\n",
"t = 1\n",
"\n",
"(hv.Curve(experiment.raw[c][t][0, :], label='Raw')\n",
" * hv.Curve(experiment.result[c, t][0, :], label='Decontaminated')\n",
"(\n",
" hv.Curve(experiment.raw[c][t][0, :], label=\"Raw\")\n",
" * hv.Curve(experiment.result[c, t][0, :], label=\"Decontaminated\")\n",
")"
]
},
Expand Down Expand Up @@ -509,7 +514,9 @@
"metadata": {},
"outputs": [],
"source": [
"experiment = fissa.Experiment(images_location, rois_location, output_folder, lowmemory_mode=True)\n",
"experiment = fissa.Experiment(\n",
" images_location, rois_location, output_folder, lowmemory_mode=True\n",
")\n",
"experiment.separate(redo_prep=True)"
]
},
Expand Down Expand Up @@ -550,6 +557,7 @@
"# appropriately. In this case, we only need to overwrite the\n",
"# `image2array` method to work with our custom data format.\n",
"\n",
"\n",
"class DataHandlerCustom(DataHandlerTifffile):\n",
" @staticmethod\n",
" def image2array(image):\n",
Expand All @@ -569,6 +577,7 @@
" # Some custom code\n",
" pass\n",
"\n",
"\n",
"# Then pass an instance of this class to fissa.Experiment when creating\n",
"# a new experiment.\n",
"datahandler = DataHandlerCustom()\n",
Expand Down
32 changes: 19 additions & 13 deletions examples/SIMA example.ipynb
Expand Up @@ -38,8 +38,9 @@
"\n",
"# Plotting toolbox, with notebook embedding options\n",
"import holoviews as hv\n",
"\n",
"%load_ext holoviews.ipython\n",
"%output widgets='embed'"
"%output widgets=\"embed\""
]
},
{
Expand All @@ -63,20 +64,20 @@
"outputs": [],
"source": [
"# Define folder where tiffs are present\n",
"tiff_folder = 'exampleData/20150529/'\n",
"tiff_folder = \"exampleData/20150529/\"\n",
"\n",
"# Find tiffs in folder\n",
"tiffs = sorted(glob.glob(tiff_folder + '/*.tif*'))\n",
"tiffs = sorted(glob.glob(tiff_folder + \"/*.tif*\"))\n",
"\n",
"# define motion correction method\n",
"mc_approach = sima.motion.DiscreteFourier2D()\n",
"\n",
"# Define SIMA dataset\n",
"sequences = [sima.Sequence.create('TIFF', tiff) for tiff in tiffs[:1]]\n",
"sequences = [sima.Sequence.create(\"TIFF\", tiff) for tiff in tiffs[:1]]\n",
"try:\n",
" dataset = sima.ImagingDataset(sequences, 'example.sima')\n",
" dataset = sima.ImagingDataset(sequences, \"example.sima\")\n",
"except:\n",
" dataset = sima.ImagingDataset.load('example.sima')"
" dataset = sima.ImagingDataset.load(\"example.sima\")"
]
},
{
Expand All @@ -96,7 +97,7 @@
"stica_approach.append(sima.segment.SparseROIsFromMasks())\n",
"stica_approach.append(sima.segment.SmoothROIBoundaries())\n",
"stica_approach.append(sima.segment.MergeOverlapping(threshold=0.5))\n",
"rois = dataset.segment(stica_approach, 'auto_ROIs')"
"rois = dataset.segment(stica_approach, \"auto_ROIs\")"
]
},
{
Expand Down Expand Up @@ -173,7 +174,7 @@
"metadata": {},
"outputs": [],
"source": [
"output_folder = 'fissa_sima_example'\n",
"output_folder = \"fissa_sima_example\"\n",
"exp = fissa.Experiment(tiff_folder, [rois_fissa], output_folder)\n",
"exp.separate()"
]
Expand All @@ -195,9 +196,9 @@
"\n",
"\n",
"def plot_cell_regions(roi_polys, plot_neuropil=False):\n",
" '''\n",
" \"\"\"\n",
" Plot a single cell region, using holoviews.\n",
" '''\n",
" \"\"\"\n",
" out = hv.Overlay()\n",
"\n",
" if plot_neuropil:\n",
Expand Down Expand Up @@ -225,16 +226,21 @@
"\n",
"# Generate plots for raw extracts and neuropil removed\n",
"traces_plots = {\n",
" i_cell: hv.Curve(exp.raw[i_cell][i_trial][0, :], label='SIMA') *\n",
" hv.Curve(exp.result[i_cell][i_trial][0, :], label='FISSA')\n",
" i_cell: (\n",
" hv.Curve(exp.raw[i_cell][i_trial][0, :], label=\"SIMA\")\n",
" * hv.Curve(exp.result[i_cell][i_trial][0, :], label=\"FISSA\")\n",
" )\n",
" for i_cell in range(exp.nCell)\n",
"}\n",
"\n",
"# Get average image\n",
"avg_img = hv.Raster(exp.means[i_trial])\n",
"\n",
"# Render holoviews\n",
"avg_img * hv.HoloMap(region_plots,kdims=['Cell']) * fig + hv.HoloMap(traces_plots,kdims=['Cell'])"
"(\n",
" avg_img * hv.HoloMap(region_plots, kdims=[\"Cell\"]) * fig\n",
" + hv.HoloMap(traces_plots, kdims=[\"Cell\"])\n",
")"
]
},
{
Expand Down