Rfits comes with a number of useful methods that operate on Rfits_image and Rfits_pointer objects. Using these you can do a lot of useful thing!
First we will load up an image in RAM (temp_image) and as a pointer to the disk object (temp_point)
file_image = system.file('extdata', 'image.fits', package = "Rfits")
temp_image = Rfits_read_image(file_image)
temp_point = Rfits_point(file_image)
We can look at both of these, since they have distinct print methods by default:
print(temp_image)
#> Class: Rfits_image
#> File path: /Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rfits/extdata/image.fits
#> Ext num: 1
#> Ext name:
#> RAM size: 0.9871 MB
#> BITPIX: -32
#> NAXIS1: 356
#> NAXIS2: 356
#> Key N: 23
print(temp_point)
#> File path: /Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rfits/extdata/image.fits
#> Ext num: 1
#> Ext name:
#> Class: Rfits_pointer
#> Type: image
#> Dim: 356 356
#> Disk size: 0.4889 MB
#> BITPIX: -32
#> Key N: 23
The two data structures are a bit different, but we can still plot both directly:
Behind the scene the S3 plot method does different things depending on the Rfits object encountered. If it is an Rfits_image then it will directly plot it using Rwcs_image with a WCS. If it is a Rfits_pointer then it will first fully load the data into RAM, and then plot it using Rwcs_image.
If you have a Rfits_pointer object then you can convert it to a Rfits_image very easily:
temp_point[]
#> Class: Rfits_image
#> File path: /Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rfits/extdata/image.fits
#> Ext num: 1
#> Ext name:
#> RAM size: 0.9871 MB
#> BITPIX: -32
#> NAXIS1: 356
#> NAXIS2: 356
#> Key N: 23
This is because Rfits has special subset operation that work specifically on Rfits_image and Rfits_pointer objects. This means we can plot a subset:
For convenience the following will achieve the same outcomes:
And we can also cutout a box on a specific location:
We can also subset based on RA/Dec coordinates:
plot(temp_image[coords[1], coords[2], box=100, type='coord'])
plot(temp_point[coords[1], coords[2], box=100, type='coord'])
Rfits comes with a whole lot of specific Rfits_image and Rfits_pointer class methods (for details see ?Rfits_methods):
They are designed to give identical results, i.e.:
print(temp_image)
#> Class: Rfits_image
#> File path: /Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rfits/extdata/image.fits
#> Ext num: 1
#> Ext name:
#> RAM size: 0.9871 MB
#> BITPIX: -32
#> NAXIS1: 356
#> NAXIS2: 356
#> Key N: 23
print(temp_point)
#> File path: /Library/Frameworks/R.framework/Versions/4.2/Resources/library/Rfits/extdata/image.fits
#> Ext num: 1
#> Ext name:
#> Class: Rfits_pointer
#> Type: image
#> Dim: 356 356
#> Disk size: 0.4889 MB
#> BITPIX: -32
#> Key N: 23
centre(temp_image)
#> RA Dec
#> [1,] 352.2914 -31.8223
centre(temp_point)
#> RA Dec
#> [1,] 352.2914 -31.8223
corners(temp_image)
#> RA Dec
#> BL 352.3111 -31.83906
#> TL 352.3111 -31.80554
#> TR 352.2717 -31.80554
#> BR 352.2717 -31.83906
corners(temp_point)
#> RA Dec
#> BL 352.3111 -31.83906
#> TL 352.3111 -31.80554
#> TR 352.2717 -31.80554
#> BR 352.2717 -31.83906
Rfits_image objects can be usefully operated on as if they were matrices:
Most R mathematical operators will work. You can also directly operate with Rfits_image and Rfits_point objects:
If you mix Rfits object types you will need to convert the Rfits_pointer to a Rfits_image using the subset operation: