Skip to content
Snippets Groups Projects
Commit 18818fb7 authored by David Verelst's avatar David Verelst
Browse files

prepost.GenerateDLCs: some fail safe warnings, cosmetics

parent c79c6871
No related branches found
No related tags found
No related merge requests found
...@@ -79,32 +79,31 @@ class GeneralDLC(object): ...@@ -79,32 +79,31 @@ class GeneralDLC(object):
cases_len.append(len(v)) cases_len.append(len(v))
cases_index = multi_for(list(map(range, cases_len))) cases_index = multi_for(list(map(range, cases_len)))
# for irow, row in enumerate(cases_index): if '[wsp]' in variables_order:
# counter = floor(irow/len(variables['[wsp]']))+1 i_wsp = variables_order.index('[wsp]')
# for icol, col in enumerate(row): len_wsp = len(variables['[wsp]'])
# if variables_order[icol] == '[seed]': else:
# value = '%4.4i' % (1000*counter + row[variables_order.index('[wsp]')]+1) raise ValueError('Missing VARIABLE (V) [wsp] tag!')
# elif variables_order[icol] == '[wave_seed]': #shfe: wave_seed if '[seed]' in variables_order:
# value = '%4.4i' % (1000*counter + row[variables_order.index('[wsp]')]+1) i_seed = variables_order.index('[seed]')
# else: if '[wave_seed]' in variables_order:
# value = variables[variables_order[icol]][col] i_wave_seed = variables_order.index('[wave_seed]')
# if not isinstance(value, float) and not isinstance(value, int): if i_seed > i_wsp:
# value = str(value) raise ValueError('column [seed] should come BEFORE [wsp] !!')
# dlc[variables_order[icol]].append(value)
for irow, row in enumerate(cases_index): for irow, row in enumerate(cases_index):
counter = floor(irow/len(variables['[wsp]']))+1
for icol, col in enumerate(row): for icol, col in enumerate(row):
if variables_order[icol] == '[seed]': if variables_order[icol] == '[seed]':
value = '%4.4i' % (1000*counter + row[variables_order.index('[wsp]')]+1) counter = floor(irow/len_wsp) + 1
value = '%4.4i' % (1000*counter + row[i_wsp] + 1)
elif variables_order[icol] == '[wave_seed]': elif variables_order[icol] == '[wave_seed]':
value = '%4.4i' % ( 100*(row[variables_order.index('[wsp]')]+1) + \ value = '%4.4i' % (100*(row[i_wsp]+1) + row[i_wave_seed] + 1)
row[variables_order.index('[wave_seed]')]+1) # value = '%4.4i' % (1000*counter + row[i_wsp] + 101)
# value = '%4.4i' % (irow+1) # value = '%4.4i' % (irow+1)
# value = '%4.4i' % (10000*(row[variables_order.index('[wave_dir]')]+1) + \ # value = '%4.4i' % (10000*(row[i_wave_dir])] + 1) + \
# 1000*(row[variables_order.index('[Hs]')]+1) + \ # 1000*(row[i_Hs])] + 1) + \
# 10*(row[variables_order.index('[Tp]')]+1) +\ # 10*(row[i_Tp])] + 1) +\
# row[variables_order.index('[seed]')]+1) # row[i_seed])] + 1)
else: else:
value = variables[variables_order[icol]][col] value = variables[variables_order[icol]][col]
...@@ -153,8 +152,8 @@ class GeneralDLC(object): ...@@ -153,8 +152,8 @@ class GeneralDLC(object):
# specify the precision of the tag as used in the formulas # specify the precision of the tag as used in the formulas
# this does NOT affect the precision of the tag itself, only when used # this does NOT affect the precision of the tag itself, only when used
# in a formula based tag. # in a formula based tag.
formats = {'[wsp]':'%2.2i', '[gridgustdelay]':'%2.2i', formats = {'[wsp]':'%02i', '[gridgustdelay]':'%02i',
'[wdir]':'%3.3i', '[G_phi0]':'%3.3i', '[wdir]':'%03i', '[G_phi0]':'%03i',
'[sign]':'%s', '[sign]':'%s',
'[Hs]':'%05.02f', '[Tp]':'%05.02f'} '[Hs]':'%05.02f', '[Tp]':'%05.02f'}
...@@ -168,7 +167,7 @@ class GeneralDLC(object): ...@@ -168,7 +167,7 @@ class GeneralDLC(object):
try: try:
fmt = formats[key] fmt = formats[key]
except KeyError: except KeyError:
fmt = '%4.4i' fmt = '%04i'
try: try:
value = float(dlc[key][i]) value = float(dlc[key][i])
except ValueError: except ValueError:
...@@ -209,14 +208,15 @@ class GenerateDLCCases(GeneralDLC): ...@@ -209,14 +208,15 @@ class GenerateDLCCases(GeneralDLC):
""" """
def execute(self, filename='DLCs.xlsx', folder=''): def execute(self, filename='DLCs.xlsx', folder='', isheets=None):
book = xlrd.open_workbook(filename) book = xlrd.open_workbook(filename)
nsheets = book.nsheets if isheets is None:
isheets = list(range(1, book.nsheets))
# Loop through all the sheets. Each sheet correspond to a DLC. # Loop through all the sheets. Each sheet correspond to a DLC.
for isheet in range(1, nsheets): for isheet in isheets:
# Read all the initialization constants and functions in the # Read all the initialization constants and functions in the
# first sheet # first sheet
...@@ -277,29 +277,6 @@ class GenerateDLCCases(GeneralDLC): ...@@ -277,29 +277,6 @@ class GenerateDLCCases(GeneralDLC):
df.to_excel(os.path.join(folder, sheet.name+'.xlsx'), index=False) df.to_excel(os.path.join(folder, sheet.name+'.xlsx'), index=False)
class RunTest():
"""
Class to perform basic testing of the GenerateDLCCases class. It writes the
spreadsheets and compare them with a reference set.
"""
def execute(self):
from pandas.util.testing import assert_frame_equal
a = GenerateDLCCases()
a.execute()
book = xlrd.open_workbook('DLCs.xlsx')
nsheets = book.nsheets
for isheet in range(1, nsheets):
sheet = book.sheets()[isheet]
print('Sheet #%i' % isheet, sheet.name)
book1 = pd.read_excel('Reference/'+sheet.name+'.xlsx')
book2 = pd.read_excel(sheet.name+'.xls')
book2 = book2[book1.columns]
assert_frame_equal(book1, book2, check_dtype=False)
if __name__ == '__main__': if __name__ == '__main__':
parser = ArgumentParser(description = "generator of DLB spreadsheets") parser = ArgumentParser(description = "generator of DLB spreadsheets")
......
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