Example #1
0
//*******************************************
//       TIMESERIES SEARCH ALGORITHM
//*******************************************
vector<Gpulse> giantsearch(int n, float * data, float thresh, double RMS, float bintol, int tscrfac, float dm) {
	int i;
	Gpulse pulse;
	bool detected = false, first = true;
	int xstart = 0, width = 0; //first bin of detected pulse
	int j, imax, ngiants=0, lastend=0; //counters
	float snr; //imax will store the location in d of the max peak of a pulse
	vector<Gpulse> giants;

	for (i=0; i<n; i++) {
		if (data[i]>thresh && detected==false)//when we get above the threshold, note where it began.
		{
			detected = true;
			if (first==false) {
				if ((i-lastend) > bintol) {
					pulse.put_pulse(data[imax], data[imax]/RMS, xstart*tscrfac,
							imax*tscrfac, (lastend-xstart)*tscrfac, tscrfac, dm);
					giants.push_back(pulse);
					xstart = i;//if the last pulse ended more than bintol bins ago, count this as a new pulse.
				}
			} else {
				first = false;
				xstart = i;
			}
		} else if (data[i]<thresh && detected==true) //when we go under the threshold, search the in-to-out width for the maximum.
		{
			imax = xstart;
			lastend = i;
			for (j=xstart; j<i; j++)
				if (data[imax]<data[j])
					imax=j;
			detected = false;
		} else if (i==n-1) {
			if (data[i]>thresh && detected==true) {
				pulse.put_pulse(data[imax], data[imax]/RMS, xstart*tscrfac,
						imax*tscrfac, (i-xstart)*tscrfac, tscrfac, dm);
				giants.push_back(pulse);
			} else if (first==false && data[i]<thresh) {
				pulse.put_pulse(data[imax], data[imax]/RMS, xstart*tscrfac,
						imax*tscrfac, (lastend-xstart)*tscrfac, tscrfac, dm);
				giants.push_back(pulse);
			}
		}
	}
	return (giants);
}
Example #2
0
vector<Gpulse>* assoc_giants(vector<Gpulse> uapulses, int *nsinglebeamcands,float irrel) {
	int maxdm=0, scanrangelo, scanrangehi, ncandidates=0;
	int npulses = uapulses.size(),suslo,sushi,ninonecand,maxsnrindex=1;
	vector<Gpulse> *candidates;
	vector<Gpulse> onecand, RFIpulses;
	Gpulse placeholder;
	bool newpulse;
	float maxsnr;

	if (npulses == 0) {
		fprintf(stderr,"\nDid not find any giant pulses in this block.\n");
		*nsinglebeamcands=0;
		return (candidates);
	}

	candidates = new vector<Gpulse>[uapulses.size()/2];
	while (uapulses.size() > 0) {
		//	if (uapulses[0].dm == uapulses[npulses].dm){
		//	    fprintf(stderr,"Only found lone high-DM spikes.\n",irrel);
		//	    return(candidates);
		//	}
		placeholder.put_pulse(0, 0, 0, 0, 0, 0, 0);
		onecand.push_back(placeholder); //first element holds "best of" info
//		printf("\nSussing a pulse at DM %f\n",placeholder.dm);
		onecand.push_back(uapulses[0]); //put on first pulse from unassociated ones
		uapulses.erase(uapulses.begin()); //remove first element
		npulses--;

		scanrangelo = onecand[1].start;
		scanrangehi = onecand[1].start+onecand[1].width;
		maxsnr = onecand[1].SNR;
		maxsnrindex = 1;
//		printf("\n\n\nmaxsnr at first is %f\n\n\n",maxsnr);
		//printf("*start* %d %f %f\n",(int)onecand.size(), onecand[1].dm,onecand[1].SNR);

		newpulse = true;
		ninonecand=1; //begins with pulse already pushed on
		while (newpulse) {
//		    printf("-----------------Scanning range %d to %d---------------\n",scanrangelo,scanrangehi);
		    newpulse = false;
		    for (int i=1; i<npulses; i++) {
			suslo = uapulses[i].start;
			sushi = uapulses[i].start+uapulses[i].width;
			if ((scanrangelo>=suslo&&scanrangelo<=sushi)||(scanrangehi>=suslo&&scanrangehi<=sushi)||(suslo>=scanrangelo&&suslo<=scanrangehi)){
//			    printf("Found associated pulse: DM %f, SNR %f, loc %i, start %i\n",uapulses[i].dm,uapulses[i].SNR,uapulses[i].loc,uapulses[i].start);
			    if (suslo < scanrangelo) {
				scanrangelo = suslo;
			    	newpulse = true;
			    }
			    if (sushi>scanrangehi) {
			    	scanrangehi = sushi;
			    	newpulse = true;
			    }
			    if (uapulses[i].SNR>maxsnr) {
//				printf("newp(%f) is more than maxsnr(%f)\n",uapulses[i].SNR,maxsnr);
			    	maxsnr=uapulses[i].SNR;
			    	maxsnrindex=ninonecand+1;
//				printf("new index for SNR %f is %d\n",maxsnr,maxsnrindex);
			    }
			    onecand.push_back(uapulses[i]);
//			    fprintf(stderr,"loc: %d start: %d wid: %d\n",uapulses[i].loc,uapulses[i].start,uapulses[i].width);
			    uapulses.erase(uapulses.begin()+i); //remove associated element
//			    fprintf(stderr,"i,npulses,uap.size,ninonecand: %d,%d,%d,%d\n",i,npulses,uapulses.size(),ninonecand);
			    onecand[0].width = scanrangehi-scanrangelo;
			    ninonecand++;
			    npulses--;
			    i--;
//			    fprintf(stderr,"cand loc: %d start: %d wid: %d\n\n",onecand[ninonecand].loc,onecand[ninonecand].start,onecand[ninonecand].width);
			}
		    }
		}
//		printf("finished loop. Max SNR at index %d was %f\n",maxsnrindex,onecand[maxsnrindex].SNR);
		if (onecand.size()<=3 || onecand[maxsnrindex].dm<irrel) {
// 		    printf("The burst is RFI. %d %d %f %f\n\n",onecand.size(),maxsnrindex,onecand[maxsnrindex].dm,onecand[maxsnrindex].SNR);
		    RFIpulses.insert(RFIpulses.end(), onecand.begin()+1, onecand.end());
		} else {
		    onecand[0].put_pulse(onecand[maxsnrindex].amp,
					 onecand[maxsnrindex].SNR, scanrangelo,
					 onecand[maxsnrindex].loc, scanrangehi-scanrangelo,
					 onecand[maxsnrindex].tscrfac, onecand[maxsnrindex].dm);
		    candidates[ncandidates] = onecand;
//		    printf("!!GOOD!! %4d %10d %5.2f %5.3f\n",onecand.size(),onecand[0].start,onecand[maxsnrindex].dm,onecand[maxsnrindex].SNR);
		    ncandidates++;
		}
		onecand.clear();
	}
	*nsinglebeamcands = ncandidates;
	return (candidates);
}
Example #3
0
vector<Gpulse>* assoc_giants(vector<Gpulse> uapulses, int *nsinglebeamcands,char* resultsfilename,char* filetimestamp,int beamID,float irrel) {
	int maxdm=0, scanrangelo, scanrangehi, ncandidates=0;
	int npulses = uapulses.size(),suslo,sushi,ninonecand,maxsnrindex=1;
	vector<Gpulse> *candidates;
	vector<Gpulse> onecand;
	FILE* resultsfile = fopen(resultsfilename,"a");
	Gpulse placeholder;
	bool newpulse;
	float maxsnr;
	char dettype;
	cout<<"Associating...\n";
	if (npulses == 0) {
		fprintf(stderr,"\nDid not find any giant pulses in this block.\n");
		*nsinglebeamcands=0;
		return (candidates);
	}

	candidates = new vector<Gpulse>[uapulses.size()/2];
	while (uapulses.size() > 0) {
		//	if (uapulses[0].dm == uapulses[npulses].dm){
		//	    fprintf(stderr,"Only found lone high-DM spikes.\n",irrel);
		//	    return(candidates);
		//	}
		placeholder.put_pulse(0, 0, 0, 0, 0, 0, 0);
		onecand.push_back(placeholder); //first element holds "best of" info
//		printf("\nSussing a pulse at DM %f\n",placeholder.dm);
		onecand.push_back(uapulses[0]); //put on first pulse from unassociated ones
		uapulses.erase(uapulses.begin()); //remove first element
		npulses--;

		scanrangelo = onecand[1].start;
		scanrangehi = onecand[1].start+onecand[1].width;
		maxsnr = onecand[1].SNR;
		maxsnrindex = 1;
//		printf("\n\n\nmaxsnr at first is %f\n\n\n",maxsnr);
		//printf("*start* %d %f %f\n",(int)onecand.size(), onecand[1].dm,onecand[1].SNR);

		newpulse = true;
		ninonecand=1; //begins with pulse already pushed on
		while (newpulse) {
//		    printf("-----------------Scanning range %d to %d---------------\n",scanrangelo,scanrangehi);
		    newpulse = false;
		    for (int i=1; i<npulses; i++) {
			suslo = uapulses[i].start;
			sushi = uapulses[i].start+uapulses[i].width;
			if ((scanrangelo>=suslo&&scanrangelo<=sushi)||(scanrangehi>=suslo&&scanrangehi<=sushi)||(suslo>=scanrangelo&&suslo<=scanrangehi)){
//			    printf("Found associated pulse: DM %f, SNR %f, loc %i, start %i\n",uapulses[i].dm,uapulses[i].SNR,uapulses[i].loc,uapulses[i].start);
			    if (suslo < scanrangelo) {
				scanrangelo = suslo;
			    	newpulse = true;
			    }
			    if (sushi>scanrangehi) {
			    	scanrangehi = sushi;
			    	newpulse = true;
			    }
			    if (uapulses[i].SNR>maxsnr) {
//				printf("newp(%f) is more than maxsnr(%f)\n",uapulses[i].SNR,maxsnr);
			    	maxsnr=uapulses[i].SNR;
			    	maxsnrindex=ninonecand+1;
//				printf("new index for SNR %f is %d\n",maxsnr,maxsnrindex);
			    }
			    onecand.push_back(uapulses[i]);
//			    fprintf(stderr,"loc: %d start: %d wid: %d\n",uapulses[i].loc,uapulses[i].start,uapulses[i].width);
			    uapulses.erase(uapulses.begin()+i); //remove associated element
//			    fprintf(stderr,"i,npulses,uap.size,ninonecand: %d,%d,%d,%d\n",i,npulses,uapulses.size(),ninonecand);
			    onecand[0].width = scanrangehi-scanrangelo;
			    ninonecand++;
			    npulses--;
			    i--;
//			    fprintf(stderr,"cand loc: %d start: %d wid: %d\n\n",onecand[ninonecand].loc,onecand[ninonecand].start,onecand[ninonecand].width);
			}
		    }
		}

		if (onecand.size()<3 || onecand[maxsnrindex].dm<irrel) {
		    printf("The burst is RFI. Npulses:%d DM:%f SNR:%f Loc'n:%d Wid:%d Scr:%d\n\n",onecand.size(),onecand[maxsnrindex].dm,onecand[maxsnrindex].SNR,onecand[maxsnrindex].loc,onecand[0].width,onecand[maxsnrindex].tscrfac);
		    if (onecand.size()<3){
			dettype = 'g';
			fprintf(resultsfile,"%s\t%8.5f %8.5f %12d %12d %12d %6d %8.2f %d %c %d\n",filetimestamp,onecand[maxsnrindex].amp,onecand[maxsnrindex].SNR,scanrangelo,onecand[maxsnrindex].loc,scanrangehi-scanrangelo,onecand[maxsnrindex].tscrfac,onecand[maxsnrindex].dm,beamID,'G',onecand[maxsnrindex].loc);
		    } else if (onecand[maxsnrindex].dm<irrel){
			//nrfi++;
			//detnum = nrfi; //!!! NEED TO MAKE NRFI/DETNUM/DETTYPE
			dettype = 'r';
			fprintf(resultsfile,"%s\t%8.5f %8.5f %12d %12d %12d %6d %8.2f %d %c %d\n",filetimestamp,onecand[maxsnrindex].amp,onecand[maxsnrindex].SNR,scanrangelo,onecand[maxsnrindex].loc,scanrangehi-scanrangelo,onecand[maxsnrindex].tscrfac,onecand[maxsnrindex].dm,beamID,'R',onecand[maxsnrindex].loc);
		    }
		    for (int j=0;j<onecand.size();j++){
			fprintf(resultsfile,"%s\t%8.5f %8.5f %12d %12d %12d %6d %8.2f %d %c %d\n",filetimestamp,onecand.at(j).amp,onecand.at(j).SNR,onecand.at(j).start,onecand.at(j).loc,onecand.at(j).width,onecand.at(j).tscrfac,onecand.at(j).dm,beamID,dettype,onecand[maxsnrindex].loc);
		    }
		    //RFIpulses.insert(RFIpulses.end(), onecand.begin()+1, onecand.end());
		} else {
		    onecand[0].put_pulse(onecand[maxsnrindex].amp,
					 onecand[maxsnrindex].SNR, scanrangelo,
					 onecand[maxsnrindex].loc, scanrangehi-scanrangelo,
					 onecand[maxsnrindex].tscrfac, onecand[maxsnrindex].dm);
		    candidates[ncandidates] = onecand;
//		    printf("GOOD! %4d %10d %5.2f %5.3f\n",onecand.size(),onecand[0].start,onecand[maxsnrindex].dm,onecand[maxsnrindex].SNR);
		    fprintf(resultsfile,"%s\t%8.5f %8.5f %12d %12d %12d %6d %8.2f %d %c %d\n",filetimestamp,onecand[maxsnrindex].amp,onecand[maxsnrindex].SNR,scanrangelo,onecand[maxsnrindex].loc,scanrangehi-scanrangelo,onecand[maxsnrindex].tscrfac,onecand[maxsnrindex].dm,beamID,'C',onecand[maxsnrindex].loc);
		    for (int j=0;j<onecand.size();j++){
			fprintf(resultsfile,"%s\t%8.5f %8.5f %12d %12d %12d %6d %8.2f %d %c %d\n",filetimestamp,onecand.at(j).amp,onecand.at(j).SNR,onecand.at(j).start,onecand.at(j).loc,onecand.at(j).width,onecand.at(j).tscrfac,onecand.at(j).dm,beamID,'c',onecand[maxsnrindex].loc);
		    }
		    cout<<"...done printing.\n";
		    ncandidates++;
		}
		onecand.erase(onecand.begin(),onecand.end());
	}
	fclose(resultsfile);

	*nsinglebeamcands = ncandidates;
	return (candidates);
}