-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWDfilter
executable file
·75 lines (65 loc) · 2.49 KB
/
WDfilter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
from __future__ import print_function, division
import os
import argparse
import pandas as pd
import subprocess
#Dom Rowan REU 2018
desc="""
Go through AllData.csv and remove sources with x in comments. This will remove the output files, galexcsv, pdf, and add to list of filtered sources in WhiteDwarfs/filteredsources.txt
"""
#Add sources to text file of bad sources
def main():
assert(os.path.isfile("Output/AllData.csv"))
#Create file if it doesn't already exist
if not os.path.isfile("../filtersources.txt"):
with open('../filtersources.txt', 'w') as f:
f.close()
#Read in AllData.csv
df_rank = pd.read_csv("Output/AllData.csv")
#Intialize Lists
idx_drop = []
name_drop = []
band_drop = []
galexcsv_drop = []
outputcsv_drop = []
pdf_drop = []
#Iterate through DF
for i in range(len(df_rank['Comment'])):
if df_rank['Comment'][i] == 'x':
idx_drop.append(i)
name = df_rank['SourceName'][i]
band = df_rank['Band'][i]
name_drop.append(name)
band_drop.append(band)
galexcsv_drop.append(name+"-"+band+".csv")
outputcsv_drop.append("Output/"+name+"-"+band+"-output.csv")
pdf_drop.append("PDFs/"+name+"_"+band+"_combined.pdf")
confirm = input("Filtering all rows with 'x' in comment. Hit y to confirm --- ")
if confirm == 'y':
for gname, outputname, pdfname in zip(galexcsv_drop, outputcsv_drop, pdf_drop):
subprocess.run(['rm', gname])
subprocess.run(['rm', outputname])
subprocess.run(['rm', pdfname])
with open('../filtersources.txt', 'r') as f:
currentlines = f.readlines()
with open('../filtersources.txt', 'a') as f:
if not (gname in currentlines):
f.write(gname)
else:
return
#Used to filter a new sample by known 'bad' sources
def filterdir():
assert(os.path.isfile("../filtersources.txt"))
with open("../filtersources.txt", 'r') as f:
filteredfiles = f.readlines()
for filename in filteredfiles:
subprocess.run(['rm', filename])
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=desc)
parser.add_argument("--filterdir", help="Use current filtered information to reduce sample in current directory", default=False, action='store_true')
args= parser.parse_args()
if args.filterdir:
filterdir()
else:
main()