// //----------------------------------------------------------------------- /// @copyright /// (c) Copyright 2008 by GATS, Inc., /// 11864 Canon Blvd, Suite 101, Newport News VA 23606 /// /// All Rights Reserved. No part of this software or publication may be /// reproduced, stored in a retrieval system, or transmitted, in any form /// or by any means, electronic, mechanical, photocopying, recording, or /// otherwise without the prior written permission of GATS, Inc. /// //----------------------------------------------------------------------- /// /// @file Level1Profiles.cpp /// /// @author John Burton /// /// @date Thu Jan 17 15:25:36 2008 /// //----------------------------------------------------------------------- // //----------------------------------------------------------------------- // Include Files: //----------------------------------------------------------------------- // #include #include #include #include #include #include #include "Level1Profiles.h" #include "GATS_Utilities.hpp" #include "ChainSawFilter.h" // //----------------------------------------------------------------------- // Defines and Macros: //----------------------------------------------------------------------- // // //----------------------------------------------------------------------- // Global Variables: //----------------------------------------------------------------------- // static const double ARCMIN_TO_RADIANS = M_PI / (double)10800.0; //static EventVar X_Mapping; //static EventVar Y_Mapping; //static EventVar X_Mapping(Xname,511.0,-512.0,-1.0); //static EventVar Y_Mapping(Yname,-511.0,512.0,1.0); static double det_el = 636.15625; // now in units of pixels static double det_az = 518.46875; // now in units of pixels static double CSUM_INT = 347.00; // Center Sum integration time (us) static double XROI_INT = 467.67; // X Edge ROI integration time (us) static double YROI_INT = 456.83; // Y Edge ROI integration time (us) // //----------------------------------------------------------------------- // Class Methods: //----------------------------------------------------------------------- // void Level1Profiles::initNames(void) { TrackTimeStamp_.setName("SolarTrackerTimes"); PixelTimeStamp_.setName("SolarImageTimes"); SunSensorTimeStamp_.setName("SS_ScienceTimeGrid"); Track_Low_X_.setName("SolarTrackXLow"); Track_High_X_.setName("SolarTrackXHigh"); Track_Low_Y_.setName("SolarTrackYLow"); Track_High_Y_.setName("SolarTrackYHigh"); SolarHighEl_.setName("SolarHighElevationEdge"); SolarLowEl_.setName("SolarLowElevationEdge"); SolarHighAz_.setName("SolarHighAzimuthEdge"); SolarLowAz_.setName("SolarLowAzimuthEdge"); SolarExtent_.setName("SolarExtent"); DetectorAz_.setName("DetectorLockdown_AZ"); DetectorEl_.setName("DetectorLockdown_EL"); RecordType_.setName("SolarTrackRecordType"); CenterOffsets_.setName("SolarCenterSumsOffsets"); NormalizedSolarExtent_.setName("NormalizedSolarExtent"); SumsData_.setName("SolarSums"); LocsVect_.setName("SolarSumsLocations"); CenterSumsVect_.setName("SolarCenterSums"); CenterRowsVect_.setName("SolarCenterRows"); CenterAvesVect_.setName("CenterAveragePixelValues"); AvePixVect_.setName("AveragePixelValues"); CenterOffsetsVect_.setName("SolarCenterSumsOffsetsVect"); } Level1Profiles::Level1Profiles() { } Level1Profiles::Level1Profiles(SunSensorEvent &sse, Event &L1) { initNames(); L1.getEventVar("L1_DetectorTimes", SunSensorTimeStamp_); cf_ = sse.getConfigFile(); section_ = sse.getSection(); eventNumber_ = sse.getEventNumber(); srssflag_ = sse.getSRSSFlag(); RecordType_ = sse.getRecordType(RecordType_); TrackTimeStamp_ = sse.getTrackTimeStamp(TrackTimeStamp_); PixelTimeStamp_ = sse.getPixelTimeStamp(PixelTimeStamp_); Track_Low_X_ = sse.getTrackLoX(Track_Low_X_); Track_High_X_ = sse.getTrackHiX(Track_High_X_); Track_Low_Y_ = sse.getTrackLoY(Track_Low_Y_); Track_High_Y_ = sse.getTrackHiY(Track_High_Y_); CenterAvesVect_ = sse.getCenterAvePixVals(CenterAvesVect_); CenterSumsVect_ = sse.getCenterSums(CenterSumsVect_); CenterRowsVect_ = sse.getCenterSumsRows(CenterRowsVect_); CenterOffsetsVect_ = sse.getCenterSumsOffsets(CenterOffsetsVect_); LocsVect_ = sse.getAverageLocations(LocsVect_); AvePixVect_ = sse.getAveragePixVals(AvePixVect_); CSUM_INT = (eventNumber_ > 10732) ? 347.00 : 249.00; // Track_Low_X_.Plot("Track_Low_X_","In Level1Profiles"); } void Level1Profiles::ChainSawFilterAvePixVect(void) { int nelem = AvePixVect_.size(); int nlen = AvePixVect_[0].size(); int minrow = 1023; int maxrow = 0; int tmp,i,j; int istart, istop; EventVarVect FPASeries; EventVarVect AvePixOut; EventVar evtmp(nlen); EventVar count(1024); std::string cval_name = "Threshold_cval"; std::string xval_name = "Threshold_xval"; std::string yval_name = "Threshold_yval"; double cval_threshold = 0.003; double xval_threshold = 0.003; double yval_threshold = 0.003; if(cf_.ValidEntry(section_,cval_name)) cval_threshold = cf_.GetReal(section_,cval_name); if(cf_.ValidEntry(section_,xval_name)) xval_threshold = cf_.GetReal(section_,xval_name); if(cf_.ValidEntry(section_,yval_name)) yval_threshold = cf_.GetReal(section_,yval_name); evtmp.setValueZero(); for(i=0;i 1023) tmp = 1023; tmp = LocsVect_[i][j]; FPASeries[tmp][j] = AvePixVect_[i][j]; count[tmp] = count[tmp] + 1; } } int maxcount = count.max(); for(i=0;i<1024;i++) { if(count[i] > 2) { FPASeries[i] = applyChainSawFilter(FPASeries[i],xval_threshold); } } for(i=istart;i 1023) tmp = 1023; tmp = LocsVect_[i][j]; AvePixVect_[i][j] = FPASeries[tmp][j]; } } // // Do y Edges // istart = 14; istop = 24; count.setValueZero(); for(i=0;i<1024;i++) FPASeries[i].setValueToMissing(); for(i=istart;i 1023) tmp = 1023; FPASeries[tmp][j] = AvePixVect_[i][j]; count[tmp] = count[tmp] + 1; } } for(i=0;i<1024;i++) { if(count[i] > 2) { FPASeries[i] = applyChainSawFilter(FPASeries[i],xval_threshold); } } for(i=istart;i 1023) tmp = 1023; AvePixVect_[i][j] = FPASeries[tmp][j]; } } // // Do Center Sums // istart = 24; istop = 31; count.setValueZero(); for(i=0;i<1024;i++) FPASeries[i].setValueToMissing(); for(i=istart;i 1023) tmp = 1023; FPASeries[tmp][j] = AvePixVect_[i][j]; count[tmp] = count[tmp] + 1; } } for(i=0;i<1024;i++) { if(count[i] > 2) { FPASeries[i] = applyChainSawFilter(FPASeries[i],xval_threshold); } } for(i=istart;i 1023) tmp = 1023; AvePixVect_[i][j] = FPASeries[tmp][j]; } } } void Level1Profiles::doChainSawFilter(void) { EventVarVect evv; std::string lox_name = "Threshold_lox"; std::string hix_name = "Threshold_hix"; std::string loy_name = "Threshold_loy"; std::string hiy_name = "Threshold_hiy"; double lox_threshold = 0.000015; double hix_threshold = 0.000015; double loy_threshold = 0.0002; double hiy_threshold = 0.0002; if(cf_.ValidEntry(section_,lox_name)) lox_threshold = cf_.GetReal(section_,lox_name); if(cf_.ValidEntry(section_,hix_name)) hix_threshold = cf_.GetReal(section_,hix_name); if(cf_.ValidEntry(section_,loy_name)) loy_threshold = cf_.GetReal(section_,loy_name); if(cf_.ValidEntry(section_,hiy_name)) hiy_threshold = cf_.GetReal(section_,hiy_name); evv.addEventVar(Track_Low_X_); std::cerr << "doChainSawFilter::Track_Low_X\n"; Track_Low_X_ = applyChainSawFilter(Track_Low_X_,lox_threshold); evv.addEventVar(Track_Low_X_); if(cf_.GetFlag(section_,"PlotTrackingData")) evv.Plot("Low_X_Track_","Level1Profiles::doChainSawFilter"); evv.clear(); evv.addEventVar(Track_High_X_); // std::cerr << "doChainSawFilter::Track_High_X\n"; Track_High_X_ = applyChainSawFilter(Track_High_X_,hix_threshold); evv.addEventVar(Track_High_X_); if(cf_.GetFlag(section_,"PlotTrackingData")) evv.Plot("High_X_Track_","Level1Profiles::doChainSawFilter"); evv.clear(); // std::cerr << "doChainSawFilter::Track_Low_Y\n"; Track_Low_Y_ = applyChainSawFilter(Track_Low_Y_,loy_threshold); // std::cerr << "doChainSawFilter::Track_High_Y\n"; Track_High_Y_ = applyChainSawFilter(Track_High_Y_,hiy_threshold); // Track_Low_X_.Plot("Track_Low_X_","After Chainsaw Filter"); if(cf_.GetFlag(section_,"PlotTrackingData")) { EventVarVect evv; evv.addEventVar(Track_Low_X_); evv.addEventVar(Track_High_X_); evv.addEventVar(Track_Low_Y_); evv.addEventVar(Track_High_Y_); evv.Plot("Filtered Tracking Data","Level1Profiles::doChainSawFilter"); evv.clear(); } } void Level1Profiles::transformCoordinates(Event &SD) { std::string fname; std::string Xname = "X_Pixel_Spacing"; std::string Xfile = "X_MappingFile"; std::string Yname = "Y_Pixel_Spacing"; std::string Yfile = "Y_MappingFile"; std::string det_az_name; std::string det_el_name; if(srssflag_ == 'r') { det_az_name = "Detector_lockdown_az_SR"; det_el_name = "Detector_lockdown_el_SR"; } else if(srssflag_ == 's') { det_az_name = "Detector_lockdown_az_SS"; det_el_name = "Detector_lockdown_el_SS"; } else { det_az_name = "Detector_lockdown_az"; det_el_name = "Detector_lockdown_el"; } EventVar X_Mapping(Xname,511.0,-512.0,-1.0); EventVar Y_Mapping(Yname,-511.0,512.0,1.0); if(SD.EventVarExists(Xname)) SD.getEventVar(Xname,X_Mapping); else { if(cf_.ValidEntry(section_,Xfile)) { fname = cf_.GetStr(section_,Xfile); std::cerr << "Reading " << fname << std::endl; X_Mapping.readVar(fname); } X_Mapping = X_Mapping * ARCMIN_TO_RADIANS; SD.addEventVar(X_Mapping); } if(SD.EventVarExists(Yname)) SD.getEventVar(Yname,Y_Mapping); else { if(cf_.ValidEntry(section_,Yfile)) { fname = cf_.GetStr(section_,Yfile); std::cerr << "Reading " << fname << std::endl; Y_Mapping.readVar(fname); } Y_Mapping = Y_Mapping * ARCMIN_TO_RADIANS; SD.addEventVar(Y_Mapping); } if(cf_.ValidEntry(section_,det_az_name)) det_az = cf_.GetReal(section_,det_az_name); if(cf_.ValidEntry(section_,det_el_name)) det_el = cf_.GetReal(section_,det_el_name); det_az = Y_Mapping.Interpol_ndx(det_az); det_el = X_Mapping.Interpol_ndx(det_el); SolarHighEl_ = X_Mapping.VInterpol_ndx(Track_Low_X_); SolarLowEl_ = X_Mapping.VInterpol_ndx(Track_High_X_); SolarHighAz_ = Y_Mapping.VInterpol_ndx(Track_High_Y_); SolarLowAz_ = Y_Mapping.VInterpol_ndx(Track_Low_Y_); for (int i=0; i SunCenterAz; SunCenterAz = (SolarLowAz_ + SolarHighAz_) / 2.0; DetectorAz_ = SunCenterAz - det_az; DetectorEl_ = SolarHighEl_ - det_el; } void Level1Profiles::determineCenterSumsElevation(void) { for(int i = 0; i good = ((TrackTimeStamp_ >= 60.0) && (TrackTimeStamp_ <= 80.0)); // SolarExtent_.Plot("Solar Extent","FPACorrection"); EventVar tmp = SolarExtent_; // EventVar mstd; // mstd = tmp[std::slice(1700,500,1)]; // double mean = mstd.Mean(); // double stddev = mstd.Stddev(); // std::cerr << "SolarExtent mean, std dev: "; // std::cerr << mean << ", " << stddev << "\n"; tmp = tmp[good]; // SolarExtent_.Plot("Solar Extent",""); exoExtent = tmp.max(); // str = "Event " + GATS_Utilities::ConvertToString(eventNumber_) + // " SD = " + GATS_Utilities::ConvertToString(tmp.Stddev()); // std::cerr << "tmp.stddev() = " << tmp.Stddev() << "\n"; NormalizedSolarExtent_ = SolarExtent_ / exoExtent; } EventVar Level1Profiles::getSolarExtent(void) { EventVar SolarAzExtent; SolarAzExtent = (SolarHighAz_ + SolarLowAz_) / 2.0; // return SolarExtent_; return SolarAzExtent; } void Level1Profiles::adjustToScienceTimeStamp(Event& L1) { std::string offset_name = "SunSensorTimeShift"; std::string str, tmpstr; std::stringstream oss; double SS_TimeShift = 0.0; if(cf_.ValidEntry(section_,offset_name)) SS_TimeShift = cf_.GetReal(section_,offset_name); oss << eventNumber_; str = "Event " + oss.str(); EventVar xloc_ts, csum_ts, hiy_ts, loy_ts, xsum_ts; xloc_ts = TrackTimeStamp_ - SS_TimeShift; csum_ts = TrackTimeStamp_ - SS_TimeShift; hiy_ts = TrackTimeStamp_ - SS_TimeShift; loy_ts = TrackTimeStamp_ - SS_TimeShift; xsum_ts = TrackTimeStamp_ - SS_TimeShift; // xloc_ts = TrackTimeStamp_ - 0.05; // csum_ts = TrackTimeStamp_ - 0.04; // hiy_ts = TrackTimeStamp_ - 0.08; // loy_ts = TrackTimeStamp_ - 0.07; // xsum_ts = TrackTimeStamp_ - 0.02; SolarHighEl_ = SolarHighEl_.VInterpol(xloc_ts, SunSensorTimeStamp_); SolarLowEl_ = SolarLowEl_.VInterpol (xloc_ts, SunSensorTimeStamp_); SolarHighAz_ = SolarHighAz_.VInterpol(hiy_ts, SunSensorTimeStamp_); SolarLowAz_ = SolarLowAz_.VInterpol (loy_ts, SunSensorTimeStamp_); SolarExtent_ = SolarExtent_.VInterpol(xloc_ts, SunSensorTimeStamp_); NormalizedSolarExtent_ = NormalizedSolarExtent_.VInterpol(xloc_ts, SunSensorTimeStamp_); DetectorAz_ = DetectorAz_.VInterpol (xloc_ts, SunSensorTimeStamp_); DetectorEl_ = DetectorEl_.VInterpol (xloc_ts, SunSensorTimeStamp_); CenterAvesVect_ = CenterAvesVect_.VInterpol(csum_ts,SunSensorTimeStamp_); // SolarHighEl_.Plot("SolarHighEl_","After AdjustToScienceTimeGrid"); } void Level1Profiles::copyDataToEvent(Event& eventobj) { initNames(); eventobj.addEventVar(TrackTimeStamp_); eventobj.addEventVar(Track_Low_X_); eventobj.addEventVar(Track_High_X_); eventobj.addEventVar(Track_Low_Y_); eventobj.addEventVar(Track_High_Y_); eventobj.addEventVar(SolarHighEl_); eventobj.addEventVar(SolarLowEl_); eventobj.addEventVar(SolarHighAz_); eventobj.addEventVar(SolarLowAz_); eventobj.addEventVar(SolarExtent_); eventobj.addEventVar(DetectorEl_); eventobj.addEventVar(DetectorAz_); eventobj.addEventVar(PixelTimeStamp_); eventobj.addEventVar(SumsData_); eventobj.addEventVar(NormalizedSolarExtent_); eventobj.addEventVar(CenterOffsets_); eventobj.addEventVar(CenterAvesVect_); // eventObj.addEventVar(CenterOffsetsVect_); eventobj.addEventVar(CenterSumsVect_); eventobj.addEventVar(SunSensorTimeStamp_); eventobj.addEventVar(LocsVect_); eventobj.addEventVar(AvePixVect_); } void Level1Profiles::correctCenterSumsLocations() { std::stringstream oss; std::string str, tmpstr; std::map > CenterAveMap; std::map > CenterOffsetMap; std::map >::iterator iter; std::vector rowvect; int nvars = CenterAvesVect_.size(); int len = TrackTimeStamp_.size(); valarray good = ((TrackTimeStamp_ >= 70.0) && (TrackTimeStamp_ <= 71.0)); EventVar Rows; EventVar Aves; EventVar Offs; EventVar tmp(len); int row; CenterOffsets_.resize(nvars); for(int j=0; jaddEventVar(Offs); } } void Level1Profiles::correctSumsLocations() { std::stringstream oss; std::string str, tmpstr; std::map > AveMap; std::map > LocationMap; std::map >::iterator iter; std::vector rowvect; int nvars = AvePixVect_.size(); // int len = sstVec_.size(); int len = TrackTimeStamp_.size(); valarray good = ((TrackTimeStamp_ >= 70.0) && (TrackTimeStamp_ <= 71.0)); EventVar Rows; EventVar Aves; EventVar Offs; EventVar tmp(len); int row; for(int j=0; jPlot("Average PixelValues",str,3,4); // CenterOffsetsVect_->Plot("Center Sums Offsets",str); } void Level1Profiles::smoothData(void) { int len = TrackTimeStamp_.size(); int i,j,n; int maf_points = 1; int maf_passes = 0; std::vector maf_variables; std::string MAFVars = "MAF_Variables"; std::string MAFPoints = "MAF_Points"; std::string MAFPasses = "MAF_Passes"; if(cf_.ValidEntry(section_,MAFPoints)) { maf_points = cf_.GetInt(section_,MAFPoints); } if(cf_.ValidEntry(section_,MAFPasses)) { maf_passes = cf_.GetInt(section_,MAFPasses); } // if(cf_.ValidEntry(section_,MAFVars)) // { // maf_variables = cf_.GetStrValues(section_,MAFVars); // for(n = 0; n < maf_variables.size(); n++) // { // std::string str = maf_variables[n]; // switch(VarMap[str]) // { // case evLowX: // for(i=0; iSmooth(maf_points); // Track_Low_X_->setName(str); // break; // case evHighX: // for(i=0; iSmooth(maf_points); // Track_High_X_->setName(str); // break; // case evLowY: // for(i=0; iSmooth(maf_points); // Track_Low_Y_->setName(str); // break; // case evHighY: // for(i=0; iSmooth(maf_points); // Track_High_Y_->setName(str); // break; // case evHighEl: // for(i=0; iSmooth(maf_points); // SolarHighEl_->setName(str); // break; // case evLowEl: // for(i=0; iSmooth(maf_points); // SolarLowEl_->setName(str); // break; // case evHighAz: // for(i=0; iSmooth(maf_points); // SolarHighAz_->setName(str); // break; // case evLowAz: // for(i=0; iSmooth(maf_points); // SolarLowAz_->setName(str); // break; // case evExtent: // for(i=0; iSmooth(maf_points); // SolarExtent_->setName(str); // break; // case evDetAz: // for(i=0; iSmooth(maf_points); // DetectorAz_->setName(str); // break; // case evDetEl: // for(i=0; iSmooth(maf_points); // DetectorEl_->setName(str); // break; // case evSums: // for(j=0; jsize(); j++) // { // for(i=0; i avepix; valarray good = ((PixelTimeStamp_ >= 60.0) && (PixelTimeStamp_ <= 80.0)); for(int i=0; i tmp) ? maxint : tmp; } factor = 1023.0 / maxint; for(int i=0; i avepix; valarray good = ((PixelTimeStamp_ >= 60.0) && (PixelTimeStamp_ <= 80.0)); for(int i=0; i tmp) ? maxint : tmp; } // EventVar ev(Track_Low_X_.size()); // EventVarVect evv; // for(int i=0; i timestamp; // Track_Low_X_.Plot("Track_Low_X_","In dumpData"); // SolarHighEl_.Plot("SolarHighEl_","In dumpData"); timestamp = (grid > 0) ? SunSensorTimeStamp_ : PixelTimeStamp_; int len = timestamp.size(); std::cerr << "Track_Low_X_.size() = " << Track_Low_X_.size() << "\n"; std::cerr << "timestamp.size() = " << timestamp.size() << "\n"; for(int i=0;i timestamp; int mafpoints = 25; int len; if(SunSensorTimeStamp_.size() == 0) timestamp = PixelTimeStamp_; else timestamp = SunSensorTimeStamp_; len = timestamp.size(); std::valarray ok = (timestamp > t1) && (timestamp < t2); for(int i=0;i timestamp; // int mafpoints = 25; // // int len; // if(SunSensorTimeStamp_.size() == 0) // timestamp = PixelTimeStamp_; // else // timestamp = SunSensorTimeStamp_; // len = timestamp.size(); // EventVar Ave(len),SmoothAve(len),SD_a(len), SD_sa(len); // EventVar s2(len),s3(len),s4(len),s5(len); // EventVar sd2(len),sd3(len),sd4(len),sd5(len),sdave(len); // EventVar s_sd2(len),s_sd3(len),s_sd4(len),s_sd5(len); // EventVar tmp1,tmp2,tmp3,tmp4; // // std::valarray ok = (timestamp > t1) && (timestamp < t2); // std::valarray ok1 = (timestamp > 30.0) && (timestamp <= 40.0); // std::valarray ok2 = (timestamp > 40.0) && (timestamp <= 50.0); // std::valarray ok3 = (timestamp > 50.0) && (timestamp <= 60.0); // std::valarray ok4 = (timestamp > 60.0) && (timestamp <= 70.0); // // tmp1 = CenterAvesVect_[2]; // tmp2 = CenterAvesVect_[3]; // tmp3 = CenterAvesVect_[4]; // tmp4 = CenterAvesVect_[5]; // // Ave = (tmp1 + tmp2 + tmp3 + tmp4) / 4.0; // SmoothAve = Ave.Smooth(mafpoints); // SD_a = Ave.Stddev(mafpoints); // SD_sa = SmoothAve.Stddev(mafpoints); // // // tmp1 = tmp1[ok1]; // tmp2 = tmp2[ok2]; // tmp3 = tmp3[ok3]; // tmp4 = tmp4[ok4]; // // len = tmp1.size(); // // EventVar ts(len),ave(len),save(len),ave_sd(len),save_sd(len); // // ts = timestamp[ok1]; // // ave = (tmp1 + tmp2 + tmp3 + tmp4) / 4.0; // save = ave.Smooth(mafpoints); // ave_sd = ave.Stddev(mafpoints); // save_sd = save.Stddev(mafpoints); // // // s2 = CenterAvesVect_[2].Smooth(mafpoints); // s3 = CenterAvesVect_[3].Smooth(mafpoints); // s4 = CenterAvesVect_[4].Smooth(mafpoints); // s5 = CenterAvesVect_[5].Smooth(mafpoints); // // sd2 = CenterAvesVect_[2].Stddev(mafpoints); // sd3 = CenterAvesVect_[3].Stddev(mafpoints); // sd4 = CenterAvesVect_[4].Stddev(mafpoints); // sd5 = CenterAvesVect_[5].Stddev(mafpoints); // // sdave = sd2 + sd3 + sd4 + sd5; // sdave = sdave / 4.0; // // s_sd2 = s2.Stddev(mafpoints); // s_sd3 = s3.Stddev(mafpoints); // s_sd4 = s4.Stddev(mafpoints); // s_sd5 = s5.Stddev(mafpoints); // // Ave = Ave[ok1]; // SmoothAve = SmoothAve[ok1]; // SD_a = SD_a[ok1]; // SD_sa = SD_sa[ok1]; // sdave = sdave[ok1]; // // for(int i=0;i