Coverage for webgeodyn/inout/__init__.py: 100%
3 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-12-18 09:33 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-12-18 09:33 +0000
1"""
2This submodule contains readers/writers functions for input/output of data files.
4Each module file corresponds to a format (e.g. ``zforecast.py`` implements the "zforecast" format).
6A format name must be used when loading a Model :
8.. code-block:: python
10 models = Models()
11 model = models.loadModel("/path/to/data/", "modelName", "dataFormat")
13This command will use (if it exists) the ``inout/dataformat.py`` file to read the data and load it into webgeodyn.
15Function template
16#################
18Inside the .py files, webgeodyn is looking for ``load`` and ``save`` functions.
20``load`` and ``save`` should have the following behaviour :
22.. code-block:: python
24 def load(dataDirectory, dataModel, keepRealisations=True):
25 # 1 -
26 # Load the data from dataDirectory
27 #
28 # 2 -
29 # if keepRealisations:
30 # Make a 3D data array
31 # [times, semiNormalisedSchmidt spherical harmonics coef, realisations]
32 # else:
33 # Make a 2D data array
34 # [times, semiNormalisedSchmidt spherical harmonics coefs]
35 #
36 # 3 -
37 # add measures to the dataModel object by using the following
38 dataModel.addMeasure(measureName, measureType, lmax, units, measureData, times=times)
40 # measureName : Any measure name
41 # measureType : "MF" or "SV" or "U"
42 # lmax : (int) spherical harmonics order
43 # units : (string) e.g. "nT"
44 # measureData : 2D (without realisations) or 3D (with realisations) array
45 # times : 1D array containing time values in years
48 def save(dataDirectory, dataModel, forceOverwrite=False):
49 # Use dataModel to save files into dataDirectory
50 # If forceOverwrite is set to True, the file should be overwritten if exists.
51 # If forceOverwrite is set to False, an error should be raised if the file exists.
54"""
57import os
59abs_path = os.path.dirname(os.path.abspath(__file__))
60_formats = [f[:-3] for f in os.listdir(abs_path) if f.endswith('.py') and not f.startswith('__')]