-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored some code to make it easier to find things. Added more det…
…ail to the README.
- Loading branch information
Showing
7 changed files
with
135 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,67 @@ | ||
# gaia-astrometry-net | ||
Code to generate astrometry.net index files from the GAIA catalog | ||
*Code to generate astrometry.net index files from the GAIA DR2 catalog* | ||
|
||
## Prerequisites | ||
- numpy | ||
- sqlalchemy | ||
- astrometry | ||
- astropy | ||
- lcogt_logging | ||
- sep | ||
- pyyaml | ||
|
||
|
||
## Installation | ||
All of the dependencies below install automatically when you run python setup.py | ||
install (or via pip) except *astrometry*. The *astrometry* package is not | ||
currently on PyPi and is provided directly by astrometry.net. This can be installed | ||
by cloning the astrometry.net repo at https://github.com/dstndstn/astrometry.net | ||
and running python setup.py install in the top directory. | ||
|
||
Once the *astrometry* package is installed, the code can be installed in the | ||
usual way by running python setup.py install. | ||
|
||
## Usage | ||
There are two main purposes for the code in this repo. The first is to generate | ||
astrometry.net index files from the GAIA DR2 catalog. The second is wrap | ||
astrometry.net to use the new index files to solve for the astrometry of an | ||
image. | ||
|
||
The index file creation logic is mostly in index_file_creator.py. To create the index files | ||
go into an empty directory and run | ||
``` | ||
create_gaia_index_files | ||
``` | ||
from the command line. | ||
This will then use the network mounted of the GAIA DR2 csv files to create astrometry.net | ||
index files. The first issue is that csv files do not cover consistent patches of the sky. | ||
As such, the first thing that we do is build an SQLite database with all of the positions | ||
and fluxes of the GAIA sources. This DB includes two tables: sources and positions. | ||
The positions table is indexed using an r-tree index so that cone searches are | ||
fast (even for the 1.5 billion GAIA sources). Generating the DB can take a few days | ||
of cpu time to complete. The final DB will be ~200 GB. After we have the queryable | ||
catalog (the DB), we split the catalog into healpixels (see https://healpix.jpl.nasa.gov/). | ||
The sources in each healpixel are stored in a binary table extension of a fits file | ||
that astrometry.net can read. Finally, we use astrometry.net's internal tools | ||
to create index files that astrometry.net can use for solves. We create a range | ||
of index files that have quads for many different image scales | ||
(large field of view to small field of view images). The meta data for the index | ||
files is stored in an ascii file called `gaia-dr2-index-files.dat`. | ||
|
||
Once the index files are created, we need to wrap astrometry.net to use them. | ||
The code to do this is mostly in `solve.py`. | ||
|
||
## Examples | ||
To solve an image using the GAIA astrometry.net index files, you can run | ||
``` | ||
solve-astrometry-gaia --filename {filename} --index-file-path {path} --ra {ra} --dec {dec} --radius {radius} | ||
``` | ||
`filename` is the name of the image to solve. | ||
The `index-file-path` argument should point to the directory with the GAIA astrometry index files. | ||
By default, the code will try to extra RA and DEC from the header, but the | ||
user can manually override those values using `--ra` and `--dec`. The default | ||
search radius is 2 degrees but this can also be overridden by the user. | ||
|
||
## Support | ||
[API documentation]() | ||
[Create an issue](https://issues.lco.global/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import gzip | ||
import logging | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def parse_csv(catalog_file): | ||
with gzip.open(catalog_file, 'rt') as csv_file: | ||
columns = csv_file.readline().split(',') | ||
indices = [columns.index(i) for i in ['ra', 'ra_error', 'dec', 'dec_error', 'phot_g_mean_flux', 'phot_g_mean_flux_error']] | ||
logger.info('Making rows variable') | ||
rows = [parse_row(line, indices) for line in csv_file] | ||
return rows | ||
|
||
|
||
def parse_row(line, indicies): | ||
# This only works for GAIA DR2. We could get the headers from | ||
values = line.split(',') | ||
return (values[index] for index in indicies) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from glob import glob | ||
|
||
import numpy as np | ||
from astropy.io import fits | ||
|
||
|
||
def plot_source_density(): | ||
source_density = np.zeros((1000, 1000)) | ||
merged_catalogs = glob('gaia-fullcatalog*.fits') | ||
for catalog in merged_catalogs: | ||
print(catalog) | ||
# Read in the file | ||
data = fits.getdata(catalog, 1) | ||
# Convert the decs to thetas: theta = 90 - dec | ||
theta = 90 - data['dec'] | ||
# calculate z: z = cos(theta) | ||
z = np.cos(np.deg2rad(theta)) | ||
# if abs(z) < 2/3: | ||
# xs = ra (in radians) | ||
xs = np.deg2rad(data['ra'].copy()) | ||
# ys = (3 pi / 8) z | ||
ys = 3.0 * np.pi / 8.0 * z | ||
# else: | ||
# sigma = 2 - (3 (1 - abs(z)))^1/2 | ||
sigma = 2 - (3 * (1.0 - np.abs(z)))**0.5 | ||
# sigma(-z) = -sigma(z) | ||
sigma[z < 0] = -sigma[z < 0] | ||
# phi_l = ra % pi/2 | ||
phi_l = np.deg2rad(data['ra']) % (np.pi / 2.0) | ||
# xs = ra - (abs(sigma(z)) - 1)(phi_l - pi / 4) | ||
polar_cap = np.abs(z) > (2.0 / 3.0) | ||
xs[polar_cap] = np.deg2rad(data['ra'][polar_cap]) - (np.abs(sigma[polar_cap]) - 1.0)*(phi_l[polar_cap] - (np.pi / 4.0)) | ||
# ys = pi / 4 * sigma(z) | ||
ys[polar_cap] = np.pi / 4.0 * sigma[polar_cap] | ||
source_density += np.histogram2d(xs, ys, bins=(1000, 1000), | ||
range=[[0.0, 2.0 * np.pi], [-np.pi / 2.0, np.pi / 2.0]])[0] | ||
return source_density |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters