Skip to content
Snippets Groups Projects
Commit d5bb5600 authored by Mads M. Pedersen's avatar Mads M. Pedersen
Browse files

add title to exec_long_task and update ascii2bin

parent b0385c24
No related branches found
No related tags found
1 merge request!241add title to exec_long_task and update ascii2bin
Pipeline #52085 failed
......@@ -8,11 +8,11 @@
[tool.poetry]
name = "wetb"
version = "v0.1.4"
description = "The Wind Energy Toolbox (or ```wetb```, pronounce as wee-tee-bee) is a collection of Python scripts that facilitate working with (potentially a lot) of HAWC2, HAWCStab2, FAST or other text input based simulation tools. Note that this toolbox is very much a WIP (work in progress). For example, some of the functions in the [prepost](#prepost) module have a similar functions in [Hawc2io](wetb/hawc2/Hawc2io.py). These different implementations will be merged in due time. Both Python2 and Python3 are supported"
version = "v0.1.8.dev1+g80b1595"
description = "The Wind Energy Toolbox (or ```wetb```, pronounce as wee-tee-bee) is a collection of Python scripts that facilitate working with (potentially a lot) of HAWC2, HAWCStab2, FAST or other text input based simulation tools. Note that this toolbox is very much"
authors = ["DTU Wind and Energy Systems <you@example.com>"]
license = "wetb is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (GPL, http://www.gnu.org/copyleft/gpl.html) as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. wetb is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details http://www.gnu.org/licenses/ We encourage you to submit new code for possible inclusion in future versions of wetb."
readme = "README.md"
[tool.poetry.dependencies]
click = "^8.0.4"
......@@ -24,6 +24,7 @@ matplotlib = "^3.8"
pillow = "^10.0.1" # This is only needed as long as matplotlib does not require pillow >= 10.0.1.
mock = "^5.0.2"
numpy = ">=1.4"
numba = ">=0.56"
openpyxl = { version = "^3.1.2", optional = true }
pandas = "^1.1.5"
paramiko = {version="^3.2.0", optional = true}
......@@ -46,4 +47,4 @@ all = ["openpyxl", "tables", "wafo", "xlwt", "Cython", "paramiko", "sshtunnel"]
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
build-backend = "poetry.core.masonry.api"
\ No newline at end of file
from wetb.hawc2.ascii2bin.pandas_dat_ascii2bin import pandas_dat_ascii2bin
import sys
import warnings
warnings.filterwarnings("ignore", message="numpy.ufunc size changed")
from wetb.hawc2.ascii2bin.pandas_dat_ascii2bin import pandas_dat_ascii2bin
class TextUI(object):
def show_message(self, m):
print (m)
print(m)
def exec_long_task(self, text, allow_cancel, task, *args, **kwargs):
print (text)
def exec_long_task(self, title, text, allow_cancel, task, *args, **kwargs):
print(text)
return task(*args, **kwargs)
sys.path.append(".")
def size_from_file(selfilename):
with open(selfilename, encoding='utf-8') as f:
info = f.readlines()[8].split()
......@@ -22,6 +24,7 @@ def size_from_file(selfilename):
no_sensors = int(info[1])
return (scans, no_sensors)
def ascii2bin(ascii_selfilename, bin_selfilename=None, ui=TextUI()):
# Convert dat file
......@@ -29,7 +32,6 @@ def ascii2bin(ascii_selfilename, bin_selfilename=None, ui=TextUI()):
if bin_selfilename is None:
bin_selfilename = ascii_selfilename[:-4] + "_bin.sel"
# Read, convert and write sel file
with open(ascii_selfilename, encoding='utf-8') as f:
lines = f.readlines()
......@@ -51,9 +53,10 @@ def ascii2bin(ascii_selfilename, bin_selfilename=None, ui=TextUI()):
if ui is not None:
ui.show_message("Finish converting %s to %s" % (ascii_selfilename, bin_selfilename))
if __name__ == "__main__":
if len(sys.argv) < 2:
print ("syntax: ascii2bin ascii_sel_filename [bin_sel_filename]")
print("syntax: ascii2bin ascii_sel_filename [bin_sel_filename]")
elif len(sys.argv) == 2:
ascii2bin(sys.argv[1])
else:
......
......@@ -8,21 +8,20 @@ import numpy as np
from pandas import read_csv
def pandas_dat_ascii2bin(ascii_filename, bin_filename, ui):
df = ui.exec_long_task("Reading ascii file", False, read_csv, ascii_filename, sep=" ", skipinitialspace=True, header=None)
df = ui.exec_long_task("Please wait...", "Reading ascii file", False, read_csv, ascii_filename, sep=" ",
skipinitialspace=True, header=None)
def compress(df, bin_filename):
with open(bin_filename, 'wb') as outfile:
scale_factors = []
for _, sensor in df.iteritems():
for _, sensor in df.items():
sf = sensor.abs().max() / 32000
if sf > 0:
sensor /= sf
np.round(sensor.values).astype(np.int16).tofile(outfile)
scale_factors.append(sf)
return np.array(scale_factors)
#return compress(df, bin_filename)
return ui.exec_long_task("Compress and save as binary", False, compress, df, bin_filename)
# return compress(df, bin_filename)
return ui.exec_long_task("Please wait...", "Compress and save as binary", False, compress, df, bin_filename)
......@@ -13,22 +13,14 @@ from wetb.hawc2.ascii2bin.ascii2bin import ascii2bin, size_from_file
testfilepath = os.path.join(os.path.dirname(__file__), 'test_files/') # test file path
class TextUI(object):
def show_message(self, m):
pass
def exec_long_task(self, text, allow_cancel, task, *args, **kwargs):
return task(*args, **kwargs)
class TestAscii2Bin(unittest.TestCase):
def testAscii2bin(self):
for f in ["Hawc2ascii_bin.sel", "Hawc2ascii_bin.dat"]:
if os.path.exists(testfilepath + f):
os.remove(testfilepath + f)
ascii2bin(testfilepath + "Hawc2ascii.sel", ui=TextUI())
ascii2bin(testfilepath + "Hawc2ascii.sel")
ascii_file = Hawc2io.ReadHawc2(testfilepath + 'Hawc2ascii')
bin_file = Hawc2io.ReadHawc2(testfilepath + "Hawc2ascii_bin")
......@@ -40,7 +32,7 @@ class TestAscii2Bin(unittest.TestCase):
for f in ["Hawc2bin.sel", "Hawc2bin.dat"]:
if os.path.exists(testfilepath + f):
os.remove(testfilepath + f)
ascii2bin(testfilepath + "Hawc2ascii.sel", testfilepath + "Hawc2bin.sel", ui=TextUI())
ascii2bin(testfilepath + "Hawc2ascii.sel", testfilepath + "Hawc2bin.sel")
ascii_file = Hawc2io.ReadHawc2(testfilepath + 'Hawc2ascii')
bin_file = Hawc2io.ReadHawc2(testfilepath + "Hawc2bin")
......@@ -48,12 +40,10 @@ class TestAscii2Bin(unittest.TestCase):
np.testing.assert_array_almost_equal(ascii_file.ReadAscii(), bin_file.ReadBinary(), 1)
self.assertEqual(ascii_file.ChInfo, bin_file.ChInfo)
def testSizeOfFile(self):
self.assertEqual(size_from_file(testfilepath + "Hawc2ascii.sel"), (800, 28))
if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testName']
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment