From aff562210abe71fc24ea939a65014615a80f9f18 Mon Sep 17 00:00:00 2001 From: Stephen Bannister Date: Sun, 1 Nov 2015 10:56:00 +1300 Subject: [PATCH 1/3] changes made to obspyIO.py and focalmechplotter.py for string eqyuivalence --- hashpy/io/obspyIO.py | 23 ++++++++++++----------- hashpy/plotting/focalmechplotter.py | 8 +++++--- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/hashpy/io/obspyIO.py b/hashpy/io/obspyIO.py index a78e267..bad029a 100644 --- a/hashpy/io/obspyIO.py +++ b/hashpy/io/obspyIO.py @@ -37,7 +37,7 @@ def inputOBSPY(hp, event): hp.sez = _o.origin_uncertainty.confidence_ellipsoid.semi_intermediate_axis_length if _m: hp.qmag = _m.mag - + # The index 'k' is deliberately non-Pythonic to deal with the fortran # subroutines which need to be called and the structure of the original HASH code. # May be able to update with a rewrite... YMMV @@ -63,21 +63,22 @@ def inputOBSPY(hp, event): if arrv.phase not in 'Pp': continue - if (pick.polarity is 'positive'): - hp.p_pol[k] = 1 - elif (pick.polarity is 'negative'): - hp.p_pol[k] = -1 - else: - continue - - if (pick.onset is 'impulsive'): + if (pick.onset == 'impulsive'): hp.p_qual[k] = 0 - elif (pick.onset is 'emergent'): + elif (pick.onset == 'emergent'): hp.p_qual[k] = 1 - elif (pick.onset is 'questionable'): + elif (pick.onset == 'questionable'): hp.p_qual[k] = 1 else: hp.p_qual[k] = 0 + + if (pick.polarity == 'positive'): + hp.p_pol[k] = 1 + elif (pick.polarity == 'negative'): + hp.p_pol[k] = -1 + else: + continue + # polarity check in original code... doesn't work here #hp.p_pol[k] = hp.p_pol[k] * hp.spol diff --git a/hashpy/plotting/focalmechplotter.py b/hashpy/plotting/focalmechplotter.py index f9f09b0..4ae7306 100644 --- a/hashpy/plotting/focalmechplotter.py +++ b/hashpy/plotting/focalmechplotter.py @@ -110,6 +110,7 @@ def plot_on_stereonet(self, axis=None, fm=None): 'markeredgewidth' : 2, } for ind, a in enumerate(self._orig.arrivals): + plotit = True p = a.pick_id.getReferredObject() # Calculate strike azi from direct (dip-pointing) azi azi = a.azimuth - 90. @@ -122,16 +123,17 @@ def plot_on_stereonet(self, axis=None, fm=None): elif 90. <= a.takeoff_angle <= 180.: toa = 270. - a.takeoff_angle # project upward angles else: + plotit = False raise ValueError("Takeoff angle ({0}) must be in [0, 180]".format(a.azimuth)) - if p.polarity is 'positive': + if p.polarity == 'positive' and plotit == True: #plot_specs.update({'markeredgecolor' : 'black', 'markerfacecolor' : 'red' }) h += ax.rake(azi, toa, 90, 'o', markeredgecolor='black', markerfacecolor='red', **plot_specs) - if p.polarity is 'negative': + if p.polarity == 'negative' and plotit == True: #plot_specs.update({'markeredgecolor' : 'blue', 'markerfacecolor' : 'white' }) h += ax.rake(azi, toa, 90, 'o', markeredgecolor='blue', markerfacecolor='white', **plot_specs) index.append(ind) - if True: + if plotit: h_text = ax.rake(azi, toa+5, 90, marker='$ {0}$'.format(p.waveform_id.station_code), color='black',markersize=20) for comm in self.focm.comments: From bc6129ae3c0a739f217d5105b01d577e0906cef2 Mon Sep 17 00:00:00 2001 From: Stephen Bannister Date: Fri, 27 Nov 2015 12:49:43 +1300 Subject: [PATCH 2/3] small changes to io/obspyIO.py --- hashpy/io/obspyIO.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hashpy/io/obspyIO.py b/hashpy/io/obspyIO.py index bad029a..5961d07 100644 --- a/hashpy/io/obspyIO.py +++ b/hashpy/io/obspyIO.py @@ -86,6 +86,7 @@ def inputOBSPY(hp, event): k += 1 hp.npol = k # k is zero indexed in THIS loop + def outputOBSPY(hp, event=None, only_fm_picks=False): """ Make an Event which includes the current focal mechanism information from HASH From d9355994872b4b0a3957eadb6fd408716b2d4e82 Mon Sep 17 00:00:00 2001 From: Stephen Bannister Date: Fri, 27 Nov 2015 13:23:09 +1300 Subject: [PATCH 3/3] 2 small changes in io/obspyIO.py --- hashpy/io/obspyIO.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hashpy/io/obspyIO.py b/hashpy/io/obspyIO.py index 5961d07..66620ab 100644 --- a/hashpy/io/obspyIO.py +++ b/hashpy/io/obspyIO.py @@ -25,8 +25,10 @@ def inputOBSPY(hp, event): event.origins you want to use """ # Takes an obspy event and loads FM data into HASH - _o = event.preferred_origin() - _m = event.preferred_magnitude() +# _o = event.preferred_origin() + _o = event.preferred_origin +# _m = event.preferred_magnitude() + _m = event.preferred_magnitude hp.tstamp = _o.time.timestamp hp.qlat = _o.latitude @@ -86,6 +88,7 @@ def inputOBSPY(hp, event): k += 1 hp.npol = k # k is zero indexed in THIS loop +# =============================================================== def outputOBSPY(hp, event=None, only_fm_picks=False): """ @@ -109,6 +112,7 @@ def outputOBSPY(hp, event=None, only_fm_picks=False): Event will be new if no event was input, FocalMech added to existing event """ + # Returns new (or updates existing) Event with HASH solution n = hp.npol if event is None: @@ -139,6 +143,7 @@ def outputOBSPY(hp, event=None, only_fm_picks=False): event.picks.append(p) event.origins.append(origin) event.preferred_origin_id = str(origin.resource_id) + else: # just update the changes origin = event.preferred_origin() picks = [] @@ -153,8 +158,10 @@ def outputOBSPY(hp, event=None, only_fm_picks=False): if only_fm_picks: origin.arrivals = arrivals event.picks = picks + # Use me double couple calculator and populate planes/axes etc x = hp._best_quality_index + # Put all the mechanisms into the 'focal_mechanisms' list, mark "best" as preferred for s in range(hp.nmult): dc = DoubleCouple([hp.str_avg[s], hp.dip_avg[s], hp.rak_avg[s]]) @@ -181,5 +188,6 @@ def outputOBSPY(hp, event=None, only_fm_picks=False): event.focal_mechanisms.append(focal_mech) if s == x: event.preferred_focal_mechanism_id = str(focal_mech.resource_id) + return event