Scaler Service

The ScalerService gives access to the windPRO Scaler. You can add new scaler, modify an existing scaler or get all existing scalers. A displacement height model for forests Engineering Forest Service can be added to be used in the scaler as well. Additionally, it is possible to add post scaling calibrations. The example below shows how to access existing scalers and add a scaler including a displacement height calculated from forest data. Properties of the object representing this tool can be found here TApiSclSetupItems.

"""
Copyright 2023 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 WindProApi
from windproapi import nan_to_skipvalue

_windproapi = WindProApi()
_windproapi.start_windpro_random_port()

# Makiing example
working_dir = os.path.join(get_windpro_sample_path('4.0'), 'Scalar Service')
os.makedirs(working_dir, exist_ok=True)
project_path = os.path.join(working_dir, 'Scalar Example.w36p')

# Services
scaler_service = _windproapi.get_service('ScalerService')
online_data_service = _windproapi.get_service('OnlineDataService')
project_service = _windproapi.get_service('ProjectService')
objects_service = _windproapi.get_service('ObjectsService')
eng_forest_service = _windproapi.get_service('EngForestService')
obj_elevation_grid_service = _windproapi.get_service('ObjElevationGridService')
obj_site_data_service = _windproapi.get_service('ObjSiteDataService')
factory = _windproapi.get_factory('WindproService')


# Create a WindPRO project in a given location
lng = 13
lat = 57
project_service.NewProject(lng=lng, lat=lat, filename=project_path)

# Getting the defaul scalars
default_scalars = scaler_service.GetScalers()
print(default_scalars)

# Adding forest layers
forest_layer = objects_service.AddLayer(layerName='Forest data', parentFolderHandle=0)
terrain_data_type = 'ODSObjHeightsGrid'
online_data_service.PrepareService(dataType=terrain_data_type, lat=lat, lon=lng)
available_data = online_data_service.GetServices(dataType=terrain_data_type)
handle_forest = online_data_service.DownloadHeightData(dataType=terrain_data_type,
                                                       implId='SLU_FOREST_TREEHEIGHTS_ServiceID',
                                                       userDesc='Forest Data',
                                                       lat=lat,
                                                       lon=lng,
                                                       width=10000,
                                                       height=10000,
                                                       useAsTin=False)
elevation_grid_obj = obj_elevation_grid_service.GetElevationGridObject(handle=handle_forest)

# Getting roughness and terrain data
terrain_layer = objects_service.AddLayer(layerName='Terrain data', parentFolderHandle=0)
objects_service.SetEditLayer(handle=terrain_layer)

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)
# Choosing a specific dataset and downloading the data
terrain_service_id = 'SWE50_Grid'
terrain_handle = online_data_service.DownloadHeightData(dataType=terrain_data_type,
                                                        implId=terrain_service_id,
                                                        userDesc='Terrain data grid',
                                                        lat=lat,
                                                        lon=lng,
                                                        width=20000,
                                                        height=20000,
                                                        useAsTin=True)

# Getting roughness dataset sets
roughness_data_type = 'ODSRoughnessGridToLine'
online_data_service.PrepareService(dataType=roughness_data_type, lat=lat, lon=lng)
roughness_service = online_data_service.GetServices(dataType=roughness_data_type)
# Choosing a specific roughness dataset and downloading it
roughness_service_id = 'DataService_Rou_grid_GlobCover'
roughness_handle = online_data_service.DownloadRoughnessData(dataType=roughness_data_type,
                                                             implId=roughness_service_id,
                                                             userDesc='Roughness data',
                                                             lat=lat,
                                                             lon=lng,
                                                             width=20000,
                                                             height=20000)

# Adding the displacement height calculation
newEngforestName = 'Displacement height from scripting'
newEngforest = eng_forest_service.AddEngForest(name=newEngforestName)
newEngforest.HeightGridObjectHandle = handle_forest
newEngforest.InputType = 'fApihitHeightGrid'
newEngforest.HeightGridObjectLayerId = elevation_grid_obj.GridToHcSetup.Items.TApiGridToHCSetupItem[0].LayerID
nan_to_skipvalue(newEngforest)
eng_forest_service.SetEngForest(engForest=newEngforest)

# Adding a site data object
terrain_layer = objects_service.AddLayer(layerName='Site Data Objects', parentFolderHandle=0)
objects_service.SetEditLayer(handle=terrain_layer)

# Statistical wind climate with a Stat Gen Calculation
obj_site_data_statgen = objects_service.AddObject(apiObjType='SiteData',
                                                  lat=lat,
                                                  lng=lng,
                                                  userDesc='STATGEN SiteData')
obj_site_data_service.SetPurpose(handle=obj_site_data_statgen.Handle, purpose='SdPurpStatgen')
# Connecting elevation and roughness data and
obj_site_data_service.TerrainLinkElevationAndRoughnessLine(handle=obj_site_data_statgen.Handle,
                                                           elevHandle=terrain_handle,
                                                           rouLineHandle=roughness_handle)
# Getting an update of the changes that have been made to the object back to python
obj_site_data_statgen = obj_site_data_service.GetSiteDataObject(obj_site_data_statgen.Handle)

# Making a scalar that uses the engineering forest height
scaler = scaler_service.AddScaler(name='Engineering Forest Model')

# Adding the displacement height model
scaler.DisplCalcHandle = newEngforest.Handle
scaler.DisplType = 'ScalerDisplTypeCalc'

# Scaling type is from Mast measurement data
scaler.ScalerType = 'ScalerTypeMastScalingGeo'

# Adding site data and with it the link terrain and roughness data
scaler.SiteDataHandle = obj_site_data_statgen.Handle

nan_to_skipvalue(scaler)
scaler_service.SetScaler(scaler=scaler)