#################################################################################
#
# Tutorial file how to read in hdf5 data from SP-Wind Windfarm simulations,
# generated in the context of the TotalControl project.
#
# A thorough description of the simulations and data can be found at in the deliverable report
#
# author: Ishaan Sood
# date: 24 Feb 2020
# email: sood.ishaan26@gmail.com
#
#################################################################################

'''
Read and plot timeseries aerodynamic and structural data of all wind turbines.

'''


import numpy as np
import matplotlib.pyplot as plt
import h5py as hp

plt.close("all")

# open the file

meta_data = hp.File('turb_performance.h5', 'r')

###########################################################################################################################
#
# FILE: turb_performance.h5
#
#   group: aerodynamics
#       description:    Aerodynamics performance data
#       dataset: time_array ( 900 to 4500 in steps of 1s)
#       subgroups: power, rot_spd, pitch, thrust
#           datasets:  turb_* (1 and 2)
#
#   group: structural
#       description:    structural performance data
#       dataset: time_array ( 900 to 4500 in steps of 0.01s)
#       subgroups: Moo (out of plane blade root bending moment) , Mii (in plane moments)
#           datasets:  turb_* (1 and 2)
#
#  Turbine coordinates in the 16 km X 16 km domain
#
#   turb_1 = (5773.9, 11343.1)
#   turb_2 = (6665.4, 10897.4)
#
###########################################################################################################################

group = 'aerodynamics'
component = 'power'
turbine = 'turb_2'

time = np.array(meta_data[group]['time_array'])
data = np.array(meta_data[group][component][turbine])

data = data[0]

plt.plot(time[0], data)
plt.savefig('power.png')
plt.show()
