.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorial-config/eg_02_custom_config.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorial-config_eg_02_custom_config.py: Custom configuration ^^^^^^^^^^^^^^^^^^^^ It is possible to customise the configuration and save it for use later. Configurations can either be customised at initialisation or after initialisation. Configurations can be saved as JSON files and later reloaded. This allows users to keep a library of configurations that can be used depending on the use case or the survey. .. GENERATED FROM PYTHON SOURCE LINES 13-18 .. code-block:: default from pathlib import Path from resistics.config import Configuration from resistics.time import Add from resistics.transfunc import TransferFunction .. GENERATED FROM PYTHON SOURCE LINES 19-21 Creating a new configuration requires only a name. In this instance, default parameters will be used for everything else. .. GENERATED FROM PYTHON SOURCE LINES 21-24 .. code-block:: default custom_config = Configuration(name="example") custom_config.summary() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none { 'name': 'example', 'time_readers': [ { 'name': 'TimeReaderAscii', 'apply_scalings': True, 'extension': '.txt', 'delimiter': None, 'n_header': 0 }, { 'name': 'TimeReaderNumpy', 'apply_scalings': True, 'extension': '.npy' } ], 'time_processors': [ {'name': 'InterpolateNans'}, {'name': 'RemoveMean'} ], 'dec_setup': { 'name': 'DecimationSetup', 'n_levels': 8, 'per_level': 5, 'min_samples': 256, 'div_factor': 2, 'eval_freqs': None }, 'decimator': { 'name': 'Decimator', 'resample': True, 'max_single_factor': 3 }, 'win_setup': { 'name': 'WindowSetup', 'min_size': 128, 'min_olap': 32, 'win_factor': 4, 'olap_proportion': 0.25, 'min_n_wins': 5, 'win_sizes': None, 'olap_sizes': None }, 'windower': {'name': 'Windower'}, 'fourier': { 'name': 'FourierTransform', 'win_fnc': ['kaiser', 14], 'detrend': 'linear', 'workers': -2 }, 'spectra_processors': [], 'evals': {'name': 'EvaluationFreqs'}, 'sensor_calibrator': { 'name': 'SensorCalibrator', 'chans': None, 'readers': [ { 'name': 'SensorCalibrationJSON', 'extension': '.json', 'file_str': 'IC_$sensor$extension' } ] }, 'tf': { 'name': 'ImpedanceTensor', 'variation': 'default', 'out_chans': ['Ex', 'Ey'], 'in_chans': ['Hx', 'Hy'], 'cross_chans': ['Hx', 'Hy'], 'n_out': 2, 'n_in': 2, 'n_cross': 2 }, 'regression_preparer': {'name': 'RegressionPreparerGathered'}, 'solver': { 'name': 'SolverScikitTheilSen', 'fit_intercept': False, 'normalize': False, 'n_jobs': -2, 'max_subpopulation': 2000, 'n_subsamples': None } } .. GENERATED FROM PYTHON SOURCE LINES 25-26 However, it is possible to customise more at initialisation time. .. GENERATED FROM PYTHON SOURCE LINES 26-33 .. code-block:: default custom_config = Configuration( name="example", time_processors=[Add(add=5)], tf=TransferFunction(in_chans=["A", "B"], out_chans=["M", "N"]), ) custom_config.summary() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none { 'name': 'example', 'time_readers': [ { 'name': 'TimeReaderAscii', 'apply_scalings': True, 'extension': '.txt', 'delimiter': None, 'n_header': 0 }, { 'name': 'TimeReaderNumpy', 'apply_scalings': True, 'extension': '.npy' } ], 'time_processors': [{'name': 'Add', 'add': 5.0}], 'dec_setup': { 'name': 'DecimationSetup', 'n_levels': 8, 'per_level': 5, 'min_samples': 256, 'div_factor': 2, 'eval_freqs': None }, 'decimator': { 'name': 'Decimator', 'resample': True, 'max_single_factor': 3 }, 'win_setup': { 'name': 'WindowSetup', 'min_size': 128, 'min_olap': 32, 'win_factor': 4, 'olap_proportion': 0.25, 'min_n_wins': 5, 'win_sizes': None, 'olap_sizes': None }, 'windower': {'name': 'Windower'}, 'fourier': { 'name': 'FourierTransform', 'win_fnc': ['kaiser', 14], 'detrend': 'linear', 'workers': -2 }, 'spectra_processors': [], 'evals': {'name': 'EvaluationFreqs'}, 'sensor_calibrator': { 'name': 'SensorCalibrator', 'chans': None, 'readers': [ { 'name': 'SensorCalibrationJSON', 'extension': '.json', 'file_str': 'IC_$sensor$extension' } ] }, 'tf': { 'name': 'TransferFunction', 'variation': 'generic', 'out_chans': ['M', 'N'], 'in_chans': ['A', 'B'], 'cross_chans': ['A', 'B'], 'n_out': 2, 'n_in': 2, 'n_cross': 2 }, 'regression_preparer': {'name': 'RegressionPreparerGathered'}, 'solver': { 'name': 'SolverScikitTheilSen', 'fit_intercept': False, 'normalize': False, 'n_jobs': -2, 'max_subpopulation': 2000, 'n_subsamples': None } } .. GENERATED FROM PYTHON SOURCE LINES 34-38 A configuration can be updated after it has been initialised. For example, let's update a windowing parameter. First, have a look at the summary of the windowing parameters. Then they can be updated and the summary can be inspected again. .. GENERATED FROM PYTHON SOURCE LINES 38-42 .. code-block:: default custom_config.win_setup.summary() custom_config.win_setup.min_size = 512 custom_config.win_setup.summary() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none { 'name': 'WindowSetup', 'min_size': 128, 'min_olap': 32, 'win_factor': 4, 'olap_proportion': 0.25, 'min_n_wins': 5, 'win_sizes': None, 'olap_sizes': None } { 'name': 'WindowSetup', 'min_size': 512, 'min_olap': 32, 'win_factor': 4, 'olap_proportion': 0.25, 'min_n_wins': 5, 'win_sizes': None, 'olap_sizes': None } .. GENERATED FROM PYTHON SOURCE LINES 43-44 Configuration information can be saved to JSON files. .. GENERATED FROM PYTHON SOURCE LINES 44-48 .. code-block:: default save_path = Path("..", "..", "data", "config", "custom_config.json") with save_path.open("w") as f: f.write(custom_config.json()) .. GENERATED FROM PYTHON SOURCE LINES 49-50 Configurations can also be loaded from JSON files. .. GENERATED FROM PYTHON SOURCE LINES 50-52 .. code-block:: default reloaded_config = Configuration.parse_file(save_path) reloaded_config.summary() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none { 'name': 'example', 'time_readers': [ { 'name': 'TimeReaderAscii', 'apply_scalings': True, 'extension': '.txt', 'delimiter': None, 'n_header': 0 }, { 'name': 'TimeReaderNumpy', 'apply_scalings': True, 'extension': '.npy' } ], 'time_processors': [{'name': 'Add', 'add': 5.0}], 'dec_setup': { 'name': 'DecimationSetup', 'n_levels': 8, 'per_level': 5, 'min_samples': 256, 'div_factor': 2, 'eval_freqs': None }, 'decimator': { 'name': 'Decimator', 'resample': True, 'max_single_factor': 3 }, 'win_setup': { 'name': 'WindowSetup', 'min_size': 512, 'min_olap': 32, 'win_factor': 4, 'olap_proportion': 0.25, 'min_n_wins': 5, 'win_sizes': None, 'olap_sizes': None }, 'windower': {'name': 'Windower'}, 'fourier': { 'name': 'FourierTransform', 'win_fnc': ['kaiser', 14.0], 'detrend': 'linear', 'workers': -2 }, 'spectra_processors': [], 'evals': {'name': 'EvaluationFreqs'}, 'sensor_calibrator': { 'name': 'SensorCalibrator', 'chans': None, 'readers': [ { 'name': 'SensorCalibrationJSON', 'extension': '.json', 'file_str': 'IC_$sensor$extension' } ] }, 'tf': { 'name': 'TransferFunction', 'variation': 'generic', 'out_chans': ['M', 'N'], 'in_chans': ['A', 'B'], 'cross_chans': ['A', 'B'], 'n_out': 2, 'n_in': 2, 'n_cross': 2 }, 'regression_preparer': {'name': 'RegressionPreparerGathered'}, 'solver': { 'name': 'SolverScikitTheilSen', 'fit_intercept': False, 'normalize': False, 'n_jobs': -2, 'max_subpopulation': 2000, 'n_subsamples': None } } .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.039 seconds) .. _sphx_glr_download_tutorial-config_eg_02_custom_config.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: eg_02_custom_config.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: eg_02_custom_config.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_