From b65630967c8f1a65aab5d04e442b79cc3148b93d Mon Sep 17 00:00:00 2001 From: Adam Tyson Date: Tue, 21 May 2024 11:13:41 +0100 Subject: [PATCH 1/5] Capitalise classes --- README.md | 6 +++--- brainglobe_heatmap/__init__.py | 2 +- brainglobe_heatmap/heatmaps.py | 2 +- brainglobe_heatmap/planner.py | 4 ++-- examples/cellfinder_cell_density.py | 2 +- examples/heatmap_2d.py | 2 +- examples/heatmap_3d.py | 2 +- examples/heatmap_human_brain.py | 2 +- examples/heatmap_spinal_cord.py | 2 +- examples/heatmap_zebrafish.py | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a24be58..83fb412 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ The position of the center of the plane is given by a set of `(x, y, z)` coordin Whe using one of the named orientation, you don't need to pass a whole set of `(x, y, z)` coordinates for the plane center. A single value is sufficient as the other two won't affect the plane position: ```python -f = bgh.heatmap( +f = bgh.Heatmap( values, position=1000, orientation="sagittal", # 'frontal' or 'sagittal', or 'horizontal' or a tuple (x,y,z) @@ -84,7 +84,7 @@ f = bgh.heatmap( Also, you can create a slice with a plane centered in the brain by passing `position=None`: ```python -f = bgh.heatmap( +f = bgh.Heatmap( values, position=None, orientation="sagittal", # 'frontal' or 'sagittal', or 'horizontal' or a tuple (x,y,z) @@ -100,7 +100,7 @@ Once happy with the position of the slicing planes, creating a visualization is ```python -bgh.heatmap( +bgh.Heatmap( values, position=( 8000, diff --git a/brainglobe_heatmap/__init__.py b/brainglobe_heatmap/__init__.py index 64a69c2..8b6517e 100644 --- a/brainglobe_heatmap/__init__.py +++ b/brainglobe_heatmap/__init__.py @@ -6,6 +6,6 @@ # package is not installed pass -from brainglobe_heatmap.heatmaps import heatmap +from brainglobe_heatmap.heatmaps import Heatmap from brainglobe_heatmap.planner import plan from brainglobe_heatmap.slicer import get_structures_slice_coords diff --git a/brainglobe_heatmap/heatmaps.py b/brainglobe_heatmap/heatmaps.py index c959cd3..be0aab1 100644 --- a/brainglobe_heatmap/heatmaps.py +++ b/brainglobe_heatmap/heatmaps.py @@ -48,7 +48,7 @@ def check_values(values: dict, atlas: Atlas) -> Tuple[float, float]: return vmax, vmin -class heatmap: +class Heatmap: def __init__( self, values: Dict, diff --git a/brainglobe_heatmap/planner.py b/brainglobe_heatmap/planner.py index e455b81..bbf614d 100644 --- a/brainglobe_heatmap/planner.py +++ b/brainglobe_heatmap/planner.py @@ -16,7 +16,7 @@ from rich.table import Table from vedo import Arrow, Sphere -from brainglobe_heatmap.heatmaps import heatmap +from brainglobe_heatmap.heatmaps import Heatmap from brainglobe_heatmap.plane import Plane settings.BACKGROUND_COLOR = amber_lighter @@ -47,7 +47,7 @@ def fmt_array(x: np.ndarray) -> str: ) -class plan(heatmap): +class plan(Heatmap): def __init__( self, regions: Union[dict, list], diff --git a/examples/cellfinder_cell_density.py b/examples/cellfinder_cell_density.py index b16fc92..b1c9497 100644 --- a/examples/cellfinder_cell_density.py +++ b/examples/cellfinder_cell_density.py @@ -39,7 +39,7 @@ print(cell_counts) -f = bgh.heatmap( +f = bgh.Heatmap( cell_counts.density.to_dict(), position=( 8000, diff --git a/examples/heatmap_2d.py b/examples/heatmap_2d.py index 96fb674..0bbfb73 100644 --- a/examples/heatmap_2d.py +++ b/examples/heatmap_2d.py @@ -23,7 +23,7 @@ ) -f = bgh.heatmap( +f = bgh.Heatmap( values, # when using a named orientation, you can pass a single value! position=5000, diff --git a/examples/heatmap_3d.py b/examples/heatmap_3d.py index fa4a615..315a4e1 100644 --- a/examples/heatmap_3d.py +++ b/examples/heatmap_3d.py @@ -23,7 +23,7 @@ ) -scene = bgh.heatmap( +scene = bgh.Heatmap( values, position=(8000, 5000, 5000), orientation="frontal", # or 'sagittal', or 'horizontal' or a tuple (x,y,z) diff --git a/examples/heatmap_human_brain.py b/examples/heatmap_human_brain.py index 37ed820..63703aa 100644 --- a/examples/heatmap_human_brain.py +++ b/examples/heatmap_human_brain.py @@ -10,7 +10,7 @@ values = dict(SFG=1, PrCG=2, Ca=4, Pu=10) # scalar values for each region -scene = bgh.heatmap( +scene = bgh.Heatmap( values, position=(100000, 100000, 100000), thickness=1000, diff --git a/examples/heatmap_spinal_cord.py b/examples/heatmap_spinal_cord.py index 4ffd1ff..19e0b18 100644 --- a/examples/heatmap_spinal_cord.py +++ b/examples/heatmap_spinal_cord.py @@ -19,7 +19,7 @@ } -f = bgh.heatmap( +f = bgh.Heatmap( values, position=1000, # 'frontal' or 'sagittal', or 'horizontal' or a tuple (x,y,z) diff --git a/examples/heatmap_zebrafish.py b/examples/heatmap_zebrafish.py index 36002a3..fd9c492 100644 --- a/examples/heatmap_zebrafish.py +++ b/examples/heatmap_zebrafish.py @@ -20,7 +20,7 @@ "cerebellum": 0.5, } -f = bgh.heatmap( +f = bgh.Heatmap( values, position=175, # 'frontal' or 'sagittal', or 'horizontal' or a tuple (x,y,z) From 6bd11bfbebb255ff0fabf3b843b94e47178469a6 Mon Sep 17 00:00:00 2001 From: Adam Tyson Date: Tue, 21 May 2024 11:13:59 +0100 Subject: [PATCH 2/5] Remove main script --- brainglobe_heatmap/planner.py | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/brainglobe_heatmap/planner.py b/brainglobe_heatmap/planner.py index bbf614d..100ebdf 100644 --- a/brainglobe_heatmap/planner.py +++ b/brainglobe_heatmap/planner.py @@ -116,38 +116,3 @@ def show(self): self.scene.render(interactive=self.interactive, zoom=self.zoom) return self.scene - - -if __name__ == "__main__": - regions = dict( # scalar values for each region - TH=1, - RSP=0.2, - AI=0.4, - SS=-3, - MO=2.6, - PVZ=-4, - LZ=-3, - VIS=2, - AUD=0.3, - RHP=-0.2, - STR=0.5, - CB=0.5, - FRP=-1.7, - HIP=3, - PA=-4, - ) - - plan( - regions, - # position of the center point of the plane - position=( - 8000, - 5000, - 5000, - ), - # or 'sagittal', or 'horizontal' or a tuple (x,y,z) - orientation="frontal", - # thickness of the slices used for rendering (in microns) - thickness=2000, - arrow_scale=750, - ).show() From 4f906560bb6f709a82d8f441da37e438d0ed8b05 Mon Sep 17 00:00:00 2001 From: Adam Tyson Date: Tue, 21 May 2024 11:14:15 +0100 Subject: [PATCH 3/5] Add additional ruff rule --- brainglobe_heatmap/slicer.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/brainglobe_heatmap/slicer.py b/brainglobe_heatmap/slicer.py index 363b041..de5a415 100644 --- a/brainglobe_heatmap/slicer.py +++ b/brainglobe_heatmap/slicer.py @@ -136,7 +136,7 @@ def slice_scene(self, scene: Scene, regions: List[Actor]): Slices the meshes in a 3D brainrender scene using the gien planes """ # slice the scene - for n, plane in enumerate((self.plane0, self.plane1)): + for _, plane in enumerate((self.plane0, self.plane1)): scene.slice(plane, actors=regions, close_actors=True) scene.slice(self.plane0, actors=scene.root, close_actors=False) diff --git a/pyproject.toml b/pyproject.toml index d420054..b5816fc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -78,7 +78,7 @@ exclude = ["__init__.py", "build", ".eggs"] fix = true [tool.ruff.lint] -select = ["I", "E", "F"] +select = ["I", "E", "F", "B"] [tool.tox] legacy_tox_ini = """ From a47b62d157f191f896c8db13631e7b5c12d4acc6 Mon Sep 17 00:00:00 2001 From: Adam Tyson Date: Tue, 21 May 2024 11:14:38 +0100 Subject: [PATCH 4/5] Allow cell count example to be run from anywhere --- examples/cellfinder_cell_density.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/cellfinder_cell_density.py b/examples/cellfinder_cell_density.py index b1c9497..1320f9d 100644 --- a/examples/cellfinder_cell_density.py +++ b/examples/cellfinder_cell_density.py @@ -4,6 +4,8 @@ density (count/volume) of cells in each brain region """ +from pathlib import Path + import pandas as pd from brainglobe_atlasapi.bg_atlas import BrainGlobeAtlas from brainrender._io import load_mesh_from_file @@ -11,7 +13,9 @@ import brainglobe_heatmap as bgh # get the number of cells for each region -data = pd.read_hdf("examples/cell_counts_example.h5") +cells_path = Path(__file__).parent / "cell_counts_example.h5" + +data = pd.read_hdf(cells_path) cell_counts = data.groupby("region").count() # get regions two levels up the hierarchy From 18b0f2b91ef76509bfcf71afe426f796d8f5e372 Mon Sep 17 00:00:00 2001 From: Adam Tyson Date: Tue, 21 May 2024 11:14:49 +0100 Subject: [PATCH 5/5] Make pre-commit happy --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 83fb412..b9b5317 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,8 @@ Whe using one of the named orientation, you don't need to pass a whole set of `( f = bgh.Heatmap( values, position=1000, - orientation="sagittal", # 'frontal' or 'sagittal', or 'horizontal' or a tuple (x,y,z) + orientation="sagittal", + # 'frontal' or 'sagittal', or 'horizontal' or a tuple (x,y,z) thickness=1000, atlas_name="allen_cord_20um", format='2D', @@ -83,11 +84,13 @@ f = bgh.Heatmap( ``` Also, you can create a slice with a plane centered in the brain by passing `position=None`: + ```python f = bgh.Heatmap( values, position=None, - orientation="sagittal", # 'frontal' or 'sagittal', or 'horizontal' or a tuple (x,y,z) + orientation="sagittal", + # 'frontal' or 'sagittal', or 'horizontal' or a tuple (x,y,z) thickness=1000, atlas_name="mpin_zfish_1um", format='2D', @@ -107,7 +110,8 @@ bgh.Heatmap( 5000, 5000, ), - orientation="horizontal", # 'frontal' or 'sagittal', or 'horizontal' or a tuple (x,y,z) + orientation="horizontal", + # 'frontal' or 'sagittal', or 'horizontal' or a tuple (x,y,z) title="horizontal view", vmin=-5, vmax=3,