def drawPreview(self, pointingsName, index, title=None): if title is None: title = "Preview of pointing number %d in %s"%(index, pointingsName) print "Creating preview: %s"%title objectList = self.getStoredObject(pointingsName) if objectList is None: return pointingObject = objectList[index] print "mean: %f"%pointingObject.mean self.previewFigure = matplotlib.pyplot.figure(title, figsize=(self.previewSize, self.previewSize)) self.previewFigure.frameon = False self.previewFigure.set_tight_layout(True) axes = matplotlib.pyplot.gca() axes.cla() axes.set_axis_off() self.previewFigure.add_axes(axes) imgplot = matplotlib.pyplot.imshow(numpy.flipud(pointingObject.data), cmap="hsv", interpolation='nearest') matplotlib.pyplot.plot(pointingObject.maxPosition[1], self.superPixelSize - 2 - pointingObject.maxPosition[0], color = 'r', marker='o', markersize=25, lw=4, fillstyle='none') matplotlib.pyplot.plot(10, 10, color = 'g', marker='x') matplotlib.pyplot.draw() matplotlib.pyplot.show() matplotlib.pyplot.pause(0.01) print pointingObject.data print pointingObject.ra, pointingObject.dec, generalUtils.toSexagesimal((pointingObject.ra, pointingObject.dec)) return
def loadFITSFile(self, filename): hdulist = fits.open(filename) self.filename = filename self.rootname = filename.split(".")[0] FITSHeaders = [] for card in hdulist: # print(card.header.keys()) # print(repr(card.header)) for key in card.header.keys(): self.FITSHeaders[key] = card.header[key] if 'WFFBAND' in key: self.filter = card.header[key] import astropy.io.fits as pf self.originalImageData = pf.getdata(filename, uint=False, do_not_scale_image_data=False) # self.originalImageData = hdulist[1].data self.height, self.width = numpy.shape(self.originalImageData) self.wcsSolution = WCS(hdulist[1].header) print "width, height", self.width, self.height, "shape:", numpy.shape(self.originalImageData) self.getRADECmargins() imageCentre = (self.width/2, self.height/2) ra, dec = self.wcsSolution.all_pix2world([imageCentre], 1)[0] self.centre = (ra, dec) positionString = generalUtils.toSexagesimal((ra, dec)) print "RA, DEC of image centre is: ", positionString, ra, dec hdulist.close()
def calculateBMJD(slotID): slot = slots.getSlotByID(slotID) times = slot.getPhotometryColumn('MJD') # Double-check that we have the info we need to perform this calculation if slot.telescope == None: print "Sorry. There is no telescope information set for this object." return if slot.coordinates == None: print "Sorry. We don't have the coordinates for this object. You can set them with the 'set' command." return print "Calculating barycentric MJD or BMJD" obsLong = slot.telescope['longitude'] obsLat = slot.telescope['latitude'] obsAlt = slot.telescope['altitude'] obsName = slot.telescope['name'] print "Using the following telescope information:\nName: %s\nLongitude: %.2f [deg]\tLatitude: %.2f [deg]\t Altitude: %.1f [m]"%(obsName, obsLong, obsLat, obsAlt) obsLocation = astropy.coordinates.EarthLocation(lon = obsLong, lat = obsLat, height=obsAlt) ra, dec = slot.coordinates targetRADEC = generalUtils.toSexagesimal((ra,dec)) print "Target position: %s (%f, %f)"%(targetRADEC, ra, dec) targetCoords = astropy.coordinates.SkyCoord(ra, dec, unit='deg') BMJD = [] t = times[0] observationTime = slbarycentric.Time(t, format='mjd', location = obsLocation) for index, t in enumerate(times): observationTime.__init__(t, format='mjd', location = obsLocation) delta, bcor = observationTime.bcor(targetCoords) bmjd = float(bcor.mjd) BMJD.append(bmjd) sys.stdout.write("\r[%d/%d] MJD %5.8f ---> BMJD %5.8f = %f seconds "%(index, len(times)-1, t, bmjd, delta)) sys.stdout.flush() print slot.addColumn("BMJD", numpy.array(BMJD), clobber=True) return
ppgplot.pgsvp(0.0, 1.0, 0.0, 1.0) ppgplot.pgswin(0, width, 0, height) # ppgplot.pgenv(0., width,0., height, 1, -2) imagePlot['pgPlotTransform'] = [0, 1, 0, 0, 0, 1] boostedImage = generalUtils.percentiles(imageData, 20, 99) ppgplot.pggray(boostedImage, 0, width - 1, 0, height - 1, 0, 255, imagePlot['pgPlotTransform']) # Determine the RA, DEC of the centre of the image, using the WCS solution found in the FITS header imageCentre = [width / 2, height / 2] ra, dec = wcsSolution.all_pix2world([imageCentre], 1)[0] positionString = generalUtils.toSexagesimal((ra, dec)) print("RA, DEC of image centre is: ", positionString, ra, dec) margins = wcsSolution.all_pix2world([[0, 0], [width, height]], 1) margins = checkMargins(margins) print("ra, dec limits:", margins) print("Looking for bright stars") brightStars = getBrightStars(ra, dec, 0.5) filenameParts = args.filename.split('.') dr2Filename = filenameParts[0] + "_dr2_cache.fits" cached = False if not args.ignorecache: print("Looking for a cached copy of the DR2 catalogue:", dr2Filename) if os.path.exists(dr2Filename): cached = True
ppgplot.pgswin(0, width, 0, height) # ppgplot.pgenv(0., width,0., height, 1, -2) imagePlot['pgPlotTransform'] = [0, 1, 0, 0, 0, 1] boostedImage = generalUtils.percentiles(imageData, 20, 99) ppgplot.pggray(boostedImage, 0, width-1, 0, height-1, 0, 255, imagePlot['pgPlotTransform']) # Determine the RA, DEC of the centre of the image, using the WCS solution found in the FITS header imageCentre = [ width/2, height/2] ra, dec = wcsSolution.all_pix2world([imageCentre], 1)[0] positionString = generalUtils.toSexagesimal((ra, dec)) print "RA, DEC of image centre is: ", positionString, ra, dec margins = wcsSolution.all_pix2world([[0, 0], [width, height]], 1) margins = checkMargins(margins) print "ra, dec limits:", margins xlimits = (0, width) ylimits = (0, height) # try: x=width/2 y=height/2 newWidth = width newHeight = height ppgplot.pgsci(3)
print "RA, DEC of the target:", ephemeris.ra, ephemeris.dec print "Calculating barycentric MJD or BMJD" telescope = telescopes[0] obsLong = telescope['longitude'] obsLat = telescope['latitude'] obsAlt = telescope['altitude'] obsName = telescope['name'] print "Using the following telescope information:\nName: %s\nLongitude: %.2f [deg]\tLatitude: %.2f [deg]\t Altitude: %.1f [m]"%(obsName, obsLong, obsLat, obsAlt) obsLocation = astropy.coordinates.EarthLocation(lon = obsLong, lat = obsLat, height=obsAlt) ra, dec = ephemeris.ra, ephemeris.dec targetRADEC = generalUtils.toSexagesimal((ra,dec)) print "Target position: %s (%f, %f)"%(targetRADEC, ra, dec) targetCoords = astropy.coordinates.SkyCoord(ra, dec, unit='deg') BMJD = [] t = times[0] observationTime = slbarycentric.Time(t, format='mjd', location = obsLocation) for index, t in enumerate(times): observationTime.__init__(t, format='mjd', location = obsLocation) delta, bcor = observationTime.bcor(targetCoords) bmjd = float(bcor.mjd) BMJD.append(bmjd) sys.stdout.write("\r[%d/%d] MJD %5.8f ---> BMJD %5.8f = %f seconds "%(index, len(times)-1, t, bmjd, delta)) sys.stdout.flush() print