Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/examples/plot_fixel_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
# # activate your conda environment first
# conda activate <env_name>
#
# confixel \
# modelarrayio mif-to-h5 \
# --index-file /home/username/myProject/data/FD/index.mif \
# --directions-file /home/username/myProject/data/FD/directions.mif \
# --cohort-file /home/username/myProject/data/cohort_FD.csv \
Expand All @@ -118,7 +118,7 @@
#
# .. code-block:: console
#
# fixelstats_write \
# modelarrayio h5-to-mif \
# --index-file /home/username/myProject/data/FD/index.mif \
# --directions-file /home/username/myProject/data/FD/directions.mif \
# --cohort-file /home/username/myProject/data/cohort_FD.csv \
Expand All @@ -144,7 +144,7 @@
#
# .. code-block:: console
#
# confixel --help
# fixelstats_write --help
# modelarrayio mif-to-h5 --help
# modelarrayio h5-to-mif --help
#
# or in the :doc:`/usage` page of this documentation.
8 changes: 4 additions & 4 deletions docs/examples/plot_voxel_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
# # activate your conda environment first
# conda activate <env_name>
#
# convoxel \
# modelarrayio nifti-to-h5 \
# --group-mask-file /home/username/myProject/data/group_mask.nii.gz \
# --cohort-file /home/username/myProject/data/cohort_FA.csv \
# --output-hdf5 /home/username/myProject/data/FA.h5
Expand All @@ -121,7 +121,7 @@
#
# .. code-block:: console
#
# volumestats_write \
# modelarrayio h5-to-nifti \
# --group-mask-file /home/username/myProject/data/group_mask.nii.gz \
# --cohort-file /home/username/myProject/data/cohort_FA.csv \
# --analysis-name mylm \
Expand Down Expand Up @@ -177,7 +177,7 @@
#
# .. code-block:: console
#
# convoxel --help
# volumestats_write --help
# modelarrayio nifti-to-h5 --help
# modelarrayio h5-to-nifti --help
#
# or in the :doc:`/usage` page of this documentation.
72 changes: 36 additions & 36 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,60 @@ Usage
#####


********
confixel
********
**********
mif-to-h5
**********

.. argparse::
:ref: modelarrayio.cli.mif_to_h5.get_parser
:prog: confixel
:func: get_parser
:ref: modelarrayio.cli.mif_to_h5._parse_mif_to_h5
:prog: modelarrayio mif-to-h5
:func: _parse_mif_to_h5


********
convoxel
********
**********
nifti-to-h5
**********

.. argparse::
:ref: modelarrayio.cli.nifti_to_h5.get_parser
:prog: convoxel
:func: get_parser
:ref: modelarrayio.cli.nifti_to_h5._parse_nifti_to_h5
:prog: modelarrayio nifti-to-h5
:func: _parse_nifti_to_h5


********
concifti
********
**********
cifti-to-h5
**********

.. argparse::
:ref: modelarrayio.cli.cifti_to_h5.get_parser
:prog: concifti
:func: get_parser
:ref: modelarrayio.cli.cifti_to_h5._parse_cifti_to_h5
:prog: modelarrayio cifti-to-h5
:func: _parse_cifti_to_h5


****************
fixelstats_write
****************
**********
h5-to-mif
**********

.. argparse::
:ref: modelarrayio.cli.h5_to_mif.get_parser
:prog: fixelstats_write
:func: get_parser
:ref: modelarrayio.cli.h5_to_mif._parse_h5_to_mif
:prog: modelarrayio h5-to-mif
:func: _parse_h5_to_mif

*****************
volumestats_write
*****************
***********
h5-to-nifti
***********

.. argparse::
:ref: modelarrayio.cli.h5_to_nifti.get_parser
:prog: volumestats_write
:func: get_parser
:ref: modelarrayio.cli.h5_to_nifti._parse_h5_to_nifti
:prog: modelarrayio h5-to-nifti
:func: _parse_h5_to_nifti


****************
ciftistats_write
****************
***********
h5-to-cifti
***********

.. argparse::
:ref: modelarrayio.cli.h5_to_cifti.get_parser
:prog: ciftistats_write
:func: get_parser
:ref: modelarrayio.cli.h5_to_cifti._parse_h5_to_cifti
:prog: modelarrayio h5-to-cifti
:func: _parse_h5_to_cifti
7 changes: 1 addition & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ Repository = "https://github.com/PennLINC/ModelArrayIO"
Documentation = "https://modelarrayio.readthedocs.io"

[project.scripts]
confixel = "modelarrayio.cli.mif_to_h5:main"
convoxel = "modelarrayio.cli.nifti_to_h5:main"
concifti = "modelarrayio.cli.cifti_to_h5:main"
fixelstats_write = "modelarrayio.cli.h5_to_mif:main"
volumestats_write = "modelarrayio.cli.h5_to_nifti:main"
ciftistats_write = "modelarrayio.cli.h5_to_cifti:main"
modelarrayio = "modelarrayio.cli.main:main"

#
# Hatch
Expand Down
62 changes: 49 additions & 13 deletions src/modelarrayio/cli/cifti_to_h5.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,55 @@ def _process_scalar_job(scalar_name, source_files):
return 0


def get_parser():
def cifti_to_h5_main(
cohort_file,
backend='hdf5',
output_hdf5='fixelarray.h5',
output_tiledb='arraydb.tdb',
storage_dtype='float32',
compression='gzip',
compression_level=4,
shuffle=True,
chunk_voxels=0,
target_chunk_mb=2.0,
tdb_compression='zstd',
tdb_compression_level=5,
tdb_shuffle=True,
tdb_tile_voxels=0,
tdb_target_tile_mb=2.0,
tdb_workers=None,
scalar_columns=None,
s3_workers=1,
log_level='INFO',
):
"""Entry point for the ``modelarrayio cifti-to-h5`` command."""
logging.basicConfig(
level=getattr(logging, str(log_level).upper(), logging.INFO),
format='[%(levelname)s] %(name)s: %(message)s',
)
return cifti_to_h5(
cohort_file=cohort_file,
backend=backend,
output_hdf5=output_hdf5,
output_tiledb=output_tiledb,
storage_dtype=storage_dtype,
compression=compression,
compression_level=compression_level,
shuffle=shuffle,
chunk_voxels=chunk_voxels,
target_chunk_mb=target_chunk_mb,
tdb_compression=tdb_compression,
tdb_compression_level=tdb_compression_level,
tdb_shuffle=tdb_shuffle,
tdb_tile_voxels=tdb_tile_voxels,
tdb_target_tile_mb=tdb_target_tile_mb,
tdb_workers=tdb_workers,
scalar_columns=scalar_columns,
s3_workers=s3_workers,
)


def _parse_cifti_to_h5():
parser = argparse.ArgumentParser(
description='Create a hdf5 file of CIDTI2 dscalar data',
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
Expand All @@ -228,15 +276,3 @@ def get_parser():
)
add_s3_workers_arg(parser)
return parser


def main():
parser = get_parser()
args = parser.parse_args()
kwargs = vars(args)
log_level = kwargs.pop('log_level')
logging.basicConfig(
level=getattr(logging, str(log_level).upper(), logging.INFO),
format='[%(levelname)s] %(name)s: %(message)s',
)
return cifti_to_h5(**kwargs)
29 changes: 15 additions & 14 deletions src/modelarrayio/cli/h5_to_cifti.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,33 +90,34 @@ def h5_to_cifti(example_cifti, in_file, analysis_name, output_dir):
temp_nifti2_1mpvalue.to_filename(out_cifti_1mpvalue)


def main():
"""Write the contents of an hdf5 file to a cifti directory."""
parser = get_parser()
args = parser.parse_args()

if os.path.exists(args.output_dir):
def h5_to_cifti_main(
analysis_name,
in_file,
output_dir,
cohort_file=None,
example_cifti=None,
):
"""Entry point for the ``modelarrayio h5-to-cifti`` command."""
if os.path.exists(output_dir):
print('WARNING: Output directory exists')
os.makedirs(args.output_dir, exist_ok=True)
os.makedirs(output_dir, exist_ok=True)

# Get an example cifti
example_cifti = args.example_cifti
if example_cifti is None:
logger.warning(
'No example cifti file provided, using the first cifti file from the cohort file'
)
cohort_df = pd.read_csv(args.cohort_file)
cohort_df = pd.read_csv(cohort_file)
example_cifti = cohort_df['source_file'][0]

h5_to_cifti(
example_cifti=example_cifti,
in_file=args.in_file,
analysis_name=args.analysis_name,
output_dir=args.output_dir,
in_file=in_file,
analysis_name=analysis_name,
output_dir=output_dir,
)


def get_parser():
def _parse_h5_to_cifti():
parser = argparse.ArgumentParser(
description='Create a directory with cifti results from an hdf5 file',
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
Expand Down
30 changes: 13 additions & 17 deletions src/modelarrayio/cli/h5_to_mif.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,36 +92,32 @@ def h5_to_mif(example_mif, in_file, analysis_name, output_dir):
nifti2_to_mif(temp_nifti2_1mpvalue, out_mif_1mpvalue)


def main():
parser = get_parser()
args = parser.parse_args()

if os.path.exists(args.output_dir):
def h5_to_mif_main(index_file, directions_file, cohort_file, analysis_name, in_file, output_dir):
"""Entry point for the ``modelarrayio h5-to-mif`` command."""
if os.path.exists(output_dir):
print('WARNING: Output directory exists')
os.makedirs(args.output_dir, exist_ok=True)
os.makedirs(output_dir, exist_ok=True)

# Copy in the index and directions
shutil.copyfile(
args.directions_file,
os.path.join(args.output_dir, os.path.basename(args.directions_file)),
directions_file,
os.path.join(output_dir, os.path.basename(directions_file)),
)
shutil.copyfile(
args.index_file,
os.path.join(args.output_dir, os.path.basename(args.index_file)),
index_file,
os.path.join(output_dir, os.path.basename(index_file)),
)

# Get an example mif file
cohort_df = pd.read_csv(args.cohort_file)
cohort_df = pd.read_csv(cohort_file)
example_mif = cohort_df['source_file'][0]
h5_to_mif(
example_mif=example_mif,
in_file=args.in_file,
analysis_name=args.analysis_name,
output_dir=args.output_dir,
in_file=in_file,
analysis_name=analysis_name,
output_dir=output_dir,
)


def get_parser():
def _parse_h5_to_mif():
parser = argparse.ArgumentParser(
description='Create a fixel directory from an hdf5 file',
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
Expand Down
36 changes: 20 additions & 16 deletions src/modelarrayio/cli/h5_to_nifti.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,28 @@ def _decode_names(arr):
output_img_1mpvalue.to_filename(out_file_1mpvalue)


def main():
parser = get_parser()
args = parser.parse_args()

if os.path.exists(args.output_dir):
def h5_to_nifti_main(
group_mask_file,
analysis_name,
in_file,
output_dir,
output_extension='.nii.gz',
):
"""Entry point for the ``modelarrayio h5-to-nifti`` command."""
if os.path.exists(output_dir):
print('WARNING: Output directory exists')
os.makedirs(args.output_dir, exist_ok=True)

h5_to_nifti(*vars(args))
os.makedirs(output_dir, exist_ok=True)

h5_to_nifti(
in_file=in_file,
analysis_name=analysis_name,
group_mask_file=group_mask_file,
output_extension=output_extension,
output_dir=output_dir,
)


def get_parser():
def _parse_h5_to_nifti():
parser = argparse.ArgumentParser(
description='Convert statistical results from an hdf5 file to a volume data (NIfTI file)',
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
Expand All @@ -150,13 +160,6 @@ def get_parser():
required=True,
type=IsFile,
)
parser.add_argument(
'--cohort-file',
'--cohort_file',
help='Path to a csv with demographic info and paths to data.',
required=True,
type=IsFile,
)
parser.add_argument(
'--analysis-name',
'--analysis_name',
Expand All @@ -180,6 +183,7 @@ def get_parser():
parser.add_argument(
'--output-ext',
'--output_ext',
dest='output_extension',
help=(
'The extension for output volume data. '
'Options are .nii.gz (default) and .nii. Please provide the prefix dot.'
Expand Down
Loading
Loading