GLAMERDOC++
Gravitational Lensing Code Library
|
Image structure that can be manipulated and exported to/from fits files. More...
#include <pixelmap.h>
Public Member Functions | |
PixelMap (const PixelMap< T > &pmap, double res_ratio) | |
Creates a PixelMap at a different resolution. The new counts are calculated integrating over the input pixels. No interpolation or smoothing is performed. | |
PixelMap (const PixelMap< T > &other) | |
PixelMap (PixelMap< T > &&other) | |
PixelMap (const PixelMap< T > &pmap, const double *center, std::size_t Npixels) | |
Creates a new PixelMap from a square region of a PixelMap. If the region exceeds the boundaries of the original map, the new map is completed with zeros. | |
PixelMap (const PixelMap< T > &pmap, long nx, long ny, std::size_t Npixels) | |
Produces a square cut-out of the input PixelMap. | |
PixelMap (const double *center, std::size_t Npixels, double resolution, PixelMapUnits u=PixelMapUnits::ndef) | |
make square PixelMap | |
PixelMap (const double *center, std::size_t Nx, std::size_t Ny, double resolution, PixelMapUnits u=PixelMapUnits::ndef) | |
make rectangular PixelMap with square pixels | |
PixelMap (std::string fitsfilename, double resolution=-1, PixelMapUnits u=PixelMapUnits::ndef) | |
Constructs a PixelMap reading in a fits file Infos about resolution, Npixels and center are read from the header. | |
template<typename OtherT > | |
PixelMap (const PixelMap< OtherT > &) | |
PixelMap< T > & | operator= (const PixelMap< T > &other) |
PixelMap< T > & | operator= (PixelMap< T > &&other) |
void | ChangeUnits (PixelMapUnits u) |
PixelMapUnits | getUnits () const |
bool | valid () const |
std::size_t | size () const |
std::size_t | getNx () const |
std::size_t | getNy () const |
double | getRangeX () const |
double | getRangeY () const |
void const | getCenter (Point_2d &c) const |
Point_2d | getCenter () const |
double | getResolution () const |
Point_2d | getLLBoundary () const |
double | getRA () |
returns right accention of center | |
double | getDEC () |
returns declination of center | |
void | setRAandDec (double RAin, double DECin) |
set the coordinates of center | |
void | Clean () |
void | AddImages (ImageInfo *imageinfo, int Nimages, float rescale=1.) |
Add an image to the map. | |
void | AddImages (std::vector< ImageInfo > &imageinfo, int Nimages, float rescale=1.) |
void | AddGridBrightness (Grid &grid) |
Add an image from a the surface brightnesses of a Grid to the PixelMap. | |
void | AddGridMapBrightness (const GridMap &grid) |
Add an image from a the surface brightnesses of a GridMap to the PixelMap. | |
void | AddUniformImages (ImageInfo *imageinfo, int Nimages, T value) |
Add images with uniform surface brightness set by input parameter value. | |
PosType | AddSource (Source &source) |
PosType | AddSource (Source &source, int oversample) |
Add a source to the pixel map by oversamples the source so that oversample^2 points within each pixel are averaged. | |
void | AddPointSource (const Point_2d &x, T flux) |
void | copy_in (const PixelMap &pmap) |
copy a PixelMap into this one. | |
void | paste (const PixelMap &pmap) |
Replace overlaping pixel values with those of the input map. | |
void | paste (const PixelMap &pmap, long nx, long ny) |
paste a PixelMap on with the lower left pixel match to [nx,ny] of this | |
PixelMap< T > | convolve (const PixelMap< T > &kernel) |
convolve the image with a kernel. | |
PixelMap< T > | convolve2 (const PixelMap< T > &kernel) |
PixelMap< T > | cutout (long xmin, long xmax, long ymin, long ymax) |
cut out a part of the PixelMap | |
void | duplicate (const PixelMap &pmap) |
copy a PixelMap that must be the same without creating a new one.. | |
template<typename S > | |
PosType | AddSource_parallel (S &source, int oversample) |
Adds source to map. This version breaks pixels up into blocks and does them in seporate threads. | |
void | AddCurve (ImageInfo *curve, T value) |
Draws a closed curve through the points in curve->imagekist. | |
void | AddCurve (Kist< Point > *imagekist, T value) |
void | AddCurve (std::vector< Point_2d > &curve, T value) |
void | AddCurve (std::vector< RAY > &curve, T value) |
void | drawline (double x1[], double x2[], T value, bool add) |
simple line | |
void | DrawLine (long x0, long x1, long y0, long y1, T value, bool add) |
line by Bresenham's line algorithm | |
void | DrawLineGS (long x0, long x1, long y0, long y1, T value, bool add) |
void | drawcircle (PosType r_center[], PosType radius, PosType value) |
Draws a circle. | |
void | drawdisk (PosType r_center[], PosType radius, PosType value, int Nstrip) |
Draws a disk. | |
void | AddGrid (const Grid &grid, T value=1.0) |
Fills in pixels where the image plane points in the grid are located with the value given. | |
void | AddGrid (const Grid &grid, LensingVariable val) |
Fills in pixels with the selected quantity from the grid points. | |
void | Renormalize (T factor) |
Multiplies the whole map by a scalar factor. | |
void | AddValue (std::size_t i, T value) |
Adds a value to the i-th pixel. | |
void | AssignValue (std::size_t i, T value) |
Assigns a value to the i-th pixel. | |
void | printASCII () const |
Print an ASCII table of all the pixel values. | |
void | printASCIItoFile (std::string filename) const |
Print an ASCII table of all the pixel values. | |
void | printFITS (std::string filename, bool Xflip=false, bool verbose=false) |
Output the pixel map as a fits file. | |
void | printFITS (std::string filename, std::vector< std::tuple< std::string, double, std::string > > &extra_header_info, bool verbose) |
void | printFITS (std::string filename, std::vector< std::string > &headercards) |
This overides all header information and relaces it with the inputs. Meant for making a modified copy. | |
void | smooth (double sigma) |
Smoothes a map with a Gaussian kernel of width sigma (in arcseconds) | |
T | getValue (std::size_t i) const |
T & | operator[] (std::size_t i) |
T | operator[] (std::size_t i) const |
T & | operator() (std::size_t i) |
T | operator() (std::size_t i) const |
T | operator() (std::size_t i, std::size_t j) const |
T & | operator() (std::size_t i, std::size_t j) |
PixelMap & | operator+= (const PixelMap &rhs) |
Add the values of another PixelMap to this one. | |
void | operator+= (float f) |
void | operator+= (double f) |
PixelMap | operator+ (const PixelMap &) const |
Add two PixelMaps. | |
PixelMap & | operator-= (const PixelMap &rhs) |
Subtract the values of another PixelMap from this one. | |
PixelMap | operator- (const PixelMap &) const |
Subtract two PixelMaps. | |
void | operator-= (float f) |
void | operator-= (double f) |
PixelMap & | operator*= (const PixelMap &rhs) |
Multiply the values of another PixelMap by this one. | |
PixelMap | operator* (const PixelMap &a) const |
Multiply two PixelMaps. | |
PixelMap | operator/ (const PixelMap &a) const |
Multiply two PixelMaps. | |
PixelMap & | operator*= (PosType b) |
PixelMap | operator* (PosType b) const |
std::valarray< T > & | data () |
bool | agrees (const PixelMap &other) const |
Check whether two PixelMaps agree in their physical dimensions. | |
PosType | ave () const |
return average pixel value | |
PosType | sum () const |
return sum of all pixel values | |
size_t | size () |
Total number of pixels. | |
T | max () const |
T | min () const |
void | FindArc (PosType &radius, PosType *xc, PosType *arc_center, PosType &arclength, PosType &width, PosType threshold) |
Find arcs in image WARNING: THIS IS UNDER CONSTRUCTION! | |
long | find_index (PosType const x[], long &ix, long &iy) const |
get the index for a position, returns -1 if out of map, this version returns the 2D grid coordinates | |
long | find_index (PosType const x[]) const |
get the index for a position, returns -1 if out of map | |
long | find_index (PosType x, PosType y, long &ix, long &iy) const |
get the index for a position, returns -1 if out of map, this version returns the 2D grid coordinates | |
long | find_index (PosType x, PosType y) const |
get the index for a position, returns -1 if out of map | |
void | find_position (PosType x[], std::size_t const index) const |
get the index for a position, returns -1 if out of map | |
void | find_position (PosType x[], std::size_t const ix, std::size_t const iy) const |
get the index for a position, returns -1 if out of map | |
PixelMap< T > | rotate (PosType theta, T scale=1) |
rotate and scale the image while keeping pixels, resoluiton | |
T | linear_interpolate (PosType x[]) |
interpolate to point x[] | |
void | drawgrid (int N, PosType value) |
draw a grid on the image that divides the each demension into N cells | |
void | drawPoints (std::vector< Point * > points, PosType size, PosType value) |
void | drawPoints (std::vector< Point > points, PosType size, PosType value) |
void | drawCurve (std::vector< Point * > points, PosType value) |
void | drawCurve (std::vector< Point > points, PosType value) |
void | drawPoints (std::vector< Point_2d > points, PosType size, PosType value) |
void | drawCurve (std::vector< Point_2d > points, PosType value) |
void | drawSquare (PosType p1[], PosType p2[], PosType value) |
Draw a rectangle. | |
void | drawBox (PosType p1[], PosType p2[], PosType value, int Nstrip) |
Draws a box (filling the inside with horizontal lines, starting from the top) | |
void | PowerSpectrum (std::vector< PosType > &power_spectrum, std::vector< PosType > &lvec, bool overwrite=true) |
Find the power spectrum of the map. | |
void | PowerSpectrum (std::vector< PosType > &power_spectrum, const std::vector< PosType > &lbins, std::vector< PosType > &lave, bool overwrite=true) |
Find the power spectrum of the map. | |
void | AdaptiveSmooth (PosType value) |
void | find_contour (T level, std::vector< std::vector< Point_2d > > &points, std::vector< bool > &hits_edge) const |
returns a vector of contour curves | |
void | find_islands_holes (T level, std::vector< std::vector< size_t > > &points) const |
void | lens_definition (T min_sn_per_image, T pixel_threshold, int &Nimages, T &total_sig_noise_source, std::vector< size_t > &maxima_indexes, std::vector< std::vector< size_t > > &image_points, bool &lens_TF, T &level, size_t &n_pix_in_source, bool verbose=false) |
std::vector< size_t > | maxima (T minlevel) const |
find maxima that are above minlevel | |
int | count_islands (std::vector< size_t > &pixel_index) const |
For a list of pixel indexes this will count and separated islands that are not connected. | |
size_t | threshold (std::list< size_t > &pixel_index, PosType value) |
get a list of pixels above value | |
void | flipY () |
reflects the image about the horizontal mid-line | |
void | flipX () |
reflects the image about the vertical mid-line | |
void | doubleFlip () |
rotate the image by 180deg or equivalently reflect it through the origin | |
void | recenter (PosType newcenter[2]) |
recenter the map without changing anything else. | |
void | recenter (Point_2d newcenter) |
PixelMap< T > | downsize (int n) |
Creates a PixelMap with a lower resolution. The value of the pixels are added for the new pixels. If n does not go into the orginial number of pixels evenly the right (top) redge is dropped. | |
PixelMap | interpolate (int n) |
Makes a PixelMap with resolution 1/n of the original with the values linearly interpolated. | |
void | addheader (std::string label, long value, std::string comment) |
add a heaader keyword that will appear in fits output | |
void | addheader (std::string label, size_t value, std::string comment) |
void | addheader (std::string label, float value, std::string comment) |
void | addheader (std::string label, double value, std::string comment) |
void | addheader (std::string label, std::string value, std::string comment) |
PixelMap (const PixelMap< double > &other) | |
Static Public Member Functions | |
static void | swap (PixelMap< T > &, PixelMap< T > &) |
Image structure that can be manipulated and exported to/from fits files.
PixelMap< T >::PixelMap | ( | const PixelMap< T > & | pmap, |
double | res_ratio ) |
Creates a PixelMap at a different resolution. The new counts are calculated integrating over the input pixels. No interpolation or smoothing is performed.
res_ratio | resolution of map is res_ratio times the resolution of the input map |
PixelMap< T >::PixelMap | ( | const PixelMap< T > & | pmap, |
const double * | center, | ||
std::size_t | my_Npixels ) |
Creates a new PixelMap from a square region of a PixelMap. If the region exceeds the boundaries of the original map, the new map is completed with zeros.
center | Input PixelMap (from which the stamp is taken) |
my_Npixels | center of the region to be duplicated (in rads) size of the region to be duplicated (in pixels) |
PixelMap< T >::PixelMap | ( | const PixelMap< T > & | pmap, |
long | nx, | ||
long | ny, | ||
std::size_t | my_Npixels ) |
PixelMap< T >::PixelMap | ( | const double * | center, |
std::size_t | Npixels, | ||
double | resolution, | ||
PixelMapUnits | u = PixelMapUnits::ndef ) |
make square PixelMap
Npixels | The location of the center of the map |
resolution | Number of pixels in one dimension of map. One dimensional range of map in whatever units the point positions are in |
PixelMap< T >::PixelMap | ( | const double * | center, |
std::size_t | myNx, | ||
std::size_t | myNy, | ||
double | resolution, | ||
PixelMapUnits | u = PixelMapUnits::ndef ) |
make rectangular PixelMap with square pixels
myNx | The location of the center of the map |
myNy | Number of pixels in x dimension of map. |
resolution | Number of pixels in y dimension of map. One dimensional range of map in whatever units the point positions are in |
PixelMap< T >::PixelMap | ( | std::string | fitsfilename, |
double | my_res = -1, | ||
PixelMapUnits | u = PixelMapUnits::ndef ) |
Constructs a PixelMap reading in a fits file Infos about resolution, Npixels and center are read from the header.
fitsfilename | file name of fits file to be read |
my_res | resolution (rad) of fits image if not given in fits file, use default or -1 otherwise |
Draws a closed curve through the points in curve->imagekist.
This differs form PixelMap<T>::AddImage() in that it draws lines between the points and takes no account of the cells that the points are in or the surface brightness. The points must be ordered already. Particularly useful for drawing the caustics that may have irregular cell sizes. The last point will be connected to the first point.
void PixelMap< T >::AddGrid | ( | const Grid & | grid, |
LensingVariable | val ) |
Fills in pixels with the selected quantity from the grid points.
The grid and PixelMap do not need to be related in any way. Using this function multiple grids can be added to the same image.
This is for lensing quantities and not surface brightness. If you want surface brightness use PixelMap<T>::AddGridBrightness()
Warning: When adding a new grid it should not overlap with any of the previously added grids.
Fills in pixels where the image plane points in the grid are located with the value given.
This is for lensing quantities and not surface brightness. If you want surface brightness use PixelMap<T>::AddGridBrightness()
void PixelMap< T >::AddImages | ( | ImageInfo * | imageinfo, |
int | Nimages, | ||
float | rescale = 1. ) |
Add an image to the map.
If rescale==0 gives constant surface brightness, if < 0 the surface brightness is not scaled by the pixel area as for the flux (default: 1). Negative values are good for mapping some quantity independant of the pixel size
imageinfo | An array of ImageInfo-s. There is no reason to separate images for this routine |
Nimages | Number of images on input. |
rescale | rescales the surface brightness while leaving the image unchanged, see full notes |
void PixelMap< T >::AddImages | ( | std::vector< ImageInfo > & | imageinfo, |
int | Nimages, | ||
float | rescale = 1. ) |
imageinfo | An array of ImageInfo-s. There is no reason to separate images for this routine |
Nimages | Number of images on input. |
rescale | rescales the surface brightness while leaving the image unchanged, see full notes |
void PixelMap< T >::AddUniformImages | ( | ImageInfo * | imageinfo, |
int | Nimages, | ||
T | value ) |
Add images with uniform surface brightness set by input parameter value.
This does not use the surface brightnesses stored in the image points.
imageinfo | An array of ImageInfo-s. There is no reason to separate images for this routine |
convolve the image with a kernel.
It is assumed that the kernal has the same pixel size as the image.
The center of the kernel is at N/2+1. If it has an odd number of pixels in both directions this will be the center.
copy a PixelMap into this one.
The size, resolution and center of the pixel maps are not changed and do not need to match. The input pixel map is added while conserving the area integral of the map within the area of overlaping pixels.
int PixelMap< T >::count_islands | ( | std::vector< size_t > & | pixel_index | ) | const |
For a list of pixel indexes this will count and separated islands that are not connected.
On return, 'pixel_index' is ordered into groups and the 'heads' list points to the first elemant in each group plus the end of the list so that heads[i] to heads[i+1] is a group for 0 <= i <= ngroups. The number of groups is returned which is also heads.size() - 1
PixelMap< T > PixelMap< T >::cutout | ( | long | xmin, |
long | xmax, | ||
long | ymin, | ||
long | ymax ) |
cut out a part of the PixelMap
Inputs are in pixels. xmax and xmin are one after the disired region so that the output size is (xmax-xmin) x (ymax-ymin)
Creates a PixelMap with a lower resolution. The value of the pixels are added for the new pixels. If n does not go into the orginial number of pixels evenly the right (top) redge is dropped.
n | number of pixels each direction added into each new pixel |
void PixelMap< T >::drawcircle | ( | PosType | r_center[], |
PosType | radius, | ||
PosType | value ) |
Draws a circle.
r_center | center of circle |
radius | radius of circle |
value | value that it is set to on the map |
void PixelMap< T >::drawdisk | ( | PosType | r_center[], |
PosType | radius, | ||
PosType | value, | ||
int | Nstrip ) |
Draws a disk.
r_center | center of disk |
radius | radius of disk |
value | value that it is set to on the map |
Nstrip | number of lines we want |
void PixelMap< T >::drawgrid | ( | int | N, |
PosType | value ) |
draw a grid on the image that divides the each demension into N cells
Draws a grid.
void PixelMap< T >::drawline | ( | double | x1[], |
double | x2[], | ||
T | value, | ||
bool | add ) |
simple line
Draws a line between two points on the image by setting the pixels equal to value.
TODO: Could be improved by detecting if the line passes through the map at all before starting. Could also be improved by making the line fatter by including neighbor points.
x1 | one end point of line |
x2 | other end point of line |
value | value that it is set to on the map |
add | true : add value, false replace with value |
void PixelMap< T >::drawSquare | ( | PosType | p1[], |
PosType | p2[], | ||
PosType | value ) |
Draw a rectangle.
Draws a square.
copy a PixelMap that must be the same without creating a new one..
This avoids calling a any constructor or destructor.
long PixelMap< T >::find_index | ( | PosType const | x[], |
long & | ix, | ||
long & | iy ) const |
get the index for a position, returns -1 if out of map, this version returns the 2D grid coordinates
get the index for a position, returns -1 if out of map
long PixelMap< T >::find_index | ( | PosType | x, |
PosType | y, | ||
long & | ix, | ||
long & | iy ) const |
get the index for a position, returns -1 if out of map, this version returns the 2D grid coordinates
get the index for a position, returns -1 if out of map
void PixelMap< T >::find_islands_holes | ( | T | level, |
std::vector< std::vector< size_t > > & | points ) const |
find all the points above level divided into seprated groups
Groups with points are connected regions above level. Groups without points are regions surrounded by regions above level, i.e. holes.
Makes a PixelMap with resolution 1/n of the original with the values linearly interpolated.
This normalizes so that the sum of the pixels is approximately constant.
void PixelMap< T >::lens_definition | ( | T | min_sn_per_image, |
T | pixel_threshold, | ||
int & | Nimages, | ||
T & | total_sig_noise_source, | ||
std::vector< size_t > & | maxima_indexes, | ||
std::vector< std::vector< size_t > > & | image_points, | ||
bool & | lens_TF, | ||
T & | level, | ||
size_t & | n_pix_in_source, | ||
bool | verbose = false ) |
This applies a definition of lesning for a resolved source based on that of Sonnenfeld et al. 2023
This is meant to be used on a signal-to-noise map of the lensed source only.
The definition does the following tests: 1) define a footprint at surface brightness level pixel_threshold
2) romove disconected region that have signal-to-noise below min_sn_per_image
3) if there are multiple images or a hole in the image lens_TF =true
4) if there is one image with no hole increase the threshold and apply 3) until the it is classified as a lens or it reaches the maximum surface brightness level
min_sn_per_image | signal-to-noise required for a seporate image (ex 10) |
pixel_threshold | signal-to-noise threshold that defines the footprint (ex. 2) |
Nimages | the number of images |
total_sig_noise_source | gives the total signal-to-noise of all images |
maxima_indexes | index of maxima |
lens_TF | whether it passes lens diffintion |
level | levels on which the multiple images are defined |
n_pix_in_source | number of pixels in footprint |
T PixelMap< T >::linear_interpolate | ( | PosType | x[] | ) |
interpolate to point x[]
bilinear interpolation
std::vector< size_t > PixelMap< T >::maxima | ( | T | minlevel | ) | const |
find maxima that are above minlevel
find the index of the pixels that are larger than all its neighbors
Replace overlaping pixel values with those of the input map.
No attempt is made to interpolate or average the pixels of pmap. No integration is done. If the resolution of input map is higher than the reslution of the map then the pixels values will just be that of the last pixel visited while going through them.
This can be used to sew tiles together into a larger map.
void PixelMap< T >::PowerSpectrum | ( | std::vector< PosType > & | power_spectrum, |
const std::vector< PosType > & | lbins, | ||
std::vector< PosType > & | lave, | ||
bool | overwrite = true ) |
Find the power spectrum of the map.
power_spectrum | output power spectrum |
lbins | output l values of bands |
lave | output l values of bands |
overwrite | if false add power to existing power_spectrum (used for averaging over many fields |
void PixelMap< T >::PowerSpectrum | ( | std::vector< PosType > & | power_spectrum, |
std::vector< PosType > & | lvec, | ||
bool | overwrite = true ) |
Find the power spectrum of the map.
power_spectrum | output power spectrum |
lvec | output l values of bands |
overwrite | if false add power to existing power_spectrum (used for averaging over many fields |
void PixelMap< T >::printFITS | ( | std::string | filename, |
std::vector< std::string > & | headercards ) |
This overides all header information and relaces it with the inputs. Meant for making a modified copy.
filename | file to create |
headercards | header information in cfitsio "card" format |
newcenter | in radians |
void PixelMap< T >::recenter | ( | PosType | newcenter[2] | ) |
recenter the map without changing anything else.
newcenter | in radians |
rotate and scale the image while keeping pixels, resoluiton
theta | counter-clockwise rotation (radians) |
scale | scale <1 shrinks it |