| Title: | Cosmic Insights: Statistical Frameworks for Astronomers |
|---|---|
| Description: | A comprehensive toolkit for astronomical and cosmological computations. Provides functions for angular coordinate conversions (degrees, hours-minutes-seconds, degrees-minutes-seconds, and radians), access to fundamental physical constants, queries to the Gaia Archive TAP (Table Access Protocol) service, cosmological distance calculations, early-universe thermal physics including photon density and 'Saha' equation solutions, and the Drake equation for estimating the number of communicating extraterrestrial civilisations in the Milky Way. |
| Authors: | Samrit Pramanik [aut, cre] (ORCID: <https://orcid.org/0000-0003-2055-9007>), Kazi Abu Rousan [aut] (ORCID: <https://orcid.org/0000-0002-7906-2030>) |
| Maintainer: | Samrit Pramanik <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.0 |
| Built: | 2026-06-07 18:07:45 UTC |
| Source: | https://github.com/samrit2442/astronomr |
Retrieves the value and unit of a specified physical constant from the
constants_df dataset. You can search by the constant's name and
choose whether to retrieve the value in SI units or natural units.
constant_value(constant_name, unit = "SI")constant_value(constant_name, unit = "SI")
constant_name |
Character. The name (or part of the name) of the constant to search for. Case-insensitive and partial matches are allowed. |
unit |
Character. The unit system to retrieve the constant in. Options are:
|
A list containing:
name: The full name of the constant.
value: The numeric value of the constant.
unit: The unit string for the selected unit system.
constant_value("speed of light", unit = "SI") constant_value("planck", unit = "SI") constant_value("electron mass", unit = "Natural")constant_value("speed of light", unit = "SI") constant_value("planck", unit = "SI") constant_value("electron mass", unit = "Natural")
A dataset containing commonly used physical constants in both SI units and natural units. The dataset includes the constant's name, symbol, value in SI units, SI unit, value in natural units, and natural unit representation.
constants_dfconstants_df
A tibble with 19 rows and 6 columns:
Character. Name of the physical constant.
Character. Symbol representing the constant.
Numeric. The value of the constant in SI units.
Character. The SI unit for the constant.
Numeric. The value of the constant in natural units.
Character. The unit of the constant in natural units.
constants_dfconstants_df
Converts a decimal degree angle to the Degrees-Minutes-Seconds (DMS) format commonly used in astronomy for expressing declination and other angles.
deg_to_dms(deg, type = "cat", digit = 5)deg_to_dms(deg, type = "cat", digit = 5)
deg |
Numeric vector of angles in decimal degrees. All values must be between -90 and 90. |
type |
Character string specifying the output format. Options are:
|
digit |
Integer specifying the number of digits to round the seconds
to. Default is |
When type = "cat", prints the DMS string and returns
NULL invisibly. When type = "mat", returns a character
matrix with columns SIGN, DEG, MIN, and SEC.
deg_to_dms(45.5042) deg_to_dms(-12.5, type = "mat") deg_to_dms(c(10.25, 45.5), type = "mat")deg_to_dms(45.5042) deg_to_dms(-12.5, type = "mat") deg_to_dms(c(10.25, 45.5), type = "mat")
Converts a decimal degree angle to Hours-Minutes-Seconds (HMS) format, which is used in astronomy to express Right Ascension (RA).
deg_to_hms(deg, type = "cat", digit = 5)deg_to_hms(deg, type = "cat", digit = 5)
deg |
Numeric vector of angles in decimal degrees. Values can range from 0 to 360. |
type |
Character string specifying the output format. Options are:
|
digit |
Integer specifying the number of decimal places to round
seconds to. Default is |
When type = "cat", prints the HMS string and returns
NULL invisibly. When type = "mat", returns a numeric matrix
with columns HRS, MIN, and SEC.
deg_to_hms(deg = 45) deg_to_hms(deg = 45, type = "mat") deg_to_hms(deg = 177.74208, digit = 3)deg_to_hms(deg = 45) deg_to_hms(deg = 45, type = "mat") deg_to_hms(deg = 177.74208, digit = 3)
Converts angles from degrees to radians. Supports vectorized input.
deg2rad(deg)deg2rad(deg)
deg |
Numeric. The angle(s) in degrees to convert to radians. |
Numeric. The corresponding angle(s) in radians.
deg2rad(180) deg2rad(c(0, 90, 180))deg2rad(180) deg2rad(c(0, 90, 180))
Converts an angle expressed in Degrees-Minutes-Seconds (DMS) format to decimal degrees. Accepts either separate numeric arguments or a single formatted string.
dms_to_deg(d, m, s, digit = 5)dms_to_deg(d, m, s, digit = 5)
d |
Numeric or character. The degrees component. If a single character
string is provided (e.g., |
m |
Numeric. The minutes component. Must be less than 60. Optional when
|
s |
Numeric. The seconds component. Must be less than 60. Optional when
|
digit |
Integer. Number of decimal places to round the result to.
Default is |
Numeric. The angle in decimal degrees.
dms_to_deg(d = 12, m = 34, s = 56) dms_to_deg(d = "12\u00B034'56\"", digit = 3)dms_to_deg(d = 12, m = 34, s = 56) dms_to_deg(d = "12\u00B034'56\"", digit = 3)
Computes **N**, the estimated number of active, technologically advanced civilizations capable of interstellar communication in the Milky Way, using the Drake equation:
drake_equation( R_star = 1.5, fp = 1, ne = 0.4, fl = 1, fi = 1, fc = 0.1, L = 1000 )drake_equation( R_star = 1.5, fp = 1, ne = 0.4, fl = 1, fi = 1, fc = 0.1, L = 1000 )
R_star |
Numeric. Average rate of star formation per year in the Milky
Way (stars yr |
fp |
Numeric. Fraction of stars that have planetary systems.
Must be in |
ne |
Numeric. Mean number of planets per planetary system that
could potentially support life (Earth-like / habitable-zone planets).
Default: |
fl |
Numeric. Fraction of suitable planets on which life actually
appears. Must be in |
fi |
Numeric. Fraction of life-bearing planets on which intelligent
life evolves. Must be in |
fc |
Numeric. Fraction of intelligent civilizations that develop
detectable communication technology. Must be in |
L |
Numeric. Mean longevity (years) of a communicating
civilization. Default: |
Default values reflect widely cited contemporary estimates (see References).
All fraction parameters must lie in .
A named list with the following elements:
NNumeric. Estimated number of communicating civilizations.
inputsNamed numeric vector of all seven input parameters.
equationCharacter. Human-readable form of the equation with values substituted.
interpretationCharacter. A qualitative interpretation of N
spanning six tiers from effectively zero () to
galaxy teeming with life ().
Drake, F. D. (1961). Discussion at the first SETI conference, Green Bank, West Virginia. NRAO.
Vakoch, D. A., & Dowd, M. F. (Eds.) (2015). The Drake Equation: Estimating the Prevalence of Extraterrestrial Life through the Ages. Cambridge University Press.
# Using all defaults (optimistic estimate) drake_equation() # Pessimistic "Rare Earth" scenario drake_equation(R_star = 1.5, fp = 1.0, ne = 0.4, fl = 0.01, fi = 0.01, fc = 0.01, L = 304) # Custom values result <- drake_equation(R_star = 3, fp = 0.9, ne = 0.5, fl = 0.5, fi = 0.1, fc = 0.1, L = 10000) result$N# Using all defaults (optimistic estimate) drake_equation() # Pessimistic "Rare Earth" scenario drake_equation(R_star = 1.5, fp = 1.0, ne = 0.4, fl = 0.01, fi = 0.01, fc = 0.01, L = 304) # Custom values result <- drake_equation(R_star = 3, fp = 0.9, ne = 0.5, fl = 0.5, fi = 0.1, fc = 0.1, L = 10000) result$N
Queries the Gaia Archive TAP service to retrieve stellar data based on specified variables and filter conditions. Uses the Gaia Early Data Release 3 (EDR3) catalog.
get_gaia_data(vars, condition)get_gaia_data(vars, condition)
vars |
A character string specifying the variables (columns) to
retrieve, separated by commas (e.g., |
condition |
A character string specifying the SQL WHERE clause used to
filter rows (e.g., |
This function sends a synchronous ADQL query to the Gaia Archive TAP service at https://gea.esac.esa.int/tap-server/tap/sync. An internet connection is required.
A data frame containing the requested columns for all rows matching
condition.
vars <- "source_id, ra, dec, phot_bp_mean_mag, phot_rp_mean_mag, parallax" condition <- "parallax > 40" result <- get_gaia_data(vars, condition) head(result)vars <- "source_id, ra, dec, phot_bp_mean_mag, phot_rp_mean_mag, parallax" condition <- "parallax > 40" result <- get_gaia_data(vars, condition) head(result)
Converts an angle expressed in Hours-Minutes-Seconds (HMS) format to decimal degrees. Accepts either separate numeric arguments or a single formatted string.
hms_to_deg(h, m, s, digit = 5)hms_to_deg(h, m, s, digit = 5)
h |
Numeric or character. The hours component. If a single character
string is provided (e.g., |
m |
Numeric. The minutes component. Optional when |
s |
Numeric. The seconds component. Optional when |
digit |
Integer. Number of decimal places to round the result to.
Default is |
Numeric. The angle in decimal degrees.
hms_to_deg(h = 3, m = 15, s = 30) hms_to_deg(h = 3, m = 15, s = 30.123) hms_to_deg(h = "03h15m30s")hms_to_deg(h = 3, m = 15, s = 30) hms_to_deg(h = 3, m = 15, s = 30.123) hms_to_deg(h = "03h15m30s")
This function converts a distance value from kilometers (km) to megaparsecs (Mpc).
The conversion factor is based on 1 parsec being equivalent to 3.262 light-years,
and 1 light-year being approximately kilometers.
km_to_Mpc(km)km_to_Mpc(km)
km |
A numeric value representing the distance in kilometers. |
A numeric value representing the equivalent distance in megaparsecs (Mpc).
km_to_Mpc(3.086e19) # Converts 3.086e19 km (approx. 1 Mpc) to megaparsecskm_to_Mpc(3.086e19) # Converts 3.086e19 km (approx. 1 Mpc) to megaparsecs
This function converts a distance value from megaparsecs (Mpc) to kilometers (km).
The conversion factor is based on 1 parsec being equivalent to 3.262 light-years,
and 1 light-year being approximately kilometers.
Mpc_to_km(mpc)Mpc_to_km(mpc)
mpc |
A numeric value representing the distance in megaparsecs. |
A numeric value representing the equivalent distance in kilometers (km).
Mpc_to_km(1) # Converts 1 Mpc to kilometersMpc_to_km(1) # Converts 1 Mpc to kilometers
Calculates the photon energy density for a given temperature ,
using .
photon_energy_density_fn_T(temp, unit = "eV")photon_energy_density_fn_T(temp, unit = "eV")
temp |
Numeric. Temperature in either eV or Kelvin. |
unit |
Character. The unit of the temperature input. Either
|
Numeric. The photon energy density in natural units.
photon_energy_density_fn_T(1, "eV") photon_energy_density_fn_T(300, "K")photon_energy_density_fn_T(1, "eV") photon_energy_density_fn_T(300, "K")
Calculates the photon energy density at a given cosmological redshift
by first converting to temperature in eV.
photon_energy_density_fn_z(z)photon_energy_density_fn_z(z)
z |
Numeric. The redshift value. |
Numeric. The photon energy density in natural units.
photon_energy_density_fn_z(1300)photon_energy_density_fn_z(1300)
Calculates the photon number density for a given temperature ,
using .
photon_number_density_fn_T(temp, unit = "eV")photon_number_density_fn_T(temp, unit = "eV")
temp |
Numeric. Temperature in either eV or Kelvin. |
unit |
Character. The unit of the temperature input. Either
|
Numeric. The photon number density in natural units.
photon_number_density_fn_T(1, "eV") photon_number_density_fn_T(300, "K")photon_number_density_fn_T(1, "eV") photon_number_density_fn_T(300, "K")
Calculates the photon number density at a given cosmological redshift
by first converting to temperature in eV.
photon_number_density_fn_z(z)photon_number_density_fn_z(z)
z |
Numeric. The redshift value. |
Numeric. The photon number density in natural units.
photon_number_density_fn_z(1300)photon_number_density_fn_z(1300)
Converts angles from radians to degrees. Supports vectorized input.
rad2deg(rad)rad2deg(rad)
rad |
Numeric. The angle(s) in radians to convert to degrees. |
Numeric. The corresponding angle(s) in degrees.
rad2deg(pi) rad2deg(c(0, pi / 2, pi))rad2deg(pi) rad2deg(c(0, pi / 2, pi))
Calculates the ionization fraction as a function of redshift
using the Saha equation for hydrogen recombination.
Saha_Xe(z)Saha_Xe(z)
z |
Numeric. The redshift value. |
Numeric. The ionization fraction (between 0 and 1).
Saha_Xe(1300) Saha_Xe(1100)Saha_Xe(1300) Saha_Xe(1100)
Returns , useful for finding the redshift at which the
ionization fraction equals 0.5 (e.g., via root-finding).
soln_saha(z)soln_saha(z)
z |
Numeric. The redshift value. |
Numeric. .
soln_saha(1350)soln_saha(1350)