Coverage for webgeodyn/inout/nath.py: 0%

17 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-12-18 09:33 +0000

1import os 

2import numpy as np 

3 

4 

5def load(dataDirectory, dataModel, keepRealisations=False): 

6 """ Loading function for XSHELLS(?) data. Also adds the data to the dataModel. 

7 

8 :param dataDirectory: directory where the data is located 

9 :type dataDirectory: str (path) 

10 :param dataModel: Model to which the data should be added 

11 :type dataModel: Model 

12 :param keepRealisations: indicating if realisations should be kept or averaged (not used) 

13 :type keepRealisations: bool (default: False) 

14 :return: 0 if everything went well, -1 otherwise 

15 :rtype: int 

16 """ 

17 # load times 

18 times = np.loadtxt(os.path.join(dataDirectory, "T_yr_S1.dat")) 

19 

20 # Reading MF in nT 

21 data = np.loadtxt(os.path.join(dataDirectory, "GNM_top_nT_S1.dat")) 

22 # detect lmax 

23 lmax = (-2 + np.sqrt(4 + 4 * data.shape[1])) / 2 

24 if int(lmax) != lmax: 

25 raise ValueError("Data length %i does not correspond to lmax*(lmax+2)" % data.shape[1]) 

26 else: 

27 lmax = int(lmax) 

28 dataModel.addMeasure("MF", "MF", lmax, "nT", data, times=times) 

29 

30 # Reading MF in km/yr 

31 data = np.loadtxt(os.path.join(dataDirectory, "TNM_kmperyr_S1.dat")) 

32 lmax = (-2 + np.sqrt(4 + 4 * (data.shape[1]) / 2)) / 2 

33 if int(lmax) != lmax: 

34 raise ValueError("Data length %i does not correspond to 2*lmax*(lmax+2)" % data.shape[1]) 

35 else: 

36 lmax = int(lmax) 

37 dataModel.addMeasure("U", "U", lmax, "km/yr", data, times=times) 

38 

39 # Reading SV diff in nT/yr 

40 # data = np.loadtxt(os.path.join(dataDirectory,"SVdiffNM_nTperyr_S1.dat")) # data est un array 

41 # lmax = (-2+np.sqrt(4+4*data.shape[1]))/2 

42 # if int(lmax) != lmax: 

43 # raise ValueError("Data length %i does not correspond to lmax*(lmax+2)" % data.shape[1]) 

44 # else: 

45 # lmax = int(lmax) 

46 # dataModel.addMeasure("Diff","SV",lmax,"nT/yr",data,times=times) 

47 

48 return 0