Skip to content

Commit

Permalink
Change usage of file pattern in reader
Browse files Browse the repository at this point in the history
  • Loading branch information
lauraporta committed Nov 8, 2024
1 parent e85206c commit bb41c55
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 21 deletions.
14 changes: 6 additions & 8 deletions calcium_imaging_automation/core/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ class ReadAllPathsInFolder:
def __init__(
self,
raw_data_folder: Path,
filetypes_of_interest: List[str],
folder_read_pattern: str,
file_read_pattern: str,
file_read_pattern: list,
):
self.filetypes_of_interest = filetypes_of_interest
self.folder_read_pattern = folder_read_pattern
self.file_read_pattern = file_read_pattern

Expand All @@ -25,19 +23,19 @@ def get_folders_first_layer(self, file_path: Path) -> List[Path]:
def get_files_paths(self, folder: Path) -> List[Path]:
return [
file
for filetype in self.filetypes_of_interest
for file in folder.rglob(f"*.{filetype}")
for pattern in self.folder_read_pattern
for file in folder.rglob(pattern)
]

def total_objects_by_filetype(self, folder: Path) -> dict:
def total_objects_by_format(self, folder: Path) -> dict:
return {
filetype: len(self.get_files_paths(folder))
for filetype in self.filetypes_of_interest
for filetype in self.folder_read_pattern.split(".")[-1]
}

def max_session_number(self, filetype="tif", max_allowed=5) -> int:
total_tif_number = [
self.total_objects_by_filetype(dataset_path).get(filetype, 0)
self.total_objects_by_format(dataset_path).get(filetype, 0)
for dataset_path in self.datasets_paths
]

Expand Down
15 changes: 2 additions & 13 deletions examples/example_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
def main(
raw_data_path: Path,
output_path: Path,
filetypes_of_interest: list,
folder_read_pattern: str,
file_read_pattern: str,
):
Expand All @@ -25,7 +24,6 @@ def main(

reader = ReadAllPathsInFolder(
raw_data_path,
filetypes_of_interest,
folder_read_pattern,
file_read_pattern,
)
Expand Down Expand Up @@ -53,13 +51,6 @@ def main(
parser.add_argument(
"output_path", type=Path, help="Path to the output data."
)
parser.add_argument(
"--filetypes",
type=list,
nargs="+",
help="Filetypes of interest.",
default=["tif", "bin"],
)
parser.add_argument(
"--folder_read_pattern",
type=str,
Expand All @@ -68,22 +59,20 @@ def main(
)
parser.add_argument(
"--file_read_pattern",
type=str,
type=list,
help="Glob pattern for reading files.",
default="*",
default=["*.tif", "*.bin"],
)

args = parser.parse_args()
raw_data_path = args.raw_data_path
output_path = args.output_path
file_types = args.filetypes
folder_read_pattern = args.folder_read_pattern
file_read_pattern = args.file_read_pattern

main(
raw_data_path,
output_path,
file_types,
folder_read_pattern,
file_read_pattern,
)
1 change: 1 addition & 0 deletions examples/example_usage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ python ./examples/example_usage.py \
/nfs/winstor/margrie/SimonWeiler/RawData/Invivo_imaging/3photon_rotation/shared/ \
/ceph/margrie/laura/cimaut/ \
--folder_read_pattern '2*' \
--file_read_pattern 'rotation_00001.tif, *.bin' \

0 comments on commit bb41c55

Please sign in to comment.