# NOT RUN {
temp=matrix(1:121,11)
#The central value is at:
temp[6,6]
print(magcutout(temp, dim(temp)/2, box=c(3,3))$image)
#Given we cutout around the centre of the central pixel [5.5,5.5], the new centre
#relative to the cutout image output should be at [1.5,1.5]:
print(magcutout(temp, dim(temp)/2, box=c(3,3))$loc.orig)
print(magcutout(temp, dim(temp)/2, box=c(3,3))$loc)
# A simple WCS cutout example:
image=readFITS(system.file("extdata", 'VIKING/mystery_VIKING_Z.fits', package="ProFit"))
par(mar=c(3.1,3.1,1.1,1.1))
magcutout(image$imDat, loc=c(50.5,50.5), plot=TRUE)
magcutoutWCS(image, loc=c(50.5,50.5), loc.type = 'image', plot=TRUE)
#We can cut out using the coordinates instead:
print({tempcoord=magWCSxy2radec(50.5,50.5,header=image$hdr)})
magcutoutWCS(image, loc=tempcoord, plot=TRUE)
#You can select coordinates too:
magcutoutWCS(image, loc=c(352.29167, -31.827777), box=c(30,30), plot=TRUE)$loc.WCS
magcutoutWCS(image, loc=c("23:29:10", "-31:49:40"), box=c(30,30) , coord.type = 'sex',
plot=TRUE)$loc.WCS
#We can add RA Dec specific decorations easily:
cutim=magcutoutWCS(image, loc=c(352.2918, -31.82652), box=c(30,30), plot=TRUE)
#Approx overlays:
points(cutim$approx.map(c(352.2918, 352.2897), c(-31.82652, -31.8252)), pch=3, col='blue')
#Exact overlays:
points(magWCSradec2xy(c(352.2918, 352.2897), c(-31.82652, -31.8252), header=cutim$header),
col='red')
#Given we correctly modify the header, we can actually use the cut down image directly:
magimageWCS(cutim)
# Now test the various cutout size options by asking for a large cutout near the image boundary
loc = c(300,340)
box = c(200,200)
loc.type = c("image","image")
# By default, the cutout is exactly the request size, but the centre is shifted:
cutim=magcutoutWCS(image, loc=loc, box=box, coord.type="image", loc.type=loc.type,
plot=TRUE, shiftloc=TRUE, paddim=TRUE)
# Setting shiftloc=FALSE pads the image with NAs instead, preserving the size:
cutim=magcutoutWCS(image, loc=loc, box=box, coord.type="image", loc.type=loc.type,
plot=TRUE, shiftloc=FALSE, paddim=TRUE)
# Setting paddim=FALSE returns the largest possible cutout within the image bounds,
# without shifting the centre:
cutim=magcutoutWCS(image, loc=loc, box=box, coord.type="image", loc.type=loc.type, plot=TRUE,
shiftloc=FALSE, paddim=FALSE)
# Setting paddim=FALSE and shiftloc=TRUE returns a larger cutout, but with at most
# box/2 padding on either side:
cutim=magcutoutWCS(image, loc=loc, box=box, coord.type="image", loc.type=loc.type, plot=TRUE,
shiftloc=TRUE, paddim=FALSE)
# Setting shiftloc=FALSE and requesting a box size larger than the image returns a cutout with the
# requested box size:
box = c(400,400)
cutim=magcutoutWCS(image, loc=loc, box=box, coord.type="image", loc.type=loc.type, plot=TRUE,
shiftloc=FALSE, paddim=TRUE)
# }
Run the code above in your browser using DataLab