funfilters(7)

🌸 NAME 🌸

okay bestie, welcome to funfilters β€” the page about Filtering Rows in a Table. πŸ’– It's part of the SAORD Documentation, section 7, so its whole little name tag is funfilters(7).


✨ SYNOPSIS ✨

Real talk, this whole doc is a summary of the user interface for filtering rows in binary tables. That's it, that's the assignment. πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

So, table filtering lets a program pick rows out of a table (think X-ray event list energy) by checking every single row against one or more expressions that involve the columns in that table. When a table gets filtered, only the valid rows that satisfy those expressions get passed through for processing. Everything else? Not invited. πŸ’…

You write a filter expression using bracket notation, just tacked onto the filename of the data you're processing:

foo.fits[pha==1&&pi==2]

You can also stash a region specification inside a file and then hand over that filename in bracket notation:

foo.fits[@my.reg]
⚠️ Filters have to go after the extension and image section information, when that info is present. The correct order is:
  • file[fileinfo,sectioninfo][filters]
  • file[fileinfo,sectioninfo,filters]

where:

  • file is the Funtools file name
  • fileinfo is an ARRAY, EVENT, FITS extension, or FITS index
  • sectioninfo is the image section to extract
  • filters are spatial region and table (row) filters to apply

See Funtools Files for more info on file and image section specifications. πŸ‘‘

🧚 Filter Expressions

Table filtering can be done on columns of data in a FITS binary table or a raw event file. It's accomplished by means of table filter specifications. A table filter specification is made of one or more filter expressions β€” and it can also contain comments and local/global processing directives. Multi-talented, honestly.

More specifically, a filter specification consists of one or more lines containing:

# comment until end of line
# include the following file in the table descriptor
@file
# each row expression can contain filters separated by operators
[filter_expression] BOOLOP [filter_expression2], ...
# each row expression can contain filters separated by the comma operator
[filter_expression1], [filter_expression2], ...
# the special row# keyword allows a range of rows to be processed
row#=m:n
# or a single row
row#=m
# regions are supported -- but are described elsewhere
[spatial_region_expression]

A single filter expression is an arithmetic, logical, or other operation involving one or more column values from a table. Columns can be compared to other columns, to header values, or to numeric constants. Standard math functions can be applied to columns too. And separate filter expressions can be combined using boolean operators. Standard C semantics apply when you're constructing expressions β€” the usual precedence and associativity rules hold sway, no cap:

  • () β€” left to right
  • !! (logical not) β€” right to left
  • ! (bitwise not) - (unary minus) β€” right to left
  • * / β€” left to right
  • + - β€” left to right
  • < <= > >= β€” left to right
  • == != β€” left to right
  • & (bitwise and) β€” left to right
  • ^ (bitwise exclusive or) β€” left to right
  • | (bitwise inclusive or) β€” left to right
  • && (logical and) β€” left to right
  • || (logical or) β€” left to right
  • = β€” right to left

For example, if energy and pha are columns in a table, then these are all valid expressions:

pha>1
energy == pha
(pha>1) && (energy<=2)
max(pha,energy)>=2.5

Comparison values can be integers or floats. Integer comparison values can be written in decimal, octal (with a 0 prefix), hex (with a 0x prefix), or binary (with a 0b prefix). So all of these specify the exact same comparison test of a status mask, it's giving four flavors of one vibe:

(status & 15) == 8           # decimal
(status & 017) == 010        # octal
(status & 0xf) == 0x8        # hex
(status & 0b1111) == 0b1000  # binary

The special keyword row# lets you process a range of rows. When row# is specified, the filter code skips to the designated row and only processes the specified number of rows. The * character can be used as the high limit value to denote processing of the remaining rows. Thus:

row#=100:109

processes 10 rows, starting with row 100 (counting from 1), while:

row#=100:*

specifies that all but the first 99 rows are to be processed. Bye besties, the first 99 didn't make the cut. πŸ™ˆ

Spatial region filtering lets a program select regions of an image or rows of a table (e.g., X-ray events) using simple geometric shapes and boolean combinations of shapes. For the full description of regions, see Spatial Region Filtering.

πŸ’« Separators Also Are Operators

Like I said before, you can put multiple filter expressions in one filter descriptor, separated by commas or new-lines. When a comma or new-line separator is used, the boolean AND operator is automatically generated in its place. So an expression like:

pha==1,pi=2:4

is equivalent to:

(pha==1) && (pi>=2&&pi<=4)
[Note that the behavior of separators is different for filter expressions and spatial region expressions. The former uses AND as the operator, while the latter uses OR. See Combining Region and Table Filters for more information about these conventions and how they are treated when combined.]

🌈 Range Lists

Aside from the standard C syntax, filter expressions can make use of IRAF-style range lists, which specify a range of values. The syntax requires that the column name be followed by an = sign, which is followed by one or more comma-delimited range expressions of the form:

col = vv              # col == vv in range
col = :vv             # col <= vv in range
col = vv:             # col >= vv in range
col = vv1:vv2         # vv1 <= col <= vv2 in range

The vv's above must be numeric constants β€” the right hand side of a range list cannot contain a column name or header value. Sorry, no sneaky column refs in there. 😭

Note that, unlike an ordinary comma separator, the comma separator used between two or more range expressions denotes OR. So when two or more range expressions are combined with a comma separator, the resulting expression is a shortcut for more complicated boolean logic. For example:

col = :3,6:8,10:

is equivalent to:

(col=6 && col =10)

Note also that the single-valued rangelist:

col = val

is equivalent to the C-based filter expression:

col == val

assuming, of course, that val is a numeric constant. πŸ’–

πŸŽ€ Math Operations and Functions

It is permissible to specify C math functions as part of the filter syntax. When the filter parser recognizes a function call, it automatically includes the math.h and links in the C math library. So yes, you can absolutely filter rows with expressions like these:

  • (pi+pha)>(2+log(pi)-pha)
  • min(pi,pha)*14>x
  • max(pi,pha)==(pi+1)
  • feq(pi,pha)
  • div(pi,pha)>0

The function feq(a,b) returns true (1) if the difference between a and b (taken as double precision values) is less than approximately 10E-15.

The function div(a,b) divides a by b, but returns NaN (not a number) if b is 0. It's a safe way to avoid floating point errors when dividing one column by another. Iconic, protective, we love her. 🫢

πŸ“ Include Files

The special @filename directive specifies an include file containing filter expressions. This file is processed as part of the overall filter descriptor:

foo.fits[pha==1,@foo]

⭐ Header Parameters

The filter syntax supports comparison between a column value and a header parameter value of a FITS binary tables (raw event files have no such header). The header parameters can be taken from the binary table header or the primary header. For example, assuming there is a header value MEAN_PHA in one of these headers, you can select photons having exactly this value using:

  • pha==MEAN_PHA

Table filtering is more easily described by means of examples. Consider data containing the following table structure:

  • double TIME
  • int X
  • int Y
  • short PI
  • short PHA
  • int DX
  • int DY

Tables can be filtered on these columns using IRAF/QPOE range syntax or any valid C syntax. The following examples illustrate the possibilities:

  • pha=10
  • pha==10

select rows whose pha value is exactly 10

  • pha=10:50

select rows whose pha value is in the range of 10 to 50

  • pha=10:50,100

select rows whose pha value is in the range of 10 to 50 or is equal to 100

  • pha>=10 && pha<=50

select rows whose pha value is in the range of 10 to 50

  • pi=1,2&&pha>3

select rows whose pha value is 1 or 2 and whose pi value is 3

  • pi=1,2 || pha>3

select rows whose pha value is 1 or 2 or whose pi value is 3

  • pha==pi+1

select rows whose pha value is 1 less than the pi value

  • (pha==pi+1) && (time>50000.0)

select rows whose pha value is 1 less than the pi value and whose time value is greater than 50000

  • (pi+pha)>20

select rows in which the sum of the pi and pha values is greater than 20

  • pi%2==1

select rows in which the pi value is odd

Currently, integer range list limits cannot be specified in binary notation (use decimal, hex, or octal instead). Please contact us if this is a problem. πŸ’€

πŸ”₯ SEE ALSO πŸ”₯

See funtools(7) for a list of Funtools help pages.


and that's a wrap, bestie πŸ’œ this was funfilters(7) from version 1.4.5, dated April 14, 2011 β€” SAORD Documentation, out. slay, go filter some rows. βœ¨πŸ‘‘