mirror of
https://github.com/AllenDowney/AstronomicalData.git
synced 2026-07-28 14:47:02 -07:00
88 KiB
88 KiB
In [1]:
# If we're running on Colab, install libraries
import sys
IN_COLAB = 'google.colab' in sys.modules
if IN_COLAB:
!pip install astroquery astro-gala pyia python-wgetIn [2]:
import os
from wget import download
filename = 'gd1_candidates.hdf5'
path = 'https://github.com/AllenDowney/AstronomicalData/raw/main/data/'
if not os.path.exists(filename):
print(download(path+filename))In [3]:
import pandas as pd
candidate_df = pd.read_hdf(filename, 'candidate_df')In [4]:
import matplotlib.pyplot as plt
x = candidate_df['phi1']
y = candidate_df['phi2']
plt.plot(x, y, 'ko', markersize=0.3, alpha=0.3)
plt.xlabel('ra (degree GD1)')
plt.ylabel('dec (degree GD1)');In [5]:
from astropy.table import Table
candidate_table = Table.from_pandas(candidate_df)
type(candidate_table)Out [5]:
astropy.table.table.Table
In [6]:
table = candidate_table[['source_id']]
table.write('candidate_df.xml', format='votable', overwrite=True)In [7]:
!head candidate_df.xml<?xml version="1.0" encoding="utf-8"?>
<!-- Produced with astropy.io.votable version 4.0.1.post1
http://www.astropy.org/ -->
<VOTABLE version="1.4" xmlns="http://www.ivoa.net/xml/VOTable/v1.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.ivoa.net/xml/VOTable/v1.4">
<RESOURCE type="results">
<TABLE>
<FIELD ID="source_id" datatype="long" name="source_id"/>
<DATA>
<TABLEDATA>
<TR>
In [8]:
!ls -lh candidate_df.xml-rw-rw-r-- 1 downey downey 396K Oct 19 14:48 candidate_df.xml
In [9]:
table = candidate_table[['source_id']]
type(table)Out [9]:
astropy.table.table.Table
In [10]:
column = candidate_table['source_id']
type(column)Out [10]:
astropy.table.column.Column
In [11]:
# writeto(column, 'candidate_df.xml')In [12]:
query = """SELECT *
FROM tap_upload.candidate_df
"""In [13]:
from astroquery.gaia import Gaia
job = Gaia.launch_job_async(query=query,
upload_resource='candidate_df.xml',
upload_table_name='candidate_df')Created TAP+ (v1.2.1) - Connection: Host: gea.esac.esa.int Use HTTPS: True Port: 443 SSL Port: 443 Created TAP+ (v1.2.1) - Connection: Host: geadata.esac.esa.int Use HTTPS: True Port: 443 SSL Port: 443 INFO: Query finished. [astroquery.utils.tap.core]
In [14]:
results = job.get_results()
resultsOut [14]:
Table length=7346
| source_id |
|---|
| int64 |
| 635559124339440000 |
| 635860218726658176 |
| 635674126383965568 |
| 635535454774983040 |
| 635497276810313600 |
| 635614168640132864 |
| 635821843194387840 |
| 635551706931167104 |
| 635518889086133376 |
| 635580294233854464 |
| ... |
| 612282738058264960 |
| 612485911486166656 |
| 612386332668697600 |
| 612296172717818624 |
| 612250375480101760 |
| 612394926899159168 |
| 612288854091187712 |
| 612428870024913152 |
| 612256418500423168 |
| 612429144902815104 |
In [15]:
len(candidate_table), len(results)Out [15]:
(7346, 7346)
In [16]:
set(candidate_table['source_id']) == set(results['source_id'])Out [16]:
True
In [17]:
query1 = """SELECT *
FROM gaiadr2.panstarrs1_best_neighbour as best
JOIN tap_upload.candidate_df as candidate_df
ON best.source_id = candidate_df.source_id
"""In [18]:
job1 = Gaia.launch_job_async(query=query1,
upload_resource='candidate_df.xml',
upload_table_name='candidate_df')INFO: Query finished. [astroquery.utils.tap.core]
In [19]:
results1 = job1.get_results()
results1Out [19]:
Table length=3724
| source_id | original_ext_source_id | angular_distance | number_of_neighbours | number_of_mates | best_neighbour_multiplicity | gaia_astrometric_params | source_id_2 |
|---|---|---|---|---|---|---|---|
| arcsec | |||||||
| int64 | int64 | float64 | int32 | int16 | int16 | int16 | int64 |
| 635860218726658176 | 130911385187671349 | 0.053667035895467084 | 1 | 0 | 1 | 5 | 635860218726658176 |
| 635674126383965568 | 130831388428488720 | 0.038810268141577516 | 1 | 0 | 1 | 5 | 635674126383965568 |
| 635535454774983040 | 130631378377657369 | 0.034323028828991076 | 1 | 0 | 1 | 5 | 635535454774983040 |
| 635497276810313600 | 130811380445631930 | 0.04720255413250006 | 1 | 0 | 1 | 5 | 635497276810313600 |
| 635614168640132864 | 130571395922140135 | 0.020304189709964143 | 1 | 0 | 1 | 5 | 635614168640132864 |
| 635598607974369792 | 130341392091279513 | 0.036524626853403054 | 1 | 0 | 1 | 5 | 635598607974369792 |
| 635737661835496576 | 131001399333502136 | 0.036626827820716606 | 1 | 0 | 1 | 5 | 635737661835496576 |
| 635850945892748672 | 132011398654934147 | 0.021178742393378396 | 1 | 0 | 1 | 5 | 635850945892748672 |
| 635600532119713664 | 130421392285893623 | 0.04518820915043015 | 1 | 0 | 1 | 5 | 635600532119713664 |
| ... | ... | ... | ... | ... | ... | ... | ... |
| 612241781249124608 | 129751343755995561 | 0.04235715830001815 | 1 | 0 | 1 | 5 | 612241781249124608 |
| 612332147361443072 | 130141341458538777 | 0.02265249859012977 | 1 | 0 | 1 | 5 | 612332147361443072 |
| 612426744016802432 | 130521346852465656 | 0.03247653009961843 | 1 | 0 | 1 | 5 | 612426744016802432 |
| 612331739340341760 | 130111341217793839 | 0.036064240818025735 | 1 | 0 | 1 | 5 | 612331739340341760 |
| 612282738058264960 | 129741340445933519 | 0.025293237353496898 | 1 | 0 | 1 | 5 | 612282738058264960 |
| 612386332668697600 | 130351354570219774 | 0.02010316001403086 | 1 | 0 | 1 | 5 | 612386332668697600 |
| 612296172717818624 | 129691338006168780 | 0.051264212025836205 | 1 | 0 | 1 | 5 | 612296172717818624 |
| 612250375480101760 | 129741346475897464 | 0.031783740347530905 | 1 | 0 | 1 | 5 | 612250375480101760 |
| 612394926899159168 | 130581355199751795 | 0.04019174830546698 | 1 | 0 | 1 | 5 | 612394926899159168 |
| 612256418500423168 | 129931349075297310 | 0.009242789669513156 | 1 | 0 | 1 | 5 | 612256418500423168 |
In [20]:
results1.colnamesOut [20]:
['source_id', 'original_ext_source_id', 'angular_distance', 'number_of_neighbours', 'number_of_mates', 'best_neighbour_multiplicity', 'gaia_astrometric_params', 'source_id_2']
In [21]:
len(results1)Out [21]:
3724
In [22]:
import pandas as pd
nn = pd.Series(results1['best_neighbour_multiplicity'])
nn.value_counts()Out [22]:
1 3724 dtype: int64
In [23]:
nm = pd.Series(results1['number_of_mates'])
nm.value_counts()Out [23]:
0 3724 dtype: int64
In [24]:
# Solution
table = results1[['source_id', 'original_ext_source_id']]
table.write('external.xml', format='votable', overwrite=True)In [25]:
!head external.xml<?xml version="1.0" encoding="utf-8"?>
<!-- Produced with astropy.io.votable version 4.0.1.post1
http://www.astropy.org/ -->
<VOTABLE version="1.4" xmlns="http://www.ivoa.net/xml/VOTable/v1.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.ivoa.net/xml/VOTable/v1.4">
<RESOURCE type="results">
<TABLE>
<FIELD ID="source_id" datatype="long" name="source_id" ucd="meta.id;meta.main">
<DESCRIPTION>
Unique Gaia source identifier
</DESCRIPTION>
In [26]:
# Solution
query2 = """SELECT *
FROM tap_upload.external as external
"""In [27]:
# Solution
query2 = """SELECT TOP 10 *
FROM gaiadr2.panstarrs1_original_valid
"""In [28]:
# Solution
query2 = """SELECT *
FROM gaiadr2.panstarrs1_original_valid as ps
JOIN tap_upload.external as external
ON ps.obj_id = external.original_ext_source_id
"""In [29]:
# Solution
query2 = """SELECT
external.source_id, ps.g_mean_psf_mag, ps.i_mean_psf_mag
FROM gaiadr2.panstarrs1_original_valid as ps
JOIN tap_upload.external as external
ON ps.obj_id = external.original_ext_source_id
"""In [30]:
print(query2)SELECT external.source_id, ps.g_mean_psf_mag, ps.i_mean_psf_mag FROM gaiadr2.panstarrs1_original_valid as ps JOIN tap_upload.external as external ON ps.obj_id = external.original_ext_source_id
In [31]:
job2 = Gaia.launch_job_async(query=query2,
upload_resource='external.xml',
upload_table_name='external')INFO: Query finished. [astroquery.utils.tap.core]
In [32]:
results2 = job2.get_results()
results2Out [32]:
Table length=3724
| source_id | g_mean_psf_mag | i_mean_psf_mag |
|---|---|---|
| mag | ||
| int64 | float64 | float64 |
| 635860218726658176 | 17.8978004455566 | 17.5174007415771 |
| 635674126383965568 | 19.2873001098633 | 17.6781005859375 |
| 635535454774983040 | 16.9237995147705 | 16.478099822998 |
| 635497276810313600 | 19.9242000579834 | 18.3339996337891 |
| 635614168640132864 | 16.1515998840332 | 14.6662998199463 |
| 635598607974369792 | 16.5223999023438 | 16.1375007629395 |
| 635737661835496576 | 14.5032997131348 | 13.9849004745483 |
| 635850945892748672 | 16.5174999237061 | 16.0450000762939 |
| 635600532119713664 | 20.4505996704102 | 19.5177001953125 |
| ... | ... | ... |
| 612241781249124608 | 20.2343997955322 | 18.6518001556396 |
| 612332147361443072 | 21.3848991394043 | 20.3076000213623 |
| 612426744016802432 | 17.8281002044678 | 17.4281005859375 |
| 612331739340341760 | 21.8656997680664 | 19.5223007202148 |
| 612282738058264960 | 22.5151996612549 | 19.9743995666504 |
| 612386332668697600 | 19.3792991638184 | 17.9923000335693 |
| 612296172717818624 | 17.4944000244141 | 16.926700592041 |
| 612250375480101760 | 15.3330001831055 | 14.6280002593994 |
| 612394926899159168 | 16.4414005279541 | 15.8212003707886 |
| 612256418500423168 | 20.8715991973877 | 19.9612007141113 |
In [33]:
filename = 'gd1_photo.fits'
results2.write(filename, overwrite=True)In [34]:
!ls -lh gd1_photo.fits-rw-rw-r-- 1 downey downey 96K Oct 19 14:49 gd1_photo.fits
In [ ]:
