Skip to content

Commit

Permalink
classes broken into functions to improve docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sambit-giri committed Aug 21, 2024
1 parent c62e7f5 commit d6281c6
Show file tree
Hide file tree
Showing 2 changed files with 172 additions and 1 deletion.
142 changes: 141 additions & 1 deletion src/AstronomyCalc/cosmo_equations.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,144 @@ def luminosity_dist(self, z=None, a=None):
return dc*(1+z)

def horizon_dist(self):
return self.comoving_dist(self, a=1e-8)
return self.comoving_dist(self, a=1e-8)


def Hubble(param, z=None, a=None):
"""
Calculate the Hubble parameter at a given redshift or scale factor.
Parameters:
param (dict): A dictionary containing cosmological parameters.
z (float, optional): The redshift at which to evaluate the Hubble parameter.
a (float, optional): The scale factor at which to evaluate the Hubble parameter.
Only one of `z` or `a` should be provided.
Returns:
float: The Hubble parameter (H) at the specified redshift or scale factor.
"""
cosmo = CosmoDistances(param)
return cosmo.H(z=z, a=a)

def cosmic_age(param, z=None, a=None):
"""
Calculate the cosmic age at a given redshift or scale factor.
Parameters:
param (dict): A dictionary containing cosmological parameters.
z (float, optional): The redshift at which to calculate the cosmic age.
a (float, optional): The scale factor at which to calculate the cosmic age.
Only one of `z` or `a` should be provided.
Returns:
float: The age of the universe in Gyr at the specified redshift or scale factor.
"""
cosmo = CosmoDistances(param)
return cosmo.age(z=z, a=a)

def Hubble_distance(param):
"""
Calculate the Hubble distance.
Parameters:
param (dict): A dictionary containing cosmological parameters.
Returns:
float: The Hubble distance (c / H0) in Mpc.
"""
cosmo = CosmoDistances(param)
return cosmo.Hubble_dist()

def comoving_distance(param, z=None, a=None):
"""
Calculate the comoving distance at a given redshift or scale factor.
Parameters:
param (dict): A dictionary containing cosmological parameters.
z (float, optional): The redshift at which to calculate the comoving distance.
a (float, optional): The scale factor at which to calculate the comoving distance.
Only one of `z` or `a` should be provided.
Returns:
float: The comoving distance in Mpc at the specified redshift or scale factor.
"""
cosmo = CosmoDistances(param)
return cosmo.comoving_dist(z=z, a=a)

def proper_distance(param, z=None, a=None):
"""
Calculate the proper distance at a given redshift or scale factor.
Parameters:
param (dict): A dictionary containing cosmological parameters.
z (float, optional): The redshift at which to calculate the proper distance.
a (float, optional): The scale factor at which to calculate the proper distance.
Only one of `z` or `a` should be provided.
Returns:
float: The proper distance in Mpc at the specified redshift or scale factor.
"""
cosmo = CosmoDistances(param)
return cosmo.proper_dist(z=z, a=a)

def light_travel_distance(param, z=None, a=None):
"""
Calculate the light travel distance (also known as lookback distance) at a given redshift or scale factor.
Parameters:
param (dict): A dictionary containing cosmological parameters.
z (float, optional): The redshift at which to calculate the light travel distance.
a (float, optional): The scale factor at which to calculate the light travel distance.
Only one of `z` or `a` should be provided.
Returns:
float: The light travel distance in Mpc at the specified redshift or scale factor.
"""
cosmo = CosmoDistances(param)
return cosmo.light_travel_dist(z=z, a=a)

def angular_distance(param, z=None, a=None):
"""
Calculate the angular diameter distance at a given redshift or scale factor.
Parameters:
param (dict): A dictionary containing cosmological parameters.
z (float, optional): The redshift at which to calculate the angular distance.
a (float, optional): The scale factor at which to calculate the angular distance.
Only one of `z` or `a` should be provided.
Returns:
float: The angular diameter distance in Mpc at the specified redshift or scale factor.
"""
cosmo = CosmoDistances(param)
return cosmo.angular_dist(z=z, a=a)

def luminosity_distance(param, z=None, a=None):
"""
Calculate the luminosity distance at a given redshift or scale factor.
Parameters:
param (dict): A dictionary containing cosmological parameters.
z (float, optional): The redshift at which to calculate the luminosity distance.
a (float, optional): The scale factor at which to calculate the luminosity distance.
Only one of `z` or `a` should be provided.
Returns:
float: The luminosity distance in Mpc at the specified redshift or scale factor.
"""
cosmo = CosmoDistances(param)
return cosmo.luminosity_dist(z=z, a=a)

def horizon_distance(param):
"""
Calculate the horizon distance, which is the maximum distance from which light has traveled to the observer
in the age of the universe.
Parameters:
param (dict): A dictionary containing cosmological parameters.
Returns:
float: The horizon distance in Mpc.
"""
cosmo = CosmoDistances(param)
return cosmo.horizon_dist()
31 changes: 31 additions & 0 deletions src/AstronomyCalc/create_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,37 @@ def Hubble1929_data(data_link=None):
# print(df.head())
return np.array(df['distance']), np.array(df['velocity'])

def SPARC_galaxy_rotation_curves_data(filename=None, name=None):
"""
Retrieves the rotation curve data for a specific galaxy from the SPARC dataset.
This function utilizes the SPARC_Galaxy_dataset class to read the rotation curves
of galaxies from the SPARC dataset. The data can be accessed either by directly
providing the filename or by specifying the galaxy name.
Parameters:
filename (str, optional): The path to the rotation curve file. If provided,
this file will be used directly.
name (str, optional): The name of the galaxy for which to retrieve rotation
curve data. If provided, the function will look for
the corresponding file in the dataset.
Returns:
dict: A dictionary containing the rotation curve data. The dictionary has two keys:
- 'values': A dictionary where each key corresponds to a specific quantity
(e.g., 'Rad', 'Vobs') and the value is an array of data for
that quantity.
- 'units': A dictionary mapping each quantity to its unit (e.g., 'kpc',
'km/s').
Raises:
AssertionError: If neither `filename` nor `name` is provided, the function
raises an assertion error, requiring one of the inputs.
"""
SPARC = SPARC_Galaxy_dataset()
data = SPARC.read_rotation_curves(filename=filename, name=name)
return data

class SPARC_Galaxy_dataset:
"""
A class to handle the SPARC Galaxy dataset (http://astroweb.cwru.edu/SPARC/).
Expand Down

0 comments on commit d6281c6

Please sign in to comment.