ioutils.ephemeris.filter_ephem
ioutils.ephemeris.filter_ephem(
filelist,
dtypes=None,
filter_per_file=True,
output=None,
overwrite=False,
columns=None,
coord_map=None,
*,
filters=None,
**filter_kwargs,
)Filter ephemeris parquet files and optionally save the result.
This function loads compacted ephemeris Parquet files, applies filters based on column values, and returns the filtered DataFrame. It can process files individually or concatenate first, and optionally save the result.
Parameters
filelist : str, Path, or list-like-
Files to filter. Can be:
- Glob pattern string (e.g., ’data/*.parquet’)
- Single file path
- List of file paths
dtypes : dict, default = None-
Dictionary mapping column names to (factor, stored_dtype, navalue, desired_dtype). If None, uses EPH_DTYPES_BASE.
filter_per_file : bool, default = True-
If True (default), apply filters to each file separately then concatenate. If False, load all files first, decode, concatenate, then filter once. Compact integer missing masks are preserved during filtering even if the requested output dtype represents missing values as zero. Use True for better memory efficiency with large datasets.
output : str or Path, default = None-
Path to save the filtered result as Parquet. If None, result is not saved.
overwrite : bool, default = False-
If True, overwrite existing output file. Default is False.
columns : list of str, default = None-
Columns to load and return. Use original column names.
coord_map : dict, default = None-
Mapping from coord_name to (lon_col, lat_col). If None, uses DEFAULT_COORD_MAP.
filters : str, list, or pqfilt expression, default = None-
Filter using original column names, in any format accepted by
load_compact_parq_ephem: PQfilt strings or expression trees, flat tuple lists (AND), or lists of tuple lists (OR of AND groups). Repeated columns, parentheses, AND (&), OR (|), and NOT (~) are supported. Combined with keyword filters using AND. **filter_kwargs :-
Filter conditions as keyword arguments. Each kwarg becomes a filter:
- Column name as key
- Filter value as value (see formats below)
Supported filter formats:
Comparison operators (as tuples)::
filter_ephem(files, vmag=('<', 20)) filter_ephem(files, filter_per_file=False, dec=('>', 30), ra=('<=', 180))Equality/inequality::
filter_ephem(files, desig=123) # Equal to filter_ephem(files, desig=('!=', 123)) # Not equalMembership (lists or tuples without operator)::
filter_ephem(files, desig=[1, 2, 3]) # desig in [1, 2, 3] filter_ephem(files, desig=(1, 2, 3)) # desig in (1, 2, 3) filter_ephem(files, desig=('not in', [1, 2, 3]))A two-item tuple is interpreted as
(operator, value)only when its first item is a supported operator; otherwise it is membership.Supported operators: ‘>’, ‘>=’, ‘<’, ‘<=’, ‘==’, ‘!=’, ‘in’, ‘not in’, ‘is null’, ‘is not null’.
Returns
: pd.DataFrame-
Filtered ephemeris DataFrame with original column names and values.
Raises
: FileNotFoundError-
If no files match the glob pattern or file list is empty.
: FileExistsError-
If output file exists and overwrite=False.
: ValueError-
If filter syntax is invalid or filters on coordinate columns.
Examples
Filter by magnitude and designation::
df = filter_ephem('data/*.parquet', vmag=('<', 20), desig=[1, 2, 3])
Filter and save to file::
df = filter_ephem(
'data/*.parquet',
filters='vmag > 10 & vmag < 20',
output='filtered.parquet'
)
Load all files first, then filter::
df = filter_ephem(
['file1.parquet', 'file2.parquet'],
filter_per_file=False,
alpha=('>', 10)
)
Notes
- Coordinate columns (ra, dec, etc.) cannot be pre-filtered during file loading due to HEALPix encoding. To filter on coordinates, use filter_per_file=False or filter the returned DataFrame manually.
- When filter_per_file=True, filters are applied during Parquet read for better memory efficiency.
- Missing values (nulls, NaNs, and compact integer sentinels) do not satisfy comparisons, including negated comparisons. Use
is nulloris not nullto test missingness. Another OR branch can still match. Both modes use PQfilt predicates with these ephemeris missing-value rules. - Scaled pushdown thresholds can round differently from decoded values at quantization boundaries. For exact comparisons against loaded values, use
filter_per_file=False(e.g., a stored -99 with factor 360 decodes to -0.275, whose floating-point product with 360 is not exactly -99).