[main] adding convertion scripts
This commit is contained in:
parent
f34cbc6cd2
commit
1af6fa4f7b
@ -7,6 +7,8 @@ from IPython import embed
|
|||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
|
|
||||||
from oephys2nix.logging import setup_logging
|
from oephys2nix.logging import setup_logging
|
||||||
|
from oephys2nix.stimulus_recreation import StimulusToNix
|
||||||
|
from oephys2nix.tonix import RawToNix
|
||||||
|
|
||||||
app = typer.Typer()
|
app = typer.Typer()
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -25,30 +27,25 @@ def main(
|
|||||||
readable=True,
|
readable=True,
|
||||||
resolve_path=True,
|
resolve_path=True,
|
||||||
),
|
),
|
||||||
ttl: bool = typer.Option(
|
ttl: bool = typer.Option(default=True, help="For recordings that did not have a ttl pulse"),
|
||||||
default=True, help="For recordings that did not have a ttl pulse"
|
|
||||||
),
|
|
||||||
overwrite: bool = typer.Option(default=True, help="Overwrites nix file"),
|
overwrite: bool = typer.Option(default=True, help="Overwrites nix file"),
|
||||||
):
|
debug: bool = typer.Option(default=True, help="Shows more information and plots the results"),
|
||||||
"""
|
) -> None:
|
||||||
Combines open ephys data with relacs data from data_path to a new nix file
|
"""Combines open ephys data with relacs data from data_path to a new nix file."""
|
||||||
"""
|
|
||||||
|
|
||||||
log.info(f"Selected data_path is {data_path}")
|
log.info(f"Selected data_path is {data_path}")
|
||||||
open_ephys_data_paths = list(Path(data_path).rglob("*open-ephys"))
|
open_ephys_data_paths = list(Path(data_path).rglob("*open-ephys"))
|
||||||
relacs_data_paths = list(Path(data_path).rglob("*relacs"))
|
relacs_data_paths = list(Path(data_path).rglob("*relacs/*.nix"))
|
||||||
|
|
||||||
if not len(open_ephys_data_paths) == len(relacs_data_paths):
|
if len(open_ephys_data_paths) != len(relacs_data_paths):
|
||||||
log.error(
|
log.error(
|
||||||
f"Missmatch in data directory found open-ephys data {len(open_ephys_data_paths)} and relacs data {len(relacs_data_paths)}"
|
f"Missmatch in data directory found open-ephys data {len(open_ephys_data_paths)} "
|
||||||
|
f"and relacs data {len(relacs_data_paths)}"
|
||||||
)
|
)
|
||||||
log.error("Please check if both are present")
|
log.error("Please check if both are present")
|
||||||
raise typer.Exit()
|
raise typer.Exit()
|
||||||
|
|
||||||
for open_ephys, relacs in zip(
|
for open_ephys, relacs in zip(open_ephys_data_paths, relacs_data_paths, strict=True):
|
||||||
open_ephys_data_paths, relacs_data_paths, strict=True
|
nix_file_name = relacs.parent.name.split("_")[0] + "-recording.nix"
|
||||||
):
|
|
||||||
nix_file_name = relacs.name.split("_")[0] + "-recording.nix"
|
|
||||||
|
|
||||||
console.print(
|
console.print(
|
||||||
f"Converting [bold cyan]{open_ephys.name}[/bold cyan] and "
|
f"Converting [bold cyan]{open_ephys.name}[/bold cyan] and "
|
||||||
@ -56,20 +53,38 @@ def main(
|
|||||||
f"[green]{nix_file_name}[/green]"
|
f"[green]{nix_file_name}[/green]"
|
||||||
)
|
)
|
||||||
|
|
||||||
nix_path = relacs.parent / nix_file_name
|
nix_path = relacs.parent.parent / nix_file_name
|
||||||
|
|
||||||
if nix_path.exists and nix_path.is_file():
|
if nix_path.exists and nix_path.is_file():
|
||||||
if overwrite:
|
if overwrite:
|
||||||
log.warning("Overwriting nix file")
|
log.warning("Overwriting nix file")
|
||||||
nix_files = nixio.File(str(nix_file_name), nixio.FileMode.Overwrite)
|
nix_file = nixio.File(str(nix_path), nixio.FileMode.Overwrite)
|
||||||
else:
|
else:
|
||||||
log.error(
|
log.error("Converted nix file already exits, and Overwrite is not enabled")
|
||||||
"Converted nix file already exits, and Overwrite is not enabled"
|
|
||||||
)
|
|
||||||
raise typer.Exit()
|
raise typer.Exit()
|
||||||
else:
|
else:
|
||||||
log.debug("Creating nix file")
|
log.debug("Creating nix file")
|
||||||
nix_files = nixio.File(str(nix_file_name), nixio.FileMode.Overwrite)
|
nix_file = nixio.File(str(nix_path), nixio.FileMode.Overwrite)
|
||||||
|
|
||||||
|
nix_file.close()
|
||||||
|
|
||||||
|
log.info("Appending raw data from relacs and open-ephys to new nix-file")
|
||||||
|
to_nix = RawToNix(open_ephys, str(relacs), str(nix_path))
|
||||||
|
to_nix.append_section()
|
||||||
|
to_nix.append_fish_lines()
|
||||||
|
to_nix.append_relacs_lines()
|
||||||
|
to_nix.append_raw_data()
|
||||||
|
to_nix.close()
|
||||||
|
log.info("Finished!")
|
||||||
|
|
||||||
|
log.info("Starting with stimulus recreation")
|
||||||
|
stim = StimulusToNix(open_ephys, str(relacs), str(nix_path))
|
||||||
|
stim.create_repros_automatically()
|
||||||
|
stim.print_table()
|
||||||
|
stim.checks()
|
||||||
|
|
||||||
|
if debug:
|
||||||
|
stim.plot_stimulus()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user