From fc2784296ec0dc2f195addd9b1d01a20fc3927ca Mon Sep 17 00:00:00 2001
From: Marcus Herrmann <marcus.herrmann@sed.ethz.ch>
Date: Tue, 20 Dec 2016 12:54:34 +0100
Subject: [PATCH] Clean up of scripts (reorder + more comments)

---
 Example/script.py     | 30 +++++++++++++++++-------------
 Example/script_mpi.py | 24 +++++++++++++++---------
 TM/plotting.py        |  4 ++--
 TM/setupclass.py      |  3 ++-
 version               |  2 +-
 5 files changed, 37 insertions(+), 26 deletions(-)

diff --git a/Example/script.py b/Example/script.py
index 7909dca..a644679 100644
--- a/Example/script.py
+++ b/Example/script.py
@@ -77,14 +77,14 @@ config.templateShiftCorr = False    # Whether to shift templates to align them t
 config.timeTol = 0.5                # (post-processing) Used to unify detections of templates
 
 # -- Scanning parameters
-config.filtConf = [5, 30, 4]; config.stop50Hz = False
-config.filterBuff = 1.0             # To avoid filter response in signal:
-                                    #    Time to prepend and append before filtering waveform
+config.filtConf = [5, 30, 4]        # BP Filter limits & order
+config.stop50Hz = False             # 50Hz Bandstop?
+config.filterBuff = 1.0             # Waveform filter margin to avoid filter response in signal
 config.FFT_filt = False             # Filter in frequency domain? (useful if FFT resampling anyway)
 
 config.threshold = .40              # The general threshold (as fraction of 1)
 config.threshCred = .50             # The credible (more conservative) threshold
-config.threshPerChannel = False     # Apply thresh to EACH channel (and not MEAN among channels)
+config.threshPerChannel = False     # Apply thresh to EACH channel? (and not MEAN among channels)
 
 # -- Timing
 config.startdate = UTCDateTime("2015-01-01")
@@ -101,7 +101,7 @@ config.parallelFilter = False       # (process-based-parallel can take up huge a
 config.use_threads = True           # Use threads for certain tasks (e.g., read, calc_std_window)
 
 # Immitate MPI-related config parameters (to avoid 'Value not set' error when NOT using MPI)
-config.chunk_len = 24*60*60
+config.chunk_len = 24*60*60         # 24 hours
 config.overlap_len = 0
 config.max_chunk_on_disk = 0
 config.num_readers = 0
@@ -110,26 +110,30 @@ config.num_readers = 0
 config.select_fastest_approach()    # Will benchmark for 2x1 minute
 #config.conv_method = 'fftconvolve' # Choose method right away ['convolve', 'fftconvolve']
 
-
-# Define more threshold values
-threshs = sorted(set([config.threshold, config.threshCred] +
-                     [0.45, 0.5, 0.55, 0.6, 0.8]))
-
 # -- Set output directory (for results)
 config.set_dir(regionName=True, openEnd=True, moreInfo=False)
 
-
 # -- Treat template selection ( = making a templateSet)
 
 # * Auto mode
-templateSet = []            # Start with empty templateSet
+templateSet = []                       # Start with empty templateSet
 config.templateMagRange = (-2.0, 1.2)  # Magnitude range of events to use for scanning
 config.firstTemplateMinMag = 0.5       # Minimum magnitude of first template event
 config.threshNewTemplate = .75         # Catalog events that were detected with CC smaller than
-                                       #    this will become a new template
+                                       #    this value will become a new template
+
+# -- Define more threshold values
+threshs = sorted(set([config.threshold, config.threshCred] +
+                     [0.45, 0.5, 0.55, 0.6, 0.8]))
+
+#
+# [setup complete]
 
 #exit()  # Maybe you want to stop here first?
 
+
+# --- Load the catalog (= potential templates)
+
 # Run SQL script, and delete the events not needed in the csv
 #  (i.e. events before startdate, or AUTOMATIC locations/magnitudes)
 #getEventsFromSC3DB()
diff --git a/Example/script_mpi.py b/Example/script_mpi.py
index a5b144b..8a28974 100644
--- a/Example/script_mpi.py
+++ b/Example/script_mpi.py
@@ -54,7 +54,7 @@ config.FDSN_waveforms = False       # Whether to use FDSN also as data source fo
 # -- Network / Station related parameters
 config.network = 'CH'
 config.region =  'Chamonix'
-config.station = 'SALAN';
+config.station = 'SALAN'
 config.load_station_info()          # Gets station meta data (e.g., channels, sampling rate)
 
 # Limit to certain channel codes
@@ -70,14 +70,14 @@ config.templateShiftCorr = False    # Whether to shift templates to align them t
 config.timeTol = 0.5                # (post-processing) Used to unify detections of templates
 
 # -- Scanning parameters
-config.filtConf = [5, 30, 4]; config.stop50Hz = False
-config.filterBuff = 1.0             # To avoid filter response in signal:
-                                    #    Time to prepend and append before filtering waveform
+config.filtConf = [5, 30, 4]        # BP Filter limits & order
+config.stop50Hz = False             # 50Hz Bandstop?
+config.filterBuff = 1.0             # Waveform filter margin to avoid filter response in signal
 config.FFT_filt = False             # Filter in frequency domain? (useful if FFT resampling anyway)
 
 config.threshold = .40              # The general threshold (as fraction of 1)
 config.threshCred = .50             # The credible (more conservative) threshold
-config.threshPerChannel = False     # Apply thresh to EACH channel (and not MEAN among channels)
+config.threshPerChannel = False     # Apply thresh to EACH channel? (and not MEAN among channels)
 
 # -- Timing
 config.startdate = UTCDateTime("2015-01-01")
@@ -93,7 +93,7 @@ config.set_resampling('auto')       # or: 'none', or: 'manual' with srate= or fa
 config.parallelFilter = False       # (process-based-parallel can take up huge amounts of memory)
 config.use_threads = False          # Use threads for certain tasks (e.g., read, calc_std_window)
 
-# MPI
+# MPI settings
 config.chunk_len = 60*60*6    # 6 hours
 config.overlap_len = 30       # 30 seconds
 config.max_chunk_on_disk = 3  # max number of chunks on disks
@@ -107,18 +107,23 @@ config.select_fastest_approach()    # Will benchmark for 2x1 minute
 # -- Set output directory (for results)
 config.set_dir(regionName=True, openEnd=True, moreInfo=False)
 
-
 # -- Treat template selection ( = making a templateSet)
 
 # * Auto mode
-templateSet = []            # Start with empty templateSet
+templateSet = []                       # Start with empty templateSet
 config.templateMagRange = (-2.0, 1.2)  # Magnitude range of events to use for scanning
 config.firstTemplateMinMag = 0.5       # Minimum magnitude of first template event
 config.threshNewTemplate = .75         # Catalog events that were detected with CC smaller than
-                                       #    this will become a new template
+                                       #    this value will become a new template
+
+#
+# [setup complete]
 
 #exit()  # Maybe you want to stop here first?
 
+
+# --- Load the catalog (= potential templates)
+
 # Run SQL script, and delete the events not needed in the csv
 #  (i.e. events before startdate, or AUTOMATIC locations/magnitudes)
 #getEventsFromSC3DB()
@@ -127,6 +132,7 @@ catalog = readCatalogSEDDB()
 #preload_events(catalog, readALLagain=False)
 # NOW CHECK IF THERE ARE DOUBLE EVENTS (o qualcosa) ... and exclude them!
 
+
 # --- Do the Template Matching
 
 # Adjust canditate catalog list
diff --git a/TM/plotting.py b/TM/plotting.py
index cc6bc0d..8b3e264 100644
--- a/TM/plotting.py
+++ b/TM/plotting.py
@@ -313,7 +313,7 @@ def plot_hist_template_distribution(foundEvents, foundEvents_full=[], threshold=
     plt.legend()
 
     plt.savefig(config.directory + "/_templateSet_hist_distribution%s_thresh%.2f.png"
-                % (suffix, threshold), dpi=150)
+                % (suffix, threshold), dpi=150, bbox_inches='tight')
     plt.close()
 
 
@@ -348,7 +348,7 @@ def plot_hist_template_counts(foundEvents, threshold=None):
     plt.xticks(np.arange(1, maxRange+1))
     plt.tick_params(axis='x', which='major', labelsize=6)
     plt.savefig(config.directory + "/_templateSet_hist_counts_thresh%.2f.png" % threshold,
-                dpi=150)
+                dpi=150, bbox_inches='tight')
     plt.close()
 
 
diff --git a/TM/setupclass.py b/TM/setupclass.py
index f897a48..2977dc7 100644
--- a/TM/setupclass.py
+++ b/TM/setupclass.py
@@ -47,8 +47,9 @@ class Setup:
 
     # Scanning parameters
     resampling = None           # maximum sampling rate (to save memory)
-    filtConf = None             # Upper & Lower bounds & Filter order
+    filtConf = None             # BP Filter limits & order
     stop50Hz = None             # Whether to remove the 50Hz
+    filterBuff = None           # Waveform filter margin to avoid filter response in signal
     FFT_filt = None             # Whether to filter in frequency domain
 
     threshold = None
diff --git a/version b/version
index 0ea3a94..0c62199 100644
--- a/version
+++ b/version
@@ -1 +1 @@
-0.2.0
+0.2.1
-- 
GitLab