Skip to content

Commit

Permalink
Version 0.0.27
Browse files Browse the repository at this point in the history
#bugfix: beim öffnen eines pnt-files abfangen wenn die shot-noise-parameter nicht bestimmt werden können (z.B. weil surface und ground schon falsch gefunden wurden)
  • Loading branch information
thiemot committed Mar 12, 2018
1 parent 3edf002 commit 5c31f08
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 51 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
setup(
name='snowmicropyn',
description='SnowMicroPyn, an Application to view and analyze Snow Profiles recorded by Snow Micro Pen by SLF',
version='0.0.26',
version='0.0.27',
author='WSL Institute for Snow and Avalanche Research SLF',
author_email='[email protected]',
url='https://www.slf.ch/en/about-the-slf/instrumented-field-sites-and-laboratories/cold-chambers/snowmicropenr.html',
Expand Down
139 changes: 89 additions & 50 deletions snowmicropyn/SnowMicroPyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
exec_path = os.path.dirname(__file__)
name = "SnowMicroPyn"
title = "%s - The bit more complex PNT Reader for SnowMicroPen (R) Measurements" % name
version = "0.0.26 alpha"
version = "0.0.27 alpha"
author = "Sascha Grimm"
trademark = u"\u2122"
company = """WSL Institute for Snow and Avalanche Research SLF"""
Expand Down Expand Up @@ -499,32 +499,40 @@ def draw_figure(self, show=True, autozoom=True):
line.remove()
elif self.showDensity.IsChecked():
# plot density with second axis
shotNoiseData = self.File[self.current].shotnoise_data
density = shotNoiseData[:, 5]
x_density = shotNoiseData[:, 7]
self.axes2.get_yaxis().set_visible(True)
for line in self.axes2.lines:
line.remove()
self.axes2.set_ylabel("Density (kg/m^3)")
self.axes2.set_ylim(0, 700)
self.axes2.plot(x_density, density,
color=self.plotOptions.grad_color,
linestyle=self.plotOptions.grad_style,
linewidth=self.plotOptions.grad_width)
error=self.updateShotNoiseParameters(2.5,50,1)
if(error==1):
self.viewMenu.Check(self.showDensity.GetId(), False)
else:
shotNoiseData = self.File[self.current].shotnoise_data
density = shotNoiseData[:, 5]
x_density = shotNoiseData[:, 7]
self.axes2.get_yaxis().set_visible(True)
for line in self.axes2.lines:
line.remove()
self.axes2.set_ylabel("Density (kg/m^3)")
self.axes2.set_ylim(0, 700)
self.axes2.plot(x_density, density,
color=self.plotOptions.grad_color,
linestyle=self.plotOptions.grad_style,
linewidth=self.plotOptions.grad_width)
elif self.showSSA.IsChecked():
# plot ssa with second axis
shotNoiseData = self.File[self.current].shotnoise_data
ssa = shotNoiseData[:, 6]
x_ssa = shotNoiseData[:, 7]
self.axes2.get_yaxis().set_visible(True)
for line in self.axes2.lines:
line.remove()
self.axes2.set_ylabel("SSA (m^2/kg)")
self.axes2.set_ylim(0, 60)
self.axes2.plot(x_ssa, ssa,
color=self.plotOptions.median_color,
linestyle=self.plotOptions.grad_style,
linewidth=self.plotOptions.grad_width)
error = self.updateShotNoiseParameters(2.5, 50,1)
if (error == 1):
self.viewMenu.Check(self.showSSA.GetId(), False)
else:
shotNoiseData = self.File[self.current].shotnoise_data
ssa = shotNoiseData[:, 6]
x_ssa = shotNoiseData[:, 7]
self.axes2.get_yaxis().set_visible(True)
for line in self.axes2.lines:
line.remove()
self.axes2.set_ylabel("SSA (m^2/kg)")
self.axes2.set_ylim(0, 60)
self.axes2.plot(x_ssa, ssa,
color=self.plotOptions.median_color,
linestyle=self.plotOptions.grad_style,
linewidth=self.plotOptions.grad_width)
else:
self.axes2.get_yaxis().set_visible(False)
for line in self.axes2.lines:
Expand Down Expand Up @@ -687,9 +695,17 @@ def OnOpen(self, e):
data.ground = calc.GetGround(data)
data.ylim = None
data.xlim = None
window = 2.5
overlap = 50
data.shotnoise_data = numpy.array(calc.getSNParams(data, window, overlap))
try:
window = 2.5
overlap = 50
data.shotnoise_data = numpy.array(calc.getSNParams(data, window, overlap))
except:
dlg = wx.MessageDialog(self,
message="ERROR: Could not create shot-noise-parameters. Check if surface < ground!",
caption="Error",
style=wx.OK | wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()
self.File.append(data)
except:
dlg = wx.MessageDialog(self,
Expand Down Expand Up @@ -926,28 +942,31 @@ def SaveData(self, path=os.getcwd(), filename="", precision=3):

def SaveShotNoise(self, path=os.getcwd(), filename="", window=2.5, overlap=50):

if filename == "":
filename = self.File[self.current].filename
filename = os.path.basename(filename)
filename = filename.replace(".pnt", ".shn")

filename = os.path.join(path, filename)

numpy.savetxt(filename,
calc.getSNParams(self.File[self.current], window, overlap),
delimiter="\t",
newline="\n",
fmt="%3g",
header="""Automatic written Shot Noise Parameters by %s %s\n
File: %s\n
Window: %.2f mm\n
Overlap: %.2f\n
Surface: %.3f\n
Ground: %.3f\n
Lambda[1/mm]\tf_0[N]\tDelta[mm]\tL[mm]\tMedianF[N]\tDensity_Proksch[kg/m^3]\tSSA_Proksch[m^2/kg]\tz[mm]""" % (
name, version, self.File[self.current].filename, window, overlap,
self.File[self.current].surface,
self.File[self.current].ground))
error = self.updateShotNoiseParameters(window,overlap,0)
if (error == 0):
shotNoiseData = self.File[self.current].shotnoise_data.tolist()
if filename == "":
filename = self.File[self.current].filename
filename = os.path.basename(filename)
filename = filename.replace(".pnt", ".shn")

filename = os.path.join(path, filename)

numpy.savetxt(filename,
shotNoiseData,
delimiter="\t",
newline="\n",
fmt="%3g",
header="""Automatic written Shot Noise Parameters by %s %s\n
File: %s\n
Window: %.2f mm\n
Overlap: %.2f\n
Surface: %.3f\n
Ground: %.3f\n
Lambda[1/mm]\tf_0[N]\tDelta[mm]\tL[mm]\tMedianF[N]\tDensity_Proksch[kg/m^3]\tSSA_Proksch[m^2/kg]\tz[mm]""" % (
name, version, self.File[self.current].filename, window, overlap,
self.File[self.current].surface,
self.File[self.current].ground))

self.updateStatus("Saved Shot Noise Parameters to %s" % path)

Expand Down Expand Up @@ -1378,6 +1397,26 @@ def OpenFiles(self, files):
self.updateIndex()
self.draw_figure()

def updateShotNoiseParameters(self,window,overlap,calculateOnlyIfNotExisting=1):
error = 0
if(len(self.File[self.current].shotnoise_data)>0):
#shotNoiseParameters were already calculated
if(calculateOnlyIfNotExisting==1):
return error
data = self.File[self.current]
try:
self.File[self.current].shotnoise_data = numpy.array(calc.getSNParams(data, window, overlap))
except:
dlg = wx.MessageDialog(self,
message="ERROR: Could not create shot-noise-parameters. Check surface and ground!",
caption="Error",
style=wx.OK | wx.ICON_ERROR)
dlg.ShowModal()
dlg.Destroy()
error = 1
return error



def ask(question, caption="Confirm"):
"""show yes/no dialog"""
Expand Down

0 comments on commit 5c31f08

Please sign in to comment.