Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

#!/usr/local/bin/python 

# encoding: utf-8 

""" 

*The CL tools for breaker* 

 

:Author: 

David Young 

 

:Date Created: 

October 29, 2015 

 

Usage: 

breaker init 

breaker update [-naP] [-s <pathToSettingsFile>] 

breaker skymap [-o] <gwid> [<pathToLVMap>] [-c <centerDeg>] 

breaker plot [-a] (timeline|history|sources) [-w <gwid>] [-t <telescope>] [-p <projection>] [-f <filters>] [-s <pathToSettingsFile>] 

breaker plot comparison <gwid> <pathToMapDirectory> [-s <pathToSettingsFile>] 

breaker faker <ps1ExpId> [-s <pathToSettingsFile>] 

breaker stats <gwid> [<telescope>] [-s <pathToSettingsFile>] 

breaker listen <far> (<mjdStart> <mjdEnd> | <inLastNMins>) [-s <pathToSettingsFile>] 

breaker listen -d [<far> <sec>] [-s <pathToSettingsFile>] 

breaker contour <gwid> <ra> <dec>  

 

COMMANDS 

-------- 

init setup the breaker settings file for the first time 

update update the PS1 footprint table in breaker database and associate with GW-IDs. Optionally download overlapping NED source and also add to the database 

skymap generate an all sky FITS & PDF image map given the path to the LV likeihood map (Meractor and Mollweide projections respectively) 

plot enter plotting mode 

timeline plot from the epoch of the wave detection forward in time 

history plot from now back in time over the last days, weeks and months 

comparison produce a multi-panel plot to compare wave maps 

stats generate some coverage stats for a given wave survey campaign 

sources overplot map with NED sources found within the wave campaign footprint 

faker generate a catalogue of simulated transient sources in PS1 exposure ID footprint 

listen connect to grace DB and download maps found within the given time range 

contour determine within which likelihood contour a given transient location lies (nearest 10%) 

 

ARGUMENTS 

--------- 

ra right ascendsion (sexegesimal or decimal degrees) 

dec declination (sexegesimal or decimal degrees) 

far false alarm rate limit in Hz. Default *1e-5* (~= 1 per day) 

-w <gwid> the gravitational wave ID (graceDB or human-readable GW forms allowed) 

pathToSettingsFile path to the yaml settings file 

-c <centerDeg> the central longitude line (deg) 

pathToMapDirectory path to a directory containing localisation maps 

ps1ExpId a panstarrs exposure ID 

mjdStart start of an MJD range 

mjdEnd end of the MJD range 

inLastNMins in the last N number of minutes 

pathToLVMap path to the LV likelihood map 

sec time in seconds 

-t <telescope> select an individual telescope (default is all telescopes) [ps1|atlas] 

-p <projection> skymap projection. Default *mercator*. [mercator|gnomonic|mollweide] 

-f <filters> which exposure filters to show on plots 

 

FLAGS 

----- 

-h, --help show this help message 

-s, --settings the settings file 

-n, --updateNed update the NED database steam 

-d, --daemon listen in daemon mode 

-a, --all plot all timeline plot (including the CPU intensive -21-0 days and all transients/footprints plots) 

-P, --no-pointings do not update pointings  

-o, --default-output output files to the default breaker output location (as set in settings file) 

 

""" 

################# GLOBAL IMPORTS #################### 

import sys 

import os 

os.environ['TERM'] = 'vt100' 

import readline 

import glob 

import pickle 

from docopt import docopt 

from fundamentals import tools, times 

from breaker.update_ps1_atlas_footprint_tables import update_ps1_atlas_footprint_tables 

from breaker.plots.plot_wave_observational_timelines import plot_wave_observational_timelines 

from breaker.plots.plot_wave_matched_source_maps import plot_wave_matched_source_maps 

from breaker.fakers.generate_faker_catalogue import generate_faker_catalogue 

from breaker.stats.survey_footprint import survey_footprint 

from breaker.plots.plot_multi_panel_alternate_map_comparison import plot_multi_panel_alternate_map_comparison 

from breaker.gracedb.listen import listen as mlisten 

from astrocalc.times import now as mjdNow 

from subprocess import Popen, PIPE, STDOUT 

# from ..__init__ import * 

 

 

def main(arguments=None): 

""" 

*The main function used when ``cl_utils.py`` is run as a single script from the cl, or when installed as a cl command* 

""" 

 

# setup the command-line util settings 

su = tools( 

arguments=arguments, 

docString=__doc__, 

logLevel="WARNING", 

options_first=False, 

projectName="breaker" 

) 

arguments, settings, log, dbConn = su.setup() 

 

# unpack remaining cl arguments using `exec` to setup the variable names 

# automatically 

for arg, val in arguments.iteritems(): 

if arg[0] == "-": 

varname = arg.replace("-", "") + "Flag" 

else: 

varname = arg.replace("<", "").replace(">", "") 

if isinstance(val, str) or isinstance(val, unicode): 

exec(varname + " = '%s'" % (val,)) 

else: 

exec(varname + " = %s" % (val,)) 

if arg == "--dbConn": 

dbConn = val 

log.debug('%s = %s' % (varname, val,)) 

 

## START LOGGING ## 

startTime = times.get_now_sql_datetime() 

log.info( 

'--- STARTING TO RUN THE cl_utils.py AT %s' % 

(startTime,)) 

 

if init: 

from os.path import expanduser 

home = expanduser("~") 

filepath = home + "/.config/breaker/breaker.yaml" 

try: 

cmd = """open %(filepath)s""" % locals() 

p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True) 

except: 

pass 

try: 

cmd = """start %(filepath)s""" % locals() 

p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True) 

except: 

pass 

 

if not far: 

far = 1e-5 

 

if gwid and gwid[:2] == "GW": 

for g in settings["gravitational waves"]: 

if settings["gravitational waves"][g]["human-name"] == gwid.strip(): 

gwid = g 

if wFlag and wFlag[:2] == "GW": 

for g in settings["gravitational waves"]: 

if settings["gravitational waves"][g]["human-name"] == wFlag.strip(): 

wFlag = g 

 

# CALL FUNCTIONS/OBJECTS 

if update: 

pointingsFlag = True 

if nopointingsFlag: 

pointingsFlag = False 

u = update_ps1_atlas_footprint_tables( 

log=log, 

settings=settings, 

updateNed=updateNedFlag, 

updateAll=allFlag, 

updatePointings=pointingsFlag 

) 

u.get() 

if plot and history: 

p = plot_wave_observational_timelines( 

log=log, 

settings=settings, 

plotType="history" 

) 

p.get() 

if plot and timeline: 

if not pFlag: 

pFlag = "mercator" 

 

if fFlag: 

filters = list(fFlag) 

else: 

filters = False 

 

p = plot_wave_observational_timelines( 

log=log, 

settings=settings, 

gwid=wFlag, 

plotType="timeline", 

allPlots=allFlag, 

telescope=tFlag, 

projection=pFlag, 

filters=filters, 

probabilityCut=True 

) 

p.get() 

if plot and sources: 

p = plot_wave_matched_source_maps( 

log=log, 

settings=settings, 

gwid=gwid 

) 

p.get() 

if plot and comparison: 

p = plot_multi_panel_alternate_map_comparison( 

log=log, 

settings=settings, 

gwid=gwid, 

pathToMapDirectory=pathToMapDirectory 

) 

p.get() 

if faker: 

f = generate_faker_catalogue( 

log=log, 

settings=settings, 

ps1ExpId=ps1ExpId, 

gwid=False 

) 

f.get() 

if stats: 

s = survey_footprint( 

log=log, 

settings=settings, 

gwid=gwid, 

telescope=telescope 

) 

s.get() 

if listen and inLastNMins: 

timeNowMjd = mjdNow( 

log=log 

).get_mjd() 

startMJD = float(timeNowMjd) - float(inLastNMins) / (60 * 60 * 24.) 

this = mlisten( 

log=log, 

settings=settings, 

#label="EM_READY | EM_Selected | ADVOK", 

label="", 

farThreshold=far, 

startMJD=float(startMJD), 

endMJD=float(timeNowMjd) + 1. 

) 

this.get_maps() 

if listen and mjdStart: 

this = mlisten( 

log=log, 

settings=settings, 

# label="EM_READY | EM_Selected | ADVOK", 

label="", 

farThreshold=far, 

startMJD=float(mjdStart), 

endMJD=float(mjdEnd) 

) 

this.get_maps() 

if listen and daemonFlag: 

if sec: 

daemon = float(sec) 

else: 

daemon = True 

this = mlisten( 

log=log, 

settings=settings, 

# label="EM_READY | EM_Selected | ADVOK", 

label="", 

farThreshold=far, 

daemon=daemon 

) 

this.get_maps() 

 

if skymap: 

plotter = plot_wave_observational_timelines( 

log=log, 

settings=settings, 

databaseConnRequired=False 

) 

 

if not cFlag: 

cFlag = 0. 

else: 

cFlag = float(cFlag) 

 

if defaultoutputFlag: 

outputDirectory = False 

else: 

outputDirectory = "." 

 

plotter.generate_probability_plot( 

gwid=gwid, 

pathToProbMap=pathToLVMap, 

fileFormats=["pdf", "png"], 

outputDirectory=outputDirectory, 

projection="mollweide", 

plotType="timeline", 

folderName="all_sky_plots", 

fitsImage=False, 

allSky=True, 

center=cFlag 

) 

 

plotter.generate_probability_plot( 

gwid=gwid, 

pathToProbMap=pathToLVMap, 

fileFormats=["pdf", "png"], 

outputDirectory=outputDirectory, 

projection="cartesian", 

plotType="timeline", 

folderName="all_sky_plots", 

fitsImage=True, 

allSky=True, 

center=cFlag 

) 

 

if contour: 

from breaker.transients import annotator 

an = annotator( 

log=log, 

settings=settings, 

gwid=gwid 

) 

 

from astrocalc.coords import unit_conversion 

# ASTROCALC UNIT CONVERTER OBJECT 

converter = unit_conversion( 

log=log 

) 

ra = converter.ra_sexegesimal_to_decimal( 

ra=ra 

) 

dec = converter.dec_sexegesimal_to_decimal( 

dec=dec 

) 

transients = {"cl": (ra, dec)} 

transientNames, probs = an.annotate(transients) 

percentage = probs[0] 

print "The transient lies within the inner %(percentage)s%% likelihood contour of event %(gwid)s" % locals() 

 

if "dbConn" in locals() and dbConn: 

dbConn.commit() 

dbConn.close() 

## FINISH LOGGING ## 

endTime = times.get_now_sql_datetime() 

runningTime = times.calculate_time_difference(startTime, endTime) 

log.info('-- FINISHED ATTEMPT TO RUN THE cl_utils.py AT %s (RUNTIME: %s) --' % 

(endTime, runningTime, )) 

 

return 

 

 

if __name__ == '__main__': 

main()