def update_dict(pteldict,burst): '''If a burst is specified on pteldict, this function updates pteldict by adding a formated_time key, which gives date in the form of "http://skycam.mmto.arizona.edu/skycam/YYYYMMDD/night_movie.avi, and an extinction key.''' # Pierre- add the snippet of code from dictdate below. Do it on a per- # burst basis, and then we can use update_all_dicts to loop over everything if pteldict.has_key(burst): time1 = pteldict[burst]['ptel_time'] time2 = time1[0:4]+time1[5:7]+time1[8:10] formated = 'http://skycam.mmto.arizona.edu/skycam/'+time2+'/night_movie.avi' pteldict[burst]['formated_time'] = formated firstobs = pteldict[burst]['obs'].keys()[0] ra = pteldict[burst]['obs'][firstobs]['scope_ra'] dec = pteldict[burst]['obs'][firstobs]['scope_dec'] decpos = (ra, dec) secpos = q.dec2sex(decpos) ext = extinction.extinction(secpos[0], secpos[1]) # Just take the 0th entry of the returned extinction list; the rest # of the info is redundant positional information. pteldict[burst]['extinction'] = ext[0] else: print 'Cannot find specified burst in pteldict!'
def update_dict(pteldict, burst): '''If a burst is specified on pteldict, this function updates pteldict by adding a formated_time key, which gives date in the form of "http://skycam.mmto.arizona.edu/skycam/YYYYMMDD/night_movie.avi, and an extinction key.''' # Pierre- add the snippet of code from dictdate below. Do it on a per- # burst basis, and then we can use update_all_dicts to loop over everything if pteldict.has_key(burst): time1 = pteldict[burst]['ptel_time'] time2 = time1[0:4] + time1[5:7] + time1[8:10] formated = 'http://skycam.mmto.arizona.edu/skycam/' + time2 + '/night_movie.avi' pteldict[burst]['formated_time'] = formated firstobs = pteldict[burst]['obs'].keys()[0] ra = pteldict[burst]['obs'][firstobs]['scope_ra'] dec = pteldict[burst]['obs'][firstobs]['scope_dec'] decpos = (ra, dec) secpos = q.dec2sex(decpos) ext = extinction.extinction(secpos[0], secpos[1]) # Just take the 0th entry of the returned extinction list; the rest # of the info is redundant positional information. pteldict[burst]['extinction'] = ext[0] else: print 'Cannot find specified burst in pteldict!'
def overlay_finding_chart(self,ra,dec,uncertainty,src_name='unknown source',pos_label='UVOT',cont_str='',\ uncertainty_shape='combo',suppress_scale=False): # cont_str='Contact: Adam N. Morgan ([email protected], 510-229-7683)' self.loc_ra = ra self.loc_dec = dec self.loc_uncertainty = uncertainty self.src_name = src_name self.pos_label = pos_label self.cont_str = cont_str self.pixel_scale = self.wcs_size * 60.0 / self.img_size # arcsec/pixel self.str_loc_pos = dec2sex((self.loc_ra, self.loc_dec)) update_time = time.strftime('%Y %h %d') head_buffer = 50 uncertainty_circle_size = int(self.loc_uncertainty / self.pixel_scale) pos_pos_x = 300 #position of the error circle on the image , hard coded for now pos_pos_y = 350 # Define scale line physical length based on how large the image is # Divide by 5 so that line is never more than ~20% of image if not self.wcs_size < 5.0: scale_line_physical_length = int(self.wcs_size / 5) #arcmin elif not self.wcs_size < 2.0: scale_line_physical_length = 0.5 else: scale_line_physical_length = 0.25 scale_line_length = int(60 * scale_line_physical_length / self.pixel_scale) scale_line_start = head_buffer + self.img_size / 2 - scale_line_length / 2 scale_line_stop = head_buffer + self.img_size / 2 + scale_line_length / 2 scale_line_label = str(scale_line_physical_length) + ' arcmin' # Get rid of scale bar if desired if suppress_scale: scale_line_stop = scale_line_start scale_line_label = '' scale_line_label_pos_y = scale_line_start - 15 pos_label_pos_y = pos_pos_y - uncertainty_circle_size - 15 epoch = 'J2000' pos_label_full = self.pos_label + ' Pos. (%s)' % epoch if self.survey == 'poss2ukstu_red': self.survey_str = 'DSS2 (red)' elif self.survey == 'poss1_red': self.survey_str = 'DSS1 (red)' elif self.survey == 'sdss': self.survey_str = 'SDSS' else: print 'Unknown survey: %s' % survey sys.exit(1) ra_str = 'RA = ' + self.str_loc_pos[0] dec_str = 'Dec = ' + self.str_loc_pos[1] uncertainty_str = 'Uncertainty: ' + str(self.loc_uncertainty) + '"' if uncertainty_shape.lower() == 'circle': uncertainty_shape_string = ''' <ellipse cx="%d" cy="%d" rx="%d" ry="%d" style="fill:none; stroke:rgb(0,0,255);stroke-width:2"/> ''' % (pos_pos_x, pos_pos_y, uncertainty_circle_size, uncertainty_circle_size) elif uncertainty_shape.lower() == 'cross': cross_left_pos = pos_pos_x - uncertainty_circle_size - 15 cross_right_pos = pos_pos_x - uncertainty_circle_size cross_down_pos = pos_pos_y + uncertainty_circle_size cross_up_pos = pos_pos_y + uncertainty_circle_size + 15 uncertainty_shape_string = ''' <line x1="%d" y1="%d" x2="%d" y2="%d" style="stroke:rgb(0,0,255);stroke-width:2"/> <line x1="%d" y1="%d" x2="%d" y2="%d" style="stroke:rgb(0,0,255);stroke-width:2"/> '''% (pos_pos_x, cross_down_pos, pos_pos_x, cross_up_pos,\ cross_right_pos, pos_pos_y, cross_left_pos, pos_pos_y) else: #default to cross + circle cross_left_pos = pos_pos_x - uncertainty_circle_size - 15 cross_right_pos = pos_pos_x - uncertainty_circle_size cross_down_pos = pos_pos_y + uncertainty_circle_size cross_up_pos = pos_pos_y + uncertainty_circle_size + 15 uncertainty_shape_string = ''' <ellipse cx="%d" cy="%d" rx="%d" ry="%d" style="fill:none; stroke:rgb(0,0,255);stroke-width:2"/> <line x1="%d" y1="%d" x2="%d" y2="%d" style="stroke:rgb(0,0,255);stroke-width:2"/> <line x1="%d" y1="%d" x2="%d" y2="%d" style="stroke:rgb(0,0,255);stroke-width:2"/> '''% (pos_pos_x, pos_pos_y, uncertainty_circle_size,uncertainty_circle_size,pos_pos_x, cross_down_pos, pos_pos_x, cross_up_pos,\ cross_right_pos, pos_pos_y, cross_left_pos, pos_pos_y) im = Image.open(self.save_str) assert isinstance(im, Image.Image) im.fp.seek(0) imstr = base64.b64encode(im.fp.read()) imstr = [imstr[i:i + 76] for i in range(0, len(imstr), 76)] imstr = string.join(imstr, '\n') fc_width = im.size[0] + 200.0 fc_height = im.size[1] + 100.0 return '''<?xml version="1.0" encoding="UTF-8" standalone="no"?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="%d" height="%d"> <image y="%d" x="0" width="%d" height="%d" xlink:href="data:image/%s;base64,%s" /> <text x = "15" y = "10" fill = "black" font-size = "28"> <tspan x="15" dy="1em">%s: Finding Chart</tspan> </text> <text x = "15" y = "660" fill = "black" font-size = "16"> <tspan x="15" dy="1em">%s</tspan> </text> <text x = "15" y = "630" fill = "#222222" font-size = "11"> <tspan x="15" dy="1em">Created from http://fc.qmorgan.com on %s. Contact: Adam N. Morgan ([email protected]).</tspan> </text> <text x ="288" y="%d" fill="blue" font-size="12"> <tspan x="288" dy="1em">%s</tspan> </text> %s <text x="615" y ="55" fill = "black" font-size = "18"> <tspan x="615" dy="1em">%s</tspan> <tspan x="615" dy="1em">RA = %s</tspan> <tspan x="615" dy="1em">Dec = %s</tspan> <tspan x="615" dy="1em">Uncertainty = %s</tspan> <tspan x="615" dy="1em">(arcseconds)</tspan> </text> <text x="640" y="325" fill="black" font-size="18"> <tspan x="640" dy="1em">Image from:</tspan> <tspan x="640" dy="1em">%s</tspan> </text> <text x="640" y="500" fill="black" font-size="18"> <tspan x="640" dy="1em">Image is %s</tspan> <tspan x="640" dy="1em">arcmin/side</tspan> </text> <text x="625" y="640" fill="black" font-size ="18"> <tspan x="625" dy="1em">E</tspan> </text> <line x1="640" y1="650" x2="700" y2="650" style="stroke:Black;stroke-width:2"/> <line x1="640" y1="650" x2="650" y2="660" style="stroke:Black;stroke-width:2"/> <line x1="640" y1="650" x2="650" y2="640" style="stroke:Black;stroke-width:2"/> <text x="694" y="570" fill="black" font-size ="18"> <tspan x="694" dy="1em">N</tspan> </text> <line x1="700" y1="650" x2="700" y2="590" style="stroke:Black;stroke-width:2"/> <line x1="690" y1="600" x2="700" y2="590" style="stroke:Black;stroke-width:2"/> <line x1="710" y1="600" x2="700" y2="590" style="stroke:Black;stroke-width:2"/> <line x1="130" y1="%d" x2="130" y2="%d" style="stroke:rgb(255,0,0);stroke-width:2"/> <text x ="107" y ="%d" fill ="red" font-size = "12"> <tspan x="107" dy="1em">%s</tspan> </text> </svg>''' % ( fc_width, fc_height, head_buffer, im.size[0], im.size[1], im.format.lower(), imstr,\ self.src_name, self.cont_str, update_time, pos_label_pos_y, self.pos_label, uncertainty_shape_string,\ pos_label_full, self.str_loc_pos[0], self.str_loc_pos[1],\ str(self.loc_uncertainty),self.survey_str, str(self.wcs_size), scale_line_start,scale_line_stop,scale_line_label_pos_y, scale_line_label)
def overlay_finding_chart(self,ra,dec,uncertainty,src_name='unknown source',pos_label='UVOT',cont_str='',\ uncertainty_shape='combo',suppress_scale=False): # cont_str='Contact: Adam N. Morgan ([email protected], 510-229-7683)' self.loc_ra = ra self.loc_dec = dec self.loc_uncertainty=uncertainty self.src_name = src_name self.pos_label = pos_label self.cont_str = cont_str self.pixel_scale = self.wcs_size * 60.0 / self.img_size # arcsec/pixel self.str_loc_pos = dec2sex((self.loc_ra,self.loc_dec)) update_time = time.strftime('%Y %h %d') head_buffer = 50 uncertainty_circle_size = int(self.loc_uncertainty/self.pixel_scale) pos_pos_x = 300 #position of the error circle on the image , hard coded for now pos_pos_y = 350 # Define scale line physical length based on how large the image is # Divide by 5 so that line is never more than ~20% of image if not self.wcs_size < 5.0: scale_line_physical_length = int(self.wcs_size/5) #arcmin elif not self.wcs_size < 2.0: scale_line_physical_length = 0.5 else: scale_line_physical_length = 0.25 scale_line_length = int(60*scale_line_physical_length/self.pixel_scale) scale_line_start = head_buffer + self.img_size/2 - scale_line_length/2 scale_line_stop = head_buffer + self.img_size/2 + scale_line_length/2 scale_line_label = str(scale_line_physical_length) + ' arcmin' # Get rid of scale bar if desired if suppress_scale: scale_line_stop = scale_line_start scale_line_label = '' scale_line_label_pos_y = scale_line_start - 15 pos_label_pos_y = pos_pos_y - uncertainty_circle_size - 15 epoch = 'J2000' pos_label_full = self.pos_label + ' Pos. (%s)' % epoch if self.survey == 'poss2ukstu_red': self.survey_str = 'DSS2 (red)' elif self.survey == 'poss1_red': self.survey_str = 'DSS1 (red)' elif self.survey == 'sdss': self.survey_str = 'SDSS' else: print 'Unknown survey: %s' % survey sys.exit(1) ra_str = 'RA = ' + self.str_loc_pos[0] dec_str = 'Dec = ' + self.str_loc_pos[1] uncertainty_str = 'Uncertainty: ' + str(self.loc_uncertainty) + '"' if uncertainty_shape.lower() == 'circle': uncertainty_shape_string = ''' <ellipse cx="%d" cy="%d" rx="%d" ry="%d" style="fill:none; stroke:rgb(0,0,255);stroke-width:2"/> ''' % (pos_pos_x, pos_pos_y, uncertainty_circle_size,uncertainty_circle_size) elif uncertainty_shape.lower() == 'cross': cross_left_pos = pos_pos_x-uncertainty_circle_size-15 cross_right_pos = pos_pos_x-uncertainty_circle_size cross_down_pos = pos_pos_y+uncertainty_circle_size cross_up_pos = pos_pos_y+uncertainty_circle_size+15 uncertainty_shape_string = ''' <line x1="%d" y1="%d" x2="%d" y2="%d" style="stroke:rgb(0,0,255);stroke-width:2"/> <line x1="%d" y1="%d" x2="%d" y2="%d" style="stroke:rgb(0,0,255);stroke-width:2"/> '''% (pos_pos_x, cross_down_pos, pos_pos_x, cross_up_pos,\ cross_right_pos, pos_pos_y, cross_left_pos, pos_pos_y) else: #default to cross + circle cross_left_pos = pos_pos_x-uncertainty_circle_size-15 cross_right_pos = pos_pos_x-uncertainty_circle_size cross_down_pos = pos_pos_y+uncertainty_circle_size cross_up_pos = pos_pos_y+uncertainty_circle_size+15 uncertainty_shape_string = ''' <ellipse cx="%d" cy="%d" rx="%d" ry="%d" style="fill:none; stroke:rgb(0,0,255);stroke-width:2"/> <line x1="%d" y1="%d" x2="%d" y2="%d" style="stroke:rgb(0,0,255);stroke-width:2"/> <line x1="%d" y1="%d" x2="%d" y2="%d" style="stroke:rgb(0,0,255);stroke-width:2"/> '''% (pos_pos_x, pos_pos_y, uncertainty_circle_size,uncertainty_circle_size,pos_pos_x, cross_down_pos, pos_pos_x, cross_up_pos,\ cross_right_pos, pos_pos_y, cross_left_pos, pos_pos_y) im = Image.open(self.save_str) assert isinstance(im, Image.Image) im.fp.seek(0) imstr = base64.b64encode(im.fp.read()) imstr = [ imstr[i:i+76] for i in range(0, len(imstr), 76) ] imstr = string.join(imstr, '\n') fc_width = im.size[0] + 200.0 fc_height = im.size[1] + 100.0 return '''<?xml version="1.0" encoding="UTF-8" standalone="no"?> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="%d" height="%d"> <image y="%d" x="0" width="%d" height="%d" xlink:href="data:image/%s;base64,%s" /> <text x = "15" y = "10" fill = "black" font-size = "28"> <tspan x="15" dy="1em">%s: Finding Chart</tspan> </text> <text x = "15" y = "660" fill = "black" font-size = "16"> <tspan x="15" dy="1em">%s</tspan> </text> <text x = "15" y = "630" fill = "#222222" font-size = "11"> <tspan x="15" dy="1em">Created from http://fc.qmorgan.com on %s. Contact: Adam N. Morgan ([email protected]).</tspan> </text> <text x ="288" y="%d" fill="blue" font-size="12"> <tspan x="288" dy="1em">%s</tspan> </text> %s <text x="615" y ="55" fill = "black" font-size = "18"> <tspan x="615" dy="1em">%s</tspan> <tspan x="615" dy="1em">RA = %s</tspan> <tspan x="615" dy="1em">Dec = %s</tspan> <tspan x="615" dy="1em">Uncertainty = %s</tspan> <tspan x="615" dy="1em">(arcseconds)</tspan> </text> <text x="640" y="325" fill="black" font-size="18"> <tspan x="640" dy="1em">Image from:</tspan> <tspan x="640" dy="1em">%s</tspan> </text> <text x="640" y="500" fill="black" font-size="18"> <tspan x="640" dy="1em">Image is %s</tspan> <tspan x="640" dy="1em">arcmin/side</tspan> </text> <text x="625" y="640" fill="black" font-size ="18"> <tspan x="625" dy="1em">E</tspan> </text> <line x1="640" y1="650" x2="700" y2="650" style="stroke:Black;stroke-width:2"/> <line x1="640" y1="650" x2="650" y2="660" style="stroke:Black;stroke-width:2"/> <line x1="640" y1="650" x2="650" y2="640" style="stroke:Black;stroke-width:2"/> <text x="694" y="570" fill="black" font-size ="18"> <tspan x="694" dy="1em">N</tspan> </text> <line x1="700" y1="650" x2="700" y2="590" style="stroke:Black;stroke-width:2"/> <line x1="690" y1="600" x2="700" y2="590" style="stroke:Black;stroke-width:2"/> <line x1="710" y1="600" x2="700" y2="590" style="stroke:Black;stroke-width:2"/> <line x1="130" y1="%d" x2="130" y2="%d" style="stroke:rgb(255,0,0);stroke-width:2"/> <text x ="107" y ="%d" fill ="red" font-size = "12"> <tspan x="107" dy="1em">%s</tspan> </text> </svg>''' % ( fc_width, fc_height, head_buffer, im.size[0], im.size[1], im.format.lower(), imstr,\ self.src_name, self.cont_str, update_time, pos_label_pos_y, self.pos_label, uncertainty_shape_string,\ pos_label_full, self.str_loc_pos[0], self.str_loc_pos[1],\ str(self.loc_uncertainty),self.survey_str, str(self.wcs_size), scale_line_start,scale_line_stop,scale_line_label_pos_y, scale_line_label)
def add_position_info(self,bat_pos=None,xrt_pos=None,uvot_pos=None,reg_path=None): '''Requires bat_pos, xrt_pos, uvot_pos in format of (ra,dec,uncertainty), where uncertainty is in arcseconds. ''' content = "" if bat_pos: bat_pos_sex = q.dec2sex((bat_pos[0],bat_pos[1])) self.best_pos = bat_pos self.best_pos_type = 'BAT' if xrt_pos: xrt_pos_sex = q.dec2sex((xrt_pos[0],xrt_pos[1])) self.best_pos = xrt_pos self.best_pos_type = 'XRT' if uvot_pos: uvot_pos_sex = q.dec2sex((uvot_pos[0],uvot_pos[1])) self.best_pos = uvot_pos self.best_pos_type = 'UVOT' if bat_pos != None: content += ''' <b>BAT</b>: RA = %s, Dec = %s, Uncertainty: %s"<br> (RA = %s, Dec = %s)<br><br> ''' % (str(bat_pos[0]).rstrip('0'),str(bat_pos[1]).rstrip('0'),str(bat_pos[2]).rstrip('0'),\ bat_pos_sex[0],bat_pos_sex[1]) if xrt_pos != None: content += ''' <b>XRT</b>: RA = %s, Dec = %s, Uncertainty: %s"<br> (RA = %s, Dec = %s)<br><br> ''' % (str(xrt_pos[0]).rstrip('0'),str(xrt_pos[1]).rstrip('0'),str(xrt_pos[2]).rstrip('0'),\ xrt_pos_sex[0],xrt_pos_sex[1]) if uvot_pos != None: content += ''' <b>UVOT</b>: RA = %s, Dec = %s, Uncertainty: %s"<br> (RA = %s, Dec = %s)<br><br> ''' % (str(uvot_pos[0]).rstrip('0'),str(uvot_pos[1]).rstrip('0'),str(uvot_pos[2]).rstrip('0'),\ uvot_pos_sex[0],uvot_pos_sex[1]) if self.best_pos: try: source_name = 'swift_' + str(self.triggerid) Gal_EB_V = extinction.qExtinction(source_name,self.best_pos[0],self.best_pos[1]) except: Gal_EB_V = 'Unknown' content += ''' <b>Extinction</b>: E_(B-V) = %s<br><br> ''' % (str(Gal_EB_V)) if reg_path != None: if os.path.exists(reg_path): self.qHTML.copy_file(reg_path) content += ''' <a href='./%s'>DS9 Region File</a> ''' % (os.path.basename(reg_path)) else: print reg_path + ' does not exist. Not including region file.' self.reg_path = reg_path self.reg_name = os.path.basename(reg_path) if content: self.qHTML.add_post(title='Spatial Information',content=content)
def add_position_info(self, bat_pos=None, xrt_pos=None, uvot_pos=None, reg_path=None): '''Requires bat_pos, xrt_pos, uvot_pos in format of (ra,dec,uncertainty), where uncertainty is in arcseconds. ''' content = "" if bat_pos: bat_pos_sex = q.dec2sex((bat_pos[0], bat_pos[1])) self.best_pos = bat_pos self.best_pos_type = 'BAT' if xrt_pos: xrt_pos_sex = q.dec2sex((xrt_pos[0], xrt_pos[1])) self.best_pos = xrt_pos self.best_pos_type = 'XRT' if uvot_pos: uvot_pos_sex = q.dec2sex((uvot_pos[0], uvot_pos[1])) self.best_pos = uvot_pos self.best_pos_type = 'UVOT' if bat_pos != None: content += ''' <b>BAT</b>: RA = %s, Dec = %s, Uncertainty: %s"<br> (RA = %s, Dec = %s)<br><br> ''' % (str(bat_pos[0]).rstrip('0'),str(bat_pos[1]).rstrip('0'),str(bat_pos[2]).rstrip('0'),\ bat_pos_sex[0],bat_pos_sex[1]) if xrt_pos != None: content += ''' <b>XRT</b>: RA = %s, Dec = %s, Uncertainty: %s"<br> (RA = %s, Dec = %s)<br><br> ''' % (str(xrt_pos[0]).rstrip('0'),str(xrt_pos[1]).rstrip('0'),str(xrt_pos[2]).rstrip('0'),\ xrt_pos_sex[0],xrt_pos_sex[1]) if uvot_pos != None: content += ''' <b>UVOT</b>: RA = %s, Dec = %s, Uncertainty: %s"<br> (RA = %s, Dec = %s)<br><br> ''' % (str(uvot_pos[0]).rstrip('0'),str(uvot_pos[1]).rstrip('0'),str(uvot_pos[2]).rstrip('0'),\ uvot_pos_sex[0],uvot_pos_sex[1]) if self.best_pos: try: source_name = 'swift_' + str(self.triggerid) Gal_EB_V = extinction.qExtinction(source_name, self.best_pos[0], self.best_pos[1]) except: Gal_EB_V = 'Unknown' content += ''' <b>Extinction</b>: E_(B-V) = %s<br><br> ''' % (str(Gal_EB_V)) if reg_path != None: if os.path.exists(reg_path): self.qHTML.copy_file(reg_path) content += ''' <a href='./%s'>DS9 Region File</a> ''' % (os.path.basename(reg_path)) else: print reg_path + ' does not exist. Not including region file.' self.reg_path = reg_path self.reg_name = os.path.basename(reg_path) if content: self.qHTML.add_post(title='Spatial Information', content=content)