gnuastro-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnuastro-commits] master a3dcfc65: Library (units.h): mag-to-luminosity


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master a3dcfc65: Library (units.h): mag-to-luminosity takes the Sun's absolute mag
Date: Fri, 6 Jun 2025 09:42:13 -0400 (EDT)

branch: master
commit a3dcfc65eb0bcfe39b1047165796695060505610
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>

    Library (units.h): mag-to-luminosity takes the Sun's absolute mag
    
    Until now, this newly added operator would assume the sun's bolometric
    absolute magnitude, which is only useful if you have the bolometric
    apparent magnitude! But in most cases, we have the apparent magnitude in a
    certain filter. So the user should be able to set the sun's absolute
    magnitude in the same filter.
    
    With this commit, the units.c functions and Arithmetic operators take three
    operands, not two (which now includes the user-provided absolute magnitdue
    of the Sun). A reference paper has also been added in the book to help
    users find the proper value.
---
 doc/gnuastro.texi    | 26 +++++++++++++++++++++-----
 lib/arithmetic.c     | 16 ++++++++--------
 lib/gnuastro/units.h |  6 ++++--
 lib/units.c          | 16 ++++++++--------
 4 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index d65df574..8de9caa2 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -22029,13 +22029,28 @@ $ astarithmetic 20 24.8 mag-to-counts --quiet
 @item mag-to-luminosity
 @cindex Luminosity to Apparent Magnitude
 @cindex Apparent Mangitude to Luminosity
-Convert apparent magnitudes to luminosity (in units of solar luminosity; or 
@mymath{3.828\times10^{26}} Watts) using the distance modulus (for the 
definition see @ref{Brightness flux magnitude}).
-For example, let's assume we want to obtain the luminosity of an object at 
redshift 0.5 with apparent magnitude of 20.
-First, we need the distance modulus which we can find with the 
CosmicCalculator program (where you can specify all the cosmological 
parameters), then call Arithmetic:
+Convert apparent magnitudes to luminosity (in units of solar luminosity for 
given band).
+It takes the following three operands:
+
+@enumerate
+@item
+Measured apparent magnitude.
+@item
+Absolute magnitude of the Sun in the filter that the apparent magnitude was 
derived from.
+Table 3 of Willmer @url{https://arxiv.org/abs/1804.07788,2018} contains the 
absolute magnitude of the sun in many of the commonly used filters.
+For example the Sun's absolute magnitude SDSS u, g, r, i and z filters are 
6.39, 5.11, 4.65, 4.53 and 4.50 in the AB magnitude system.
+@item
+Distance modulus (for the definition see @ref{CosmicCalculator basic cosmology 
calculations}).
+@end enumerate
+
+For example, let's assume we want to obtain the luminosity of an object at 
redshift 0.5 with apparent AB magnitude of 20 in the SDSS g filter.
+We need the distance modulus which we can find with the CosmicCalculator 
program (where you can specify all the cosmological parameters) and the Sun's 
absolute magnitude  from Willmer @url{https://arxiv.org/abs/1804.07788,2018} in 
this filter (which is 5.11) to complete the command:
+
+@c Check if instead of --distancemodulus we should use --absmagconv and 
correct both their documentations to clarify their different purposes.
 
 @example
 $ dmod=$(astcosmiccal --distancemodulus --redshift=0.5)
-$ astarithmetic 20 $dmod mag-to-luminosity
+$ astarithmetic 20 5.11 $dmod mag-to-luminosity
 @end example
 
 @item luminosity-to-mag
@@ -33906,7 +33921,8 @@ The luminosity distance to object at given redshift in 
Megaparsecs (Mpc).
 
 @item -u
 @itemx --distancemodulus
-The distance modulus at given redshift.
+The distance modulus (difference between the apparent and absolute magnitude 
for an object) at given redshift.
+The absolute magitude is defined at a fixed distance of 10 parsecs.
 
 @item -a
 @itemx --absmagconv
diff --git a/lib/arithmetic.c b/lib/arithmetic.c
index 9b7b6025..ad5dd279 100644
--- a/lib/arithmetic.c
+++ b/lib/arithmetic.c
@@ -3183,10 +3183,6 @@ arithmetic_function_binary_flt(int operator, int flags, 
gal_data_t *il,
       BINFUNC_F_OPERATOR_SET( gal_units_counts_to_mag, +0 ); break;
     case GAL_ARITHMETIC_OP_MAG_TO_COUNTS:
       BINFUNC_F_OPERATOR_SET( gal_units_mag_to_counts, +0 ); break;
-    case GAL_ARITHMETIC_MAG_TO_LUMINOSITY:
-      BINFUNC_F_OPERATOR_SET( gal_units_mag_to_luminosity, +0 ); break;
-    case GAL_ARITHMETIC_LUMINOSITY_TO_MAG:
-      BINFUNC_F_OPERATOR_SET( gal_units_luminosity_to_mag, +0 ); break;
     case GAL_ARITHMETIC_OP_COUNTS_TO_JY:
       BINFUNC_F_OPERATOR_SET( gal_units_counts_to_jy, +0 ); break;
     case GAL_ARITHMETIC_OP_JY_TO_COUNTS:
@@ -3317,6 +3313,10 @@ arithmetic_function_ternary_flt(int operator, int flags, 
gal_data_t *il,
     {
     case GAL_ARITHMETIC_OP_ZEROPOINT_CHANGE:
       TERFUNC_RUN_FUNCTION( gal_units_zeropoint_change ); break;
+    case GAL_ARITHMETIC_MAG_TO_LUMINOSITY:
+      TERFUNC_RUN_FUNCTION( gal_units_mag_to_luminosity ); break;
+    case GAL_ARITHMETIC_LUMINOSITY_TO_MAG:
+      TERFUNC_RUN_FUNCTION( gal_units_luminosity_to_mag ); break;
     default:
       error(EXIT_FAILURE, 0, "%s: operator code %d not recognized",
             __func__, operator);
@@ -4177,9 +4177,9 @@ gal_arithmetic_set_operator(char *string, size_t 
*num_operands)
   else if (!strcmp(string, "mag-to-counts"))
     { op=GAL_ARITHMETIC_OP_MAG_TO_COUNTS;     *num_operands=2;  }
   else if (!strcmp(string, "mag-to-luminosity"))
-    { op=GAL_ARITHMETIC_MAG_TO_LUMINOSITY;    *num_operands=2;  }
+    { op=GAL_ARITHMETIC_MAG_TO_LUMINOSITY;    *num_operands=3;  }
     else if (!strcmp(string, "luminosity-to-mag"))
-    { op=GAL_ARITHMETIC_LUMINOSITY_TO_MAG;    *num_operands=2;  }
+    { op=GAL_ARITHMETIC_LUMINOSITY_TO_MAG;    *num_operands=3;  }
   else if (!strcmp(string, "sb-to-mag"))
     { op=GAL_ARITHMETIC_OP_SB_TO_MAG;         *num_operands=2;  }
   else if (!strcmp(string, "mag-to-sb"))
@@ -4874,8 +4874,6 @@ gal_arithmetic(int operator, size_t numthreads, int 
flags, ...)
     case GAL_ARITHMETIC_OP_COUNTS_TO_JY:
     case GAL_ARITHMETIC_OP_COUNTS_TO_MAG:
     case GAL_ARITHMETIC_OP_MAG_TO_COUNTS:
-    case GAL_ARITHMETIC_LUMINOSITY_TO_MAG:
-    case GAL_ARITHMETIC_MAG_TO_LUMINOSITY:
     case GAL_ARITHMETIC_OP_NANOMAGGY_TO_COUNTS:
     case GAL_ARITHMETIC_OP_COUNTS_TO_NANOMAGGY:
     case GAL_ARITHMETIC_OP_JY_TO_WAVELENGTH_FLUX_DENSITY:
@@ -4885,6 +4883,8 @@ gal_arithmetic(int operator, size_t numthreads, int 
flags, ...)
       out=arithmetic_function_binary_flt(operator, flags, d1, d2);
       break;
 
+    case GAL_ARITHMETIC_LUMINOSITY_TO_MAG:
+    case GAL_ARITHMETIC_MAG_TO_LUMINOSITY:
     case GAL_ARITHMETIC_OP_ZEROPOINT_CHANGE:
       d1 = va_arg(va, gal_data_t *);
       d2 = va_arg(va, gal_data_t *);
diff --git a/lib/gnuastro/units.h b/lib/gnuastro/units.h
index e5cd187b..87359815 100644
--- a/lib/gnuastro/units.h
+++ b/lib/gnuastro/units.h
@@ -80,10 +80,12 @@ double
 gal_units_mag_to_counts(double mag, double zeropoint);
 
 double
-gal_units_mag_to_luminosity(double mag, double distance_modulus);
+gal_units_mag_to_luminosity(double mag, double mag_absolute_sun,
+                            double distance_modulus);
 
 double
-gal_units_luminosity_to_mag(double luminosity, double distance_modulus);
+gal_units_luminosity_to_mag(double luminosity, double mag_absolute_sun,
+                            double distance_modulus);
 
 double
 gal_units_mag_to_sb(double mag, double area_arcsec2);
diff --git a/lib/units.c b/lib/units.c
index a53bc57e..491c66b8 100644
--- a/lib/units.c
+++ b/lib/units.c
@@ -391,13 +391,14 @@ gal_units_mag_to_counts(double mag, double zeropoint)
 
 
 
-/* Conver apparent magnitude to luminosity. The absolute bolometric
-   magnitude of the Sun is taken from:
-   
https://en.wikipedia.org/wiki/Bolometric_correction#Setting_the_correction_scale
 */
+/* Convert apparent magnitude to luminosity. The absolute magnitude of the
+   sun for different filters can be taken from Table 3 of
+   https://arxiv.org/abs/1804.07788
+*/
 double
-gal_units_mag_to_luminosity(double mag, double distance_modulus)
+gal_units_mag_to_luminosity(double mag, double mag_absolute_sun,
+                            double distance_modulus)
 {
-  double mag_absolute_sun=4.74;
   return pow(10.0, (mag_absolute_sun - (mag - distance_modulus)) / 2.5);
 }
 
@@ -405,10 +406,9 @@ gal_units_mag_to_luminosity(double mag, double 
distance_modulus)
 
 
 double
-gal_units_luminosity_to_mag(double luminosity, double distance_modulus)
+gal_units_luminosity_to_mag(double luminosity, double mag_absolute_sun,
+                            double distance_modulus)
 {
-  double mag_absolute_sun=4.74;
-  /* double luminosity_sun=3.828e26; */
   return mag_absolute_sun - 2.5*log10(luminosity) + distance_modulus;
 }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]