T-RIX Calculation Service

CalcTRIXService gives access to the TRIX calculation. It only contains two function, CalcTRIXService.GetTRIXCalc for getting a ZVI calculations and CalcTRIXService.SetTRIXCalc for passing it back to windPRO. The calculation is very simple. You need at least one WTG obejct, one meteo object, and elevation data that is used as TIN for the calcualtion. For changing the underlying elevation data used in the calculation, change the dataset that is used as TIN.

"""
Copyright 2024 EMD International
License for this script: MIT https://opensource.org/license/mit/
License for windPRO commercial software: https://www.emd-international.com/contact-us/general-terms-conditions-sale/
"""

import os
from windproapi.utils import get_windpro_sample_path
from windproapi import nan_to_skipvalue
from windproapi import WindProApi

# Opening windPRO
_windproapi = WindProApi()

working_dir = os.path.join(get_windpro_sample_path('4.1'), 'Trix')
project_path = os.path.join(working_dir, 'scripring_trix.w41p')

_windproapi.start_windpro_random_port()

# Services
online_data_service = _windproapi.get_service('OnlineDataService')
project_service = _windproapi.get_service('ProjectService')
objects_service = _windproapi.get_service('ObjectsService')
calculation_service = _windproapi.get_service('CalculationService')
calc_trix_service = _windproapi.get_service('CalcTRIXService')
obj_wtg_service = _windproapi.get_service('ObjWtgService')
wtg_explorer_service = _windproapi.get_service('WtgExplorerService')
obj_elevation_grid_service = _windproapi.get_service('ObjElevationGridService')
obj_line_service = _windproapi.get_service('ObjLineService')
factory = _windproapi.get_factory('WindproService')
# Position of the site center.
lng = 10.3
lat = 51.9

# Make a new project
project_service.NewProject(lng=lng, lat=lat, filename=project_path)

# Getting elevation data sets
terrain_data_type = 'ODSTerrainGrid'
online_data_service.PrepareService(dataType=terrain_data_type, lat=lat, lon=lng)
terrain_services = online_data_service.GetServices(dataType=terrain_data_type)
print(terrain_services)
# Choosing a specific dataset and downloading the data
terrain_service_id = 'XDGM200_Grid'
terrain_handle = online_data_service.DownloadHeightData(dataType=terrain_data_type,
                                                        implId=terrain_service_id,
                                                        userDesc='Terrain data grid',
                                                        lat=lat,
                                                        lon=lng,
                                                        width=30000,
                                                        height=30000,
                                                        useAsTin=True)

# Adding some meteo objects
dataType = 'ODSClimate'
online_data_service.PrepareService(dataType=dataType, lat=lat, lon=lng)
meteo_services = online_data_service.GetServices(dataType=dataType)
meteo_handles = online_data_service.DownloadMeteoData(implId='siEra5Basic',
                                                      lat=lat,
                                                      lon=lng,
                                                      maxDist=30000,
                                                      numPoints=1,
                                                      fromYear=2020,
                                                      toYear=2020)

wtg_catalogue_entry = wtg_explorer_service.GetWtgFromUID('{AA13428B-42E2-4160-9BC1-9A6B65EA41BF}')
wtg_from_file = wtg_explorer_service.GetWtgFromFile(wtg_catalogue_entry.FileName, True)

# Adding turbines positions
for i in range(5):
    new_obj = objects_service.AddObject(apiObjType='NewWTG',
                                        lat=lat-i/100,
                                        lng=lng,
                                        userDesc='New WTG obj')
    wtgObj = obj_wtg_service.GetWtgObject(new_obj.Handle)
    wtgObj.Filename = wtg_catalogue_entry.FileName
    wtgObj.UserLabel = f'Scripting added {i}'
    wtgObj.UserDescription = f'Scripting added {i}'
    nan_to_skipvalue(wtgObj)
    obj_wtg_service.SetWtgObject(wtgObj)

handle_calc_trix = calculation_service.CreateEmpty('CalcTRIX')
calculation_service.OpenCalcForEdit(handle=handle_calc_trix)
calc_trix = calc_trix_service.GetTRIXCalc()

# showing properties of calculation.
# By default all turbines and meteoobjects are included
print(calc_trix)

calc_trix.Name = 'Script generation with DGM200 Deutschland'
calculation_service.CloseCalc(True)
calculation_service.Calculate(handle=handle_calc_trix)


# Adding another elvation grid and calculating with that one.
surface_data_type = 'ODSSurfaceGrid'
online_data_service.PrepareService(dataType=surface_data_type, lat=lat, lon=lng)
surface_services = online_data_service.GetServices(dataType=surface_data_type)

# Choosing a specific dataset and downloading the data
surface_service_id = 'Global_TandemX90_Grid'
surface_handle = online_data_service.DownloadHeightData(dataType=surface_data_type,
                                                        implId=surface_service_id,
                                                        userDesc='Terrain data grid',
                                                        lat=lat,
                                                        lon=lng,
                                                        width=30000,
                                                        height=30000,
                                                        useAsTin=True)

# Getting information of the object
grid_obj = obj_elevation_grid_service.GetElevationGridObject(handle=surface_handle)
grid_obj.DefaultHC = True
grid_obj.UserDescription = 'Surface Elevation Copernicus'
grid_obj.UserLabel = 'Surface Elevation Copernicus'
nan_to_skipvalue(grid_obj)
obj_elevation_grid_service.SetElevationGridObject(apiElevationGridobj=grid_obj)


handle_calc_trix = calculation_service.CreateEmpty('CalcTRIX')
calculation_service.OpenCalcForEdit(handle=handle_calc_trix)
calc_trix = calc_trix_service.GetTRIXCalc()

# showing properties of calculation.
# By default all turbines and meteoobjects are included
print(calc_trix)

calc_trix.Name = 'Script generation with Copernicus DSM'
calculation_service.CloseCalc(True)
calculation_service.Calculate(handle=handle_calc_trix)