Skip to content

Commit

Permalink
Merge pull request #280 from scottclowe/api_rename-to-matfile
Browse files Browse the repository at this point in the history
API: Rename run_fissa argument export_to_matlab -> export_to_matfile
  • Loading branch information
scottclowe committed Mar 25, 2022
2 parents 96c99d0 + 240cd9f commit a0ea98f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
8 changes: 4 additions & 4 deletions examples/Basic usage - Function.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@
"\n",
"The results can easily be exported to a MATLAB-compatible [MAT-file](https://mathworks.com/help/matlab/import_export/mat-file-versions.html) as follows.\n",
"\n",
"If we provide `export_to_matlab=True` to `fissa.run_fissa`, it will export the data a matfile named `\"separated.mat\"` within the cache directory (the cache directory as provided with the `folder` argument)."
"If we provide `export_to_matfile=True` to `fissa.run_fissa`, it will export the data a matfile named `\"separated.mat\"` within the cache directory (the cache directory as provided with the `folder` argument)."
]
},
{
Expand All @@ -627,15 +627,15 @@
"outputs": [],
"source": [
"result, raw = fissa.run_fissa(\n",
" images_location, rois_location, folder=output_folder, export_to_matlab=True\n",
" images_location, rois_location, folder=output_folder, export_to_matfile=True\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Alternatively, we can export to a matfile with a custom file name by setting the `export_to_matlab` argument to the target path."
"Alternatively, we can export to a matfile with a custom file name by setting the `export_to_matfile` argument to the target path."
]
},
{
Expand All @@ -645,7 +645,7 @@
"outputs": [],
"source": [
"result, raw = fissa.run_fissa(\n",
" images_location, rois_location, export_to_matlab=\"experiment_results.mat\"\n",
" images_location, rois_location, export_to_matfile=\"experiment_results.mat\"\n",
")"
]
},
Expand Down
2 changes: 1 addition & 1 deletion examples/basic_usage_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
output_dir = "fissa_example"

# Run FISSA on this data
result = fissa.run_fissa(images, rois, output_dir, export_to_matlab=True)
result = fissa.run_fissa(images, rois, output_dir, export_to_matfile=True)
2 changes: 1 addition & 1 deletion examples/basic_usage_func_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
output_dir = "fissa_example"

# Run FISSA on this data
result = fissa.run_fissa(images, rois, output_dir, export_to_matlab=True)
result = fissa.run_fissa(images, rois, output_dir, export_to_matfile=True)
20 changes: 11 additions & 9 deletions fissa/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1870,7 +1870,7 @@ def run_fissa(
freq=None,
return_deltaf=False,
deltaf_across_trials=True,
export_to_matlab=False,
export_to_matfile=False,
**kwargs
):
r"""
Expand Down Expand Up @@ -1928,10 +1928,10 @@ def run_fissa(
Δf/f\ :sub:`0` value will be relative to the trial-specific f0.
Default is ``True``.
export_to_matlab : bool or str or None, default=False
export_to_matfile : bool or str or None, default=False
Whether to export the data to a MATLAB-compatible .mat file.
If `export_to_matlab` is a string, it is used as the path to the output
file. If ``export_to_matlab=True``, the matfile is saved to the
If `export_to_matfile` is a string, it is used as the path to the output
file. If ``export_to_matfile=True``, the matfile is saved to the
default path of ``"separated.mat"`` within the `folder` directory, and
`folder` must be set. If this is ``None``, the matfile is exported to
the default path if `folder` is set, and otherwise is not exported.
Expand Down Expand Up @@ -1963,20 +1963,22 @@ def run_fissa(
fissa.core.Experiment
"""
# Parse arguments
if export_to_matlab is None:
export_to_matlab = folder is not None
if export_to_matfile is None:
export_to_matfile = folder is not None
if return_deltaf and freq is None:
raise ValueError("The argument `freq` must be set to determine df/f0.")
# Make a new Experiment object
experiment = Experiment(images, rois, folder=folder, **kwargs)
# Run separation
experiment.separate()
# Calculate Δf/f0
if return_deltaf or (export_to_matlab and freq is not None):
if return_deltaf or (export_to_matfile and freq is not None):
experiment.calc_deltaf(freq=freq, across_trials=deltaf_across_trials)
# Save to matfile
if export_to_matlab:
matlab_fname = None if isinstance(export_to_matlab, bool) else export_to_matlab
if export_to_matfile:
matlab_fname = (
None if isinstance(export_to_matfile, bool) else export_to_matfile
)
experiment.to_matfile(matlab_fname)
# Return appropriate data
if return_deltaf:
Expand Down
8 changes: 4 additions & 4 deletions fissa/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1913,7 +1913,7 @@ def test_func(self):
image_path = os.path.join(self.resources_dir, self.images_dir)
roi_path = os.path.join(self.resources_dir, self.roi_zip_path)
actual_result, actual_raw = core.run_fissa(
image_path, roi_path, self.output_dir, export_to_matlab=None
image_path, roi_path, self.output_dir, export_to_matfile=None
)
self.compare_result(actual_result)
self.compare_raw(actual_raw)
Expand All @@ -1925,7 +1925,7 @@ def test_func_explict_matlab(self):
image_path = os.path.join(self.resources_dir, self.images_dir)
roi_path = os.path.join(self.resources_dir, self.roi_zip_path)
actual_result, actual_raw = core.run_fissa(
image_path, roi_path, self.output_dir, export_to_matlab=True
image_path, roi_path, self.output_dir, export_to_matfile=True
)
self.compare_result(actual_result)
self.compare_raw(actual_raw)
Expand All @@ -1936,7 +1936,7 @@ def test_func_explict_nomatlab(self):
image_path = os.path.join(self.resources_dir, self.images_dir)
roi_path = os.path.join(self.resources_dir, self.roi_zip_path)
actual_result, actual_raw = core.run_fissa(
image_path, roi_path, self.output_dir, export_to_matlab=False
image_path, roi_path, self.output_dir, export_to_matfile=False
)
self.compare_result(actual_result)
self.compare_raw(actual_raw)
Expand All @@ -1948,7 +1948,7 @@ def test_func_manual_matlab(self):
roi_path = os.path.join(self.resources_dir, self.roi_zip_path)
fname = os.path.join(self.output_dir, "test_output.mat")
actual_result, actual_raw = core.run_fissa(
image_path, roi_path, self.output_dir, export_to_matlab=fname
image_path, roi_path, self.output_dir, export_to_matfile=fname
)
self.compare_result(actual_result)
self.compare_raw(actual_raw)
Expand Down

0 comments on commit a0ea98f

Please sign in to comment.