Skip to content
This repository has been archived by the owner on Oct 6, 2021. It is now read-only.

Commit

Permalink
Add cellfinder -> brainrender points transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
adamltyson authored Jan 27, 2020
1 parent 1b9ccd0 commit bb220e6
Show file tree
Hide file tree
Showing 9 changed files with 4,113 additions and 7 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ matrix:
- os: linux
python: 3.7
dist: bionic
- os: linux
python: 3.8
dist: bionic
before_install:
- wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
- bash miniconda.sh -b -p $HOME/miniconda
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
[![Python Version](https://img.shields.io/pypi/pyversions/neuro.svg)](https://python.org)
[![PyPI](https://img.shields.io/pypi/v/neuro.svg)](https://pypi.org/project/neuro)
[![Wheel](https://img.shields.io/pypi/wheel/neuro.svg)](https://pypi.org/project/neuro)
[![Development Status](https://img.shields.io/pypi/status/neuro.svg)](https://github.com/SainsburyWellcomeCentre/neuro)
[![Travis](https://img.shields.io/travis/com/SainsburyWellcomeCentre/neuro?label=Travis%20CI)](
https://travis-ci.com/SainsburyWellcomeCentre/neuro)
[![Coverage Status](https://coveralls.io/repos/github/SainsburyWellcomeCentre/neuro/badge.svg?branch=master)](https://coveralls.io/github/SainsburyWellcomeCentre/neuro?branch=master)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black)


# neuro
Visualisation and analysis of brain imaging data
Empty file added neuro/points/__init__.py
Empty file.
110 changes: 110 additions & 0 deletions neuro/points/points_to_brainrender.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
"""
Converts point positions from cellfinder coordinates to brainrender
N.B. This is currently specific to coronal images, with the origin at the most
caudal, ventral left point. The default is also for 10um voxel spacing.
"""

import argparse
import imlib.IO.cells as cells_io
from imlib.misc import check_positive_float, check_positive_int


def run(
cells_file,
output_filename,
pixel_size_x=10,
pixel_size_y=10,
pixel_size_z=10,
max_z=13200,
key="df",
):
print(f"Converting file: {cells_file}")
cells = cells_io.get_cells(cells_file)
cells = cells_io.cells_to_dataframe(cells)

cells["x"] = cells["x"] * pixel_size_x
cells["y"] = cells["y"] * pixel_size_y
cells["z"] = cells["z"] * pixel_size_z

cells.columns = ["z", "y", "x", "type"]

cells["x"] = max_z - cells["x"]

print(f"Saving to: {output_filename}")
cells.to_hdf(output_filename, key=key, mode="w")

print("Finished")


def get_parser():
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument(
dest="cells_file",
type=str,
help="Cellfinder cells file to be converted",
)
parser.add_argument(
dest="output_filename",
type=str,
help="Output filename. Should end with '.h5'",
)

parser.add_argument(
"-x",
"--x-pixel-size",
dest="x_pixel_size",
type=check_positive_float,
default=10,
help="Pixel_size that the cells are defined in.",
)
parser.add_argument(
"-y",
"--y-pixel-size",
dest="y_pixel_size",
type=check_positive_float,
default=10,
help="Pixel_size that the cells are defined in.",
)
parser.add_argument(
"-z",
"--z-pixel-size",
dest="z_pixel_size",
type=check_positive_float,
default=10,
help="Pixel_size that the cells are defined in.",
)
parser.add_argument(
"--max-z",
dest="max_z",
type=check_positive_int,
default=13200,
help="Maximum z extent of the atlas",
)
parser.add_argument(
"--hdf-key",
dest="hdf_key",
type=str,
default="df",
help="hdf identifier ",
)
return parser


def main():
args = get_parser().parse_args()
run(
args.cells_file,
args.output_filename,
pixel_size_x=args.x_pixel_size,
pixel_size_y=args.y_pixel_size,
pixel_size_z=args.z_pixel_size,
max_z=args.max_z,
key=args.hdf_key,
)


if __name__ == "__main__":
main()
10 changes: 8 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_namespace_packages

requirements = ["brainrender", "napari"]
requirements = ["brainrender", "napari", "imlib", "pandas"]


setup(
Expand All @@ -22,7 +22,7 @@
"coverage<=4.5.4",
]
},
python_requires=">=3.6",
python_requires=">=3.6, <3.8",
packages=find_namespace_packages(exclude=("docs", "tests*")),
include_package_data=True,
url="https://github.com/SainsburyWellcomeCentre/neuro",
Expand All @@ -37,5 +37,11 @@
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
],
entry_points={
"console_scripts": [
"points_to_brainrender = "
"neuro.points.points_to_brainrender:main",
]
},
zip_safe=False,
)
Binary file added tests/data/points/brainrender.h5
Binary file not shown.
Loading

0 comments on commit bb220e6

Please sign in to comment.