NSA Object Service

Service for accessing the NSA object (noise receptor). Noise receptors can be accessed and the data manipulated.

Noise receptors in windPRO have predefined settings for different countries as noise regulations need to be reflected. It is important to keep that in mind when making scripts that should work for multiple countries. WindPRO gives different options for these settings that are convenient for use in the GUI. These settings are mostly represented by integers in the background for windPRO and also in windPRO scripting. Below is an example for the values that are set in the noise receptor object.

'PreDefinedCountry': 7
'PreDefinedType': 8
'PreDefined': 18
'NoiseDemandNew': 50.0

Note that “PreDefinedCountry” is the country setting in windPRO, “PreDefinedType” is an additional setting available for some countries, and “PreDefined” is the selection of a specific type of dwelling. To determine the correct setting it is advised to set it in the windPRO GUI and get the correct object via scripting. Note, that it is possible to change the “NoiseDemandNew”, which is the acceptable noise level, in scripting even for predefined values. “PreDefined” takes precedent over the set noise value. Noise sensitive areas can be defined by using the corner points within the object.

A good way to determine which values need to be changed to get to the noise receptor settings required is to set it in the windPRO GUI. You can use the function compare_objects from the windproapi python package. It compares what values are not the same between two objects which can be very useful for noise receptors.

Warning

Areas can be set for noise receptors but they are not correctly shown in the windPRO GUI but are represented correctly in the calculation. Loading the noise receptor in the windPRO GUI will redraw the shape correctly.

The script shows how to manipulate noise receptors and and add new points and areas to windPRO. Properties of the object can be found here TApiObjNSA.

"""
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 nan_to_skipvalue
from windproapi import WindProApi
from windproapi import compare_objects
from copy import deepcopy

# Opening windPRO
_windproapi = WindProApi()
working_dir = os.path.join(get_windpro_sample_path('4.0'), 'Ebeltoft - Denmark\\4.0')
project_path = os.path.join(working_dir, 'DEMO - Ebeltoft, DK.w40p')

_windproapi.start_windpro_random_port()

# Services
project_service = _windproapi.get_service('ProjectService')
objects_service = _windproapi.get_service('ObjectsService')
obj_NSA_service = _windproapi.get_service('ObjNSAService')
factory = _windproapi.get_factory('WindproService')

# Loading project
project_service.LoadFromFile(filename=project_path)

# Getting all Noise Sensitive Area objects
objs = objects_service.GetObjects(apiObjType='NSA')

# Loading are object specific data
nsa_obj = obj_NSA_service.GetNSAObject(objs[0].Handle)

# Changing the shape of the noise sensitive area
nsa_obj.Points.TApiGP[0].Lat = nsa_obj.Points.TApiGP[0].Lat + 0.03

# Changing the noise demand. Caution, this will not work as this object as a predefined noise level level set!
nan_to_skipvalue(nsa_obj)
obj_NSA_service.SetNSAObject(nsa_obj)

# Comparing object that was set with what is in windPRO
nsa_obj_wp = obj_NSA_service.GetNSAObject(objs[0].Handle)
compare_objects(nsa_obj_wp, nsa_obj)

# Adding a new noise recepors
# Set those with a constant freely defined noise constraint

# Single noise receptor
new_obj = objects_service.AddObject(apiObjType='NSA',
                                    lat=56.17,
                                    lng=10.66,
                                    userDesc='Script Added Point')
nsa_obj = obj_NSA_service.GetNSAObject(new_obj.Handle)
nsa_obj_default = deepcopy(nsa_obj)

# Changing noise level to a user defined absolute noise
nsa_obj.FreeDefinable = True
nsa_obj.KindOfDemand = 'kodAbsolute'
nsa_obj.NoiseDemandNew = 37
nan_to_skipvalue(nsa_obj)
obj_NSA_service.SetNSAObject(nsa_obj)

print(compare_objects(nsa_obj, nsa_obj_default))

# Adding NSA with area
new_obj = objects_service.AddObject(apiObjType='NSA',
                                    lat=56.17,
                                    lng=10.67,
                                    userDesc='Script Added Area')
nsa_obj = obj_NSA_service.GetNSAObject(new_obj.Handle)

# Adding points to the area
for i_lat, i_lng in zip([56.172, 56.172, 56.162, 56.162], [10.67, 10.68, 10.68, 10.675]):
    point = factory.TApiGP()
    point.Lat = i_lat
    point.Lng = i_lng
    nsa_obj.Points.TApiGP.append(point)

nsa_obj.FreeDefinable = True
nsa_obj.KindOfDemand = 'kodAbsolute'
nsa_obj.NoiseDemandNew = 42
nan_to_skipvalue(nsa_obj)
obj_NSA_service.SetNSAObject(nsa_obj)