GLAMERDOC++
Gravitational Lensing Code Library
|
Structure to contain both source and image trees. More...
#include <grid_maintenance.h>
Public Member Functions | |
Grid (LensHndl lens, unsigned long N1d, const double center[2], double range) | |
Constructor for initializing square grid. | |
Grid (LensHndl lens, unsigned long Nx, const PosType center[2], PosType rangeX, PosType rangeY) | |
Constructor for initializing rectangular grid. | |
~Grid () | |
Destructor for a Grid. Frees all memory. | |
Grid | ReInitialize (LensHndl lens) |
Returns a new grid that has not been refined but has the same intial image grid, but calculated with a new lens. | |
void | zoom (LensHndl lens, double *center, double scale, Branch *top=NULL) |
Test if point is in a region of uniform magnification using the kappa and gamma calculated from the rayshooter. | |
double | RefreshSurfaceBrightnesses (Source *source) |
Reshoot the rays with the same image postions. | |
double | AddSurfaceBrightnesses (Source *source) |
Recalculate surface brightness just like Grid::RefreshSurfaceBrightness but the new source is added to any sources that were already there. | |
double | mark_closest_point_source_images (Point_2d y_source, PosType r_source_max, PosType luminosity, bool verbose=false) |
This function finds all the images for a circular source of radius r_source, then finds the points within each image that are closest to the center and then markes each surface brightness. Only one pixel per image gets flux. | |
void | find_point_source_images (Point_2d y_source, PosType r_source, PosType z_source, std::vector< RAY > &images, bool verbose=false) |
This function finds all the images for a circular source of radius r_source, then finds the points within each image that are closest to the center of the source. Only one pixel per image gets flux. Points are not marked. | |
double | ClearSurfaceBrightnesses () |
Reset the surface brightness and in_image flag in every point on image and source planes to zero (false) | |
double | refine_on_surfacebrightness (Lens &lens, Source &source) |
unsigned long | getNumberOfPoints () const |
Returns number of points on image plane. | |
PosType | EinsteinArea () const |
area of region with negative magnification | |
int | getInitNgrid () |
return initial number of grid points in each direction | |
int | getNgrid_block () |
return number of cells in each dimension into which each cell is divided when a refinement is made | |
double | getInitRange () |
return initial range of gridded region | |
Point_2d | getInitCenter () |
Point * | RefineLeaf (LensHndl lens, Point *point) |
Fundamental function used to divide a leaf in the tree into nine subcells. | |
Point * | RefineLeaves (LensHndl lens, std::vector< Point * > &points) |
Same as RefineLeaf() but multiple points can be passed. The rays are shot all together so that more parallelization can be achieved in the rayshooting. | |
void | ClearAllMarks () |
Rest all in_image markers to False. | |
template<typename T > | |
void | writeFits (const double center[], size_t Npixels, double resolution, LensingVariable lensvar, std::string filename) |
Outputs a fits image of a lensing variable of choice. | |
template<typename T > | |
void | writeFits (const double center[], size_t Nx, size_t Ny, double resolution, LensingVariable lensvar, std::string filename) |
Outputs a fits image of a lensing variable of choice. | |
template<typename T > | |
void | writeFits (double strech, LensingVariable lensvar, std::string filename) |
make a fits image of whole grid region | |
template<typename T > | |
void | writePixelFits (size_t Nx, LensingVariable lensvar, std::string filename) |
Make a fits map that is automatically centered on the grid and has approximately the same range as the grid. Nx can be used to change the resolution. Nx = grid.getInitNgrid() will give the initial grid resolution. | |
template<typename T > | |
void | writeFitsVector (const double center[], size_t Npixels, double resolution, LensingVariable lensvar, std::string filename) |
Outputs a fits file for making plots of vector fields. | |
template<typename T > | |
PixelMap< T > | writePixelMap (const double center[], size_t Npixels, double resolution, LensingVariable lensvar) |
Outputs a PixelMap of the lensing quantities of a fixed grid. | |
template<typename T > | |
PixelMap< T > | writePixelMap (const double center[], size_t Nx, size_t Ny, double resolution, LensingVariable lensvar) |
Outputs a PixelMap of the lensing quantities of a fixed grid. | |
template<typename T > | |
PixelMap< T > | writePixelMap (LensingVariable lensvar) |
With the initial boundaries and resolution, ie no refinement. | |
template<typename T > | |
void | MapSurfaceBrightness (PixelMap< T > &map) |
make image of surface brightness | |
template<typename T > | |
PixelMap< T > | MapSurfaceBrightness (double resolution) |
make a map of the whole gridded area with given resolution | |
template<typename T > | |
PixelMap< T > | writePixelMapUniform (const PosType center[], size_t Nx, size_t Ny, LensingVariable lensvar) |
Make a Pixel map of the without distribution the pixels. | |
template<typename T > | |
void | writePixelMapUniform (PixelMap< T > &map, LensingVariable lensvar) |
template<typename T > | |
void | writeFitsUniform (const PosType center[], size_t Nx, size_t Ny, LensingVariable lensvar, std::string filename) |
Output a fits map of the without distribution the pixels. | |
void | find_images (PosType *y_source, PosType r_source, int &Nimages, std::vector< ImageInfo > &imageinfo, unsigned long &Nimagepoints) |
Finds images for a given source position and size. It seporates images of different pairities. | |
void | map_images (Lens *lens, Source *source, int *Nimages, std::vector< ImageInfo > &imageinfo, PosType xmax, PosType xmin, PosType initial_size, ExitCriterion criterion, bool FindCenter, bool divide_images) |
Find images and refine them based on their surface brightness distribution. | |
Grid (Grid &&grid) | |
Grid | operator= (Grid &grid)=delete |
Grid (Grid &grid)=delete | |
Grid & | operator= (Grid &&grid) |
PosType | magnification (double sblimit=-1.0e12) const |
flux weighted local magnification that does not take multiple imaging into effect | |
PosType | UnlensedFlux (double sblimit=-1.0e12) const |
PosType | LensedFlux (double sblimit=-1.0e12) const |
Point_2d | centroid () const |
centroid of flux | |
Public Attributes | |
TreeHndl | i_tree |
tree on image plane | |
TreeHndl | s_tree |
tree on source plane | |
Structure to contain both source and image trees.
Grid::Grid | ( | LensHndl | lens, |
unsigned long | N1d, | ||
const double | center[2], | ||
double | range ) |
Constructor for initializing square grid.
Note: Deflection solver must be specified before creating a Grid.
lens | lens model for initializing grid |
N1d | Initial number of grid points in each dimension. |
center | Center of grid (usually in radian units) |
range | Full width of grid in whatever units will be used. |
Grid::Grid | ( | LensHndl | lens, |
unsigned long | Nx, | ||
const PosType | center[2], | ||
PosType | rangeX, | ||
PosType | rangeY ) |
Constructor for initializing rectangular grid.
Cells of grid will always be square with initial resolution rangeX/(Nx-1). The Y range may not be exactly rangeY, but will be the nearest value that is a whole number of cells.
Note: Deflection solver must be specified before creating a Grid.
lens | lens model for initializing grid |
Nx | Initial number of grid points in X dimension. |
center | Center of grid. |
rangeX | Full width of grid in x direction in whatever units will be used. |
rangeY | Full width of grid in y direction in whatever units will be used. |
PosType Grid::AddSurfaceBrightnesses | ( | Source * | source | ) |
Recalculate surface brightness just like Grid::RefreshSurfaceBrightness but the new source is added to any sources that were already there.
returns the total flux from new source
void Grid::find_images | ( | PosType * | y_source, |
PosType | r_source, | ||
int & | Nimages, | ||
std::vector< ImageInfo > & | imageinfo, | ||
unsigned long & | Nimagepoints ) |
Finds images for a given source position and size. It seporates images of different pairities.
No grid refinement is done. If the images is not initially found no nearest neighbor points are returned.
image points are put into imageinfo[].imagekist imageinfo[].points and imageinfo[].Npoints are not changed
side-effects : Will make in_image = true for all image points if splitparities == 0
< >
void Grid::find_point_source_images | ( | Point_2d | y_source, |
PosType | r_source, | ||
PosType | z_source, | ||
std::vector< RAY > & | images, | ||
bool | verbose = false ) |
This function finds all the images for a circular source of radius r_source, then finds the points within each image that are closest to the center of the source. Only one pixel per image gets flux. Points are not marked.
y_source | angular position of source, |
r_source | points outside this radius on the source plane will not be considered as in the image |
z_source | redhsift of source |
images | returned image rays |
unsigned long Grid::getNumberOfPoints | ( | ) | const |
Returns number of points on image plane.
Finding
void Grid::map_images | ( | Lens * | lens, |
Source * | source, | ||
int * | Nimages, | ||
std::vector< ImageInfo > & | imageinfo, | ||
PosType | xmax, | ||
PosType | xmin, | ||
PosType | initial_size, | ||
ExitCriterion | criterion, | ||
bool | FindCenter, | ||
bool | divide_images ) |
Find images and refine them based on their surface brightness distribution.
Finding
Uses ImageFinding::find_images_kist() to initially find and refine images and then uses a surface brightness based criterion to refine the most important parts of the lens.
map_images is intended for mapping images of sources more complicated than simple circles.
No Grid refinement is done.
double Grid::mark_closest_point_source_images | ( | Point_2d | y_source, |
PosType | r_source_max, | ||
PosType | luminosity, | ||
bool | verbose = false ) |
This function finds all the images for a circular source of radius r_source, then finds the points within each image that are closest to the center and then markes each surface brightness. Only one pixel per image gets flux.
y_source | angular position of source, |
r_source_max | points outside this radius on the source plane will not be considered as in the image |
Fundamental function used to divide a leaf in the tree into nine subcells.
Source and image points are created, linked, shot and added to the trees. The leaf pointers of the points including the input are assigned.
If some of the of the points are outside the original grid they will not be added in which case THERE WILL BE LESS THEN Ngrid*Ngrid-1 points added. The true number will be result->head or, if no points are added, result = NULL.
Returns a pointer to the list of image points that have been added. This array can then be used for calculating the surface brightness or marking them as in the image.
i_tree current is left in one of the new subcells.
PosType Grid::RefreshSurfaceBrightnesses | ( | Source * | source | ) |
Reshoot the rays with the same image postions.
Finding
The source positions and source tree are updated to the current lens model. The advantage over Grid::ReInitializeGrid() is that the image plane refinements are preserved.
void Grid::ReShoot(LensHndl lens){
PosType range,center[2];
range = i_tree->getTop()->boundary_p2[0] - i_tree->getTop()->boundary_p1[0]; center[0] = (i_tree->getTop()->boundary_p2[0] + i_tree->getTop()->boundary_p1[0])/2; center[1] = (i_tree->getTop()->boundary_p2[1] + i_tree->getTop()->boundary_p1[1])/2;
Grid newgrid(lens,Ngrid_init,center,rangeX,rangeY);
Grid(LensHndl lens ,unsigned long Nx ,const PosType center[2] ,PosType rangeX ,PosType rangeY);
Point *i_points,*s_points;
unsigned long i;
clear source tree delete s_tree; s_points = NewPointArray(i_tree->pointlist.size()); s_points = point_factory(i_tree->pointlist.size());
build new initial grid PointList::iterator i_tree_pointlist_it; i_tree_pointlist_it.current = i_tree->pointlist.Top(); size_t k; for(i=0,k=0;i<i_tree->pointlist.size();++i){ i_points = *i_tree_pointlist_it; if(i_points->head > 0){
link source and image points for(size_t j=0;j<i_points->head;++j,++k){ i_points[j].image = &s_points[k]; s_points[k].image = &i_points[j]; s_points[k].id = i_points[j].id; s_points[k].gridsize = i_points[j].gridsize; };
{ reshoot the rays std::lock_guard<std::mutex> hold(grid_mutex); lens->rayshooterInternal(i_points->head,i_points); } }
–i_tree_pointlist_it; }
s_tree = new TreeStruct(s_points,s_points->head,1,(i_tree->getTop()->boundary_p2[0] - i_tree->getTop()->boundary_p1[0])/10 ); return; }
Recalculate surface brightness at every point without changing the positions of the grid or any lens properties.
Whatever is in the image is replaced with the one input source. Recalculate the surface brightness at all points on the grid. This is useful when changing the source model while preserving changes in the grid. Both i_tree and s_tree are both changed although only s_tree shows up here.
returns total flux
void Grid::writeFits | ( | const double | center[], |
size_t | Npixels, | ||
double | resolution, | ||
LensingVariable | lensvar, | ||
std::string | filename ) |
Outputs a fits image of a lensing variable of choice.
center | center of image |
Npixels | number of pixels in image in on dimension |
resolution | resolution of image in radians |
lensvar | which quantity is to be displayed |
filename | file name for image – .kappa.fits, .gamma1.fits, etc will be appended |
void Grid::writeFits | ( | const double | center[], |
size_t | Nx, | ||
size_t | Ny, | ||
double | resolution, | ||
LensingVariable | lensvar, | ||
std::string | filename ) |
Outputs a fits image of a lensing variable of choice.
center | center of image |
Nx | number of pixels in image in x dimension |
Ny | number of pixels in image in y dimension |
resolution | resolution of image in radians |
lensvar | which quantity is to be displayed |
filename | file name for image – .kappa.fits, .gamma1.fits, etc will be appended |
void Grid::writeFits | ( | double | strech, |
LensingVariable | lensvar, | ||
std::string | filename ) |
make a fits image of whole grid region
strech | resolution relative to the initial resolution |
lensvar | which quantity is to be displayed |
filename | file name for image – .kappa.fits, .gamma1.fits, etc will be appended |
void Grid::writeFitsUniform | ( | const PosType | center[], |
size_t | Nx, | ||
size_t | Ny, | ||
LensingVariable | lensvar, | ||
std::string | filename ) |
Output a fits map of the without distribution the pixels.
This will be faster than Grid::writePixelMap() and Grid::writeFits(). But it puts each grid pixel in one pixelmap pixel and if there are two grid pixels in one pixelmap pixel it uses one at random. This is meant for uniform maps to make equal sized PixelMaps.
center | center of image |
Nx | number of pixels in image in on dimension |
Ny | number of pixels in image in on dimension |
lensvar | which quantity is to be displayed |
filename | file name for image – .kappa.fits, .gamma1.fits, etc will be appended |
void Grid::writeFitsVector | ( | const double | center[], |
size_t | Npixels, | ||
double | resolution, | ||
LensingVariable | lensvar, | ||
std::string | filename ) |
Outputs a fits file for making plots of vector fields.
center | center of image |
Npixels | number of pixels in image in on dimension |
resolution | resolution of image in radians |
lensvar | which quantity is to be displayed |
filename | file name for image – .kappa.fits, .gamma1.fits, etc will be appended |
void Grid::writePixelFits | ( | size_t | Nx, |
LensingVariable | lensvar, | ||
std::string | filename ) |
Make a fits map that is automatically centered on the grid and has approximately the same range as the grid. Nx can be used to change the resolution. Nx = grid.getInitNgrid() will give the initial grid resolution.
Nx | number of pixels in image in x dimension |
lensvar | which quantity is to be displayed |
filename | file name for image – .kappa.fits, .gamma1.fits, etc will be appended |
PixelMap< T > Grid::writePixelMap | ( | const double | center[], |
size_t | Npixels, | ||
double | resolution, | ||
LensingVariable | lensvar ) |
Outputs a PixelMap of the lensing quantities of a fixed grid.
center | center of image |
Npixels | number of pixels in image in on dimension |
resolution | resolution of image in radians |
lensvar | which quantity is to be displayed |
PixelMap< T > Grid::writePixelMap | ( | const double | center[], |
size_t | Nx, | ||
size_t | Ny, | ||
double | resolution, | ||
LensingVariable | lensvar ) |
Outputs a PixelMap of the lensing quantities of a fixed grid.
center | center of image |
Nx | number of pixels in image in on dimension |
Ny | number of pixels in image in on dimension |
resolution | resolution of image in radians |
lensvar | which quantity is to be displayed |
PixelMap< T > Grid::writePixelMap | ( | LensingVariable | lensvar | ) |
With the initial boundaries and resolution, ie no refinement.
Outputs a PixelMap of the lensing quantities of a fixed grid.
lensvar | which quantity is to be displayed |
PixelMap< T > Grid::writePixelMapUniform | ( | const PosType | center[], |
size_t | Nx, | ||
size_t | Ny, | ||
LensingVariable | lensvar ) |
Make a Pixel map of the without distribution the pixels.
This will be faster than Grid::writePixelMap() and Grid::writeFits(). But it puts each grid pixel in one pixelmap pixel and if there are two grid pixels in one pixelmap pixel it uses one at random. This is meant for uniform maps to make equal sized PixelMaps.
center | center of image |
Nx | number of pixels in image in on dimension |
Ny | number of pixels in image in on dimension |
lensvar | which quantity is to be displayed |
void Grid::writePixelMapUniform | ( | PixelMap< T > & | map, |
LensingVariable | lensvar ) |
lensvar | which quantity is to be displayed |
Test if point is in a region of uniform magnification using the kappa and gamma calculated from the rayshooter.
An estimate of the magnification matrix is returned if it returns true. Otherwise the magnification matrix is unspecified.
Magnification matrix elements are considered equal if their difference is smaller than maglimit which is set in the Grid constructor.
quickly refines the grid down to a specific scale at a given point
top is an optional argument that allows for the zooming to start part way down the tree. Default is to start at the root. If the point is not within top or the root nothing is done. The point will not necessarily be in the center of the smallest branch.
center | center of point where grid is refined |
scale | the smallest grid size to which the grid is refined |
top | where on the tree to start, if NULL it will start at the root |