def setup(self): """Compute parameters for reflected regions algorithm.""" geom = self.reference_map.geom self._pix_region = self.region.to_pixel(geom.wcs) self._pix_center = PixCoord.from_sky(self.center, geom.wcs) # Make the ON reference map mask = geom.region_mask([self.region], inside=True) # on_reference_map = WcsNDMap(geom=geom, data=mask) # Extract all pixcoords in the geom X, Y = geom.get_pix() ONpixels = PixCoord(X[mask], Y[mask]) # find excluded PixCoords mask = self.reference_map.data == 0 self.excluded_pixcoords = PixCoord(X[mask], Y[mask]) # Minimum angle a region has to be moved to not overlap with previous one min_ang = self._region_angular_size(ONpixels, self._pix_center) # Add required minimal distance between two off regions self._min_ang = min_ang + self.min_distance # Maximum possible angle before regions is reached again self._max_angle = Angle( "360deg") - self._min_ang - self.min_distance_input
def contains(self, skycoord): """ Check whether the given (list of) sky coordinate(s) falls inside this sky patch (region). Parameters ---------- skycoord : `~astropy.coordinate.SkyCoord` or (lon, lat) tuple The (list of) sky coordinate(s) to check, or the (list of) longitudes and latitudes of sky coordinates [ deg ] Returns ------- inside : bool (list of) boolean values indicating whether the given sky coordinate(s) is inside this sky patch. """ if not isinstance(skycoord, SkyCoord): lon, lat = skycoord skycoord = SkyCoord(lon, lat, unit=au.deg) wcs = self.wcs pixcoord = PixCoord.from_sky(skycoord, wcs=wcs) center = PixCoord(x=self.xcenter, y=self.ycenter) region = RectanglePixelRegion(center=center, width=self.xsize, height=self.ysize) return region.contains(pixcoord)
def dagga(field): "function to tag sources for dd calibration, very smoky" key = 'calibrate_dd' #make a skymodel with only dE taggable sources. #de_only_model = 'de-only-model.txt' de_sources_mode = config[key]['de_sources_mode'] print("de_sources_mode:", de_sources_mode) # if usepb: # model_cube = prefix+"-DD-precal.cube.int.model.fits" # else: # model_cube = prefix+"-DD-precal.cube.app.model.fits" outdir = field+"_ddcal" if de_sources_mode == 'auto': print("Carrying out automatic source taggig for direction dependent calibration") caracal.log.info('Carrying out automatic dE tagging') catdagger_opts = { "ds9-reg-file": "de-{0:s}.reg:output".format(field), "ds9-tag-reg-file" : "de-clusterleads-{0:s}.reg:output".format(field), "noise-map" : prefix+"_"+field+"-DD-precal.app.residual.fits", "sigma" : config[key]['sigma'], "min-distance-from-tracking-centre" : config[key]['min_dist_from_phcentre'], } recipe.add('cab/catdagger', 'tag_sources-auto_mode', catdagger_opts,input=INPUT, output=OUTPUT+"/"+outdir,label='tag_sources-auto_mode::Tag dE sources with CatDagger',shared_memory=shared_mem) if de_sources_mode == 'manual': img = prefix+"_"+field+"-DD-precal.app.restored.fits" imagefile = os.path.join(pipeline.output,DD_DIR,outdir,img) #print("Imagefile",imagefile) #print("Pipeline output", pipeline.output) w = WCS(imagefile) #coords = config[key]['de_sources_manual'] print(de_dict) sources_to_tag = de_dict[field.replace("_","-")] reg = [] for j in range(len(sources_to_tag.split(";"))): coords = sources_to_tag.split(";")[j] size = coords.split(",")[2] coords_str = coords.split(",")[0]+" "+coords.split(",")[1] #print("Coordinate String", coords_str) centre = SkyCoord(coords_str, unit='deg') separation = int(size) * u.arcsec #print("Size",separation) xlist = [] ylist = [] for i in range(5): ang_sep = (306/5)*i*u.deg p = centre.directional_offset_by(ang_sep,separation) pix = PixCoord.from_sky(p,w) xlist.append(pix.x) ylist.append(pix.y) vertices = PixCoord(x=xlist, y=ylist) region_dd = PolygonPixelRegion(vertices=vertices) reg.append(region_dd) regfile = "de-{0:s}.reg".format(field) ds9_file = os.path.join(OUTPUT,outdir,regfile) write_ds9(reg,ds9_file,coordsys='physical')
def _get_center_pixel(center, reference_geom): """Center pix coordinate""" return PixCoord.from_sky(center, reference_geom.wcs)
def center_pix(self): """Center pix coordinate""" return PixCoord.from_sky(self.center, self.geom_ref.wcs)
print("\nFirst and last entries: \n") print(tboth[0]) print() print(tboth[-1]) if test4: print("\nTest 4 - create dummy WCS, and verify it:") print(70 * "-") # Example - the location of NGC 4707 c1 = SkyCoord("12h48m22.87s +51d09m52.9s", frame="icrs") mywcs = create_dummy_wcs(c1) print(mywcs) print("For coordinate: ", c1.to_string("hmsdms")) pixcoord = PixCoord.from_sky(c1, mywcs, origin=1) print(pixcoord) print("Two arcsecond offsets in the cardinal directions") # create offsets, and make sure they are what we would expect sep = 2.0 * u.arcsec pas = np.float64([0.0, 180.0, 90.0, 270.0]) * u.deg for pa in pas: ctemp = c1.copy() skycoord = ctemp.directional_offset_by(pa, sep) print(skycoord.to_string("hmsdms")) print(skycoord.separation(ctemp).arcsec) pixcoord = PixCoord.from_sky(skycoord, mywcs, origin=1) print(pixcoord) print()