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

70 statements  

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

1 

2# CLEAR COMPILED WEBGEODYN FILES 

3import os 

4import webgeodyn 

5 

6dir_name = webgeodyn.__path__[0] 

7 

8for root, dir, files in os.walk(dir_name): 

9 for file in files: 

10 if file.endswith(".pyc"): 

11 os.remove(os.path.join(root,file)) 

12 

13# CLEAR COMPILED WEBGEODYN FILES 

14############################################################# 

15 

16import os 

17import re 

18import numpy as np 

19from webgeodyn.processing import spectra 

20from webgeodyn.filters import time 

21from webgeodyn.constants import rE, rC 

22from webgeodyn.models import Models, Model 

23import scipy.io 

24 

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

26 """ Loading function for Coupled-Earth data.""" 

27 #load times 

28 print("!! enter coupled-earth data !!") 

29 

30# times = np.loadtxt(os.path.join(dataDirectory,"time_midpath.dat")) 

31# times=np.linspace(1,1000,1000) 

32 

33# nt=times.shape[0] 

34# print(nt) 

35################# deals with gnm @ CMB 

36 

37 print("read MF mid-path data...") 

38 # Reading MF @ CMB in NS units 

39 gnmE = np.loadtxt(os.path.join(dataDirectory,"gnm")) 

40 

41 print("... mid-path gnm data read !!") 

42 

43 # Detect lmax 

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

45 print("lmax B=",lmax) 

46 if int(lmax) != lmax: 

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

48 else: 

49 lmax = int(lmax) 

50 

51 n=lmax*(lmax+2) 

52 nt=gnmE.shape[0] 

53 

54 # Load times 

55 times=np.linspace(1, nt, nt) 

56 

57 data = gnmE #* 10**9 # scale to nT ?? 

58 print("number of epochs:", nt) 

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

60 

61################# deals with gnm below the CMB 

62 

63 print("read MF mid-path data below CMB...") 

64 # Reading MF @ CMB in NS units 

65 gnmE = np.loadtxt(os.path.join(dataDirectory,"gnm_below")) 

66 

67 print("... mid-path gnm data below CMB read !!") 

68 

69 # Detect lmax 

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

71 print("lmax B=",lmax) 

72 if int(lmax) != lmax: 

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

74 else: 

75 lmax = int(lmax) 

76 

77 n=lmax*(lmax+2) 

78 nt=gnmE.shape[0] 

79 

80 # Load times 

81 times=np.linspace(1, nt, nt) 

82 

83 data = gnmE #* 10**9 # scale to nT ?? 

84 print("number of epochs:", nt) 

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

86 

87################# deals with dgnm/dt 

88 

89 print("read SV mid-path data...") 

90 # Reading MF @ CMB in NS units 

91 dgnmE = np.loadtxt(os.path.join(dataDirectory,"dgnm")) 

92 

93 print("... mid-path dgnm/dt data read !!") 

94 

95 # Detect lmax 

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

97 print("lmax B=",lmax) 

98 if int(lmax) != lmax: 

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

100 else: 

101 lmax = int(lmax) 

102 

103 n=lmax*(lmax+2) 

104 nt=dgnmE.shape[0] 

105 

106 # Load times 

107 times=np.linspace(1, nt, nt) 

108 

109 data = dgnmE #* 10**9 # scale to nT ?? 

110 print("number of epochs:", nt) 

111 dataModel.addMeasure("SV", "SV", lmax, "nT/yr", data, times=times) 

112 

113################# now deals with tnm, snm 

114 

115 # Reading flow U @ CMB in NS units 

116 tnmsnm = np.loadtxt(os.path.join(dataDirectory, "tnmsnm")) 

117 print(tnmsnm.shape) 

118 print(gnmE.shape) 

119 

120 print("... mid-path tnm+snm data read !!") 

121 

122 # Detect lmax 

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

124 print("lmax U=",lmax) 

125 if int(lmax) != lmax: 

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

127 else: 

128 lmax = int(lmax) 

129 

130 data = tnmsnm # scale in km/yr 

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