Newer
Older
prob_bbh = models.FloatField(null=True, default=None, blank=True,
validators=[models.fields.validators.MinValueValidator(0.0),
models.fields.validators.MaxValueValidator(1.0)])
prob_terrestrial = models.FloatField(null=True, default=None, blank=True,
validators=[models.fields.validators.MinValueValidator(0.0),
models.fields.validators.MaxValueValidator(1.0)])
prob_mass_gap = models.FloatField(null=True, default=None, blank=True,
validators=[models.fields.validators.MinValueValidator(0.0),
models.fields.validators.MaxValueValidator(1.0)])
# Additional RAVEN Fields
ext_gcn = models.CharField(max_length=20, default="", blank=True,
editable=False)
ext_pipeline = models.CharField(max_length=20, default="", blank=True,
editable=False)
ext_search = models.CharField(max_length=20, default="", blank=True,
editable=False)
time_coinc_far = models.FloatField(null=True, default=None, blank=True,
validators=[models.fields.validators.MinValueValidator(0.0)])
space_coinc_far = models.FloatField(null=True, default=None, blank=True,
validators=[models.fields.validators.MinValueValidator(0.0)])
comb_skymap_filename = models.CharField(max_length=100, null=True,
default=None, blank=True)
delta_t = models.FloatField(null=True, default=None, blank=True,
validators=[models.fields.validators.MinValueValidator(-1000),
models.fields.validators.MaxValueValidator(1000)])

Tanner Prestegard
committed
def fileurl(self):
# Override this method on derived classes
return NotImplemented
class VOEventBuilderException(Exception):
pass

Tanner Prestegard
committed
class VOEvent(VOEventBase, AutoIncrementModel):
"""VOEvent class for events"""
AUTO_FIELD = 'N'
AUTO_CONSTRAINTS = ('event',)

Tanner Prestegard
committed
event = models.ForeignKey(Event, null=False, on_delete=models.CASCADE)
class Meta(VOEventBase.Meta):
unique_together = (('event', 'N'),)
def fileurl(self):
if self.filename:
actual_filename = self.filename
if self.file_version >= 0:
actual_filename += ',%d' % self.file_version
return reverse('file-download', args=[self.event.graceid,
else:
return None

Tanner Prestegard
committed
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
class SignoffBase(models.Model):
"""Abstract base model for operator and advocate signoffs"""
# Instrument choices
INSTRUMENT_H1 = 'H1'
INSTRUMENT_L1 = 'L1'
INSTRUMENT_V1 = 'V1'
INSTRUMENT_CHOICES = (
(INSTRUMENT_H1, 'LHO'),
(INSTRUMENT_L1, 'LLO'),
(INSTRUMENT_V1, 'Virgo'),
)
# Operator status choices
OPERATOR_STATUS_OK = 'OK'
OPERATOR_STATUS_NOTOK = 'NO'
OPERATOR_STATUS_CHOICES = (
(OPERATOR_STATUS_OK, 'OKAY'),
(OPERATOR_STATUS_NOTOK, 'NOT OKAY'),
)
# Signoff type choices
SIGNOFF_TYPE_OPERATOR = 'OP'
SIGNOFF_TYPE_ADVOCATE = 'ADV'
SIGNOFF_TYPE_CHOICES = (
(SIGNOFF_TYPE_OPERATOR, 'operator'),
(SIGNOFF_TYPE_ADVOCATE, 'advocate'),
)
# Field definitions
submitter = models.ForeignKey(UserModel, related_name=
'%(app_label)s_%(class)s_set')
comment = models.TextField(blank=True)
instrument = models.CharField(max_length=2, blank=True,
choices=INSTRUMENT_CHOICES)
status = models.CharField(max_length=2, blank=False,
choices=OPERATOR_STATUS_CHOICES)
signoff_type = models.CharField(max_length=3, blank=False,
choices=SIGNOFF_TYPE_CHOICES)
# Timezones for instruments (this should really be handled separately
# by an instrument class)
instrument_time_zones = {
INSTRUMENT_H1: 'America/Los_Angeles',
INSTRUMENT_L1: 'America/Chicago',
INSTRUMENT_V1: 'Europe/Rome',
}

Tanner Prestegard
committed
abstract = True
def clean(self, *args, **kwargs):
"""Custom clean method for signoffs"""
# Make sure instrument is non-blank if this is an operator signoff
if (self.signoff_type == self.SIGNOFF_TYPE_OPERATOR and

Tanner Prestegard
committed
not self.instrument):
raise ValidationError({'instrument':
_('Instrument must be specified for operator signoff')})
super(SignoffBase, self).clean(*args, **kwargs)
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
def get_req_label_name(self):
if self.signoff_type == 'OP':
return self.instrument + 'OPS'
elif self.signoff_type == 'ADV':
return 'ADVREQ'
def get_status_label_name(self):
if self.signoff_type == 'OP':
return self.instrument + self.status
elif self.signoff_type == 'ADV':
return 'ADV' + self.status
@property
def opposite_status(self):
if self.status == 'OK':
return 'NO'
elif self.status == 'NO':
return 'OK'
def get_opposite_status_label_name(self):
if self.signoff_type == 'OP':
return self.instrument + self.opposite_status
elif self.signoff_type == 'ADV':
return 'ADV' + self.opposite_status
@python_2_unicode_compatible

Tanner Prestegard
committed
class Signoff(SignoffBase):
"""Class for Event signoffs"""
event = models.ForeignKey(Event)

Tanner Prestegard
committed
class Meta:
unique_together = ('event', 'instrument')
def __str__(self):
return six.text_type(
"{gid} | {instrument} | {status}".format(
self.event.graceid,
self.instrument,
self.status
)
)

Tanner Prestegard
committed
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
EMSPECTRUM = (
('em.gamma', 'Gamma rays part of the spectrum'),
('em.gamma.soft', 'Soft gamma ray (120 - 500 keV)'),
('em.gamma.hard', 'Hard gamma ray (>500 keV)'),
('em.X-ray', 'X-ray part of the spectrum'),
('em.X-ray.soft', 'Soft X-ray (0.12 - 2 keV)'),
('em.X-ray.medium', 'Medium X-ray (2 - 12 keV)'),
('em.X-ray.hard', 'Hard X-ray (12 - 120 keV)'),
('em.UV', 'Ultraviolet part of the spectrum'),
('em.UV.10-50nm', 'Ultraviolet between 10 and 50 nm'),
('em.UV.50-100nm', 'Ultraviolet between 50 and 100 nm'),
('em.UV.100-200nm', 'Ultraviolet between 100 and 200 nm'),
('em.UV.200-300nm', 'Ultraviolet between 200 and 300 nm'),
('em.UV.FUV', 'Far-Infrared, 30-100 microns'),
('em.opt', 'Optical part of the spectrum'),
('em.opt.U', 'Optical band between 300 and 400 nm'),
('em.opt.B', 'Optical band between 400 and 500 nm'),
('em.opt.V', 'Optical band between 500 and 600 nm'),
('em.opt.R', 'Optical band between 600 and 750 nm'),
('em.opt.I', 'Optical band between 750 and 1000 nm'),
('em.IR', 'Infrared part of the spectrum'),
('em.IR.NIR', 'Near-Infrared, 1-5 microns'),
('em.IR.J', 'Infrared between 1.0 and 1.5 micron'),
('em.IR.H', 'Infrared between 1.5 and 2 micron'),
('em.IR.K', 'Infrared between 2 and 3 micron'),
('em.IR.MIR', 'Medium-Infrared, 5-30 microns'),
('em.IR.3-4um', 'Infrared between 3 and 4 micron'),
('em.IR.4-8um', 'Infrared between 4 and 8 micron'),
('em.IR.8-15um', 'Infrared between 8 and 15 micron'),
('em.IR.15-30um', 'Infrared between 15 and 30 micron'),
('em.IR.30-60um', 'Infrared between 30 and 60 micron'),
('em.IR.60-100um', 'Infrared between 60 and 100 micron'),
('em.IR.FIR', 'Far-Infrared, 30-100 microns'),
('em.mm', 'Millimetric part of the spectrum'),
('em.mm.1500-3000GHz', 'Millimetric between 1500 and 3000 GHz'),
('em.mm.750-1500GHz', 'Millimetric between 750 and 1500 GHz'),
('em.mm.400-750GHz', 'Millimetric between 400 and 750 GHz'),
('em.mm.200-400GHz', 'Millimetric between 200 and 400 GHz'),
('em.mm.100-200GHz', 'Millimetric between 100 and 200 GHz'),
('em.mm.50-100GHz', 'Millimetric between 50 and 100 GHz'),
('em.mm.30-50GHz', 'Millimetric between 30 and 50 GHz'),
('em.radio', 'Radio part of the spectrum'),
('em.radio.12-30GHz', 'Radio between 12 and 30 GHz'),
('em.radio.6-12GHz', 'Radio between 6 and 12 GHz'),
('em.radio.3-6GHz', 'Radio between 3 and 6 GHz'),
('em.radio.1500-3000MHz','Radio between 1500 and 3000 MHz'),
('em.radio.750-1500MHz','Radio between 750 and 1500 MHz'),
('em.radio.400-750MHz', 'Radio between 400 and 750 MHz'),
('em.radio.200-400MHz', 'Radio between 200 and 400 MHz'),
('em.radio.100-200MHz', 'Radio between 100 and 200 MHz'),
('em.radio.20-100MHz', 'Radio between 20 and 100 MHz'),
)

Tanner Prestegard
committed
# TP (2 Apr 2018): pretty sure this class is deprecated - most recent
# production use is T137114 = April 2015.
@python_2_unicode_compatible

Tanner Prestegard
committed
class EMBBEventLog(AutoIncrementModel):
"""EMBB EventLog: A multi-purpose annotation for EM followup.
A rectangle on the sky, equatorially aligned,
that has or will be imaged that is related to an event"""
class Meta:
ordering = ['-created', '-N']
unique_together = ("event","N")
def __str__(self):
return six.text_type(
"{gid}-{name}-{N}".format(
self.event.graceid,
self.group.name,
self.N
)
)

Tanner Prestegard
committed
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
# A counter for Eels associated with a given event. This is
# important for addressibility.
N = models.IntegerField(null=False)
# The time at which this Eel was created. Important for event auditing.
created = models.DateTimeField(auto_now_add=True)
# The gracedb event that this Eel relates to
event = models.ForeignKey(Event)
# The responsible author of this communication
submitter = models.ForeignKey(UserModel) # from a table of people
# The MOU group responsible
group = models.ForeignKey(EMGroup) # from a table of facilities
# The instrument used or intended for the imaging implied by this footprint
instrument = models.CharField(max_length=200, blank=True)
# Facility-local identifier for this footprint
footprintID= models.TextField(blank=True)
# Now the global ID is a concatenation: facilityName#footprintID
# the EM waveband used for the imaging as below
waveband = models.CharField(max_length=25, choices=EMSPECTRUM)
# The center of the bounding box of the rectangular footprints, right ascension and declination
# in J2000 in decimal degrees
ra = models.FloatField(null=True)
dec = models.FloatField(null=True)
# The width and height (RA range and Dec range) in decimal degrees of each image
raWidth = models.FloatField(null=True)
decWidth = models.FloatField(null=True)
# The GPS time of the middle of the bounding box of the imaging time
gpstime = models.PositiveIntegerField(null=True)
# The duration of each image in seconds
duration = models.PositiveIntegerField(null=True)
# The lists of RA and Dec of the centers of the images
raList = models.TextField(blank=True)
decList = models.TextField(blank=True)
# The width and height of each individual image
raWidthList = models.TextField(blank=True)
decWidthList = models.TextField(blank=True)
# The list of GPS times of the images
gpstimeList = models.TextField(blank=True)
# The duration of each individual image
durationList = models.TextField(blank=True)
# Event Log status
EEL_STATUS_CHOICES = (('FO','FOOTPRINT'), ('SO','SOURCE'), ('CO','COMMENT'), ('CI','CIRCULAR'))
eel_status = models.CharField(max_length=2, choices=EEL_STATUS_CHOICES)
# Observation status. If OBSERVATION, then there is a good chance of good image
OBS_STATUS_CHOICES = (('NA', 'NOT APPLICABLE'), ('OB','OBSERVATION'), ('TE','TEST'), ('PR','PREDICTION'))
obs_status = models.CharField(max_length=2, choices=OBS_STATUS_CHOICES)
# This field is natural language for human
comment = models.TextField(blank=True)

Tanner Prestegard
committed
# This field is formal struct by a syntax TBD
# for example {"phot.mag.limit": 22.3}
extra_info_dict = models.TextField(blank=True)
# For AutoIncrementModel save
AUTO_FIELD = 'N'
AUTO_CONSTRAINTS = ('event',)

Tanner Prestegard
committed
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
# Validates the input and builds bounding box in RA/Dec/GPS
def validateMakeRects(self):
# get all the list based position and times and their widths
raRealList = []
rawRealList = []
# add a [ and ] to convert the input csv list to a json parsable text
if self.raList: raRealList = json.loads('['+self.raList+']')
if self.raWidthList: rawRealList = json.loads('['+self.raWidthList+']')
if self.decList: decRealList = json.loads('['+self.decList+']')
if self.decWidthList: decwRealList = json.loads('['+self.decWidthList+']')
if self.gpstimeList: gpstimeRealList = json.loads('['+self.gpstimeList+']')
if self.durationList: durationRealList = json.loads('['+self.durationList+']')
# is there anything in the ra list?
nList = len(raRealList)
if nList > 0:
if decRealList and len(decRealList) != nList:
raise ValueError('RA and Dec lists are different lengths.')
if gpstimeRealList and len(gpstimeRealList) != nList:
raise ValueError('RA and GPS lists are different lengths.')
# is there anything in the raWidth list?
mList = len(rawRealList)
if mList > 0:
if decwRealList and len(decwRealList) != mList:
raise ValueError('RAwidth and Decwidth lists are different lengths.')
if durationRealList and len(durationRealList) != mList:
raise ValueError('RAwidth and Duration lists are different lengths.')
# There can be 1 width for the whole list, or one for each ra/dec/gps
if mList != 1 and mList != nList:
raise ValueError('Width and duration lists must be length 1 or same length as coordinate lists')
else:
mList = 0
ramin = 360.0
ramax = 0.0
decmin = 90.0
decmax = -90.0
gpsmin = 100000000000
gpsmax = 0
for i in range(nList):
try:
ra = float(raRealList[i])
except:
raise ValueError('Cannot read RA list element %d of %s'%(i, self.raList))
try:
dec = float(decRealList[i])
except:
raise ValueError('Cannot read Dec list element %d of %s'%(i, self.decList))
try:
gps = int(gpstimeRealList[i])
except:
raise ValueError('Cannot read GPStime list element %d of %s'%(i, self.gpstimeList))
# the widths list can have 1 member to cover all, or one for each
if mList==1: j=0
else : j=i
try:
w = float(rawRealList[j])/2
except:
raise ValueError('Cannot read raWidth list element %d of %s'%(i, self.raWidthList))
# evaluate bounding box
if ra-w < ramin: ramin = ra-w
if ra+w > ramax: ramax = ra+w
try:
w = float(decwRealList[j])/2
except:
raise ValueError('Cannot read raWidth list element %d of %s'%(i, self.decWidthList))
# evaluate bounding box
if dec-w < decmin: decmin = dec-w
if dec+w > decmax: decmax = dec+w
try:
w = int(durationRealList[j])/2
except:
raise ValueError('Cannot read duration list element %d of %s'%(i, self.durationList))
# evaluate bounding box
if gps-w < gpsmin: gpsmin = gps-w
if gps+w > gpsmax: gpsmax = gps+w
# Make sure the min/max ra and dec are within bounds:
ramin = max(0.0, ramin)
ramax = min(360.0, ramax)
decmin = max(-90.0, decmin)
decmax = min(90.0, decmax)
if nList>0:
self.ra = (ramin + ramax)/2
self.dec = (decmin + decmax)/2
self.gpstime = (gpsmin+gpsmax)/2
if mList>0:
self.raWidth = ramax-ramin
self.decWidth = decmax-decmin
self.duration = gpsmax-gpsmin
return True