Skip to content

Commit

Permalink
Merge pull request #7 from ymaan4/skipRFI_opts
Browse files Browse the repository at this point in the history
New Skip-RFI-excision options, a little bit better documentation and other minor changes
  • Loading branch information
ymaan4 authored Feb 9, 2021
2 parents a147da5 + 6abe252 commit 2f04f48
Show file tree
Hide file tree
Showing 9 changed files with 264 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Mkfile.old
dkms.conf

##bin/rficlean.flags # include this in the package as an example
bin/crp_rficlean_gm.sh
#bin/crp_rficlean_gm.sh
bin/rficlean
bin/read_n_make_plot
src/read_n_make_plot.c
Expand Down
12 changes: 7 additions & 5 deletions COPYING
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ patent must be licensed for everyone's free use or not licensed at all.

The precise terms and conditions for copying, distribution and
modification follow.

GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

Expand Down Expand Up @@ -110,7 +110,7 @@ above, provided that you also meet all of these conditions:
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)

These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
Expand Down Expand Up @@ -168,7 +168,7 @@ access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.

4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
Expand Down Expand Up @@ -225,7 +225,7 @@ impose that choice.

This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
Expand Down Expand Up @@ -278,7 +278,7 @@ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

END OF TERMS AND CONDITIONS

How to Apply These Terms to Your New Programs

If you develop a new program, and you want it to be of the greatest
Expand Down Expand Up @@ -338,3 +338,5 @@ proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.


1 change: 1 addition & 0 deletions COPYRIGHT
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

14 changes: 7 additions & 7 deletions bin/crp_rficlean_fil.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#=======================================================================
# Crude parallelization of rfiClean for processing filterbank files.
# Crude parallelization of RFIClean for processing filterbank files.
#
# Yogesh Maan, Dec. 2019
#=======================================================================
Expand Down Expand Up @@ -39,13 +39,13 @@ Nb=`echo "scale=0; $nsamples/($Np*$block) + 1" | bc`



echo "Starting parallel-rfiClean processing at: "
echo "Starting parallel-RFIClean processing at: "
date
echo ""

##-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# prepare and execute the commands for all parts
mkdir -p rfiClean_ps
mkdir -p RFIClean_ps
combine_cmd="cat "
remove_cmd="rm "
count=0
Expand All @@ -57,15 +57,15 @@ for (( c=1; c<=$Np; c++ )); do
psfile=${rtag}_part${count}.ps
#-------------------------------------
if [ $count -eq 1 ]; then
cmd="rficlean -t $block $flag -o $outfile -ps rfiClean_ps/$psfile $infile -bst $bst -nbl $Nb &"
cmd="rficlean -t $block $flag -o $outfile -ps RFIClean_ps/$psfile $infile -bst $bst -nbl $Nb &"
elif [ $count -eq $Np ]; then
combine_cmd="${combine_cmd} ${tempout}"
remove_cmd="${remove_cmd} ${tempout}"
cmd="rficlean -t $block $flag -o $tempout -ps rfiClean_ps/$psfile $infile -bst $bst -headerless &"
cmd="rficlean -t $block $flag -o $tempout -ps RFIClean_ps/$psfile $infile -bst $bst -headerless &"
else
combine_cmd="${combine_cmd} ${tempout}"
remove_cmd="${remove_cmd} ${tempout}"
cmd="rficlean -t $block $flag -o $tempout -ps rfiClean_ps/$psfile $infile -bst $bst -nbl $Nb -headerless &"
cmd="rficlean -t $block $flag -o $tempout -ps RFIClean_ps/$psfile $infile -bst $bst -nbl $Nb -headerless &"
fi
echo $cmd
eval $cmd
Expand All @@ -83,7 +83,7 @@ echo $cmd
eval $cmd


echo "Finished parallel-rfiClean processing at: "
echo "Finished parallel-RFIClean processing at: "
date
echo ""

Expand Down
98 changes: 98 additions & 0 deletions bin/crp_rficlean_gm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/bash
#=======================================================================
# Crude parallelization of RFIClean for processing GMRT data files.
#
# Yogesh Maan, Dec. 2019
#=======================================================================
#



#------------------------------------------------------------------------------
if [ $# -lt 6 ] ; then
echo "========================================================================================"
echo " Usage: "
echo " crp_rficlean_gm.sh <out_filename> <flag-file> <N_parallel> <in_filename> <gm_info> <extra-flag>"
echo " "
echo "========================================================================================"
exit 0
fi
outfile=$1
flagfile=$2
Np=$3
infile=$4
gminfo_file=$5
extra_flag=$6
#------------------------------------------------------------------------------

rtag=${outfile%*.fil} # tag for part-files

##-------------------------------
## read flags from the flag-file
block=`sed -n 1p $flagfile`
flag=`sed -n 2p $flagfile`
#echo "block-size: $block"
#echo "flag: '$flag'"
## read nchan from the gm-info-file
nchans=`sed -n 4p $gminfo_file`
##-------------------------------


# deduce number of blocks to be processed in each part
fsize=$(stat -cL%s "$infile")
nsamples=`echo "scale=0; $fsize/(2*$nchans)" | bc` ## gmrt data --> 2 bytes/sample
Nb=`echo "scale=0; $nsamples/($Np*$block) + 1" | bc`
#echo "nsamples, Nblocks: $nsamples, $Nb, $Np, $block ---"


echo "Starting parallel-RFIClean processing at: "
date
echo ""

##-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# prepare and execute the commands for all parts
mkdir -p RFIClean_ps
combine_cmd="cat "
remove_cmd="rm "
count=0
for (( c=1; c<=$Np; c++ )); do
bst=$(($count*$Nb + 1))
count=$((count+1))
#echo $count
tempout=${rtag}_part${count}.fil
psfile=${rtag}_part${count}.ps
pdffile=${rtag}_part${count}.pdf
#-------------------------------------
if [ $count -eq 1 ]; then
cmd="/home/ymaan/bin/rficlean -t $block $flag -o $outfile -ps RFIClean_ps/$psfile $infile -bst $bst -nbl $Nb -gm $gminfo_file $extra_flag && ps2pdf RFIClean_ps/$psfile RFIClean_ps/$pdffile && rm RFIClean_ps/$psfile &"
elif [ $count -eq $Np ]; then
combine_cmd="${combine_cmd} ${tempout}"
remove_cmd="${remove_cmd} ${tempout}"
cmd="/home/ymaan/bin/rficlean -t $block $flag -o $tempout -ps RFIClean_ps/$psfile $infile -bst $bst -headerless -gm $gminfo_file $extra_flag && ps2pdf RFIClean_ps/$psfile RFIClean_ps/$pdffile && rm RFIClean_ps/$psfile &"
else
combine_cmd="${combine_cmd} ${tempout}"
remove_cmd="${remove_cmd} ${tempout}"
cmd="/home/ymaan/bin/rficlean -t $block $flag -o $tempout -ps RFIClean_ps/$psfile $infile -bst $bst -nbl $Nb -headerless -gm $gminfo_file $extra_flag && ps2pdf RFIClean_ps/$psfile RFIClean_ps/$pdffile && rm RFIClean_ps/$psfile &"
fi
echo $cmd
eval $cmd
done
wait
##-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


# Now combine all parts and then remove the parts
combine_cmd="${combine_cmd} >> ${outfile}"
#echo $combine_cmd
#echo $remove_cmd
cmd="$combine_cmd && $remove_cmd"
echo $cmd
eval $cmd


echo "Finished parallel-RFIClean processing at: "
date
echo ""

exit 0

2 changes: 2 additions & 0 deletions include/rficlean.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
#include "header.h"
#include <fftw3.h>
Expand All @@ -14,6 +15,7 @@ float *fftstat, *chanstat, *predist, *xpredist, *postdist, *xpostdist, *finaldis
double *tfvar, *tfmean,meanvar,rmsvar ;
double *chandata, *mspec, *rspec, *vspec, *wspec, *wt;
long int *coff;
bool RFIx,rfiFDx,rfiTx,rfiSx,rfiMSx,rfiVSx,rfiSclip;

fftw_complex *in;
fftw_complex *out;
Expand Down
89 changes: 53 additions & 36 deletions src/cleanit.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,19 @@ void cleanit(float *data, int nchans, long int nadd)
isame = all_samef(chandata,nadd);
}
if( isame == 0){
fftclean(in,out,nadd,inc); // clean some periodic RFIs
if(rfiFDx){
fftclean(in,out,nadd,inc); // clean some periodic RFIs
}
for (ii = 0; ii<nadd; ii++) chandata[ii] = in[ii][0];
tsclip(chandata,nadd,sthresh); // clean some spiky RFIs
mspec[channum]=chandata[nadd];
rspec[channum]=chandata[nadd+1];
if(rfiTx){
tsclip(chandata,nadd,sthresh); // clean some spiky RFIs
mspec[channum]=chandata[nadd];
rspec[channum]=chandata[nadd+1];
} else {
robust_meanrms(chandata,nadd);
mspec[channum]=chandata[nadd];
rspec[channum]=chandata[nadd+1];
}
}
else {
mspec[channum]=chandata[0];
Expand All @@ -388,10 +396,14 @@ void cleanit(float *data, int nchans, long int nadd)


for (i=0; i<nchans; i++) wspec[i]=+1.0;
spfind(mspec,nchans,rthresh,wspec);
spfind(vspec,nchans,rthresh,wspec);
tsfind(mspec,nchans,rthresh,wspec);
tsfind(vspec,nchans,rthresh,wspec);
if(rfiMSx){
spfind(mspec,nchans,rthresh,wspec);
tsfind(mspec,nchans,rthresh,wspec);
}
if(rfiVSx){
spfind(vspec,nchans,rthresh,wspec);
tsfind(vspec,nchans,rthresh,wspec);
}
if(pcl>0){
kk = (int)(0.9*nchans);
for (i=kk;i<nchans;i++) wspec[i]=0.0;
Expand Down Expand Up @@ -437,28 +449,32 @@ void cleanit(float *data, int nchans, long int nadd)


// Try clipping some channels in individual samples
for (t=0; t<nadd; t++){
nxc = t*nchans;
for (c=0; c<nchans; c++) chandata[c] = data[nxc+c];
spclip(chandata,nchans,clipthresh);
for (c=0; c<nchans; c++) data[nxc+c] = chandata[c];
if(rfiSclip){
for (t=0; t<nadd; t++){
nxc = t*nchans;
for (c=0; c<nchans; c++) chandata[c] = data[nxc+c];
spclip(chandata,nchans,clipthresh);
for (c=0; c<nchans; c++) data[nxc+c] = chandata[c];
}
}
// Now some timeseries cleaning
an = (double)nadd;
for (t=0; t<nadd; t++){
nxc = t*nchans;
chandata[t]=0.0;
for (c=0; c<nchans; c++) chandata[t] = chandata[t]+data[nxc+c];
chandata[t]=chandata[t]/an;
}
for (i=0; i<nadd; i++) wt[i]=+1.0;
tsfind(chandata,nadd,sthresh,wt);
spfind(chandata,nadd,sthresh,wt);
for (t=0; t<nadd; t++){
nxc = t*nchans;
if(wt[t] < 0.0){
for (c=0; c<nchans; c++) data[nxc+c] = mspec[c];
}
if(rfiTx){
an = (double)nadd;
for (t=0; t<nadd; t++){
nxc = t*nchans;
chandata[t]=0.0;
for (c=0; c<nchans; c++) chandata[t] = chandata[t]+data[nxc+c];
chandata[t]=chandata[t]/an;
}
for (i=0; i<nadd; i++) wt[i]=+1.0;
tsfind(chandata,nadd,sthresh,wt);
spfind(chandata,nadd,sthresh,wt);
for (t=0; t<nadd; t++){
nxc = t*nchans;
if(wt[t] < 0.0){
for (c=0; c<nchans; c++) data[nxc+c] = mspec[c];
}
}
}

// sometimes gpt results might need additional checks
Expand Down Expand Up @@ -536,14 +552,15 @@ void cleanit(float *data, int nchans, long int nadd)
}



if(iflip==1){ // flip the band
for (t=0; t<nadd; t++){
nxc = t*nchans;
for (c=0; c<nchans; c++) mspec[c] = data[nxc+c];
for (c=0; c<nchans; c++) data[nxc+c] = mspec[nchans-c-1];
}
}
/* ***Now the following part is in rficlean_data.c ***
// if(iflip==1){ // flip the band
// for (t=0; t<nadd; t++){
// nxc = t*nchans;
// for (c=0; c<nchans; c++) mspec[c] = data[nxc+c];
// for (c=0; c<nchans; c++) data[nxc+c] = mspec[nchans-c-1];
// }
// }
***/

}
//============================================================================
Loading

0 comments on commit 2f04f48

Please sign in to comment.