Commit b23e6990 authored by Robert Butora's avatar Robert Butora
Browse files

vlkb-obscore: sets obscore::em_ values as WAVE/LSRK/m

parent 4dc89b88
Loading
Loading
Loading
Loading
+24 −9
Original line number Diff line number Diff line

#include "SqlSchema_INSERT.hpp"

#include <iomanip>
#include <sstream> // to_string(int precision, double value)
#include <string>
#include <stdexcept>
#include <math.h> // fabs needed
@@ -23,6 +25,14 @@ using namespace std;
// utils
//----------------------------------------------------------------

string to_string(int precision, double value)
{
   stringstream stream;
   stream << fixed << setprecision(precision) << value;
   return stream.str();
}


string authPolicyToSQLEnum(string csvPolicy)
{
   if((csvPolicy.compare("FREE") == 0) ||
@@ -147,7 +157,8 @@ string asSqlString(fitsfiles::key_values_by_type key_values, string key)
   }
}

string get_wavelen(fitsfiles::key_values_by_type key_values)

string get_wavelen(int precision, fitsfiles::key_values_by_type key_values)
{
   const double UNIT_CONVERT = 0.001; // FIXME header-card unit [mm] but ObsCore em_ is [m]
   if(key_values.doubleValues.find("WAVELEN") == key_values.doubleValues.end() )
@@ -160,17 +171,17 @@ string get_wavelen(fitsfiles::key_values_by_type key_values)
         }
         else
         {
            return to_string(UNIT_CONVERT * key_values.doubleValues["WAVELNTH"]);
            return to_string(precision, UNIT_CONVERT * key_values.doubleValues["WAVELNTH"]);
         }
      }
      else
      {
         return to_string(UNIT_CONVERT * key_values.doubleValues["WAVELENG"]);
         return to_string(precision, UNIT_CONVERT * key_values.doubleValues["WAVELENG"]);
      }
   }
   else
   {
      return to_string(UNIT_CONVERT * key_values.doubleValues["WAVELEN"]);
      return to_string(precision, UNIT_CONVERT * key_values.doubleValues["WAVELEN"]);
   }
}

@@ -202,9 +213,11 @@ void SqlSchema_INSERT::appendRow(/*const int hid, const int sid,*/
   struct Vertices icrsVerts = legacy::calcVertices(hdu.m_header, "ICRS");
#else
   const string VELOLSRK{"System=VELO,StdOfRest=LSRK,Unit=km/s"};
   const string WAVELSRK{"System=WAVE,StdOfRest=LSRK,Unit=m"};
   // FIXME StdOfRest <--- SPECSYS

   vector<struct Bounds> galBounds  = calc_bounds(hdu.m_header, "GALACTIC", VELOLSRK);
   vector<struct Bounds> icrsBounds = calc_bounds(hdu.m_header, "ICRS", VELOLSRK);
   vector<struct Bounds> icrsBounds = calc_bounds(hdu.m_header, "ICRS", WAVELSRK);

   vector<point2d> galVerts  = calc_skyvertices(hdu.m_header, "GALACTIC");
   vector<point2d> icrsVerts = calc_skyvertices(hdu.m_header, "ICRS");
@@ -347,14 +360,16 @@ void SqlSchema_INSERT::appendRow(/*const int hid, const int sid,*/

   // obscore - spectral axis

   const int EM_PRECISION{10}; // nanometers

   if(icrsBounds.size() >= 3) // 3D cubes
   {
      //obscoreRow[em_min]        = to_string(galBounds[2].low);
      //obscoreRow[em_max]        = to_string(galBounds[2].up);
      obscoreRow[em_min]        = to_string(icrsBounds[2].low); // FIXME must be Wave-length in [m]
      obscoreRow[em_max]        = to_string(icrsBounds[2].up);  // FIXME must be Wave-length in [m]
      obscoreRow[em_min]        = to_string(EM_PRECISION, icrsBounds[2].low);
      obscoreRow[em_max]        = to_string(EM_PRECISION, icrsBounds[2].up);

      obscoreRow[em_res_power]  = asSqlString(hdu.key_values, "CDELT3");
      obscoreRow[em_res_power]  = "NULL";//asSqlString(hdu.key_values, "CDELT3");
      obscoreRow[em_xel]        = asSqlString(hdu.key_values, "NAXIS3");
   }
   else if(icrsBounds.size() == 2) // 2D images
@@ -362,7 +377,7 @@ void SqlSchema_INSERT::appendRow(/*const int hid, const int sid,*/
      //if(!strcmp(survey.survSpecies.c_str(), "Continuum"))
      //   dem_min = dem_max = 0.0; // FIXME transtod(psurv->transition);

      obscoreRow[em_min] = get_wavelen(hdu.key_values);
      obscoreRow[em_min] = get_wavelen(EM_PRECISION, hdu.key_values);
      obscoreRow[em_max] = obscoreRow[em_min];
      obscoreRow[em_res_power] = "NULL";
      obscoreRow[em_xel]       = "NULL";