Commit 8f0af97f authored by Jenni Rinker's avatar Jenni Rinker
Browse files

switch to uzhub

parent 9619339e
Pipeline #13710 passed with stage
in 1 minute and 10 seconds
......@@ -78,7 +78,7 @@
"\n",
"Unlike the HAWC2 format, the full-field TurbSim binary format stores all three components as well as all information required to reconstruct the turbulence box. However, we are still required to pass in `spat_df` on saving, because we need to encode the spatial information in `spat_df` into the output binary file.\n",
"\n",
"Because TurbSim requires specifying a hub height, the write function allows you to specify the coordinates of the point collocated with the hub. If no coordinates are given, the center of the grid is used."
"Because TurbSim requires specifying a hub height and corresponding wind speed, the write function allows you to specify those values directly. If no coordinates are given, the center of the grid is used."
]
},
{
......@@ -89,7 +89,7 @@
"source": [
"# save in TurbSim format (path.bts)\n",
"path = 'ts.bts' # path is name of file (with or without ending)\n",
"df_to_bts(turb_df, spat_df, path, yzhub=None) # assume hub height is in center of box\n",
"df_to_bts(turb_df, spat_df, path, uzhub=None) # assume hub height is in center of box\n",
"\n",
"# reload file\n",
"ts_df = bts_to_df(path)\n",
......
......@@ -56,7 +56,7 @@ def bts_to_df(path):
return turb_df
def df_to_bts(turb_df, spat_df, path, yzhub=None):
def df_to_bts(turb_df, spat_df, path, uzhub=None):
"""pyconturb-style turbulence dataframe to TurbSim-style binary file
Code modified based on `turbsim` in PyTurbSim:
https://github.com/lkilcher/pyTurbSim/blob/master/pyts/io/write.py
......@@ -88,15 +88,12 @@ def df_to_bts(turb_df, spat_df, path, yzhub=None):
else:
dz = np.mean(z[1:] - z[:-1]) # hopefully will reduce possible errors
dt = turb_df.index[-1] / (turb_df.shape[0] - 1) # time step
if yzhub is None: # default is center of grid
if uzhub is None: # default is center of grid
zhub = z[z.size // 2] # halfway up
u_df = turb_df.filter(regex=f'u_', axis=1).values
uhub = u_df[:, u_df.shape[1] // 2].mean() # mean of center of grid
else:
yhub, zhub = yzhub
means = turb_df.iloc[:, (np.isclose(spat_df.loc['y'], yhub) &
np.isclose(spat_df.loc['z'], zhub))].mean()
uhub = float(means.filter(regex='u_'))
uhub, zhub = uzhub
# convert pyconturb dataframe to pyturbsim format (3 x ny x nz x nt)
ts = np.empty((3, ny, nz, nt))
for i, c in enumerate('uvw'):
......
......@@ -36,11 +36,11 @@ def test_pctdf_to_bts():
spat_df = gen_spat_grid(0, [50, 70])
turb_df = pd.DataFrame(np.random.rand(100, 6),
columns=[f'{c}_p{i}' for i in range(2) for c in 'uvw'])
yzhubs = [None, (0, 50)]
uzhubs = [None, (0.5, 60)]
# when
for path in paths: # check with and without extension
for yzhub in yzhubs:
df_to_bts(turb_df, spat_df, path, yzhub=yzhub)
for uzhub in uzhubs:
df_to_bts(turb_df, spat_df, path, uzhub=uzhub)
test_df = bts_to_df(path)
os.remove('./garbage.bts')
# then
......@@ -59,7 +59,7 @@ def test_pctdf_to_bts_const():
turb_df = pd.DataFrame(np.ones((100, 6)),
columns=[f'{c}_p{i}' for i in range(2) for c in 'uvw'])
# when
df_to_bts(turb_df, spat_df, path, yzhub=None)
df_to_bts(turb_df, spat_df, path, uzhub=None)
test_df = bts_to_df(path)
os.remove('./garbage.bts')
# then
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment