Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes made to obspyIO.py and focalmechplotter.py for string equiva… #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions hashpy/io/obspyIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -63,28 +65,31 @@ 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'):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just cosmetics, but those brackets ain't necessary..

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was in Fortran mode when I did that 👎

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@megies is correct. use == to compare strings, never is.
is is a much stricter and here unwanted comparison.

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
hp.p_index.append(_i) # indicies of [arrivals] which passed
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
Expand All @@ -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:
Expand Down Expand Up @@ -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 = []
Expand All @@ -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]])
Expand All @@ -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

8 changes: 5 additions & 3 deletions hashpy/plotting/focalmechplotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:
Expand Down