Exemplo n.º 1
0
  template<class DataSource> bool VSInterpolatedPointing<DataSource>::
  getMeanTarget(SEphem::SphericalCoords& mean_ra_dec,
		double& rms_ra_rad, double& rms_dec_rad,
		const VSTime& lo_time, const VSTime& hi_time, 
		const SEphem::SphericalCoords& earth_position)
  {
    bool got_one = false;

    double phi_zero = 0;
    double theta_zero = 0;

    VSSimpleStat2<double> x_stat;
    VSSimpleStat2<double> y_stat;

    for(unsigned iscope=0;iscope<m_data.scope.size();iscope++)
      {
	unsigned npointing = m_data.scope[iscope].size();
	for(unsigned ipointing=0;ipointing<npointing;ipointing++)
	  {
	    if((m_data.scope[iscope][ipointing].timestamp < lo_time)
	       ||(m_data.scope[iscope][ipointing].timestamp > hi_time))
	      continue;

	    double mjd = m_data.scope[iscope][ipointing].timestamp.getMJDDbl();
	    SEphem::Angle lmst = 
	      SEphem::Astro::mjdToLMST(mjd, earth_position.longitudeRad());

	    SEphem::Angle zn;
	    SEphem::Angle az;
	    zn.setCoAngleRad(m_data.scope[iscope][ipointing].elevation_meas);
	    az.setRad(m_data.scope[iscope][ipointing].azimuth_meas);
	    SEphem::SphericalCoords radec(zn,az);
	    SEphem::Astro::azElToMeanRaDec(lmst, mjd, earth_position, radec);
	    
	    if(!got_one)
	      {
		phi_zero = radec.phi();
		theta_zero = radec.theta();
		got_one = true;
	      }

	    radec.rotate(-phi_zero,-theta_zero,0);
	    
	    x_stat.accumulate(radec.thetaRad()*cos(radec.phiRad()));
	    y_stat.accumulate(radec.thetaRad()*sin(radec.phiRad()));
	  }
      }

    if(!got_one)return false;

    double x = x_stat.mean();
    double y = y_stat.mean();
    mean_ra_dec.setRad(sqrt(x*x+y*y),atan2(y,x));
    mean_ra_dec.rotate(0,theta_zero,phi_zero);

    rms_dec_rad = y_stat.dev();
    rms_ra_rad = x_stat.dev();

    return true;
  }
Exemplo n.º 2
0
Arquivo: plot.c Projeto: aahud/harvey
int
bbox(int32_t extrara, int32_t extradec, int quantize)
{
	int i;
	Record *r;
	int ra, dec;
	int rah, ram, d1, d2;
	double r0;

	ramin = 0x7FFFFFFF;
	ramax = -0x7FFFFFFF;
	decmin = 0x7FFFFFFF;
	decmax = -0x7FFFFFFF;

	for(i=0,r=rec; i<nrec; i++,r++){
		if(r->type == Patch){
			radec(r->index, &rah, &ram, &dec);
			ra = 15*rah+ram/4;
			r0 = c/cos(dec*PI/180);
			ra *= c;
			dec *= c;
			if(dec == 0)
				d1 = c, d2 = c;
			else if(dec < 0)
				d1 = c, d2 = 0;
			else
				d1 = 0, d2 = c;
		}else if(r->type==SAO || r->type==NGC || r->type==Planet || r->type==Abell){
			ra = r->ngc.ra;
			dec = r->ngc.dec;
			d1 = 0, d2 = 0, r0 = 0;
		}else
			continue;
		if(dec+d2+extradec > decmax)
			decmax = dec+d2+extradec;
		if(dec-d1-extradec < decmin)
			decmin = dec-d1-extradec;
		if(folded){
			ra -= 180*c;
			if(ra < 0)
				ra += 360*c;
		}
		if(ra+r0+extrara > ramax)
			ramax = ra+r0+extrara;
		if(ra-extrara < ramin)
			ramin = ra-extrara;
	}

	if(decmax > 90*c)
		decmax = 90*c;
	if(decmin < -90*c)
		decmin = -90*c;
	if(ramin < 0)
		ramin += 360*c;
	if(ramax >= 360*c)
		ramax -= 360*c;

	if(quantize){
		/* quantize to degree boundaries */
		ramin -= ramin%m5;
		if(ramax%m5 != 0)
			ramax += m5-(ramax%m5);
		if(decmin > 0)
			decmin -= decmin%c;
		else
			decmin -= c - (-decmin)%c;
		if(decmax > 0){
			if(decmax%c != 0)
				decmax += c-(decmax%c);
		}else if(decmax < 0){
			if(decmax%c != 0)
				decmax += ((-decmax)%c);
		}
	}

	if(folded){
		if(ramax-ramin > 270*c){
			fprint(2, "ra range too wide %ld°\n", (ramax-ramin)/c);
			return -1;
		}
	}else if(ramax-ramin > 270*c){
		folded = 1;
		return bbox(0, 0, quantize);
	}

	return 1;
}