funregions(7)
bestie, welcome to funregions(7) β the SAORD Documentation glow-up of spatial region filtering. π β¨
β¨ NAME β¨
FunRegions β Spatial Region Filtering
πΈ SYNOPSIS πΈ
This document contains a summary of the user interface for spatial region filtering images and tables.
π¦ DESCRIPTION π¦
okay so spatial region filtering is literally how a program picks which parts of an image or which rows of a table (like, say, X-ray events) it wants to process β using cute geometric shapes and boolean combos of those shapes. π when you filter an image, only the pixels that live inside those shapes get processed. when you filter a table, only the rows that land inside those shapes get processed. periodt.
you do image and table filtering with region specifications. a region spec is one or more region expressions β those are geometric shapes β glued together with boolean algebra rules. and yes, region specs can also have comments and local/global processing directives. iykyk.
usually you write region specs in bracket notation, tacked onto the filename of the data you're working with. like:
foo.fits[circle(512,512,100)]
you can also shove your region spec into a file and then pass that filename in bracket notation:
foo.fits[@my.reg]
when region filters get passed in bracket notation like that, the filtering just sets itself up automatically when the file is opened, and all processing goes through the filter. programs can also use the filter library API to open filters explicitly. no big deal. π
β¨ Region Expressions β¨
more specifically, region specifications consist of one or more lines containing:
# comment until end of line
global keyword=value keyword=value ... # set global value(s)
# include the following file in the region descriptor
@file
# use the FITS image as a mask (cannot be used with other regions)
@fitsimage
# each region expression contains shapes separated by operators
[region_expression1], [region_expression2], ...
[region_expression], [region_expression], ...
a single region expression consists of:
# parens and commas are optional, as is the + sign
[+-]shape(num , num , ...) OP1 shape num num num OP2 shape ...
e.g.:
([+-]shape(num , num , ...) && shape num num βͺβͺ shape(num, num)
# a comment can come after a region -- reserved for local properties
[+-]shape(num , num , ...) # local properties go here, e.g. color=red
so a region descriptor is just one or more region expressions (or regions) separated by commas, new-lines, or semi-colons. each region is one or more geometric shapes combined with standard boolean operations. several types of shapes are supported, including:
shape: arguments:
----- ----------------------------------------
ANNULUS xcenter ycenter inner_radius outer_radius
BOX xcenter ycenter xwidth yheight (angle)
CIRCLE xcenter ycenter radius
ELLIPSE xcenter ycenter xwidth yheight (angle)
FIELD none
LINE x1 y1 x2 y2
PIE xcenter ycenter angle1 angle2
POINT x1 y1
POLYGON x1 y1 x2 y2 ... xn yn
plus, these regions also accept accelerator syntax:
shape arguments
----- ------------------------------------------
ANNULUS xcenter ycenter radius1 radius2 ... radiusn
ANNULUS xcenter ycenter inner_radius outer_radius n=[number]
BOX xcenter ycenter xw1 yh1 xw2 yh2 ... xwn yhn (angle)
BOX xcenter ycenter xwlo yhlo xwhi yhhi n=[number] (angle)
CIRCLE xcenter ycenter r1 r2 ... rn # same as annulus
CIRCLE xcenter ycenter rinner router n=[number] # same as annulus
ELLIPSE xcenter ycenter xw1 yh1 xw2 yh2 ... xwn yhn (angle)
ELLIPSE xcenter ycenter xwlo yhlo xwhi yhhi n=[number] (angle)
PIE xcenter ycenter angle1 angle2 (angle3) (angle4) (angle5) ...
PIE xcenter ycenter angle1 angle2 (n=[number])
POINT x1 y1 x2 y2 ... xn yn
note that the circle accelerators are literally just aliases for the annulus accelerators. see region geometry for more info about accelerators.
finally, these are combos of pie with different shapes (called panda for "Pie AND Annulus") that let you specify radial sections easily:
shape: arguments:
----- ---------
PANDA xcen ycen ang1 ang2 nang irad orad nrad # circular
CPANDA xcen ycen ang1 ang2 nang irad orad nrad # circular
BPANDA xcen ycen ang1 ang2 nang xwlo yhlo xwhi yhhi nrad (ang) # box
EPANDA xcen ycen ang1 ang2 nang xwlo yhlo xwhi yhhi nrad (ang) # ellipse
the panda and cpanda specify combinations of annulus and circle with pie, respectively, and give identical results. bpanda combines box and pie, while epanda combines ellipse and pie. see region geometry for more info about pandas.
these "shapes" are ignored by funtools (they're generated by ds9):
shape: arguments:
----- ---------
PROJECTION x1 y1 x2 y2 width # NB: ignored by funtools
RULER x1 y1 x2 y2 # NB: ignored by funtools
TEXT x y # NB: ignored by funtools
GRID # NB: ignored by funtools
TILE # NB: ignored by funtools
COMPASS # NB: ignored by funtools
all arguments to regions are real values; integer values are automatically converted to real where necessary. all angles are in degrees and run from the positive image x-axis to the positive image y-axis. if a rotation angle is part of the associated WCS header, that angle is added implicitly as well.
note that 3-letter abbreviations are supported for all shapes, so you can say "circle" or "cir".
π Columns Used in Region Filtering π
okay so by default, the x,y values in a region expression refer to the two image binning columns β like, the columns you'd use to bin data into an image. for images, that's just the 2 dimensions of the image. for tables, they usually default to x and y but you can change them as needed. for example, in Funtools, you specify new binning columns with a bincols=(col1,col2) statement inside the bracket string on the command line.
you can also specify alternate columns for region filtering with this syntax:
(col1,col2)=region(...)
e.g.:
(X,Y)=annulus(x,y,ri,ro)
(PHA,PI)=circle(x,y,r)
(DX,DY)=ellipse(x,y,a,b[,angle])
π§ Region Algebra π§
(see also Region Algebra for more complete information.)
so you can combine region shapes with boolean operators:
Symbol Operation Use
-------- --------- -----------------------------------
! not Exclude this shape from this region
& or && and Include only the overlap of these shapes
βͺ or βͺβͺ inclusive or Include all of both shapes
^ exclusive or Include both shapes except their overlap
btw the !region syntax has to be combined with another region so we can assign a region id properly. like:
!circle(512,512,10)
is not a legal region because there's no valid region id to work with. to get the full field without a circle, combine it with field(), like:
field() && !circle(512,512,10)
π₯ Region Separators Also Are Operators π₯
like i said before, you can have multiple region expressions in a region descriptor, separated by commas, new-lines, or semi-colons. when you use a separator like that, the boolean OR operator gets automatically generated in its place β but unlike explicitly using the OR operator, the region ID gets incremented (starting from 1).
for example, these two shapes get the same region value:
foo.fits[circle(512,512,10)βͺβͺcircle(400,400,20)]
but these two shapes get different region values:
foo.fits[circle(512,512,10),circle(400,400,20)]
obviously both examples mask the same table rows or pixels. but in programs that care about region ids (like funcnts), they act differently. the explicit OR operator gives you one region expression with two shapes sharing the same region id, and funcnts reports a single region. the comma operator makes funcnts report two region expressions, each with one shape, in its output.
generally, commas separate region expressions you enter in bracket notation on the command line:
# regions are added to the filename in bracket notation
foo.fits[circle(512,512,100),circle(400,400,20)]
new-lines separate region expressions in a file:
# regions usually are separated by new-lines in a file
# use @filename to include this file on the command line
circle(512,512,100)
circle(400,400,20)
semi-colons are there for backward compatibility with the original IRAF/PROS implementation and can be used in either case.
if a pixel is covered by two different region expressions, it gets the mask value of the first region that contains that pixel. that means successive regions do not overwrite previous regions in the mask, like they did with the original PROS regions. so an individual pixel is covered by one and only one region. this means you sometimes have to be careful about the order you define regions in. if region N is fully inside region M, then N should be defined before M, or else it'll be "covered up" by M. π
π« Region Exclusion π«
you can also globally exclude shapes from all the region specifiers in a region descriptor by putting a minus sign before a region:
operator arguments:
-------- -----------
- Globally exclude the region expression following '-' sign
from ALL regions specified in this file
the global exclude region can be used by itself; in that case, field() is implied.
a global exclude is different from a local exclude (i.e. a shape prefixed with the logical not ! symbol) because global excludes are logically performed last, so no region will contain pixels from a globally excluded shape. a local exclude is used in a boolean expression with an include shape, and only excludes pixels from that include shape. global excludes cannot be used in boolean expressions.
π Include Files π
the @filename directive specifies an include file that contains region expressions. this file gets processed as part of the overall region descriptor:
foo.fits[circle(512,512,10),@foo]
A filter include file just... drops text in, no state changes, no drama π
it literally does not change the state of the filter. Which means you can absolutely use it inside an expression. Like, if the file foo1 contains pi==1 and foo2 contains pha==2, then these are all the exact same vibe:
"[@foo1&&@foo2]" is equivalent to "[pi==1&&pha==2]"
"[pha==1βͺβͺ@foo2]" is equivalent to "[pi==1βͺβͺpha==2]"
"[@foo1,@foo2]" is equivalent to "[pi==1,pha==2]"
Okay but bestie, be careful that you specify evaluation order properly using parenthesis, especially if the include file contains multiple filter statements. Like, picture a file with two regions in it, something like:
circle 512 512 10
circle 520 520 10
If you want to include only events (or pixels) that are in these regions and have a pi value of 4, then the correct syntax is:
pi==4&&(@foo)
since this is equivalent to:
pi==4 && (circle 512 512 10 βͺβͺ circle 520 520 10)
If you leave out the parenthesis, you are filtering this statement:
pi==4 && circle 512 512 10 βͺβͺ circle 520 520 10)
which is equivalent to:
(pi==4 && circle 512 512 10) βͺβͺ circle 520 520 10)
And the latter syntax only applies the pi test to the first region π lowkey a trap. Periodt.
For image-style filtering, the @filename can specify an 8-bit or 16-bit FITS image. In this case, the pixel values in the mask image are used as the region mask. The valid pixels in the mask must have positive values. Zero values are excluded from the mask and negative values are not allowed. Moreover, the region id value is taken as the image pixel value and the total number of regions is taken to be the highest pixel value. The dimensions of the image mask must be less than or equal to the image dimensions of the data. The mask will be replicated as needed to match the size of the image. (Thus, best results are obtained when the data dimensions are an even multiple of the mask dimensions.) β¨
An image mask can be used in any image filtering operation, regardless of whether the data is of type image or table. For example, the funcnts program performs image filtering on images or tables, and so FITS image masks are valid input for either type of data in this program. An image mask cannot be used in a program such as fundisp when the input data is a table, because fundisp displays rows of a table and processes these rows using event-style filtering. π«Ά
π Global and Local Properties of Regions π
The ds9 image display program describes a host of properties such as color, font, fix/free state, etc. Such properties can be specified globally (for all regions) or locally (for an individual region). The global keyword specifies properties and qualifiers for all regions, while local properties are specified in comments on the same line as the region:
global color=red
circle(10,10,2)
circle(20,20,3) # color=blue
circle(30,30,4)
The first and third circles will be red, while the second circle will be blue. Note that funtools currently ignores region properties, as they are used in display only. π
π§ Coordinate Systems π§
For each region, it is important to specify the coordinate system used to interpret the region, i.e., to set the context in which position and size values are interpreted. For this purpose, the following keywords are recognized:
PHYSICALβ pixel coords of original file using LTM/LTVIMAGEβ pixel coords of current fileFK4,B1950β sky coordinate systemsFK5,J2000β sky coordinate systemsGALACTICβ sky coordinate systemsECLIPTICβ sky coordinate systemsICRSβ currently same as J2000LINEARβ linear wcs as defined in fileAMPLIFIERβ mosaic coords of original file using ATM/ATVDETECTORβ mosaic coords of original file using DTM/DTV
π Specifying Positions, Sizes, and Angles π
The arguments to region shapes can be floats or integers describing positions and sizes. They can be specified as pure numbers or using explicit formatting directives:
Position arguments:
[num]β context-dependent (see below)[num]dβ degrees[num]rβ radians[num]pβ physical pixels[num]iβ image pixels[num]:[num]:[num]β hms for 'odd' position arguments[num]:[num]:[num]β dms for 'even' position arguments[num]h[num]m[num]sβ explicit hms[num]d[num]m[num]sβ explicit dms
Size arguments:
[num]β context-dependent (see below)[num]"β arc seconds[num]'β arc minutes[num]dβ degrees[num]rβ radians[num]pβ physical pixels[num]iβ image pixels
When a "pure number" (i.e. one without a format directive such as 'd' for 'degrees') is specified, its interpretation depends on the context defined by the 'coordsys' keyword. In general, the rule is:
- All pure numbers have implied units corresponding to the current coordinate system.
- If no such system is explicitly specified, the default system is implicitly assumed to be PHYSICAL.
In practice this means that for IMAGE and PHYSICAL systems, pure numbers are pixels. Otherwise, for all systems other than linear, pure numbers are degrees. For LINEAR systems, pure numbers are in the units of the linear system. This rule covers both positions and sizes. π
The input values to each shape can be specified in several coordinate systems including:
IMAGEβ pixel coords of current fileLINEARβ linear wcs as defined in fileFK4,B1950β various sky coordinate systemsFK5,J2000β various sky coordinate systemsGALACTICβ various sky coordinate systemsECLIPTICβ various sky coordinate systemsICRSβ various sky coordinate systemsPHYSICALβ pixel coords of original file using LTM/LTVAMPLIFIERβ mosaic coords of original file using ATM/ATVDETECTORβ mosaic coords of original file using DTM/DTV
If no coordinate system is specified, PHYSICAL is assumed. PHYSICAL or a World Coordinate System such as J2000 is preferred and most general. The coordinate system specifier should appear at the beginning of the region description, on a separate line (in a file), or followed by a new-line or semicolon; e.g.,
global coordsys physical
circle 6500 9320 200
The use of celestial input units automatically implies WORLD coordinates of the reference image. Thus, if the world coordinate system of the reference image is J2000, then
circle 10:10:0 20:22:0 3'
is equivalent to:
circle 10:10:0 20:22:0 3' # j2000
Note that by using units as described above, you may mix coordinate systems within a region specifier; e.g.,
circle 6500 9320 3' # physical
Note that, for regions which accept a rotation angle:
ellipse (x, y, r1, r2, angle) box(x, y, w, h, angle)
the angle is relative to the specified coordinate system. In particular, if the region is specified in WCS coordinates, the angle is related to the WCS system, not x/y image coordinate axis. For WCS systems with no rotation, this obviously is not an issue. However, some images do define an implicit rotation (e.g., by using a non-zero CROTA value in the WCS parameters) and for these images, the angle will be relative to the WCS axes. In such case, a region specification such as:
fk4;ellipse(22:59:43.985, +58:45:26.92,320", 160", 30)
will not, in general, be the same region specified as:
physical;ellipse(465, 578, 40, 20, 30)
even when positions and sizes match. The angle is relative to WCS axes in the first case, and relative to physical x,y axes in the second. π
More detailed descriptions are available for: Region Geometry, Region Algebra, Region Coordinates, and Region Boundaries. π
β¨ SEE ALSO β¨
See funtools(7) for a list of Funtools help pages π
okay that's the whole thing bestie, you ate it π this page is funregions(7), version 1.4.5, dated April 14, 2011 β yeah she's an elder but she still slays, no cap πΈ go read the other funtools pages and have the best day fr fr π¦π
π¦ where this page comes from
- debian bookworm: libfuntools-dev 1.4.8-1 Β· GPL
- debian trixie: libfuntools-dev 1.4.8-1.1+b2 Β· GPL
- ubuntu jammy: libfuntools-dev 1.4.8-1 Β· GPL
- ubuntu noble: libfuntools-dev 1.4.8-1.1build2 Β· GPL
- ubuntu questing: libfuntools-dev 1.4.8-2
- ubuntu resolute: libfuntools-dev 1.4.8-2build1 Β· GPL
- ubuntu stonking: libfuntools-dev 1.4.8-2build1 Β· GPL
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms