Skip to content

Commit eff6582

Browse files
authored
Support loading stars from Tycho2 catalog (#909)
1 parent 61ff8a6 commit eff6582

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

ci/tyc_main_head.dat

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
T| 1 13 1| |00 04 30.12|+02 16 02.6| 8.50| | |001.12551719|+02.26739188| | 9.6 | 28.7 | -10.5 | 10.3 | 7.5 | 11.9 | 14.4 | 11.6 |+0.21|+0.18|-0.07|-0.21|+0.00|+0.00|+0.01|-0.12|+0.04|+0.28|116|-0.72| |10.555|0.041| 8.682|0.016|N| 1.560|0.039| |3|10.6| | 90|0.108| 8.57| 8.79| | |Y|B| |143110|225210|B+01 4824 | | |
2+
T| 1 17 1| |00 00 12.20|+01 46 17.4| 9.80| | |000.05081860|+01.77149877|X| 35.1 | -66.2 | -1.2 | 44.0 | 19.6 | 42.2 | 49.9 | 22.7 |+0.02|+0.26|+0.10|+0.04|+0.11|+0.12|+0.16|-0.13|+0.20|+0.10| 98| 4.68| |10.635|0.049| 9.874|0.039|N| 0.677|0.051| |4| 6.7| |112|0.436| 9.46|10.63| | |S|B| |143038|224725|B+00 5079 | | |
3+
T| 1 39 1| |00 09 29.13|+02 18 14.5| 9.39| | |002.37138561|+02.30404128| | 6.4 | 7.9 | -15.7 | 10.9 | 9.5 | 12.0 | 10.3 | 9.0 |+0.10|-0.09|-0.03|-0.17|+0.03|+0.03|+0.02|-0.03|+0.04|+0.16| 97| 0.78| | 9.519|0.020| 9.405|0.026|N| 0.099|0.032| |3| 9.6| | 88|0.345| 9.09| 9.69| | |Y|B| |143198| 490|B+01 6 | | |
4+
T| 1 58 1| |00 05 03.46|+01 02 16.2| 8.81| | |001.26440304|+01.03782998| | 4.4 | 84.1 | -59.9 | 10.3 | 7.6 | 11.0 | 13.7 | 9.7 |+0.22|+0.07|-0.01|-0.33|-0.14|-0.03|-0.13|-0.29|+0.00|+0.15|129| 0.83| 416| 9.735|0.021| 8.890|0.017|N| 0.744|0.022| |3|11.4| |119|0.198| 8.69| 9.07| | |Y|B| |143121|225294|B+00 5085 | | |
5+
T| 1 83 1| |00 06 40.25|+02 06 19.3|10.38| | |001.66771919|+02.10536303| |-105.5 | 36.9 | -8.0 | 36.5 | 26.2 | 38.6 | 38.2 | 26.1 |+0.28|+0.43|+0.23|-0.45|-0.20|-0.25|-0.18|-0.47|-0.09|+0.16|121|-0.23| |11.888|0.131|10.511|0.061|N| 1.163|0.127| |4| 7.9| |122|0.584| 9.97|12.06| | |Z| | | | | | | |
6+
T| 1 150 1| |00 00 32.35|+01 57 20.4|10.53| | |000.13477825|+01.95566981| | 40.2 | -22.3 | 5.6 | 51.8 | 30.0 | 55.5 | 61.1 | 32.3 |+0.04|+0.28|+0.15|-0.16|+0.17|+0.24|+0.16|-0.14|+0.12|-0.11| 82| 1.84| |12.055|0.174|10.659|0.080|N| 1.178|0.175| |5| 5.1| |105|0.712|10.07|12.41| | |Z| | | | | | | |
7+
T| 1 162 1| |00 00 47.28|+02 23 05.8| 9.52| | |000.19699697|+02.38495347| | 18.4 | 40.8 | -12.0 | 14.7 | 10.3 | 17.3 | 19.5 | 13.7 |+0.19|+0.41|+0.15|+0.10|+0.02|+0.25|-0.02|-0.09|+0.06|-0.24|121| 0.12| |10.038|0.026| 9.571|0.027|N| 0.439|0.037| |3|10.8| |114|0.211| 9.34| 9.96| | |Y|B| |143052|224794|B+01 4817 | | |
8+
T| 1 186 1| |00 08 02.73|+02 26 40.4|10.85| | |002.01135430|+02.44455274| | -2.0 | -46.8 | -40.0 | 41.8 | 36.4 | 48.5 | 42.7 | 39.9 |+0.09|+0.04|+0.19|+0.08|-0.15|-0.21|-0.13|+0.04|-0.04|+0.16|101| 2.21| |11.660|0.115|10.922|0.095|N| 0.659|0.126| |4| 6.5| |114|0.720|10.25|13.53| | |Z| | | | | | | |
9+
T| 1 193 1| |00 09 18.82|+02 27 45.0|10.99| | |002.32841415|+02.46250710| |-164.2 | 33.8 | 41.1 | 40.7 | 40.3 | 47.1 | 39.4 | 41.9 |+0.10|+0.08|+0.14|-0.20|+0.10|+0.05|+0.04|-0.02|-0.11|+0.37| 78| 0.72| |11.559|0.111|11.043|0.115|N| 0.484|0.134| |4| 5.9| | 92|0.590|10.34|13.61| | |Z| | | | | | | |
10+
T| 1 194 1| |00 00 06.41|+01 19 55.0| 9.35| | |000.02669915|+01.33195246| | -4.6 | -31.5 | 22.0 | 14.5 | 10.6 | 15.6 | 16.5 | 12.2 |+0.03|+0.12|-0.06|-0.29|+0.13|-0.12|+0.12|-0.12|+0.02|+0.05|140| 0.14| |10.614|0.038| 9.458|0.023|N| 0.989|0.036| |3|11.7| |127|0.241| 9.18| 9.74| | |Y|B| |143036|224711|B+00 5078 | | |

skyfield/data/tycho2.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
URL = 'https://cdsarc.u-strasbg.fr/ftp/cats/I/239/tyc_main.dat'
2+
3+
PANDAS_MESSAGE = """Skyfield needs Pandas to load the Tycho2 catalog
4+
5+
To load the Tycho2 star catalog, Skyfield needs the Pandas data
6+
analysis toolkit. Try installing it using your usual Python package
7+
installer, like "pip install pandas" or "conda install pandas".
8+
"""
9+
10+
_COLUMN_NAMES = (
11+
'Catalog', 'TYC', 'Proxy', 'RAhms', 'DEdms', 'Vmag', '---',
12+
'r_Vmag', 'RAdeg', 'DEdeg', 'AstroRef', 'Plx', 'pmRA',
13+
'pmDE', 'e_RAdeg', 'e_DEdeg', 'e_Plx', 'e_pmRA', 'e_pmDE', 'DE:RA',
14+
'Plx:RA', 'Plx:DE', 'pmRA:RA', 'pmRA:DE', 'pmRA:Plx', 'pmDE:RA',
15+
'pmDE:DE', 'pmDE:Plx', 'pmDE:pmRA', 'Nastro', 'F2', 'HIP', 'BTmag',
16+
'e_BTmag', 'VTmag', 'e_VTmag', 'r_BTmag', 'B-V', 'e_B-V', '---(2)',
17+
'Q', 'Fs', 'Source', 'Nphoto', 'VTscat', 'VTmax', 'VTmin', 'Var',
18+
'VarFlag', 'MultFlag', 'morePhoto', 'm_HIP', 'PPM', 'HD', 'BD', 'CoD',
19+
'CPD', 'Remark',
20+
)
21+
22+
def load_dataframe(fobj):
23+
"""Given an open file for ``tyc_main.dat``, return a parsed dataframe.
24+
25+
If the file is gzipped, it will be automatically uncompressed.
26+
27+
"""
28+
try:
29+
from pandas import read_csv
30+
except ImportError:
31+
raise ImportError(PANDAS_MESSAGE)
32+
33+
fobj.seek(0)
34+
magic = fobj.read(2)
35+
compression = 'gzip' if (magic == b'\x1f\x8b') else None
36+
fobj.seek(0)
37+
38+
df = read_csv(
39+
fobj, sep='|', names=_COLUMN_NAMES, compression=compression,
40+
usecols=['TYC', 'Vmag', 'RAdeg', 'DEdeg', 'Plx', 'pmRA', 'pmDE'],
41+
na_values=[' ', ' ', ' ', ' '],
42+
)
43+
df.columns = (
44+
'tyc', 'magnitude', 'ra_degrees', 'dec_degrees',
45+
'parallax_mas', 'ra_mas_per_year', 'dec_mas_per_year',
46+
)
47+
df = df.assign(
48+
ra_hours = df['ra_degrees'] / 15.0,
49+
epoch_year = 1991.25,
50+
)
51+
return df.set_index('tyc')
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from skyfield import api
2+
from skyfield.data.tycho2 import load_dataframe
3+
4+
def test_dataframe():
5+
with api.load.open('tyc_main_head.dat') as f:
6+
df = load_dataframe(f)
7+
star = api.Star.from_dataframe(df)
8+
assert repr(star) == 'Star(ra shape=10, dec shape=10, ra_mas_per_year shape=10, dec_mas_per_year shape=10, parallax_mas shape=10, epoch shape=10)'

0 commit comments

Comments
 (0)