gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master e26045e2: Libarary (units.h): apparent magnitu


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master e26045e2: Libarary (units.h): apparent magnitude to luminosity and vice-versa
Date: Mon, 2 Jun 2025 16:26:18 -0400 (EDT)

branch: master
commit e26045e2d1d51660520fe17220512edf5d6549ef
Author: Sepideh Eskandarlou <sepideh.eskandarlou@gmail.com>
Commit: Sepideh Eskandarlou <sepideh.eskandarlou@gmail.com>

    Libarary (units.h): apparent magnitude to luminosity and vice-versa
    
    Until now, we did not have any operators in the Arithmetic or Table (in
    columns arithmetic) programs to convert apparent magnitude to the
    luminosity (in uints of solar luminosity) and vice-versa.
    
    With this commit, new functions are added to 'lib/unit.c' and based on
    them, two new operators are added to the 'lib/arithmetic.c' libarary which
    is used in the Arithmetic and Table programs. The functions take the
    distance modulus for the conversion.
---
 NEWS                      |  9 +++++++--
 doc/gnuastro.texi         | 16 ++++++++++++++++
 lib/arithmetic.c          | 12 ++++++++++++
 lib/gnuastro/arithmetic.h |  2 ++
 lib/gnuastro/units.h      |  6 ++++++
 lib/units.c               | 22 ++++++++++++++++++++++
 6 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index f28f72ea..4f6fdc23 100644
--- a/NEWS
+++ b/NEWS
@@ -11,6 +11,13 @@ See the end of the file for license conditions.
 
   - New Operators:
 
+    - madclip-all: similar to 'sigclip-all', but after MAD-clipping.
+
+    - luminosity-to-mag:
+    - mag-to-luminosity: Convert apparent magnitude to luminosity (in units
+      of solar luminosity) and vice-versa. Implemented by Sepideh
+      Eskandarlou.
+
     - sblim-diff: calculate the expected difference in surface brighntess
       limit (purely based on exposed area (of the telescope) and exposure
       time (assuming the same filter, sky conditions and assuming no
@@ -21,8 +28,6 @@ See the end of the file for license conditions.
       sigma-clip (mean, std, median and MAD and number of used
       datasets).
 
-    - madclip-all: similar to 'sigclip-all', but after MAD-clipping.
-
 *** ConvertType
 
   --cmapblankcolor: Name of color to use for blank values when showing
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 00fac6a2..9d9d7c28 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -22026,6 +22026,22 @@ Note that because the output is a single number, we 
are using @option{--quiet} t
 $ astarithmetic 20 24.8 mag-to-counts --quiet
 @end example
 
+@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:
+
+@example
+$ dmod=$(astcosmiccal --distancemodulus --redshift=0.5)
+$ astarithmetic 20 $dmod mag-to-luminosity
+@end example
+
+@item luminosity-to-mag
+Convert luminostiy (in units of solar luminosity) to apparent magnitude using 
the distance modulus.
+This is the inverse of @option{mag-to-luminosity}, see its description for the 
details and usage example.
+
 @item counts-to-sb
 Convert counts to surface brightness using the zero point and area (in units 
of arcsec@mymath{^2}).
 The first popped operand is the area (in arcsec@mymath{^2}), the second popped 
operand is the zero point and the third are the count values.
diff --git a/lib/arithmetic.c b/lib/arithmetic.c
index 8ca00c0f..9b7b6025 100644
--- a/lib/arithmetic.c
+++ b/lib/arithmetic.c
@@ -3183,6 +3183,10 @@ 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:
@@ -4172,6 +4176,10 @@ gal_arithmetic_set_operator(char *string, size_t 
*num_operands)
     { op=GAL_ARITHMETIC_OP_COUNTS_TO_MAG;     *num_operands=2;  }
   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;  }
+    else if (!strcmp(string, "luminosity-to-mag"))
+    { op=GAL_ARITHMETIC_LUMINOSITY_TO_MAG;    *num_operands=2;  }
   else if (!strcmp(string, "sb-to-mag"))
     { op=GAL_ARITHMETIC_OP_SB_TO_MAG;         *num_operands=2;  }
   else if (!strcmp(string, "mag-to-sb"))
@@ -4554,6 +4562,8 @@ gal_arithmetic_operator_string(int operator)
     case GAL_ARITHMETIC_OP_DEGREE_TO_DEC:   return "degree-to-dec";
     case GAL_ARITHMETIC_OP_COUNTS_TO_MAG:   return "counts-to-mag";
     case GAL_ARITHMETIC_OP_MAG_TO_COUNTS:   return "mag-to-counts";
+    case GAL_ARITHMETIC_LUMINOSITY_TO_MAG:  return "luminosity-to-mag";
+    case GAL_ARITHMETIC_MAG_TO_LUMINOSITY:  return "mag-to-luminosity";
     case GAL_ARITHMETIC_OP_SB_TO_MAG:       return "sb-to-mag";
     case GAL_ARITHMETIC_OP_MAG_TO_SB:       return "mag-to-sb";
     case GAL_ARITHMETIC_OP_COUNTS_TO_SB:    return "counts-to-sb";
@@ -4864,6 +4874,8 @@ 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:
diff --git a/lib/gnuastro/arithmetic.h b/lib/gnuastro/arithmetic.h
index e863a42d..60392343 100644
--- a/lib/gnuastro/arithmetic.h
+++ b/lib/gnuastro/arithmetic.h
@@ -149,6 +149,8 @@ enum gal_arithmetic_operators
   GAL_ARITHMETIC_OP_DEGREE_TO_DEC,/* declination to decimal. */
   GAL_ARITHMETIC_OP_COUNTS_TO_MAG,/* Counts to magnitude. */
   GAL_ARITHMETIC_OP_MAG_TO_COUNTS,/* Magnitude to counts. */
+  GAL_ARITHMETIC_MAG_TO_LUMINOSITY, /* Apparent magnitude to luminosity. */
+  GAL_ARITHMETIC_LUMINOSITY_TO_MAG, /* Luminosity to apparent magnitude. */
   GAL_ARITHMETIC_OP_MAG_TO_SB,    /* Magnitude to Surface Brightness. */
   GAL_ARITHMETIC_OP_SB_TO_MAG,    /* Surface Brightness to Magnitude. */
   GAL_ARITHMETIC_OP_COUNTS_TO_SB, /* Counts to Surface Brightness. */
diff --git a/lib/gnuastro/units.h b/lib/gnuastro/units.h
index 67e967ee..e5cd187b 100644
--- a/lib/gnuastro/units.h
+++ b/lib/gnuastro/units.h
@@ -79,6 +79,12 @@ gal_units_counts_to_mag(double counts, double zeropoint);
 double
 gal_units_mag_to_counts(double mag, double zeropoint);
 
+double
+gal_units_mag_to_luminosity(double mag, double distance_modulus);
+
+double
+gal_units_luminosity_to_mag(double luminosity, 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 c4cac3ca..a53bc57e 100644
--- a/lib/units.c
+++ b/lib/units.c
@@ -391,6 +391,28 @@ 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
 */
+double
+gal_units_mag_to_luminosity(double mag, double distance_modulus)
+{
+  double mag_absolute_sun=4.74;
+  return pow(10.0, (mag_absolute_sun - (mag - distance_modulus)) / 2.5);
+}
+
+
+
+
+double
+gal_units_luminosity_to_mag(double luminosity, double distance_modulus)
+{
+  double mag_absolute_sun=4.74;
+  /* double luminosity_sun=3.828e26; */
+  return mag_absolute_sun - 2.5*log10(luminosity) + distance_modulus;
+}
+
+
 
 double
 gal_units_mag_to_sb(double mag, double area_arcsec2)



reply via email to

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