Skip to content

Commit

Permalink
add mean vector function
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias47n9e committed May 14, 2015
1 parent d16a6fa commit 2177d1c
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 6 deletions.
140 changes: 140 additions & 0 deletions innstereo/calculate_mean_vector.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions innstereo/gui_layout.glade
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,11 @@ equatorial aspect</property>
<property name="can_focus">False</property>
<property name="pixbuf">calculate_normal_plane.svg</property>
</object>
<object class="GtkImage" id="image_mean_vector">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="pixbuf">calculate_mean_vector.svg</property>
</object>
<object class="GtkImage" id="image_new_faultplane">
<property name="visible">True</property>
<property name="can_focus">False</property>
Expand Down Expand Up @@ -4099,6 +4104,20 @@ equatorial aspect</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="toolbutton_mean_vector">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">toolbutton1</property>
<property name="use_underline">True</property>
<property name="icon_widget">image_mean_vector</property>
<signal name="clicked" handler="on_toolbutton_mean_vector_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="homogeneous">True</property>
</packing>
</child>
<child>
<object class="GtkToolButton" id="toolbutton_poles_to_lines">
<property name="visible">True</property>
Expand Down
57 changes: 51 additions & 6 deletions innstereo/main_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,51 @@ def on_toolbutton_linears_to_planes_clicked(self, toolbutton):

self.redraw_plot()

def on_toolbutton_mean_vector_clicked(self, toolbutton):
"""
Calculates the mean vector and adds it to the project.
Parses line-layers and adds up all the values. then the mean vector
is calculated and added to the project. The legend will show the
dip-direction/dip of the mean vector and the coefficient of
determination (r-value).
"""
selection = self.layer_view.get_selection()
model, row_list = selection.get_selected_rows()

if len(row_list) == 0:
return

#Check if all selected layers are linear layers.
only_lines = True
for row in row_list:
layer_obj = model[row][3]
if layer_obj.get_layer_type() != "line":
only_lines = False

if only_lines is False:
return

total_dipdir = []
total_dip = []
for row in row_list:
layer_obj = model[row][3]
store = layer_obj.get_data_treestore()
dipdir, dip, sense = self.parse_lines(store)
for x, y in zip(dipdir, dip):
total_dipdir.append(x)
total_dip.append(y)

lon, lat = mplstereonet.line(total_dip, total_dipdir)
mean_vec, r_value = mplstereonet.stereonet_math.mean_vector(lon, lat)
dipdir, dip = self.convert_lonlat_to_dipdir(mean_vec[0], mean_vec[1])

new_store, new_lyr_obj = self.add_layer_dataset("eigenvector")
new_lyr_obj.set_label("Mean Vector")
self.add_linear_feature(new_store, dipdir, dip, r_value)

self.redraw_plot()

def convert_lonlat_to_dipdir(self, lon, lat):
"""
Converts lat-lon data to dip-direction and dip.
Expand Down Expand Up @@ -1047,11 +1092,11 @@ def draw_eigenvector(self, layer_obj, dipdir, dip, values):
for v in values:
values_str.append(str(v))

lbl = "{} \n {}/{}, {}\n {}/{}, {}\n {}/{}, {}".format(
layer_obj.get_label(),
dipdir_str[0], dip_str[0], values_str[0],
dipdir_str[1], dip_str[1], values_str[1],
dipdir_str[2], dip_str[2], values_str[2])
lbl = "{} \n".format(layer_obj.get_label())

for key, value in enumerate(dipdir):
lbl += " {}/{}, {}\n".format(dipdir_str[key], dip_str[key],
values_str[key])

#ax.line takes dip first and then dipdir (as strike)
self.ax_stereo.line(dip, dipdir, marker=layer_obj.get_marker_style(),
Expand Down Expand Up @@ -1920,7 +1965,7 @@ def startup():
"image_best_fitting_plane", "layer_right_click_menu",
"image_create_small_circle", "menu_plot_views", "image_eigenvector",
"poles_to_lines", "image_linears_to_planes", "image_rotate",
"image_pt_axis"))
"image_pt_axis", "image_mean_vector"))

gui_instance = MainWindow(builder)
builder.connect_signals(gui_instance)
Expand Down

0 comments on commit 2177d1c

Please sign in to comment.