Project Service

The Project Service provides access to functionality to perform operations on windPRO projects like making a project, saving, exporting or loading. Additionally, you can use it to set coordinate systems for you project. Coordinate transformations can be done in the Windpro Service. Lastly, you can adjust your WAsP settings specific to your projects here.

Basic project tools

When working wind windPRO scripting, you will work on your projects through a scripting interface. Therefore, we need to load proejcts into windPRO and export them. You can either make a new project with ProjectService.NewProject or load an exisitng project or project export file with ProjectService.LoadFromFile. Saving the projects works via ProjectService.SaveToFile and exporting it with ProjectService.ExportToFile. For closing windPRO in your script you should can use ProjectService.CloseProject. Information of the coordinate porjection can be accessed and set with ProjectService.GetProjectData and ProjectService.SetProjectData. In the following some simple examples are given accessing general project functionality.

"""
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
import time
from windproapi.utils import get_windpro_sample_path
from windproapi import WindProApi
from windproapi import nan_to_skipvalue


# Opening windPRO
_windproapi = WindProApi()
_windproapi.start_windpro_random_port()

working_dir = os.path.join(get_windpro_sample_path('4.0'), 'ProjectService')
os.makedirs(working_dir, exist_ok=True)

# Services
project_service = _windproapi.get_service('ProjectService')

# Project path and location
project_path = os.path.join(working_dir, 'test.w36p')
lng = 10.
lat = 55.

# Making a new empty project and saving it
project_service.NewProject(lng=lng, lat=lat, filename=project_path)
project_service.SaveToFile(filename=project_path)

# It is possible to get the project path from windPRO
project_path_from_windpro = project_service.GetProjectFilename()
print(f'Path from script: {project_path}')
print(f'Path from windPRO: {project_path_from_windpro}')

# Close windPRO
_windproapi.close_windpro()
time.sleep(2)

# Open windPRO again and load the project
# If you open windPRO
_windproapi = WindProApi()
_windproapi.start_windpro_random_port()
time.sleep(2)
# After closing windpro it is necessary to get the project again as the port might have changed
project_service = _windproapi.get_service('ProjectService')
project_service.LoadFromFile(filename=project_path)

# Exporting project to export file
export_path = os.path.join(working_dir, 'test.w36e')
project_service.ExportToFile(filename=export_path)

# Close windPRO again
time.sleep(2)
_windproapi.close_windpro()

Setting coordinate systems

You can set the coordinate system for you project from the EPSG number with ProjectService.SetProjectCoorEPSG. This can be used if you need a specific coordinate system for your project.

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

# Opening windPRO
windproapi = WindProApi()
working_dir = os.path.join(get_windpro_sample_path('4.0'), 'ProjectService')
os.makedirs(working_dir, exist_ok=True)

windproapi.start_windpro_random_port()
project_service = windproapi.get_service('ProjectService')

# Project path and location
project_path = os.path.join(working_dir, 'test.w36p')
lng = 11.
lat = 55.

# Making a new empty project and saving it
project_service.NewProject(lng=lng, lat=lat, filename=project_path)

# The the UTM zone's EPSG number
utm_zone = project_service.GetUtmWgs84EpsgForProject()
print(f'UTM EPSG of the project is {utm_zone}.')

# Setting the project coordinate system to DKTM1 with EPSG 4093
project_service.SetProjectCoorEPSG(epsg=4093)

WAsP parameters

WAsP parameters can be changed from within windPRO. All parameters that can be changed in WAsP are available from scripting. This also includes some paramters that are not from the GUI. Find below an example change WAsP parameters from a script.

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

# 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
project_service = _windproapi.get_service('ProjectService')
factory = _windproapi.get_factory('WindproService')

# Loading project
project_service.LoadFromFile(filename=project_path)

# Getting the current WAsP setup
wasp_params = project_service.GetProjectWaspParams()
print(wasp_params)

# Printing all descriptions and their associated IDs
for i, d in enumerate(wasp_params.WaspParams.TApiWaspConfItem):
    print(i, d.Description, d.ID)

# modifying the heat flux over over land
for conf in wasp_params.WaspParams.TApiWaspConfItem:
    if conf['ID'] == 'OFSLAND':
        print(conf)
        conf.Value = -70

for conf in wasp_params.WaspParams.TApiWaspConfItem:
    if conf['ID'] == 'OFSLAND':
        print(conf)

# Setting the values in windPRO
project_service.SetProjectWaspParams(params=wasp_params)

# Confirming that the WAsP paramter has been set correctly.
wasp_params_new = project_service.GetProjectWaspParams()
for conf in wasp_params_new.WaspParams.TApiWaspConfItem:
    if conf['ID'] == 'OFSLAND':
        print(conf)