Site Data Service

The ObjSiteDataService provides access to functionality related to Site Data objects. Site data objects can have different purposes:

Purposes of the site data object

Name of purpose

Description

SdPurpUndef

not defined

SdPurpAtlas

ATLAS service

SdPurpWasp

for WAsP calculation

SdPurpStatgen

for statistical wind climate STATGEN

SdPurpResource

for wind resource map

SdPurpCFD

for CFD calculation

Site data objects need to be linked to calculations that require them, for example STATGEN. Terrain and roughness maps can be linked to the site data object. Properties of the object can be found here TApiObjSiteData. In the following a few examples are given how to use this service.

"""
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

# Opening windPRO
_windproapi = WindProApi()
working_dir = os.path.join(get_windpro_sample_path('4.0'), 'New Salem\\4.0')
project_path = os.path.join(working_dir, 'New Salem.w40p')

_windproapi.start_windpro_random_port()

# Services
obj_wtg_service = _windproapi.get_service('ObjWtgService')
obj_site_data_service = _windproapi.get_service('ObjSiteDataService')
project_service = _windproapi.get_service('ProjectService')
objects_service = _windproapi.get_service('ObjectsService')
calculation_service = _windproapi.get_service('CalculationService')
obj_line_service = _windproapi.get_service('ObjLineService')

# Loading New Salem project
project_service.LoadFromFile(filename=project_path)

objs = objects_service.GetObjects(apiObjType='SiteData')

# Getting the second site data object
siteDataObj = obj_site_data_service.GetSiteDataObject(objs[1].Handle)
print(siteDataObj)

# Creating a new statgen calculation calculation and starting to edit it
# Adding a site data object
siteData = objects_service.AddObject(apiObjType='SiteData',
                                     lat=46.8,
                                     lng=-101.65,
                                     userDesc='STATGEN SiteData from scripting')

# Setting the purpose. See documentation
# 'SdPurpUndef' not defined
# 'SdPurpAtlas' ATLAS service
# 'SdPurpWasp' for WAsP calculation
# 'SdPurpStatgen' for statistical wind climate STATGEN
# 'SdPurpResource' for wind resource map
# 'SdPurpCFD' for CFD calculation

obj_site_data_service.SetPurpose(handle=siteData.Handle, purpose='SdPurpStatgen')

# Connecting elevation and roughness data and elevation data.
# The HC data is general line data. See ObjLineService for more on this service.
hcdata = objects_service.GetObjects(apiObjType='HCData')
for obj in objects_service.GetObjects(apiObjType='HCData'):
    print(obj_line_service.GetLineObject(obj.Handle))

# Linking the orography data to the sitedata object
obj_site_data_service.TerrainLinkElevationAndRoughnessLine(handle=siteData.Handle,
                                                           elevHandle=hcdata[0].Handle,
                                                           rouLineHandle=hcdata[1].Handle)

# Getting the site data object in python to inspect the properties
siteData = obj_site_data_service.GetSiteDataObject(siteData.Handle)
print(siteData)

# Exporting the map data connected with this object. All 0 for corners means full size.
obj_site_data_service.ExportCombinedMapFile(handle=siteData.Handle,
                                            lowerLeftLat=0.,
                                            lowerLeftLng=0.,
                                            upperRightLat=0.,
                                            upperRightLng=0.,
                                            filename=os.path.join(working_dir, 'testtgs.map'))