Skip to content

Commit

Permalink
Add standard pre-commit config (#40)
Browse files Browse the repository at this point in the history
* Add standard pre-commit config

* Add automated pre-commit fixes

* Ignore line too long
  • Loading branch information
dstansby committed Feb 27, 2023
1 parent ea9acb6 commit 3b92d54
Show file tree
Hide file tree
Showing 23 changed files with 149 additions and 169 deletions.
26 changes: 21 additions & 5 deletions .pre-commit-config.yaml
@@ -1,6 +1,22 @@
repos:
- repo: https://github.com/python/black
rev: 22.12.0
hooks:
- id: black
pass_filenames: true
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: end-of-file-fixer
- id: mixed-line-ending
args: [--fix=lf]
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.240
hooks:
- id: ruff
args: [ --config=pyproject.toml ]
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
args: [--config=pyproject.toml]
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -8,24 +8,24 @@ Utilities and scripts for the generation of cleaned-up data for the `bg-atlasapi
### To contribute
1) Fork this repo

2) Clone your repo
2) Clone your repo
```bash
git clone https://github.com/USERNAME/bg-atlasgen
```

3) Install an editable version
```bash
cd bg-atlasgen
pip install -e .
pip install -e .
```
4) Create a script to package your atlas, and place into
4) Create a script to package your atlas, and place into
`bg_atlasgen/atlas_scripts`. Please see other scripts for examples.

Your script should contain everything required to run. The raw data should be
Your script should contain everything required to run. The raw data should be
hosted on a publicly accessible repository so that anyone can run the script
to recreate the atlas.

If you need to add any dependencies, please add them as an extra in the
If you need to add any dependencies, please add them as an extra in the
setup.py file, e.g.:

```python
Expand Down
18 changes: 7 additions & 11 deletions bg_atlasgen/atlas_scripts/admba_3d_dev_mouse.py
Expand Up @@ -2,26 +2,23 @@

import dataclasses
import json
import multiprocessing as mp
import time
import zipfile

from os import listdir, path
from pathlib import Path
from typing import Tuple

import pandas as pd
import numpy as np
import multiprocessing as mp

from rich.progress import track
from pathlib import Path

import pandas as pd
from bg_atlasapi import utils
from bg_atlasgen.mesh_utils import create_region_mesh, Region
from bg_atlasgen.wrapup import wrapup_atlas_from_data
from bg_atlasapi.structure_tree_util import get_structures_tree

from rich.progress import track
from skimage import io

from bg_atlasgen.mesh_utils import Region, create_region_mesh
from bg_atlasgen.wrapup import wrapup_atlas_from_data

PARALLEL = True


Expand Down Expand Up @@ -116,7 +113,6 @@ def create_meshes(download_dir_path, structures, annotated_volume, root_id):
smooth = False # smooth meshes after creation
start = time.time()
if PARALLEL:

pool = mp.Pool(mp.cpu_count() - 2)

try:
Expand Down
25 changes: 11 additions & 14 deletions bg_atlasgen/atlas_scripts/allen_cord.py
@@ -1,31 +1,29 @@
__version__ = "1"

import json
import multiprocessing as mp
import time
import tifffile
import zipfile
from pathlib import Path
from random import choices


import pandas as pd
import numpy as np
import multiprocessing as mp
from random import choices
from loguru import logger
from rich.progress import track
from pathlib import Path
import pandas as pd
import tifffile

# import sys

# sys.path.append("./")

from bg_atlasapi import utils
from bg_atlasapi.structure_tree_util import get_structures_tree
from loguru import logger
from rich.progress import track

from bg_atlasgen.mesh_utils import (
create_region_mesh,
Region,
create_region_mesh,
inspect_meshes_folder,
)
from bg_atlasgen.wrapup import wrapup_atlas_from_data
from bg_atlasapi.structure_tree_util import get_structures_tree

PARALLEL = True
TEST = False
Expand Down Expand Up @@ -123,7 +121,7 @@ def create_meshes(download_dir_path, structures, annotated_volume, root_id):
nodes = list(tree.nodes.values())
if TEST:
logger.info(
f"Creating atlas in test mode: selecting 10 random regions for mesh creation"
"Creating atlas in test mode: selecting 10 random regions for mesh creation"
)
nodes = choices(nodes, k=10)

Expand Down Expand Up @@ -289,7 +287,6 @@ def create_atlas(working_dir):


if __name__ == "__main__":

# Generated atlas path:
bg_root_dir = Path.home() / "brainglobe_workingdir" / "allen_cord_smooth"
bg_root_dir.mkdir(exist_ok=True, parents=True)
Expand Down
8 changes: 4 additions & 4 deletions bg_atlasgen/atlas_scripts/allen_mouse.py
@@ -1,15 +1,15 @@
__version__ = "2"

from pathlib import Path

from allensdk.api.queries.ontologies_api import OntologiesApi
from allensdk.api.queries.reference_space_api import ReferenceSpaceApi
from allensdk.core.reference_space_cache import ReferenceSpaceCache

from bg_atlasapi import descriptors
from requests import exceptions
from pathlib import Path
from tqdm import tqdm

from bg_atlasgen.wrapup import wrapup_atlas_from_data
from bg_atlasapi import descriptors


def create_atlas(working_dir, resolution):
Expand Down Expand Up @@ -83,7 +83,7 @@ def create_atlas(working_dir, resolution):
]

# Wrap up, compress, and remove file:0
print(f"Finalising atlas")
print("Finalising atlas")
output_filename = wrapup_atlas_from_data(
atlas_name=ATLAS_NAME,
atlas_minor_version=__version__,
Expand Down
19 changes: 7 additions & 12 deletions bg_atlasgen/atlas_scripts/azba_zfish.py
Expand Up @@ -10,30 +10,27 @@
__version__ = "1"

import csv
import time
import tifffile
import multiprocessing as mp
import tarfile
from random import choices
import time
from pathlib import Path

import numpy as np
import multiprocessing as mp

import tifffile
from bg_atlasapi import utils
from bg_atlasapi.structure_tree_util import get_structures_tree
from rich.progress import track
from pathlib import Path

from bg_atlasgen.mesh_utils import (
Region,
create_region_mesh,
inspect_meshes_folder,
)
from bg_atlasapi.structure_tree_util import get_structures_tree
from bg_atlasgen.wrapup import wrapup_atlas_from_data
from bg_atlasapi import utils

PARALLEL = False # Disable for debugging mesh creation


def create_atlas(working_dir, resolution):

# metadata
ATLAS_NAME = "azba_zfish"
SPECIES = "Danio rerio"
Expand Down Expand Up @@ -135,7 +132,6 @@ def create_atlas(working_dir, resolution):
smooth = True

if PARALLEL:

print("Multiprocessing mesh creation...")
pool = mp.Pool(int(mp.cpu_count() / 2))

Expand All @@ -159,7 +155,6 @@ def create_atlas(working_dir, resolution):
pass

else:

print("Multiprocessing disabled")
# nodes = list(tree.nodes.values())
# nodes = choices(nodes, k=10)
Expand Down
5 changes: 2 additions & 3 deletions bg_atlasgen/atlas_scripts/example_mouse.py
@@ -1,18 +1,17 @@
__version__ = "2"

from pathlib import Path

from allensdk.api.queries.ontologies_api import OntologiesApi
from allensdk.api.queries.reference_space_api import ReferenceSpaceApi
from allensdk.core.reference_space_cache import ReferenceSpaceCache

from requests import exceptions
from pathlib import Path
from tqdm import tqdm

from bg_atlasgen.wrapup import wrapup_atlas_from_data


def create_atlas(working_dir, resolution):

# Specify information about the atlas:
RES_UM = resolution # 100
ATLAS_NAME = "example_mouse"
Expand Down
16 changes: 8 additions & 8 deletions bg_atlasgen/atlas_scripts/humanatlas.py
@@ -1,25 +1,25 @@
import json
from rich.progress import track
import pandas as pd
import numpy as np
import time
import multiprocessing as mp
import time
from pathlib import Path

import numpy as np
import pandas as pd
import treelib
from brainio import brainio
import urllib3
from allensdk.core.structure_tree import StructureTree
from bg_atlasapi.structure_tree_util import get_structures_tree
from brainio import brainio
from rich.progress import track

# import sys

# sys.path.append("./")
from bg_atlasgen.mesh_utils import (
create_region_mesh,
Region,
create_region_mesh,
inspect_meshes_folder,
)
from bg_atlasgen.wrapup import wrapup_atlas_from_data
from bg_atlasapi.structure_tree_util import get_structures_tree


def prune_tree(tree):
Expand Down
23 changes: 8 additions & 15 deletions bg_atlasgen/atlas_scripts/kim_developmental_ccf_mouse.py
@@ -1,24 +1,21 @@
__version__ = "1"

import json
import multiprocessing as mp
import time
import tarfile
import zipfile
from pathlib import Path

import pandas as pd
import imio
import numpy as np
import multiprocessing as mp

import pandas as pd
from bg_atlasapi import utils
from bg_atlasapi.structure_tree_util import get_structures_tree
from rich.progress import track
from pathlib import Path
from scipy.ndimage import zoom

from bg_atlasapi import utils
from bg_atlasgen.mesh_utils import create_region_mesh, Region
from bg_atlasgen.mesh_utils import Region, create_region_mesh
from bg_atlasgen.wrapup import wrapup_atlas_from_data
from bg_atlasapi.structure_tree_util import get_structures_tree
import imio
import zipfile
import os

PARALLEL = True # disable parallel mesh extraction for easier debugging

Expand Down Expand Up @@ -47,7 +44,6 @@ def get_structure_id_path_from_id(id, id_dict, root_id):
return structure_id_path

while True:

parent = int(id_dict[id])
structure_id_path.insert(0, parent)

Expand Down Expand Up @@ -141,7 +137,6 @@ def create_atlas(

structures = []
for row in range(df.shape[0]):

entry = {
"acronym": df["Acronym"][row],
"id": int(df["ID"][row]), # from np.int for JSON serialization
Expand Down Expand Up @@ -184,15 +179,13 @@ def create_atlas(
node.data = Region(is_label)

if mesh_creation == "generate":

closing_n_iters = 2
decimate_fraction = 0.04
smooth = False # smooth meshes after creation

start = time.time()

if PARALLEL:

pool = mp.Pool(mp.cpu_count() - 2)

try:
Expand Down

0 comments on commit 3b92d54

Please sign in to comment.