gnuastro-commits
[Top][All Lists]
Advanced

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

[gnuastro-commits] master 08369a0a: Library (arithmetic.h): new operator


From: Mohammad Akhlaghi
Subject: [gnuastro-commits] master 08369a0a: Library (arithmetic.h): new operators for Janskys to counts and mag
Date: Tue, 21 Jun 2022 19:10:01 -0400 (EDT)

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

    Library (arithmetic.h): new operators for Janskys to counts and mag
    
    Until now, there was only a single operator for converting counts to
    Janskys, but there weren't any operators to convert Janskys to
    counts. Also, there were no functions to convert Janskys to AB magnitude.
    
    With this commit the following three operators have been added for the
    missing operations mentioned above: 'jy-to-counts', 'mag-to-jy' and
    'jy-to-mag'.
---
 NEWS                      |  4 ++++
 doc/gnuastro.texi         | 10 ++++++++++
 lib/arithmetic.c          | 20 +++++++++++++++++++-
 lib/gnuastro/arithmetic.h |  3 +++
 lib/gnuastro/units.h      |  9 +++++++++
 lib/units.c               | 35 +++++++++++++++++++++++++++++++++++
 6 files changed, 80 insertions(+), 1 deletion(-)

diff --git a/NEWS b/NEWS
index b78c18fa..1088ee31 100644
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,10 @@ See the end of the file for license conditions.
        into one image).
      - noblank: Remove blank elements from the input and return a 1D output
        (irrespective of how many dimensions the input had).
+     - jy-to-counts: convert Janskys to counts using an AB-magnitude-based
+       Zeropoint (the inverse operator 'counts-to-jy' already existed).
+     - mag-to-jy: convert AB magnitudes to Janskys.
+     - jy-to-mag: convert Janskys to AB magnitudes.
 
   Crop:
    --oneelemstdout: when a crop has a single pixel and this option is
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index b9501651..f901bfbb 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -15222,6 +15222,16 @@ Therefore you can convert the units of SDSS image 
pixels to Janskys with the com
 $ astarithmetic sdss-image.fits 22.5 counts-to-jy
 @end example
 
+@item jy-to-counts
+Convert Janskys to counts (usually CCD outputs) through an AB-magnitude based 
zero point.
+This is the inverse operation of the @code{counts-to-jy}, see there for usage 
example.
+
+@item mag-to-jy
+Convert AB magnitudes to Janskys, see @ref{Brightness flux magnitude}.
+
+@item jy-to-mag
+Convert Janskys to AB magnitude, see @ref{Brightness flux magnitude}.
+
 @item au-to-pc
 @cindex Parsecs
 @cindex Astronomical Units (AU)
diff --git a/lib/arithmetic.c b/lib/arithmetic.c
index 032ff8df..9199894b 100644
--- a/lib/arithmetic.c
+++ b/lib/arithmetic.c
@@ -620,6 +620,10 @@ arithmetic_function_unary(int operator, int flags, 
gal_data_t *in)
       UNIARY_FUNCTION_ON_ELEMENT( acosh, +0, +0);         break;
     case GAL_ARITHMETIC_OP_ATANH:
       UNIARY_FUNCTION_ON_ELEMENT( atanh, +0, +0);         break;
+    case GAL_ARITHMETIC_OP_MAG_TO_JY:
+      UNIARY_FUNCTION_ON_ELEMENT( gal_units_mag_to_jy, +0, +0); break;
+    case GAL_ARITHMETIC_OP_JY_TO_MAG:
+      UNIARY_FUNCTION_ON_ELEMENT( gal_units_jy_to_mag, +0, +0); break;
     case GAL_ARITHMETIC_OP_AU_TO_PC:
       UNIARY_FUNCTION_ON_ELEMENT( gal_units_au_to_pc, +0, +0); break;
     case GAL_ARITHMETIC_OP_PC_TO_AU:
@@ -2285,6 +2289,8 @@ arithmetic_function_binary_flt(int operator, int flags, 
gal_data_t *il,
       BINFUNC_F_OPERATOR_SET( gal_units_mag_to_counts, +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:
+      BINFUNC_F_OPERATOR_SET( gal_units_jy_to_counts, +0 ); break;
     default:
       error(EXIT_FAILURE, 0, "%s: operator code %d not recognized",
             __func__, operator);
@@ -2558,6 +2564,12 @@ gal_arithmetic_set_operator(char *string, size_t 
*num_operands)
     { op=GAL_ARITHMETIC_OP_MAG_TO_COUNTS;     *num_operands=2;  }
   else if (!strcmp(string, "counts-to-jy"))
     { op=GAL_ARITHMETIC_OP_COUNTS_TO_JY;      *num_operands=2;  }
+  else if (!strcmp(string, "jy-to-counts"))
+    { op=GAL_ARITHMETIC_OP_JY_TO_COUNTS;      *num_operands=2;  }
+  else if (!strcmp(string, "mag-to-jy"))
+    { op=GAL_ARITHMETIC_OP_MAG_TO_JY;         *num_operands=1;  }
+  else if (!strcmp(string, "jy-to-mag"))
+    { op=GAL_ARITHMETIC_OP_JY_TO_MAG;         *num_operands=1;  }
   else if( !strcmp(string, "au-to-pc"))
     { op=GAL_ARITHMETIC_OP_AU_TO_PC;          *num_operands=1;  }
   else if( !strcmp(string, "pc-to-au"))
@@ -2768,6 +2780,9 @@ gal_arithmetic_operator_string(int operator)
     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_OP_COUNTS_TO_JY:    return "counts-to-jy";
+    case GAL_ARITHMETIC_OP_JY_TO_COUNTS:    return "jy-to-counts";
+    case GAL_ARITHMETIC_OP_MAG_TO_JY:       return "mag-to-jy";
+    case GAL_ARITHMETIC_OP_JY_TO_MAG:       return "jy-to-mag";
     case GAL_ARITHMETIC_OP_AU_TO_PC:        return "au-to-pc";
     case GAL_ARITHMETIC_OP_PC_TO_AU:        return "pc-to-au";
     case GAL_ARITHMETIC_OP_LY_TO_PC:        return "ly-to-pc";
@@ -2901,6 +2916,8 @@ gal_arithmetic(int operator, size_t numthreads, int 
flags, ...)
     case GAL_ARITHMETIC_OP_PC_TO_LY:
     case GAL_ARITHMETIC_OP_LY_TO_AU:
     case GAL_ARITHMETIC_OP_AU_TO_LY:
+    case GAL_ARITHMETIC_OP_MAG_TO_JY:
+    case GAL_ARITHMETIC_OP_JY_TO_MAG:
     case GAL_ARITHMETIC_OP_RA_TO_DEGREE:
     case GAL_ARITHMETIC_OP_DEC_TO_DEGREE:
     case GAL_ARITHMETIC_OP_DEGREE_TO_RA:
@@ -2912,9 +2929,10 @@ gal_arithmetic(int operator, size_t numthreads, int 
flags, ...)
     /* Binary function operators. */
     case GAL_ARITHMETIC_OP_POW:
     case GAL_ARITHMETIC_OP_ATAN2:
+    case GAL_ARITHMETIC_OP_COUNTS_TO_JY:
+    case GAL_ARITHMETIC_OP_JY_TO_COUNTS:
     case GAL_ARITHMETIC_OP_COUNTS_TO_MAG:
     case GAL_ARITHMETIC_OP_MAG_TO_COUNTS:
-    case GAL_ARITHMETIC_OP_COUNTS_TO_JY:
       d1 = va_arg(va, gal_data_t *);
       d2 = va_arg(va, gal_data_t *);
       out=arithmetic_function_binary_flt(operator, flags, d1, d2);
diff --git a/lib/gnuastro/arithmetic.h b/lib/gnuastro/arithmetic.h
index e21c2cc4..ac64e2f8 100644
--- a/lib/gnuastro/arithmetic.h
+++ b/lib/gnuastro/arithmetic.h
@@ -129,6 +129,9 @@ enum gal_arithmetic_operators
   GAL_ARITHMETIC_OP_COUNTS_TO_MAG,/* Counts to magnitude. */
   GAL_ARITHMETIC_OP_MAG_TO_COUNTS,/* Magnitude to counts. */
   GAL_ARITHMETIC_OP_COUNTS_TO_JY, /* Counts to Janskys with AB-mag zeropoint. 
*/
+  GAL_ARITHMETIC_OP_JY_TO_COUNTS, /* Janskys to Counts with AB-mag zeropoint. 
*/
+  GAL_ARITHMETIC_OP_MAG_TO_JY,    /* Magnitude to Janskys. */
+  GAL_ARITHMETIC_OP_JY_TO_MAG,    /* Janskys to Magnitude. */
   GAL_ARITHMETIC_OP_AU_TO_PC,     /* Astronomical units (AU) to Parsecs (PC). 
*/
   GAL_ARITHMETIC_OP_PC_TO_AU,     /* Parsecs (PC) to Astronomical units (AU). 
*/
   GAL_ARITHMETIC_OP_LY_TO_PC,     /* Astronomical units (AU) to Parsecs (PC). 
*/
diff --git a/lib/gnuastro/units.h b/lib/gnuastro/units.h
index e79ed29d..e7636d2f 100644
--- a/lib/gnuastro/units.h
+++ b/lib/gnuastro/units.h
@@ -82,6 +82,15 @@ gal_units_mag_to_counts(double mag, double zeropoint);
 double
 gal_units_counts_to_jy(double counts, double zeropoint_ab);
 
+double
+gal_units_jy_to_counts(double jy, double zeropoint_ab);
+
+double
+gal_units_jy_to_mag(double jy);
+
+double
+gal_units_mag_to_jy(double mag);
+
 double
 gal_units_au_to_pc(double au);
 
diff --git a/lib/units.c b/lib/units.c
index 97be0d9c..c6e243d6 100644
--- a/lib/units.c
+++ b/lib/units.c
@@ -394,6 +394,41 @@ gal_units_counts_to_jy(double counts, double zeropoint_ab)
 
 
 
+/* Convert Janskys to pixel values with an AB-magnitude based
+   zero-point. See the "Brightness, Flux, Magnitude and Surface
+   brightness". */
+double
+gal_units_jy_to_counts(double jy, double zeropoint_ab)
+{
+  return jy / 3631 / pow(10, -1 * zeropoint_ab / 2.5);
+}
+
+
+
+
+
+double
+gal_units_jy_to_mag(double jy)
+{
+  double zp=0;
+  return gal_units_counts_to_mag(gal_units_jy_to_counts(jy, zp),zp);
+}
+
+
+
+
+
+double
+gal_units_mag_to_jy(double mag)
+{
+  double zp=0;
+  return gal_units_counts_to_jy(gal_units_mag_to_counts(mag, zp),zp);
+}
+
+
+
+
+
 
 
 



reply via email to

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