#READ ME
#Article: Kordopatis et al. 2022: Stellar ages, masses, extinctions and orbital parameters based on spectroscopic parameters of Gaia DR3
arxiv.org/abs/2206.07937

## Several files are offered, containing subsamples of information: 
# ages_orbits_GDR3_RVS_** is the generic that contains all of the information (orbits and ages when available) for the 30+ million stars. 
# ages_GDR3_GSPSPEC_** contains only the ages for only the GSPspec sample( ~5 million stars). 
# ages_orbits_GDR3_GSPSPEConly_** contains the orbits and the ages for only the GSPspec sample (~5 million stars). 
# orbits_GDR3_RVS_** contains only the orbits for the RVS sample (30+ million stars). 

## Specific sub-samples can be requested at georges.kordopatis ~.at.~ oca.eu

## Python Scripts to read the file .h5 file containing the source_id, orbits, masses, ages etc.. 


### Option 1: 
#importing the necessary modules
import pandas as pd

#reading the data: 
data=pd.read_hdf('ages_orbits_GDR3_RVS_v01.h5', key='Table')

# Checking the name of the columns
print(data.columns)

# extracting the angular momentum
Lz=data['Lz_med_dgeo']

#extracting the ages: 
tau=data['age']


### Option 2 reading only specific columns (faster): 
# importing the modules
import h5py
import astropy
import numpy as np

f = h5py.File("ages_orbits_GDR3_RVS_v01.h5", "r")

num = len(f["Table"]["block0_values"])
print(f["Table"]["block0_items"][()])

age = f["Table"]["block0_values"][:, np.where(f["Table"]["block0_items"][()] == b"age")[0][0]]
age_err = f["Table"]["block0_values"][:, np.where(f["Table"]["block0_items"][()] == b"age_error")[0][0]]
source_id = (f["Table"]["block1_values"])





#Note that the columns 'Teff', 'logg' and 'meta' are the projected teff_gspspec, logg_gspspec* and mh_gspspec* (the star indicates that these values have been calibrated) on the isochrones. 
