Coverage for /wheeldirectory/casa-6.7.0-12-py3.10.el8/lib/py/lib/python3.10/site-packages/casatools/__init__.py: 52%

183 statements  

« prev     ^ index     » next       coverage.py v7.6.4, created at 2024-11-01 07:19 +0000

1from __future__ import absolute_import 

2__name__ = 'casatools' 

3__all__ = [ "ctsys", "version", "version_string" 

4 'image', 

5 'logsink', 

6 'coordsys', 

7 'synthesisutils', 

8 'synthesisnormalizer', 

9 'calanalysis', 

10 'mstransformer', 

11 'calibrater', 

12 'functional', 

13 'table', 

14 'measures', 

15 'imagepol', 

16 'simulator', 

17 'sdm', 

18 'synthesisimstore', 

19 'miriadfiller', 

20 'ms', 

21 'vpmanager', 

22 'synthesisdeconvolver', 

23 'vlafiller', 

24 'sakura', 

25 'linearmosaic', 

26 'tablerow', 

27 'iterbotsink', 

28 'sidebandseparator', 

29 'imagemetadata', 

30 'atcafiller', 

31 'agentflagger', 

32 'synthesismaskhandler', 

33 'regionmanager', 

34 'msmetadata', 

35 'imager', 

36 'singledishms', 

37 'atmosphere', 

38 'quanta', 

39 'synthesisimager', 

40 'componentlist', 

41 'spectralline', 

42 'wvr' 

43 ] 

44from .image import image 

45from .logsink import logsink 

46from .coordsys import coordsys 

47from .synthesisutils import synthesisutils 

48from .synthesisnormalizer import synthesisnormalizer 

49from .calanalysis import calanalysis 

50from .mstransformer import mstransformer 

51from .calibrater import calibrater 

52from .functional import functional 

53from .table import table 

54from .measures import measures 

55from .imagepol import imagepol 

56from .simulator import simulator 

57from .sdm import sdm 

58from .synthesisimstore import synthesisimstore 

59from .miriadfiller import miriadfiller 

60from .ms import ms 

61from .vpmanager import vpmanager 

62from .wvr import wvr 

63from .synthesisdeconvolver import synthesisdeconvolver 

64from .vlafiller import vlafiller 

65from .sakura import sakura 

66from .linearmosaic import linearmosaic 

67from .tablerow import tablerow 

68from .iterbotsink import iterbotsink 

69from .sidebandseparator import sidebandseparator 

70from .imagemetadata import imagemetadata 

71from .atcafiller import atcafiller 

72from .agentflagger import agentflagger 

73from .synthesismaskhandler import synthesismaskhandler 

74from .regionmanager import regionmanager 

75from .msmetadata import msmetadata 

76from .imager import imager 

77from .singledishms import singledishms 

78from .atmosphere import atmosphere 

79from .quanta import quanta 

80from .synthesisimager import synthesisimager 

81from .componentlist import componentlist 

82from .spectralline import spectralline 

83from .utils import utils as __utils 

84import os as __os 

85import sys as __sys 

86from casaconfig import get_data_info, do_auto_updates, config 

87from casaconfig import UnsetMeasurespath, AutoUpdatesNotAllowed, BadLock, BadReadme, NoReadme, RemoteError 

88# useful to use here 

89from casaconfig.private.print_log_messages import print_log_messages 

90 

91sakura( ).initialize_sakura( ) ## sakura requires explicit initialization 

92 

93 

94user_datapath = config.datapath 

95user_nogui = config.nogui 

96user_agg = config.agg 

97user_pipeline = config.pipeline 

98user_cachedir = __os.path.abspath(__os.path.expanduser(config.cachedir)) 

99user_measurespath = config.measurespath 

100user_verbose = config.casaconfig_verbose 

101 

102logger = logsink(config.logfile) if (hasattr(config,'logfile') and config.logfile is not None) else None 

103 

104# data checks, only if user_measurespath is not None 

105data_info = None 

106measures_found = False 

107isSevere = False 

108# accumuale messages, less confusing when the logger is being redirected to the terminal 

109msgs = [''] 

110 

111config_except = None 

112 

113# first, attempt any auto updates 

114try: 

115 # this uses config.measurespath, config.measures_auto_update and config.data_auto_update as appropriate 

116 do_auto_updates(config, logger) 

117 

118except UnsetMeasurespath as exc: 

119 msgs.append(str(exc)) 

120 isSevere = True 

121 msgs.append('') 

122 msgs.append('Either set measurespath in your personal config.py in ~/.casa or a site config file.') 

123 msgs.append('CASA may still work if the IERS data can be found in datapath, but this problem is likely to cause casatools to fail to load.') 

124 msgs.append('') 

125 # ctsys initialize needs a string for measurespath, leave it empty, it might still work (probably not) 

126 user_measurespath = "" 

127 # make sure this prints 

128 user_verbose = 2 

129 config_except = exc 

130 

131except AutoUpdatesNotAllowed as exc: 

132 msgs.append(str(exc)) 

133 msgs.append('') 

134 msgs.append('Warning: measurespath must exist as a directory and it must be owned by the user.') 

135 msgs.append('Warning: no auto update is possible on this measurespath by this user.') 

136 msgs.append('') 

137 # this is reraised only if the data isn't found in datapath 

138 # make sure this prints 

139 user_verbose = 2 

140 config_except = exc 

141 

142except BadLock as exc: 

143 msgs.append(str(exc)) 

144 # this possibly indicates a serious problem, reraise this if the data can't be found 

145 # it's severe, it will print 

146 isSevere = True 

147 config_except = exc 

148 

149except BadReadme as exc: 

150 msgs.append(str(exc)) 

151 # this likely indicates a problem, reraise this if the data can't be found 

152 msgs.append('') 

153 msgs.append('Some or all of the expected auto updates did not happen.') 

154 msgs.append('This indicates something went wrong on a previous update and the data should be reinstalled.') 

155 msgs.append('Updates will continue to fail until the data are reinstalled.') 

156 msgs.append('If the IERSeop2000 table is found in datapath then casatools will import.') 

157 msgs.append('') 

158 # it's severe, it will print 

159 isSevere = True 

160 config_except = exc 

161 

162except NoReadme as exc: 

163 # this is a symptom that's fully explained here and possibly again if this is reraised, don't print out str(exc) here 

164 msgs.append('Some or all of the expected auto updates did not happen.') 

165 msgs.append('This indicates that measurespath is not empty and does not contain data maintained by casaconfig.') 

166 msgs.append('If the IERSeop2000 table is found in datapth then casatools will import.') 

167 msgs.append('') 

168 # print this 

169 user_verbose = 2 

170 config_except = exc 

171 

172except RemoteError as exc: 

173 msgs.append(str(exc)) 

174 msgs.append('') 

175 msgs.append('Some or all of the expepcted auto updates did not happen.') 

176 msgs.append('Either there is no network connection, there is no route to the remote server, or the remote server is offline') 

177 msgs.append('If the IERSeop2000 table is found in datapath then casatools will import without any updates. Try again later for updates') 

178 msgs.append('') 

179 # print this 

180 user_verbose = 2 

181 config_except = exc 

182 

183except Exception as exc: 

184 msgs.append('ERROR! Unexpected exception while doing auto updates or checking on the status of the data at measurespath') 

185 print(str(exc)) 

186 # print this 

187 # this seems severe, it will print 

188 isSevere = True 

189 config_except = exc 

190 

191# now try and get any info 

192# skip this step if UnsetMeasurespath was previously raised 

193if not isinstance(config_except,UnsetMeasurespath): 

194 try: 

195 

196 data_info = get_data_info(user_measurespath, logger) 

197 if data_info['casarundata'] is None: 

198 isSevere = True 

199 msgs.append('The expected casa data was not found at measurespath. CASA may still work if the data can be found in datapath.') 

200 elif data_info['casarundata']['version'] == 'invalid': 

201 isSevere = True 

202 msgs.append('The contents of measurespath do not appear to be casarundata. CASA may still work if the data can be found in datapath.') 

203 elif data_info['casarundata']['version'] == 'unknown': 

204 msgs.append('The casa data found at measurespath is not being maintained by casaconfig.') 

205 else: 

206 pass 

207 

208 if data_info['measures'] is None: 

209 isSevere = True 

210 msgs.append('The expected measures data was not found at measurespath. CASA may still work if the data can be found in datapath.') 

211 elif data_info['measures']['version'] == 'invalid': 

212 isSevere = True 

213 msgs.append('The contents of measurespath do not appear to include measures data. CASA may still work if the data can be found in datapath.') 

214 elif data_info['measures']['version'] == 'unknown': 

215 msgs.append('The measures data found at measurespath is not being maintained by casaconfig.') 

216 measures_found = True 

217 else: 

218 measures_found = True 

219 

220 except Exception as exc: 

221 # no exceptions are expected here 

222 msgs.append('ERROR! Unexpected exception while checking on the status of the data at measurespath') 

223 # this seems severe 

224 isSevere = True 

225 print(str(exc)) 

226 config_except = exc 

227 

228if (len(msgs) > 1): 

229 msgs.append('visit https://casadocs.readthedocs.io/en/stable/notebooks/external-data.html for more information') 

230 msgs.append('') 

231 print_log_messages(msgs, logger, isSevere, verbose=user_verbose) 

232 

233# don't use user_measurespath here if not ok 

234if not measures_found: 

235 user_measurespath = "" 

236else: 

237 # always append measurespath to datapath if not already found there to be used by ctsys.initialize 

238 add_mp = True 

239 for apath in user_datapath: 

240 if __os.path.exists(apath) and __os.path.samefile(apath, user_measurespath): 

241 add_mp = False 

242 break 

243 if add_mp: 

244 user_datapath.append(user_measurespath) 

245 

246ctsys = __utils( ) 

247ctsys.initialize( __sys.executable, user_measurespath, user_datapath, user_nogui, 

248 user_agg, user_pipeline, user_cachedir ) 

249 

250# try and find the IERS data 

251__resolved_iers = ctsys.resolve('geodetic/IERSeop2000') 

252if __resolved_iers == 'geodetic/IERSeop2000': 

253 # this match means ctsys.resolve did not found it in datapath 

254 # if there was a previously raised casaconfig exception, re-raise it here so that casashell can know what went wrong 

255 if config_except is not None: 

256 print("measures data is not available") 

257 raise config_except 

258 else: 

259 raise ImportError('measures data is not available, visit https://casadocs.readthedocs.io/en/stable/notebooks/external-data.html for more information') 

260else: 

261 # if measures was not previously found, use this path as measurespath 

262 if not measures_found: 

263 # this removes the "geodetic/IERSeop2000" and the preceding "/" from the returned path, that's the measurespath to be used here 

264 

265 user_measurespath = __resolved_iers[:-21] 

266 ctsys.setmeasurespath(user_measurespath) 

267 print_log_messages(["Using location of IERSeop2000 table found in datapath for measurespath %s" % user_measurespath], logger) 

268 else: 

269 # check that this path is the same as what is expected at measurespath 

270 if not __os.path.samefile(__resolved_iers, __os.path.join(user_measurespath,'geodetic/IERSeop2000')): 

271 print("\nThe path to the geodetic IERSeop2000 table in measurespath is not the same location found first in datapath for that table.") 

272 print("CASA should work in this configuration. The datapath list will be used to search for data needed by CASA.") 

273 print("\nThe measurespath value is used to find that IERS table and this indicates that the") 

274 print("measures tables present in datapath may be different from those found in measurespath.") 

275 print("\nIf this was not expected you may want to use your config file (normally at ~/.casa/config.py) to") 

276 print("set datapath to put measurespath first or set measurespath to include the measures data found in datapath.") 

277 logger.post("WARNING: geodetic/IERSeop2000 found at measurespath is not the same table as found in datapath",'WARN') 

278 

279from .coercetype import coerce as __coerce 

280 

281__coerce.set_ctsys(ctsys) ## used to locate files from a partial path 

282 

283def version( ): return list(ctsys.version( )) 

284def version_string( ): return ctsys.version_string( ) 

285 

286import atexit as __atexit 

287__atexit.register(ctsys.shutdown) ## c++ shutdown