import PySAM.ResourceTools
import PySAM.Lcoefcr as lc
import PySAM.Grid as gd
import PySAM.Windpower as wp

wind_resource = PySAM.ResourceTools.FetchResourceFiles(
    'wind',
    nrel_api_key='KEY_HERE',
    nrel_api_email='EMAIL_HERE',
    workers=1,
    resource_type='psm3-5min',
    resource_year='2014',
    resource_interval_min=5,
    resource_height=80
    )

lon_lat = [(-97.1292, 33.2164)]
wind_resource.fetch(lon_lat)

wtk_path_dict = wind_resource.resource_file_paths_dict
wtk_fp = wtk_path_dict[lon_lat[0]]


# Initialize PySAM model
system_model = wp.default('WindPowerLCOECalculator')

system_model.Resource.wind_resource_filename = wtk_fp


# Initialize grid and LCOE modules from initial model
g = gd.from_existing(system_model, 'WindPowerLCOECalculator')
c = lc.from_existing(system_model, 'WindPowerLCOECalculator')

# Execute models
system_model.execute(0)
g.execute(0)
c.execute(0)

# Get LCOE ($/kWh)
lcoe_wind = c.Outputs.lcoe_fcr

# Find annual energy: difference of total generated and curtailed energy
energy_wind = g.Outputs.annual_energy_pre_curtailment_ac - g.Outputs.annual_ac_curtailment_loss_kwh

hourly_gen_wind = g.Outputs.gen

print(len(g.Outputs.gen))