diff --git a/hashpy/io/obspyIO.py b/hashpy/io/obspyIO.py index a78e267..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 @@ -37,7 +39,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 +65,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 @@ -85,6 +88,8 @@ 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 @@ -107,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: @@ -137,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 = [] @@ -151,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]]) @@ -179,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 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: