Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

IRSA Tutorials

Analyzing cloud-hosted AllWISE Source Catalog in Parquet format

Learning Goals

Introduction

This notebook demonstrates access to the HEALPix-partitioned (order 5), Apache Parquet version of the AllWISE Source Catalog. The catalog is available through the AWS Open Data program, as part of the NASA Open-Source Science Initiative. Access is free and no special permissions or credentials are required.

Parquet is convenient for large astronomical catalogs in part because the storage format supports efficient database-style queries on the files themselves, without having to load the catalog into a database (or into memory) first. The AllWISE catalog is fairly large at 340 GB. The examples below demonstrate different methods that can be used to query the catalog, filtering the data and loading only the results. Each method accesses the parquet files a bit differently and is useful for different types of queries.

Imports

1. Setup catalog paths and query filters

This AllWISE catalog is stored in an AWS S3 cloud storage bucket. To connect to an S3 bucket we just need to point the reader at S3 instead of the local filesystem. (Here, a “reader” is a python library that reads parquet files.) We’ll use pyarrow.fs.S3FileSystem for this because it is recognized by every reader in examples below, and we’re already using pyarrow. (s3fs is another common option.) To access without credentials, we’ll use the keyword argument anonymous=True. More information about accessing S3 buckets can be found at IRSA cloud access introduction.

These limits will be used to query the catalog using specific filters created in examples below. The Schema Access section (below) shows how to access column names and other schema information.

The catalog is partitioned by HEALPix pixel index at order 5. Queries can be most efficient when a filter on the partition column is included, since the reader can skip those partitions entirely. Thus, for queries that include ra/dec constraints, we can usually speed up load times significantly by including a constraint on the HEALPix order 5 pixel index. The required pixel indexes can be calculated using hpgeom, as demonstrated here.

2. Pandas with basic filters (magnitude limit and ra/dec polygon)

Example 1: Load using pandas.read_parquet. Filter for magnitudes above our w1mpro limit and a sky-area limited to the ra/dec polygon.

Pandas actually uses either pyarrow or fastparquet to interact with parquet files. We’ll choose pyarrow (the default). For filter options, see the filters arg description in ParquetDataset.

3. Pyarrow with advanced filters (color-color cuts for AGN)

Example 2: Load using pyarrow.dataset.parquet_dataset and convert to pandas. Useful for:

  1. advanced filters that combine, compare, and/or create new columns. (this example)

  2. speed. This method is more efficient at “discovering” the dataset than pandas. It also provides a persistent dataset object that can be reused for future queries, where pandas must re-discover the dataset every time. (this example and Example 3)

This example filters the catalog for AGN by making cuts in color-color space using the selection limits from Mateos et al. (2012). This is a more complicated filter than in Example 1 (it requires both constructing new columns and comparing values between columns) but this load is generally faster, demonstrating the efficiency of this method.

For basic info about the columns and filter arguments, see Scanner. The construction of columns/filters is more involved than before because they must be passed as Expressions, and all operations must be done using pyarrow.compute functions and fields. This is demonstrated below. Note that the catalog uses a file naming scheme called “hive”, which the reader uses to identify partitions. In other examples this is recognized automatically, but here we must pass it explicitly.

4. Nearest-neighbor search (using pyarrow and astropy)

Example 3: Spatial search using Astropy. Nearest-neighbor searches and cone searches generally use the on-sky separation distance to determine the matches. It would be cumbersome to construct the new column and filter on it using the methods shown above because the separation distance is a fairly complicated function of ra and dec. However, we can get pretty fast results by filtering down to the HEALPix pixels that cover the region, loading all the data in those partitions, and then using astropy to compute the separations and find the matches.

Here, we’ll search for the 3 nearest neighbors to each of the 4 corners of our ra/dec polygon. We’ll load the data with pyarrow because because it makes this query significantly faster than with pandas (see explanation in Example 2). (Note that astropy can also read parquet, but it can only read a single file at a time and so is less convenient.) We’ll use astropy.coordinates.SkyCoord.match_to_catalog_sky to do the actual nearest neighbor search.

Find the 3 nearest neighbors of each corner:

Load all the data (all columns) for all nearest neighbors:

5. Schema Access

The schema can be viewed online and also accessed from the parquet catalog itself. The example below loads it using the _common_metadata file and pyarrow.dataset.parquet_dataset. Note that the schema can also be accessed from the metadata in the footer of each Parquet file and from the _metadata file, but the method used here is generally faster and easier. In addition, this _common_metadata file has extra information (units and descriptions) stored in the custom metadata of each column.


About this notebook

Updated: 2023-07-27

Contact: the IRSA Helpdesk with questions or reporting problems.