How do I tabulate the luminosity distances for all the galaxies in the form of .csv? The code for this bit is at the very last one. Thank you!
seed = 170777306
from astropy.io import ascii
from astropy.cosmology import FlatLambdaCDM
import matplotlib.pyplot as plt
import numpy as np
#Read in data file
table_file = "galaxy_data.csv"
data = ascii.read(table_file)
#Set up cosmology for later calculating luminosity distances
cosmo = FlatLambdaCDM(H0=70, Om0=0.3, Tcmb0=2.725)
#Print information on table length (i.e., number of galaxies) and columns
print(data.info)
# Print some information for random galaxy index
rng = np.random.default_rng(seed)
a = rng.integers(low=0,high=10000)
b = rng.integers(low=0,high=10000)
print('The object ID of galaxy indexed ',a,'is : ',data['objID'][a])
print('The object ID of galaxy indexed ',b,'is : ',data['objID'][b])
print('RA of galaxy indexed',a,'is: ',data['RA'][a])
print('RA of galaxy indexed',b,'is: ',data['RA'][b])
#Calculate and print luminosity distance for Galaxy A
lumDist = cosmo.luminosity_distance(data['redshift'][a]) #returns in Mpc
print('The redshift of galaxy indexed ',a,'is :',data['redshift'][a])
print('At this redshift, for our cosmology, the luminosity distance (in Mpc) is: ',lumDist.value)
#Calculate and print luminosity distance for Galaxy B
lumDist = cosmo.luminosity_distance(data['redshift'][b]) #returns in Mpc
print('The redshift of galaxy indexed ',b,'is :',data['redshift'][b])
print('At this redshift, for our cosmology, the luminosity distance (in Mpc) is: ',lumDist.value)
#Print RA and DEC of the first 10 galaxies (rows)
print("RA and DEC of first 10 galaxies")
print(data['RA','DEC'][0:10]) #print first 10 rows of columns RA and DEC (this prints rows 0->9)
#Print RA and DEC of all galaxies with redshift z<0.01 and h-band magnitude <17
selected_gals = np.where((data['redshift']<0.01) & (data['g']<17))
print("RA and DEC of galaxies with z<0.01 and g<17")
print(data['RA','DEC'][selected_gals])
#Calculate and print luminosity distance for all galaxies
lumDist = cosmo.luminosity_distance(data['redshift']) #returns in Mpc
print('The redshifts of all the galaxies:' ,data['redshift'])
print('At these redshifts, for our cosmology, the luminosity distances (in Mpc): ',lumDist.value)
I need to export it in order to tabulate it as there are 10000 rows so it's impossible to do it manually.