.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorial-config/eg_04_project_configuration.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_04_project_configuration.py: Project configuration ^^^^^^^^^^^^^^^^^^^^^ Alternative configurations can also be used with projects. When using cutom configurations in the project environment, the name of the configuration is key as this will determine where any data is saved. The below example shows what happens when using different configurations with a project. The dataset in this example has been provided for use by the SAMTEX consortium. For more information, please refer to [Jones2009]_. Additional details about the dataset can be found at https://www.mtnet.info/data/kap03/kap03.html. .. GENERATED FROM PYTHON SOURCE LINES 14-37 .. code-block:: default from pathlib import Path import seedir as sd import plotly from resistics.config import Configuration import resistics.letsgo as letsgo from resistics.time import TimeReaderNumpy, InterpolateNans, RemoveMean, Multiply from resistics.decimate import DecimationSetup from resistics.window import WindowSetup # The first thing to do is define the configuration to use. myconfig = letsgo.Configuration( name="myconfig", time_readers=[TimeReaderNumpy()], time_processors=[ InterpolateNans(), RemoveMean(), Multiply(multiplier={"Ex": -1, "Ey": -1}), ], dec_setup=DecimationSetup(n_levels=7, per_level=3), win_setup=WindowSetup(min_size=64, min_olap=16), ) myconfig.summary() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none { 'name': 'myconfig', 'time_readers': [ { 'name': 'TimeReaderNumpy', 'apply_scalings': True, 'extension': '.npy' } ], 'time_processors': [ {'name': 'InterpolateNans'}, {'name': 'RemoveMean'}, {'name': 'Multiply', 'multiplier': {'Ex': -1.0, 'Ey': -1.0}} ], 'dec_setup': { 'name': 'DecimationSetup', 'n_levels': 7, 'per_level': 3, 'min_samples': 256, 'div_factor': 2, 'eval_freqs': None }, 'decimator': { 'name': 'Decimator', 'resample': True, 'max_single_factor': 3 }, 'win_setup': { 'name': 'WindowSetup', 'min_size': 64, 'min_olap': 16, '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 38-40 Save the configuration to a file. This is to imitate scenarios where users have an existing configuration file that they want to load in and use. .. GENERATED FROM PYTHON SOURCE LINES 40-44 .. code-block:: default myconfig_path = Path("..", "..", "data", "config", "myconfig.json") with myconfig_path.open("w") as f: f.write(myconfig.json()) .. GENERATED FROM PYTHON SOURCE LINES 45-47 Let's remind ourselves of the project contents. Note that some processing with default parameters has already taken place. .. GENERATED FROM PYTHON SOURCE LINES 47-50 .. code-block:: default project_path = Path("..", "..", "data", "project", "kap03") sd.seedir(str(project_path), style="emoji") .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 📁 kap03/ ├─📁 images/ ├─📁 time/ │ ├─📁 kap163/ │ │ └─📁 meas01/ │ │ ├─📄 data.npy │ │ └─📄 metadata.json │ ├─📁 kap160/ │ │ └─📁 meas01/ │ │ ├─📄 data.npy │ │ └─📄 metadata.json │ └─📁 kap172/ │ └─📁 meas01/ │ ├─📄 data.npy │ └─📄 metadata.json ├─📄 resistics.json ├─📁 results/ │ └─📁 kap160/ │ └─📁 default/ │ └─📄 0_200000_impedancetensor_default.json ├─📁 calibrate/ ├─📁 evals/ │ └─📁 kap160/ │ └─📁 default/ │ └─📁 meas01/ │ ├─📄 data.npz │ └─📄 metadata.json ├─📁 masks/ ├─📁 spectra/ └─📁 features/ .. GENERATED FROM PYTHON SOURCE LINES 51-52 Now load our configuration and the project with myconfig. .. GENERATED FROM PYTHON SOURCE LINES 52-57 .. code-block:: default config = Configuration.parse_file(myconfig_path) resenv = letsgo.load(project_path, config=config) resenv.config.summary() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none { 'name': 'myconfig', 'time_readers': [ { 'name': 'TimeReaderNumpy', 'apply_scalings': True, 'extension': '.npy' } ], 'time_processors': [ {'name': 'InterpolateNans'}, {'name': 'RemoveMean'}, {'name': 'Multiply', 'multiplier': {'Ex': -1.0, 'Ey': -1.0}} ], 'dec_setup': { 'name': 'DecimationSetup', 'n_levels': 7, 'per_level': 3, 'min_samples': 256, 'div_factor': 2, 'eval_freqs': None }, 'decimator': { 'name': 'Decimator', 'resample': True, 'max_single_factor': 3 }, 'win_setup': { 'name': 'WindowSetup', 'min_size': 64, 'min_olap': 16, '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': '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 58-62 Now calculate the evaluation frequency spectral data and view the directory structure. This shows how resistics handles saving data for different configurations. The data is placed in a new folder with the same name as the the configuration. This is why the configuration name is important. .. GENERATED FROM PYTHON SOURCE LINES 62-67 .. code-block:: default site = resenv.proj["kap160"] for meas in site: letsgo.process_time_to_evals(resenv, "kap160", meas.name) sd.seedir(str(project_path), style="emoji") .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 📁 kap03/ ├─📁 images/ ├─📁 time/ │ ├─📁 kap163/ │ │ └─📁 meas01/ │ │ ├─📄 data.npy │ │ └─📄 metadata.json │ ├─📁 kap160/ │ │ └─📁 meas01/ │ │ ├─📄 data.npy │ │ └─📄 metadata.json │ └─📁 kap172/ │ └─📁 meas01/ │ ├─📄 data.npy │ └─📄 metadata.json ├─📄 resistics.json ├─📁 results/ │ └─📁 kap160/ │ └─📁 default/ │ └─📄 0_200000_impedancetensor_default.json ├─📁 calibrate/ ├─📁 evals/ │ └─📁 kap160/ │ ├─📁 default/ │ │ └─📁 meas01/ │ │ ├─📄 data.npz │ │ └─📄 metadata.json │ └─📁 myconfig/ │ └─📁 meas01/ │ ├─📄 data.npz │ └─📄 metadata.json ├─📁 masks/ ├─📁 spectra/ └─📁 features/ .. GENERATED FROM PYTHON SOURCE LINES 68-70 Let's calculate the impedance tensor with this configuration. The sampling frequency to process is 0.2 (Hz) .. GENERATED FROM PYTHON SOURCE LINES 70-73 .. code-block:: default letsgo.process_evals_to_tf(resenv, 0.2, "kap160") sd.seedir(str(project_path), style="emoji") .. rst-class:: sphx-glr-script-out Out: .. code-block:: none 0%| | 0/21 [00:00` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: eg_04_project_configuration.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_