Coverage for /wheeldirectory/casa-6.7.2-31-py3.12.el8/lib/py/lib/python3.12/site-packages/casatools/__init__.py: 51%

188 statements  

« prev     ^ index     » next       coverage.py v7.10.1, created at 2025-07-31 10:44 +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, NoNetwork 

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 NoNetwork as exc: 

173 msgs.append('') 

174 msgs.append('No data or measures updates could be done because there is no network connection.') 

175 # print it, this is ONLY reraised if the IERSeop2000 table is not found so it's clearer what the root cause likely was. 

176 user_verbose = 2 

177 config_except = exc 

178 

179except RemoteError as exc: 

180 msgs.append(str(exc)) 

181 msgs.append('') 

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

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

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

185 msgs.append('') 

186 # print this 

187 user_verbose = 2 

188 config_except = exc 

189 

190except Exception as exc: 

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

192 print(str(exc)) 

193 # print this 

194 # this seems severe, it will print 

195 isSevere = True 

196 config_except = exc 

197 

198# now try and get any info 

199# skip this step if UnsetMeasurespath was previously raised 

200if not isinstance(config_except,UnsetMeasurespath): 

201 try: 

202 

203 data_info = get_data_info(user_measurespath, logger) 

204 if data_info['casarundata'] is None: 

205 isSevere = True 

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

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

208 isSevere = True 

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

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

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

212 else: 

213 pass 

214 

215 if data_info['measures'] is None: 

216 isSevere = True 

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

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

219 isSevere = True 

220 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.') 

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

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

223 measures_found = True 

224 else: 

225 measures_found = True 

226 

227 except Exception as exc: 

228 # no exceptions are expected here 

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

230 # this seems severe 

231 isSevere = True 

232 print(str(exc)) 

233 config_except = exc 

234 

235if (len(msgs) > 1): 

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

237 msgs.append('') 

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

239 

240# don't use user_measurespath here if not ok 

241if not measures_found: 

242 user_measurespath = "" 

243else: 

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

245 add_mp = True 

246 for apath in user_datapath: 

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

248 add_mp = False 

249 break 

250 if add_mp: 

251 user_datapath.append(user_measurespath) 

252 

253ctsys = __utils( ) 

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

255 user_agg, user_pipeline, user_cachedir ) 

256 

257# try and find the IERS data 

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

259if __resolved_iers == 'geodetic/IERSeop2000': 

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

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

262 if config_except is not None: 

263 print("measures data is not available") 

264 raise config_except 

265 else: 

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

267else: 

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

269 if not measures_found: 

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

271 

272 user_measurespath = __resolved_iers[:-21] 

273 ctsys.setmeasurespath(user_measurespath) 

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

275 else: 

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

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

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

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

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

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

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

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

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

285 

286from .coercetype import coerce as __coerce 

287 

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

289 

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

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

292 

293import atexit as __atexit 

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