Exemplo n.º 1
0
//! Get the mid-time of the integration
MJD dsp::PhaseSeries::get_mid_time (bool phased) const
{
  if (verbose)
  {
    cerr << "PhaseSeries::get_mid_time start=" 
      << start_time << " end=" << end_time << endl;
  }

  MJD midtime = 0.5 * (start_time + end_time);

  if (!phased)
    return midtime;

  if (folding_predictor)
  {
    // truncate midtime to the nearest pulse phase = reference_phase
    Pulsar::Phase phase = folding_predictor->phase(midtime).Floor() + reference_phase;
    midtime = folding_predictor->iphase (phase, &midtime);
  }

  if (folding_period)
  {
    double phase = reference_phase + 
      fmod (midtime.in_seconds(), folding_period)/folding_period;
    midtime -= phase * folding_period;
  }

  return midtime;
}
Exemplo n.º 2
0
void dsp::TimeDivide::set_bounds (const Observation* input)
{
  observation = input;

  double sampling_rate = input->get_rate();
  uint64_t input_ndat = input->get_ndat();

  MJD input_start = input->get_start_time();
  MJD input_end   = input->get_end_time();

  //////////////////////////////////////////////////////////////////////////
  //
  // determine the MJD at which to start
  //
  MJD divide_start = input_start;

  if (is_valid)
  {
    divide_start = std::max (current_end, input_start);

    if (Operation::verbose)
      cerr << "dsp::TimeDivide::bound continue at" 
	   << "\n        start = " << divide_start
	   << "\n  current end = " << current_end
	   << "\n  input start = " << input_start
	   << endl;
  }

  new_division = false;
  end_reached = false;
  in_next = false;

  if (input_end < lower || divide_start + 0.5/sampling_rate > upper)
  {
    /*
      This state occurs when either:
      1) this method is first called (no boundaries set)
      2) the 
    */

    if (Operation::verbose)
    {
      cerr << "dsp::TimeDivide::bound start new division" << endl;
      if (input_end < lower)
        cerr << "      input end = " << input_end << " precedes\n"
                " division start = " << lower << endl;
       else
        cerr << "          start = " << divide_start << " is after\n"
                "   division end = " << upper << endl;
    }

    new_division = true;

    set_boundaries (divide_start + 0.55/sampling_rate);
  }

  divide_start = std::max (lower, divide_start);

  if (Operation::verbose)
    cerr << "dsp::TimeDivide::bound start division at" 
	 << "\n          start = " << divide_start
	 << "\n division start = " << lower
	 << "\n    input start = " << input_start
	 << endl;

  //////////////////////////////////////////////////////////////////////////
  //
  // determine how far into the current Observation to start
  //
  MJD offset = divide_start - input_start;

  double start_sample = offset.in_seconds() * sampling_rate;

  // cerr << "start_sample=" << start_sample << endl;
  start_sample = rint (start_sample);
  // cerr << "rint(start_sample)=" << start_sample << endl;

  assert (start_sample >= 0);

  idat_start = (uint64_t) start_sample;

  if (Operation::verbose)
    cerr << "dsp::TimeDivide::bound start offset " << offset.in_seconds()*1e3
	 << " ms (" << idat_start << "pts)" << endl;

  if (idat_start >= input_ndat)
  {
    // The current data end before the start of the current division

    if (Operation::verbose)
      cerr << "dsp::TimeDivide::bound input ends before division starts"<<endl;

    is_valid = false;
    return;
  }

  //////////////////////////////////////////////////////////////////////////
  //
  // determine how far into the current input TimeSeries to end
  //
  MJD divide_end = std::min (input_end, upper);

  if (Operation::verbose)
    cerr << "dsp::TimeDivide::bound end division at "
         << "\n           end = " << divide_end
         << "\n  division end = " << upper
         << "\n     input end = " << input_end
         << endl;

  offset = divide_end - input_start;

  double end_sample = offset.in_seconds() * sampling_rate;

  // cerr << "end_sample=" << end_sample << endl;
  end_sample = rint (end_sample);
  // cerr << "rint(end_sample)=" << end_sample << endl;

  assert (end_sample >= 0);

  uint64_t idat_end = (uint64_t) end_sample;

  if (Operation::verbose)
    cerr << "dsp::TimeDivide::bound end offset " << offset.in_seconds()*1e3
	 << " ms (" << idat_end << "pts)" << endl;
 
  if (idat_end <= idat_start)
  {
#ifdef _DEBUG
    cerr << "dsp::TimeDivide::bound start division at"
         << "\n          start = " << divide_start
         << "\n division start = " << lower
         << "\n    input start = " << input_start
         << endl;

    offset = divide_start - input_start;

    cerr << "dsp::TimeDivide::bound start offset " << offset.in_seconds()*1e3
         << " ms (" << idat_start << "pts)" << endl;

    cerr << "dsp::TimeDivide::bound end division at "
         << "\n           end = " << divide_end
         << "\n  division end = " << upper
         << "\n     input end = " << input_end
         << endl;

    offset = divide_end - input_start;

    cerr << "dsp::TimeDivide::bound end offset " << offset.in_seconds()*1e3
         << " ms (" << idat_end << "pts)" << endl; 
#endif

    throw Error (InvalidState, "dsp::TimeDivide::bound",
		 "idat_end="UI64" <= idat_start="UI64, idat_end, idat_start);
  }

  if (idat_end > input_ndat)
  {
    // this can happen owing to rounding in the above call to rint()

    if (Operation::verbose)
      cerr << "dsp::TimeDivide::bound division"
	"\n   end_sample=rint(" << end_sample << ")=" << idat_end << 
	" > input ndat=" << input_ndat << endl;

    idat_end = input_ndat;
  }
  else if (idat_end < input_ndat)
  {
    // The current input TimeSeries extends more than the current
    // division.  The in_next flag indicates that the input
    // TimeSeries should be used again.

    if (Operation::verbose)
      cerr << "dsp::TimeDivide::bound input data ends "
           << (input_end-divide_end).in_seconds()*1e3 <<
        " ms after current division" << endl;

    in_next = true;
  }

  ndat = idat_end - idat_start;

  //////////////////////////////////////////////////////////////////////////
  //
  // determine if the end of the current division has been reached
  //

  double samples_to_end = (upper - divide_end).in_seconds() * sampling_rate;

  if (Operation::verbose)
    cerr << "dsp::TimeDivide::bound " << samples_to_end << 
      " samples to end of current division" << endl;

  if (samples_to_end < 0.5)
  {
    if (Operation::verbose)
      cerr << "dsp::TimeDivide::bound end of division" << endl;

    end_reached = true;
  }

  if (Operation::verbose)
  {
    double start = 1e3*idat_start/sampling_rate;
    double used = 1e3*ndat/sampling_rate;
    double available = 1e3*input_ndat/sampling_rate;
    cerr << "dsp::TimeDivide::bound division=" << division << " using "
	 << used << "/" << available << " from " << start << " ms\n  (" 
	 << ndat << "/" << input_ndat << " from " << idat_start << " to "
	 << idat_start + ndat - 1 << " inclusive.)" << endl;
  }

  is_valid = true;
  current_end = input_start + idat_end/sampling_rate;
}
Exemplo n.º 3
0
double double_cast (const MJD& mjd)
{
  return mjd.in_seconds();
}