Пример #1
0
void Pulsar::RemoveBaseline::Each::transform (Archive* archive)
{
  const unsigned nsub = archive->get_nsubint();
  const unsigned nchan = archive->get_nchan();
  const unsigned npol = archive->get_npol();

  bool pscrunch = (archive->get_state() == Signal::Coherence ||
		   archive->get_state() == Signal::PPQQ);

  for (unsigned isub=0; isub < nsub; isub++)
  {
    Integration* subint = archive->get_Integration (isub);
    for (unsigned ichan=0; ichan < nchan; ichan++)
    {
      Reference::To<Profile> profile = subint->get_Profile (0,ichan);
      if (pscrunch)
      {
	profile = profile->clone();
	profile->sum (subint->get_Profile (1,ichan));
      }

      Reference::To<PhaseWeight> baseline = profile->baseline();

      for (unsigned ipol=0; ipol < npol; ipol++)
      {
	Profile* p = subint->get_Profile(ipol, ichan);
	baseline->set_Profile (p);
	p->offset (-baseline->get_mean().val);
      }
    }
  }
};
Пример #2
0
/*! Upon completion, the flux of the archive will be normalized with
  respect to the flux of the calibrator, such that a FluxCalibrator
  simply scales the archive by the calibrator flux. */
void Pulsar::PolnCalibrator::calibrate (Archive* arch) try
{
  if (verbose > 2)
    cerr << "Pulsar::PolnCalibrator::calibrate" << endl;

  calibration_setup (arch);

  if (arch->get_npol() == 4)
  {
    BackendCorrection correct_backend;
    correct_backend (arch);

    if (verbose > 2)
      cerr << "Pulsar::PolnCalibrator::calibrate Archive::transform" <<endl;

    arch->transform (response);
    arch->set_poln_calibrated (true);

    if (receiver)
    {
      Receiver* rcvr = arch->get<Receiver>();
      if (!rcvr)
	throw Error (InvalidState, "Pulsar::PolnCalibrator::calibrate",
		     "Archive has no Receiver Extension");
      
      rcvr->set_basis_corrected (true);
    }
  }
  else if (arch->get_npol() == 1)
  {
    if (Archive::verbose)
      cerr << "Pulsar::PolnCalibrator::calibrate WARNING"
	" calibrating only absolute gain" << endl;

    unsigned nsub = arch->get_nsubint ();
    unsigned nchan = arch->get_nchan ();

    for (unsigned isub=0; isub < nsub; isub++)
    {
      Integration* subint = arch->get_Integration (isub);
      for (unsigned ichan=0; ichan < nchan; ichan++)
      {
	double gain = abs(det( response[ichan] ));
	Profile* profile = subint->get_Profile (0, ichan);

	profile -> scale (gain);
	profile -> set_weight ( profile->get_weight() / gain );
      }
    }
  }
  else
    throw Error (InvalidParam, "Pulsar::PolnCalibrator::calibrate",
		 "Archive::npol == %d not yet implemented", arch->get_npol());

  arch->set_scale (Signal::ReferenceFluxDensity);
}
catch (Error& error)
{
  throw error += "Pulsar::PolnCalibrator::calibrate";
}
Пример #3
0
int obtainB(double alpha, double* out) {
  Integration i;
  gsl_function F;
  F.function = &fIntegrand;
  F.params = &alpha;
  if (i.integrate(F)) {
    fprintf(stderr, "Calculation of b may be inaccurate.\n");
    return -1;
  }
  *out = i.getResult();
  return 0;
}
Пример #4
0
//! Add to A whatever is missing with respect to B, and vice versa
void Pulsar::PatchTime::operate (Archive* A, Archive* B) try
{
  A->expert()->sort();
  B->expert()->sort();

  contemporaneity_policy->set_archives (A, B);

  unsigned isubA = 0;
  unsigned isubB = 0;

  while (isubA < A->get_nsubint() && isubB < B->get_nsubint())
  {
    Integration* subA = A->get_Integration (isubA);
    Integration* subB = B->get_Integration (isubB);

    double ratio = contemporaneity_policy->evaluate (subA, subB);

    if (ratio < minimum_contemporaneity)
    {
      // one of the archives requires an empty sub-integration

#if 0
    cerr << "mismatch ratio=" << ratio << " isubA=" << isubA << " isubB=" << isubB
         << " A::nsubint=" << A->get_nsubint()
         << " B::nsubint=" << B->get_nsubint() << endl;

    cerr << "A::epoch=" << subA->get_epoch().printdays(13) << endl;
    cerr << "B::epoch=" << subB->get_epoch().printdays(13) << endl;
#endif

      if (subA->get_epoch() > subB->get_epoch())
      {
	if (Archive::verbose > 2)
          cerr << "Pulsar::PatchTime::operate A requires an empty sub-integration isubA=" << isubA << endl;
	insert (A, isubA, subB->get_epoch()); isubB++; isubA++;
      }
      else
      {
	if (Archive::verbose > 2)
          cerr << "Pulsar::PatchTime::operate B requires an empty sub-integration isubB=" << isubB << endl;
	insert (B, isubB, subA->get_epoch()); isubA++; isubB++;
      }
    }
    else
    {
      // A and B are contemporaneous
      isubA++;
      isubB++;
    }
  }

  if (isubA < A->get_nsubint())
    tail (A, B, isubA);
  else if (isubB < B->get_nsubint())
    tail (B, A, isubB);
}
catch (Error& error)
{
  throw error += "Pulsar::PatchTime::operate";
}
Пример #5
0
void IntDialog::accept() {
  QString formula = boxName->toPlainText().remove("\n");
  Integration *i =
      new Integration(formula, boxVariable->text(),
                      dynamic_cast<ApplicationWindow *>(this->parent()),
                      d_graph, boxStart->value(), boxEnd->value());
  i->setTolerance(boxTol->text().toDouble());
  i->setMaximumIterations(boxSteps->value());
  i->setMethodOrder(boxOrder->value());
  if (d_graph && boxPlot->isChecked())
    i->enableGraphicsDisplay(true, d_graph);
  i->run();
  delete i;
}
Пример #6
0
void Pulsar::UVMArchive::load_header (const char* filename)
{
  int newscan = 0;

  uvm_header* header = new uvm_header;
  header_ptr = header;
  
  if (uvm_getheader (filename, &program, &newscan, header) < 0)
    throw Error (InvalidState, "Pulsar::UVMArchive::load_header",
		 "%s is not a UVM archive", filename);

  cerr << "newscan=" << newscan << endl;

  char buffer[80];
  uvm_get_source (header, buffer);
  source = buffer;

  uvm_get_observatory (header, buffer);
  telescope = buffer;
  telescope = "Arecibo";

  uvm_get_windows (header, buffer);
  cerr << "Pulsar::UVMArchive::load_header windows=" << buffer
       << " nwins=" << header->nwins << endl;

  centre_frequency = header->obfreq;
  bandwidth = header->abandwd;

  npol = header->anumsbc;
  if (npol == 4)
    set_state (Signal::Stokes);

  cerr << "anumsbc=" << header->anumsbc << endl;

  /*
  if (header->apoladd)
    npol = 1;
  */

  dispersion_measure = header->adm;
  rotation_measure = header->arm;

  if (header->nwins == 0)
  {
    nbin = header->apbins;
    cerr << "nbin = apbins = " << nbin;
  }
  else
  {
    nbin = 0;
    for (int iwin=0; iwin < header->nwins; iwin++)
    {
      cerr << "nbin += " <<  header->nwbins[iwin] << endl;
      nbin += header->nwbins[iwin];
    }
  }

  nchan = 1;
  
  if (Profile::no_amps)
  {
    cerr << "no amps" << endl;
    return;
  }

  cerr << "date (dddyy)=" << header->date << endl;
  cerr << "start sec=" << header->startime << endl;

  utc_t utc;
  utc.tm_yday = header->date / 100;
  utc.tm_year = 1900 + header->date % 100;
  utc.tm_min = header->scantime / 60;
  utc.tm_sec = header->scantime - utc.tm_min * 60;
  utc.tm_hour = utc.tm_min / 60;
  utc.tm_min -= utc.tm_hour * 60;

  MJD mjd_start (utc);

  // load all BasicIntegration attributes and data from filename
  uvm_data data;
  unsigned loaded_subints = 0;

  while (uvm_getdata (program, header, &data) >= 0)
  {
    loaded_subints ++;
    resize (loaded_subints);

    Integration* integration = get_Integration(loaded_subints-1);

    // cerr << "start usec=" << header->scantime << endl;
    epoch = mjd_start + header->scantime * 1e-6;
    
    integration->set_folding_period (header->period);
    integration->set_duration (header->period);
    integration->set_epoch (epoch);
    integration->set_centre_frequency(0, centre_frequency);
    

    // scaleI is the scale to convert to microJy
    double scale = header->scaleI * 1e-3;
    double offset = header->baseval;
  
    for (unsigned ipol=0; ipol < get_npol(); ipol++)
    {
      float* amps = integration->get_Profile(ipol, 0) -> get_amps();

      for (unsigned ibin=0; ibin < get_nbin(); ibin++)
      {
	amps[ibin] = (data.data[ipol][ibin] + offset) * scale;
      }
    }
  }
}
Пример #7
0
void IntDialog::accept()
{
QString curveName = boxName->currentText();
QwtPlotCurve *c = graph->curve(curveName);
QStringList curvesList = graph->analysableCurvesList();
if (!c || !curvesList.contains(curveName))
	{
	QMessageBox::critical((ApplicationWindow *)parent(), tr("SciDAVis") +" - "+ tr("Warning"),
		tr("The curve <b> %1 </b> doesn't exist anymore! Operation aborted!").arg(curveName));
	boxName->clear();
	boxName->insertStringList(curvesList);
	return;
	}

double start = 0, stop = 0;
double minx = c->minXValue();
double maxx = c->maxXValue();

// Check the Xmin
QString from = boxStart->text().toLower();
if(from=="min")
	{
	boxStart->setText(QString::number(minx));
	return;
	}
else if(from=="max")
	{
	boxStart->setText(QString::number(maxx));
	return;
	}
else
	{
	try
		{
		MyParser parser;
		parser.SetExpr((boxStart->text()).toAscii().constData());
		start=parser.Eval();

		if(start<minx)
			{
			QMessageBox::warning((ApplicationWindow *)parent(), tr("Input error"),
				tr("Please give a number larger or equal to the minimum value of X, for the lower limit.\n If you do not know that value, type min in the box."));
			boxStart->clear();
			boxStart->setFocus();
			return;
		}
		if(start > maxx)
			{
			QMessageBox::warning((ApplicationWindow *)parent(), tr("Input error"),
				tr("Please give a number smaller or equal to the maximum value of X, for the lower limit.\n If you do not know that value, type max in the box."));
			boxStart->clear();
			boxStart->setFocus();
			return;
			}
		}
	catch(mu::ParserError &e)
		{
		QMessageBox::critical((ApplicationWindow *)parent(),tr("Start limit error"),QString::fromStdString(e.GetMsg()));
		boxStart->clear();
		boxStart->setFocus();
		return;
		}
	}

// Check Xmax
QString end=boxEnd->text().toLower();
if(end=="min")
	{
	boxEnd->setText(QString::number(minx));
	return;
	}
else if(end=="max")
	{
	boxEnd->setText(QString::number(maxx));
	return;
	}
else
	{
	try
		{
		MyParser parser;
		parser.SetExpr((boxEnd->text()).toAscii().constData());
		stop = parser.Eval();
		if(stop > maxx)
			{
			//FIXME: I don't understand why this doesn't work for FunctionCurves!!(Ion)
			/*QMessageBox::warning((ApplicationWindow *)parent(), tr("Input error"),
				tr("Please give a number smaller or equal to the maximum value of X, for the upper limit.\n If you do not know that value, type max in the box."));
			boxEnd->clear();
			boxEnd->setFocus();
			return;
			*/
			boxEnd->setText(QString::number(maxx));
			}
		if(stop < minx)
			{
			QMessageBox::warning((ApplicationWindow *)parent(), tr("Input error"),
				tr("Please give a number larger or equal to the minimum value of X, for the upper limit.\n If you do not know that value, type min in the box."));
			boxEnd->clear();
			boxEnd->setFocus();
			return;
			}
		}
	catch(mu::ParserError &e)
		{
		QMessageBox::critical((ApplicationWindow *)parent(), tr("End limit error"),QString::fromStdString(e.GetMsg()));
		boxEnd->clear();
		boxEnd->setFocus();
		return;
		}
	}

Integration *i = new Integration((ApplicationWindow *)this->parent(), graph, curveName,
                                 boxStart->text().toDouble(), boxEnd->text().toDouble());
i->setMethod((Integration::InterpolationMethod)boxMethod->currentIndex());
i->run();
delete i;
}
Пример #8
0
void Pulsar::BackendCorrection::operator () (Archive* arch) const try
{
  Backend* backend = arch->get<Backend>();

  if (!backend || backend->get_corrected())
    return;

  Signal::State state = arch->get_state();
  Signal::Basis basis = arch->get_basis();
  Signal::Hand hand = backend->get_hand();
  Signal::Argument argument = backend->get_argument();

  bool correct_lsb = must_correct_lsb (backend, arch);

  if (Archive::verbose > 2)
    cerr << "Pulsar::BackendCorrection::operator basis=" << basis
	 << " hand=" << hand << " phase=" << argument
	 << " lsb=" << correct_lsb << endl;

  /*
    complex conjugation due to lower sideband downconversion and
    backend convention have the same effect; the following lines
    effect an exclusive or operation.
  */
  if (correct_lsb)
  {
    if (Archive::verbose > 2)
      cerr << "Pulsar::BackendCorrection::operator down conversion" << endl;
    if (argument == Signal::Conjugate)
      argument = Signal::Conventional;
    else
      argument = Signal::Conjugate;
  }

  unsigned npol = arch->get_npol();

  if (npol < 2)
    return;

  bool swap01 = false;
  bool flip[4] = { false, false, false, false };

  if (npol == 4)
  {
    if (argument == Signal::Conjugate)
    {
      if (Archive::verbose > 2)
	cerr << "Pulsar::BackendCorrection::operator phase convention" << endl;
      if (state == Signal::Stokes && basis == Signal::Circular)
	flip[2] = !flip[2];   // Flip Stokes U
      else
	flip[3] = !flip[3];   // Flip Stokes V or Im[AB]
    }

    if (hand == Signal::Left) 
    {
      if (Archive::verbose > 2)
	cerr << "Pulsar::BackendCorrection::operator hand" << endl;
      if (state == Signal::Stokes && basis == Signal::Circular)
	flip[2] = !flip[2];   // Flip Stokes U and ...
      else if (state == Signal::Stokes && basis == Signal::Linear)
	flip[1] = !flip[1];   // Flip Stokes Q and ...
      else if (state == Signal::PseudoStokes)
	flip[1] = !flip[1];   // Flip AA-BB and ...
      flip[3] = !flip[3];     // Flip Stokes V or Im[AB]
    }
  }

  // If state == Coherence or PPQQ ...
  if (hand == Signal::Left && 
      (state == Signal::Coherence || state == Signal::PPQQ))
    swap01 = true;

  bool flip_something = false;
  for (unsigned ipol=0; ipol < npol; ipol++)
    if (flip[ipol])
    {
      if (Archive::verbose > 2)
	cerr << "Pulsar::BackendCorrection::operator flip " << ipol << endl;
      flip_something = true;
    }

  if (swap01 && Archive::verbose > 2)
    cerr << "Pulsar::BackendCorrection::operator swap 0 and 1" << endl;

  if (flip_something || swap01)
  {
    for (unsigned isub=0; isub < arch->get_nsubint(); isub++)
    {
      Integration* integration = arch->get_Integration(isub);
      for (unsigned ichan=0; ichan < arch->get_nchan(); ichan++)
      {
	for (unsigned ipol=0; ipol < npol; ipol++)
	  if (flip[ipol])
	    integration->get_Profile(ipol, ichan)->scale(-1);
	
	if (swap01)
	  integration->expert()->swap_profiles(0, ichan, 1, ichan);
      }
    }
  }

  backend->set_corrected ();
}
catch (Error& error)
{
  throw error += "Pulsar::BackendCorrection::operator";
}