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

1""" 

2This submodule contains readers/writers functions for input/output of data files. 

3 

4Each module file corresponds to a format (e.g. ``zforecast.py`` implements the "zforecast" format). 

5 

6A format name must be used when loading a Model : 

7 

8.. code-block:: python 

9 

10 models = Models() 

11 model = models.loadModel("/path/to/data/", "modelName", "dataFormat") 

12 

13This command will use (if it exists) the ``inout/dataformat.py`` file to read the data and load it into webgeodyn. 

14 

15Function template 

16################# 

17 

18Inside the .py files, webgeodyn is looking for ``load`` and ``save`` functions. 

19 

20``load`` and ``save`` should have the following behaviour : 

21 

22.. code-block:: python 

23 

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) 

39 

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 

46 

47 

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. 

52 

53 

54""" 

55 

56 

57import os 

58 

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('__')]