Saving and loading#
- save(fpath, obj)[source]#
Save a test result to an HDF5 file.
- Parameters:
fpath — HDF5 file path
obj — SPM (before or after inference) or list of SPMs
- Returns:
None
- Example:
Save the inference results of a paired t test on the plantar arch angle dataset and then load them again.
>>> import spm1d >>> import jikudata as jd >>> dataset = jd.PlantarArchAngle() >>> y, A = dataset.y, dataset.x # (20,101) array and (20,) array >>> y0, y1 = y[ A == 0 ], y[ A == 1 ] >>> spmi = spm1d.stats.ttest_paired( y0, y1 ).inference( 0.05 ) >>> spm1d.io.save( 'ttest_paired.h5', spmi ) >>> loaded = spm1d.io.load( 'ttest_paired.h5' ) >>> print( type( loaded ).__name__, loaded.h0reject ) SPMi1D True
The example datasets require the jiku-data package:
pip install "spm1d[data]".
- load(fpath)[source]#
Load a test result from an HDF5 file.
- Parameters:
fpath — HDF5 file path
- Returns:
SPM (before or after inference) or list of SPMs (multi-effect designs)
- Example:
Load the inference results saved in the
saveexample.>>> import spm1d >>> import jikudata as jd >>> dataset = jd.PlantarArchAngle() >>> y, A = dataset.y, dataset.x # (20,101) array and (20,) array >>> y0, y1 = y[ A == 0 ], y[ A == 1 ] >>> spmi = spm1d.stats.ttest_paired( y0, y1 ).inference( 0.05 ) >>> spm1d.io.save( 'ttest_paired.h5', spmi ) >>> loaded = spm1d.io.load( 'ttest_paired.h5' ) >>> print( loaded ) SPM{t} (1D) inference fn_name : ttest_paired STAT : T z : (101,) array df : (1, 9) Smoothness estimates: fwhm : 23.819 lkc : 6.991 resels : (1, 4.19835) Inference results: method : rft isparametric : True alpha : 0.05 dirn : 0 zc : 3.82866 zmax : 6.552 h0reject : True p_zmax : 0.002 p_set : 0.040 p_cluster : [0.040] p_point : None
The example datasets require the jiku-data package:
pip install "spm1d[data]".