Newer
Older

Tanner Prestegard
committed
ordering = ['-created', '-N']
unique_together = ("event","N")

Tanner Prestegard
committed
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
return "%s-%s-%d" % (self.event.graceid(), self.group.name, self.N)
# 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
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
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
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
# 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_FK = 'event'
# 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