Skip to content

Commit

Permalink
Update pathlib references in IO submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
willGraham01 committed Apr 10, 2024
1 parent 3b632c2 commit d15d80e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
19 changes: 13 additions & 6 deletions brainglobe_utils/IO/cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import logging
import os
import pathlib
from pathlib import Path
from typing import List, Optional, Union
from xml.dom import minidom
from xml.etree import ElementTree
Expand Down Expand Up @@ -88,7 +88,7 @@ def raise_cell_read_error(cells_file_path):
)


def get_cells_xml(xml_file_path, cells_only=False):
def get_cells_xml(xml_file_path: Path, cells_only: Optional[bool] = False):
"""
Read cells from an xml file.
Expand Down Expand Up @@ -121,7 +121,11 @@ def get_cells_xml(xml_file_path, cells_only=False):
return cells


def get_cells_yml(cells_file_path, ignore_type=False, marker="markers"):
def get_cells_yml(
cells_file_path: Path,
ignore_type: Optional[bool] = False,
marker: Optional[str] = "markers",
):
"""
Read cells from a yml file.
Expand Down Expand Up @@ -158,7 +162,7 @@ def get_cells_yml(cells_file_path, ignore_type=False, marker="markers"):
return cells


def get_cells_dir(cells_file_path, cell_type=None):
def get_cells_dir(cells_file_path: Path, cell_type: Optional[bool] = None):
"""
Read cells from a directory. Cells will be created based on the filenames
of files in the directory, one cell per file.
Expand Down Expand Up @@ -230,7 +234,10 @@ def save_cells(


def cells_to_xml(
cells, xml_file_path, indentation_str=" ", artifact_keep=True
cells: Cell,
xml_file_path: Path,
indentation_str: Optional[str] = " ",
artifact_keep: Optional[bool] = True,
):
"""
Save cells to an xml file.
Expand Down Expand Up @@ -263,7 +270,7 @@ def cells_to_dataframe(cells: List[Cell]) -> pd.DataFrame:
return pd.DataFrame([c.to_dict() for c in cells])


def cells_to_csv(cells: List[Cell], csv_file_path: Union[str, pathlib.Path]):
def cells_to_csv(cells: List[Cell], csv_file_path: Union[str, Path]):
"""Save cells to csv file"""
df = cells_to_dataframe(cells)
df.to_csv(csv_file_path)
Expand Down
12 changes: 11 additions & 1 deletion brainglobe_utils/IO/surfaces.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
def marching_cubes_to_obj(marching_cubes_out, output_file):
from typing import TYPE_CHECKING, Tuple, Union

if TYPE_CHECKING:
from pathlib import Path

from numpy.typing import NDArray


def marching_cubes_to_obj(
marching_cubes_out: Tuple["NDArray"], output_file: Union[str, "Path"]
):
"""
Saves the output of skimage.measure.marching_cubes as an .obj file
Expand Down
17 changes: 14 additions & 3 deletions brainglobe_utils/IO/yaml.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from typing import TYPE_CHECKING, Any, Dict, Optional, Union

import yaml

if TYPE_CHECKING:
from pathlib import Path


def read_yaml_section(yaml_file, section):
def read_yaml_section(
yaml_file: Union[str, "Path"], section: str
) -> Dict[str, Any]:
"""
Read section from yaml file.
Expand All @@ -21,7 +28,7 @@ def read_yaml_section(yaml_file, section):
return contents


def open_yaml(yaml_file):
def open_yaml(yaml_file: Union[str, "Path"]) -> Dict[str, Any]:
"""
Read the contents of a yaml file.
Expand All @@ -40,7 +47,11 @@ def open_yaml(yaml_file):
return yaml_contents


def save_yaml(yaml_contents, output_file, default_flow_style=False):
def save_yaml(
yaml_contents: Dict[str, Any],
output_file: Union[str, "Path"],
default_flow_style: Optional[bool] = False,
):
"""
Save contents to a yaml file.
Expand Down

0 comments on commit d15d80e

Please sign in to comment.