hong2p.suite2p module

Functions for working with suite2p as part of analysis.

exception hong2p.suite2p.LabelsNotModifiedError[source]

Bases: hong2p.suite2p.ROIsNotLabeledError

exception hong2p.suite2p.LabelsNotSelectiveError[source]

Bases: hong2p.suite2p.ROIsNotLabeledError

exception hong2p.suite2p.ROIsNotLabeledError[source]

Bases: Exception

hong2p.suite2p.diff_dicts(d1, d2, label1='<', label2='>', header=None)[source]

Prints differences between two dictionaries.

Return type

None

hong2p.suite2p.get_iscell_path(s2p_out_dir)[source]
Return type

Path

hong2p.suite2p.get_suite2p_combined_dir(analysis_dir)[source]
Return type

Path

hong2p.suite2p.get_suite2p_dir(analysis_dir)[source]
Return type

Path

hong2p.suite2p.gui_params_equal(ops1, ops2, print_diff=True, **kwargs)[source]

Returns whether GUI-settable parameters differ.

Parameters
  • ops1 (Dict[str, Any]) – as returned by load_s2p_ops

  • ops2 (Dict[str, Any]) – to be compared to ops1

  • print_diff (bool) – whether to print any differences

Return type

bool

hong2p.suite2p.inputs_equal(ops1, ops2, print_diff=True, **kwargs)[source]

Returns whether input data and GUI-settable parameters differ.

Return type

bool

hong2p.suite2p.invert_combined_view_offset(combined_ops, roi)[source]
hong2p.suite2p.is_iscell_modified(s2p_out_dir, warn=True)[source]
hong2p.suite2p.load(path)[source]
hong2p.suite2p.load_iscell(s2p_out_dir)[source]
hong2p.suite2p.load_ops(s2p_dir)[source]
Return type

Dict[str, Any]

hong2p.suite2p.load_s2p_combined_outputs(analysis_dir, **kwargs)[source]

Raises IOError if corresponding suite2p output not found (i.e. suite2p needs to be run), LabelsNotModifiedError, or LabelsNotSelectiveError.

hong2p.suite2p.load_s2p_masks(s2p_dir)[source]

Returns normalized (each sums to 1) cell footprints

Return type

ndarray

hong2p.suite2p.load_s2p_ops(ops_path)[source]
Parameters

ops_path (Union[str, Path]) – if path does not end with ‘*.npy’, assumed to be a directory containing a file named ‘ops.npy’

Return type

Dict[str, Any]

hong2p.suite2p.load_s2p_outputs(plane_or_combined_dir, good_only=True, merge_inputs=False, merge_outputs=False, subset_stat=True, err=False)[source]

Returns suite2p outputs, with traces as a DataFrame

Loads outputs from plane_or_combined_dir, tossing data for ROIs marked “not a cell” and ROIs merged to create others (by default).

Parameters
  • plane_or_combined_dir (Union[str, Path]) – directory containing suite2p outputs

  • good_only – whether to drop data for ROIs marked “not a cell” in suite2p GUI

  • merge_inputs – whether to drop data for ROIs merged to create other ROIs

  • merge_outputs – whether to drop data for ROIs created via merging in suite2p

  • subset_stat – whether to also drop data in roi_stats according to the above criteria.

Returns

DataFrame w/ ROI numbers and extracted signals stat_dict: dict of ROI num -> suite2ps “stat” ROI data ops: suite2p options merges: dict of ROI nums of ROIs created via merging pointing to a list of the

ROI nums merged to create them. can be used for implementing your own merging strategies.

err: whether to raise errors about ROI “cell / not cell” labels if good_only

Return type

traces

Raises
  • IOError – if suite2p outputs did not exist

  • LabelsNotModifiedError – if err and good_only and the “cell / not cell” labels have not been modified.

  • LabelsNotSelectiveError – if err and good_only and no ROIs were marked “not a cell” in suite2p (assumes that some noise ROIs would have been pulled out). This can be caused by setting the threshold to 0 and not modifying the ROIs further manually.

hong2p.suite2p.load_s2p_pickle(npy_path)[source]
hong2p.suite2p.load_stat(s2p_dir)[source]

Returns array of dicts, each describing one ROI.

Return type

ndarray

hong2p.suite2p.load_traces(s2p_dir)[source]

Returns traces in shape (#-cells, #-timepoints)

Return type

ndarray

hong2p.suite2p.mark_all_suite2p_rois_good(s2p_out_dir)[source]

Modify iscell.npy to set all labels (first column) 1.

This is to undo the automatic classification step that I do not want and can not seem to disable. It should be equivalent to entering 0 for the probability threshold in the GUI.

hong2p.suite2p.modify_iscell_in_suite2p(stat_path)[source]
hong2p.suite2p.plot_roi(roi_stat, ops, ax=None)[source]
hong2p.suite2p.print_suite2p_params(thorimage_dir, print_movie_shape=False)[source]
hong2p.suite2p.remerge_suite2p_merged(traces, stat_dict, ops, merges, response_stats=None, how='best_plane', renumber=False, verbose=False)[source]

Accepts input as the output of load_s2p_outputs

Parameters

response_stats

hong2p.suite2p.set_suite2p_iscell_label(s2p_out_dir, roi_num, is_good)[source]
Parameters
  • roi_num (int) – index of ROI to change label of, according to suite2p

  • s2p_out_dir (str) – must directly contain a single iscell.npy file

hong2p.suite2p.suite2p_footprint2bool_mask(roi_stat, ops)[source]
hong2p.suite2p.suite2p_params(thorimage_dir)[source]
hong2p.suite2p.suite2p_roi_stat2roi(roi_stat, ops, xy_only=False, fillna_0=True, invert_combined=True)[source]

Takes a single suite2p ROI to a dense numpy representation

roi_stat and ops are both assumed to come from the ‘combined’ folder outputs

hong2p.suite2p.suite2p_stat2rois(stat, ops, merges=None, as_xarray=True, **kwargs)[source]

Takes suite2p ‘stat’ array / dict (roi # -> roi stat) to array / xarray ROIs.