-
Notifications
You must be signed in to change notification settings - Fork 39
/
clearJunk.py
55 lines (45 loc) · 1.8 KB
/
clearJunk.py
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
# REDPy - Repeating Earthquake Detector in Python
# Copyright (C) 2016-2020 Alicia Hotovec-Ellis ([email protected])
# Licensed under GNU GPLv3 (see LICENSE.txt)
import redpy.config
import redpy.table
import redpy.plotting
import argparse
import numpy as np
import os
"""
Run this script to clear the contents of the junk table.
usage: clearJunk.py [-h] [-v] [-c CONFIGFILE]
optional arguments:
-h, --help show this help message and exit
-v, --verbose increase written print statements
-c CONFIGFILE, --configfile CONFIGFILE
use configuration file named CONFIGFILE instead of
default settings.cfg
"""
parser = argparse.ArgumentParser(description=
"Run this script to clear the contents of the junk table.")
parser.add_argument("-v", "--verbose", action="count", default=0,
help="increase written print statements")
parser.add_argument("-c", "--configfile",
help="use configuration file named CONFIGFILE instead of default settings.cfg")
args = parser.parse_args()
if args.configfile:
opt = redpy.config.Options(args.configfile)
if args.verbose: print("Using config file: {0}".format(args.configfile))
else:
opt = redpy.config.Options("settings.cfg")
if args.verbose: print("Using config file: settings.cfg")
if args.verbose: print("Opening hdf5 table: {0}".format(opt.filename))
h5file, rtable, otable, ttable, ctable, jtable, dtable, ftable = redpy.table.openTable(opt)
if args.verbose: print("Removing junk...")
if len(jtable) > 1:
# This will remove all but the last row (have to leave one)
for n in range(len(jtable)-1,0,-1):
jtable.remove_row(n)
jtable.flush()
else:
if args.verbose: print("No junk to remove!")
if args.verbose: print("Closing table...")
h5file.close()
if args.verbose: print("Done")