.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorial-project/eg_02_navigating_a_project.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-project_eg_02_navigating_a_project.py: Navigating a project ^^^^^^^^^^^^^^^^^^^^ After creating a project and copying in the time data into the time folder, it is useful to be able to navigate a project. This example shows the various types of objects available in resistics that can help navigate a project and access data. The data in this example has been provided for use by the SAMTEX consortium. For more information, please refer to [Jones2009]_. Additional details about the data can be found at https://www.mtnet.info/data/kap03/kap03.html. .. GENERATED FROM PYTHON SOURCE LINES 14-19 .. code-block:: default from pathlib import Path import seedir as sd import plotly import resistics.letsgo as letsgo .. GENERATED FROM PYTHON SOURCE LINES 21-23 Let's remind ourselves of the project contents, load the project and have a look at its contents. .. GENERATED FROM PYTHON SOURCE LINES 23-27 .. code-block:: default project_path = Path("..", "..", "data", "project", "kap03") sd.seedir(str(project_path), style="emoji") resenv = letsgo.load(project_path) .. 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/ ├─📁 calibrate/ ├─📁 evals/ ├─📁 masks/ ├─📁 spectra/ └─📁 features/ .. GENERATED FROM PYTHON SOURCE LINES 28-30 Project summaries can be quite verbose. Instead, let's convert it to a pandas DataFrame and see the information in tabular form. .. GENERATED FROM PYTHON SOURCE LINES 30-32 .. code-block:: default print(resenv.proj.to_dataframe()) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none name first_time last_time fs site 0 meas01 2003-10-28 15:30:00 2003-11-24 11:40:30 0.2 kap163 0 meas01 2003-10-28 10:00:00 2003-11-24 15:31:55 0.2 kap160 0 meas01 2003-10-30 13:00:00 2003-11-23 12:41:25 0.2 kap172 .. GENERATED FROM PYTHON SOURCE LINES 33-35 The project has three sites, each with a single recording. Another way to look at the sites in the project is to make a list of them. .. GENERATED FROM PYTHON SOURCE LINES 35-38 .. code-block:: default sites = [site.name for site in resenv.proj] print(sites) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none ['kap163', 'kap160', 'kap172'] .. GENERATED FROM PYTHON SOURCE LINES 39-41 To get more information about a single site, get the corresponding Site object. .. GENERATED FROM PYTHON SOURCE LINES 41-44 .. code-block:: default site = resenv.proj["kap160"] print(type(site)) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 45-47 Like most objects in resistics, the Site object has a summary method, which prints out a comprehensive summary of the site. .. GENERATED FROM PYTHON SOURCE LINES 47-49 .. code-block:: default site.summary() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none { 'dir_path': '../../data/project/kap03/time/kap160', 'measurements': { 'meas01': { 'site_name': 'kap160', 'dir_path': '../../data/project/kap03/time/kap160/meas01', 'metadata': { 'file_info': { 'created_on_local': '2021-07-07T22:26:48.851498', 'created_on_utc': '2021-07-07T21:26:48.851498', 'version': '1.0.0a0' }, 'fs': 0.2, 'chans': ['Hx', 'Hy', 'Hz', 'Ex', 'Ey'], 'n_chans': 5, 'n_samples': 470544, 'first_time': '2003-10-28 10:00:00.000000_000000_000000_000000', 'last_time': '2003-11-24 15:31:55.000000_000000_000000_000000', 'system': '', 'serial': '', 'wgs84_latitude': -999.0, 'wgs84_longitude': -999.0, 'easting': -999.0, 'northing': -999.0, 'elevation': -999.0, 'chans_metadata': { 'Hx': { 'name': 'Hx', 'data_files': ['data.npy'], 'chan_type': 'magnetic', 'chan_source': None, 'sensor': '', 'serial': '', 'gain1': 1.0, 'gain2': 1.0, 'scaling': 1.0, 'chopper': False, 'dipole_dist': 1.0, 'sensor_calibration_file': '', 'instrument_calibration_file': '' }, 'Hy': { 'name': 'Hy', 'data_files': ['data.npy'], 'chan_type': 'magnetic', 'chan_source': None, 'sensor': '', 'serial': '', 'gain1': 1.0, 'gain2': 1.0, 'scaling': 1.0, 'chopper': False, 'dipole_dist': 1.0, 'sensor_calibration_file': '', 'instrument_calibration_file': '' }, 'Hz': { 'name': 'Hz', 'data_files': ['data.npy'], 'chan_type': 'magnetic', 'chan_source': None, 'sensor': '', 'serial': '', 'gain1': 1.0, 'gain2': 1.0, 'scaling': 1.0, 'chopper': False, 'dipole_dist': 1.0, 'sensor_calibration_file': '', 'instrument_calibration_file': '' }, 'Ex': { 'name': 'Ex', 'data_files': ['data.npy'], 'chan_type': 'electric', 'chan_source': None, 'sensor': '', 'serial': '', 'gain1': 1.0, 'gain2': 1.0, 'scaling': 1.0, 'chopper': False, 'dipole_dist': 1.0, 'sensor_calibration_file': '', 'instrument_calibration_file': '' }, 'Ey': { 'name': 'Ey', 'data_files': ['data.npy'], 'chan_type': 'electric', 'chan_source': None, 'sensor': '', 'serial': '', 'gain1': 1.0, 'gain2': 1.0, 'scaling': 1.0, 'chopper': False, 'dipole_dist': 1.0, 'sensor_calibration_file': '', 'instrument_calibration_file': '' } }, 'history': {'records': []} }, 'reader': { 'name': 'TimeReaderNumpy', 'apply_scalings': True, 'extension': '.npy' } } }, 'begin_time': '2003-10-28 10:00:00.000000_000000_000000_000000', 'end_time': '2003-11-24 15:31:55.000000_000000_000000_000000' } .. GENERATED FROM PYTHON SOURCE LINES 50-52 Sometimes, it can be more convenient to access the information from the Site object directly. .. GENERATED FROM PYTHON SOURCE LINES 52-58 .. code-block:: default print(site.name) print(site.begin_time) print(site.end_time) measurements = [meas.name for meas in site] print(measurements) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none kap160 2003-10-28 10:00:00 2003-11-24 15:31:55 ['meas01'] .. GENERATED FROM PYTHON SOURCE LINES 59-60 It's also possible to plot the timeline of a single site. .. GENERATED FROM PYTHON SOURCE LINES 60-63 .. code-block:: default fig = site.plot() plotly.io.show(fig) .. raw:: html :file: images/sphx_glr_eg_02_navigating_a_project_001.html .. GENERATED FROM PYTHON SOURCE LINES 64-66 There is only a single measurement in this site named "meas01". Let's get its Measurement object. .. GENERATED FROM PYTHON SOURCE LINES 66-69 .. code-block:: default meas = site["meas01"] print(type(meas)) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 70-71 Unsurprisingly, Measurement objects also have a summary method. .. GENERATED FROM PYTHON SOURCE LINES 71-73 .. code-block:: default meas.summary() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none { 'site_name': 'kap160', 'dir_path': '../../data/project/kap03/time/kap160/meas01', 'metadata': { 'file_info': { 'created_on_local': '2021-07-07T22:26:48.851498', 'created_on_utc': '2021-07-07T21:26:48.851498', 'version': '1.0.0a0' }, 'fs': 0.2, 'chans': ['Hx', 'Hy', 'Hz', 'Ex', 'Ey'], 'n_chans': 5, 'n_samples': 470544, 'first_time': '2003-10-28 10:00:00.000000_000000_000000_000000', 'last_time': '2003-11-24 15:31:55.000000_000000_000000_000000', 'system': '', 'serial': '', 'wgs84_latitude': -999.0, 'wgs84_longitude': -999.0, 'easting': -999.0, 'northing': -999.0, 'elevation': -999.0, 'chans_metadata': { 'Hx': { 'name': 'Hx', 'data_files': ['data.npy'], 'chan_type': 'magnetic', 'chan_source': None, 'sensor': '', 'serial': '', 'gain1': 1.0, 'gain2': 1.0, 'scaling': 1.0, 'chopper': False, 'dipole_dist': 1.0, 'sensor_calibration_file': '', 'instrument_calibration_file': '' }, 'Hy': { 'name': 'Hy', 'data_files': ['data.npy'], 'chan_type': 'magnetic', 'chan_source': None, 'sensor': '', 'serial': '', 'gain1': 1.0, 'gain2': 1.0, 'scaling': 1.0, 'chopper': False, 'dipole_dist': 1.0, 'sensor_calibration_file': '', 'instrument_calibration_file': '' }, 'Hz': { 'name': 'Hz', 'data_files': ['data.npy'], 'chan_type': 'magnetic', 'chan_source': None, 'sensor': '', 'serial': '', 'gain1': 1.0, 'gain2': 1.0, 'scaling': 1.0, 'chopper': False, 'dipole_dist': 1.0, 'sensor_calibration_file': '', 'instrument_calibration_file': '' }, 'Ex': { 'name': 'Ex', 'data_files': ['data.npy'], 'chan_type': 'electric', 'chan_source': None, 'sensor': '', 'serial': '', 'gain1': 1.0, 'gain2': 1.0, 'scaling': 1.0, 'chopper': False, 'dipole_dist': 1.0, 'sensor_calibration_file': '', 'instrument_calibration_file': '' }, 'Ey': { 'name': 'Ey', 'data_files': ['data.npy'], 'chan_type': 'electric', 'chan_source': None, 'sensor': '', 'serial': '', 'gain1': 1.0, 'gain2': 1.0, 'scaling': 1.0, 'chopper': False, 'dipole_dist': 1.0, 'sensor_calibration_file': '', 'instrument_calibration_file': '' } }, 'history': {'records': []} }, 'reader': { 'name': 'TimeReaderNumpy', 'apply_scalings': True, 'extension': '.npy' } } .. GENERATED FROM PYTHON SOURCE LINES 74-77 Measurement objects only hold metadata to avoid loading in lots of data when projects are loaded. However, it is possible to read the data from the measurement. .. GENERATED FROM PYTHON SOURCE LINES 77-80 .. code-block:: default time_data = meas.reader.run(meas.dir_path, metadata=meas.metadata) time_data.summary() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none ##---Begin Summary------------------------- file_info: created_on_local: '2021-07-07T22:26:48.851498' created_on_utc: '2021-07-07T21:26:48.851498' version: 1.0.0a0 fs: 0.2 chans: - Hx - Hy - Hz - Ex - Ey n_chans: 5 n_samples: 470544 first_time: 2003-10-28 10:00:00.000000_000000_000000_000000 last_time: 2003-11-24 15:31:55.000000_000000_000000_000000 system: '' serial: '' wgs84_latitude: -999.0 wgs84_longitude: -999.0 easting: -999.0 northing: -999.0 elevation: -999.0 chans_metadata: Hx: name: Hx data_files: - data.npy chan_type: magnetic chan_source: null sensor: '' serial: '' gain1: 1.0 gain2: 1.0 scaling: 1.0 chopper: false dipole_dist: 1.0 sensor_calibration_file: '' instrument_calibration_file: '' Hy: name: Hy data_files: - data.npy chan_type: magnetic chan_source: null sensor: '' serial: '' gain1: 1.0 gain2: 1.0 scaling: 1.0 chopper: false dipole_dist: 1.0 sensor_calibration_file: '' instrument_calibration_file: '' Hz: name: Hz data_files: - data.npy chan_type: magnetic chan_source: null sensor: '' serial: '' gain1: 1.0 gain2: 1.0 scaling: 1.0 chopper: false dipole_dist: 1.0 sensor_calibration_file: '' instrument_calibration_file: '' Ex: name: Ex data_files: - data.npy chan_type: electric chan_source: null sensor: '' serial: '' gain1: 1.0 gain2: 1.0 scaling: 1.0 chopper: false dipole_dist: 1.0 sensor_calibration_file: '' instrument_calibration_file: '' Ey: name: Ey data_files: - data.npy chan_type: electric chan_source: null sensor: '' serial: '' gain1: 1.0 gain2: 1.0 scaling: 1.0 chopper: false dipole_dist: 1.0 sensor_calibration_file: '' instrument_calibration_file: '' history: records: - time_local: '2021-10-14T22:19:27.906654' time_utc: '2021-10-14T22:19:27.906653' creator: name: TimeReaderNumpy apply_scalings: true extension: .npy messages: - Reading raw data from ../../data/project/kap03/time/kap160/meas01 - Sampling frequency 0.2 Hz - 'From sample, time: 0, 2003-10-28 10:00:00' - 'To sample, time: 470543, 2003-11-24 15:31:55' record_type: process ##---End summary--------------------------- .. GENERATED FROM PYTHON SOURCE LINES 81-82 Let's plot the time data. .. GENERATED FROM PYTHON SOURCE LINES 82-85 .. code-block:: default fig = time_data.plot() fig.update_layout(height=700) plotly.io.show(fig) .. raw:: html :file: images/sphx_glr_eg_02_navigating_a_project_002.html .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 6.065 seconds) .. _sphx_glr_download_tutorial-project_eg_02_navigating_a_project.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_navigating_a_project.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: eg_02_navigating_a_project.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_