Examples
Submit Multiple Measurements for Different Flow Cases - Python
Submits multiple measurements to the API covering different flow cases, then gets the results.
A flow case ID is specified to determine which measurements should be run together.
Written and tested using Python 3.5.
# Import some modules from the standard python distribution
from datetime import datetime # datetime for generating timestamps for the measurements
import time # time for sleeping between API request attempts
from pprint import pprint # pprint for pretty-printing data
import requests # use the `requests` library (install using `pip install requests`).
# More info: http://docs.python-requests.org
api_base_url = 'https://app.wakeblaster.net/api'
measurements = []
# Create the measurements to submit - 12 direction sectors
for direction in range(0, 360, 30):
# Create a flow case ID with the format flow_case_X_degrees
flow_case_id = 'flow_case_{}_degrees'.format(direction)
wind_speed_measurement = {
'signal_id': 'WMET_WindSpeed1_avg', # Signal ID for this measurement
'instance_id': 'Lidar', # Instance ID for this measurement
'value': 8, # Value for this measurement
'flow_case_id': flow_case_id # Flow case ID for this measurement
}
wind_direction_measurement = {
'signal_id': 'WMET_WindDirection1_avg', # Signal ID for this measurement
'instance_id': 'Lidar', # Instance ID for this measurement
'value': direction, # Value for this measurement
'flow_case_id': flow_case_id # Flow case ID for this measurement
}
measurements += [
wind_speed_measurement,
wind_direction_measurement
]
# Specify the farm that the measurement belongs to
farm_id = 'DemoFarm_SingleTurbine'
# Create the measurement data object
measurement_data = {
'farm_id': farm_id,
'measurements': measurements # This is an array of measurements
}
# Call the measurements endpoint to submit the measurements
print('Submitting measurements...')
response = requests.post(
api_base_url + '/measurement-sets',
json=measurement_data,
headers={'x-api-key': ''}
)
print(response.text)
# Store the ID of the measurement set
measurement_set_id = response.json()['id']
print('Measurement submitted: ', measurement_set_id)
# Start the simulation
simulation_start_data = {
'simulation_config': {
'measurements': {
'wind_conditions_inference': 'ReferenceBased'
},
'wake_model': {
'type': 'Park'
}
},
'measurement_set_ids': [measurement_set_id]
}
print('Starting simulation...')
response = requests.post(
api_base_url + '/simulations',
json=simulation_start_data,
headers={'x-api-key': ''}
)
# Store the ID of the result set
simulation_id = response.json()['id']
print('Simulation started: ', simulation_id)
# Get simulation results
# Ensure that the correct number of results are returned
# We should get a result for every timestep we submitted measurements for
simulation_state_url = api_base_url + '/simulations/' + simulation_id
simulation_results_url = api_base_url + '/results?simulation_id=' + simulation_id
results = None
attempts = 0
while attempts < 10:
# Get the results
# First get the simulation state, to see the result count
print('Getting simulation state...')
simulation_state = requests.get(
simulation_state_url,
headers={'x-api-key': ''}
)
n_results = simulation_state.json()['result_count']
if n_results == 12:
# We have our results - get the results and break out of the loop
print('Results ready - getting results')
get_result = requests.get(
simulation_results_url,
headers={'x-api-key': ''}
)
results = get_result.json()
break
# The results aren't ready yet - sleep for 0.1 seconds and try again
attempts += 1
print('Attempts made: ', attempts)
time.sleep(5)
# Raise an exception if the results were not returned from the API
if results is None:
raise Exception('Error loading WakeBlaster results')
# Print the results
pprint(results)
Submit Measurement - Python
Submits a measurement to the API, then gets the result.
A clean measurement is submitted, so no processing needs to take place before the measurement is submitted to the simulation.
A timestamp is specified in order to ensure that only the data we want to retrieve is returned.
Written and tested using Python 3.5.
# Import some modules from the standard python distribution
from datetime import datetime # datetime for generating timestamps for the measurements
import time # time for sleeping between API request attempts
from pprint import pprint # pprint for pretty-printing data
import requests # use the `requests` library (install using `pip install requests`).
# More info: http://docs.python-requests.org
api_base_url = 'https://app.wakeblaster.net/api'
# Create a measurement to submit
# Initialise the timestamp in ISO 8601 format
timestamp = datetime.now().isoformat()
wind_speed_measurement = {
'signal_id': 'WMET_WindSpeed1_avg', # Signal ID for this measurement
'instance_id': 'Lidar', # Instance ID for this measurement
'value': 8, # Value for this measurement
'timestamp': timestamp # Timestamp for this measurement
}
wind_direction_measurement = {
'signal_id': 'WMET_WindDirection1_avg', # Signal ID for this measurement
'instance_id': 'Lidar', # Instance ID for this measurement
'value': 60, # Value for this measurement
'timestamp': timestamp # Timestamp for this measurement
}
# Specify the farm that the measurement belongs to
farm_id = 'DemoFarm_SingleTurbine'
# Create the measurement data object
measurement_data = {
'farm_id': farm_id,
'measurements': [
wind_speed_measurement,
wind_direction_measurement
] # This is an array of measurements
}
# Call the measurements endpoint to submit the measurements
print('Submitting measurements...')
response = requests.post(
api_base_url + '/measurement-sets',
json=measurement_data,
headers={'x-api-key': ''}
)
# Store the ID of the measurement set
measurement_set_id = response.json()['id']
print('Measurement submitted: ', measurement_set_id)
# Start the simulation
simulation_start_data = {
'simulation_config': {
'measurements': {
'wind_conditions_inference': 'ReferenceBased'
},
'wake_model': {
'type': 'Park'
}
},
'measurement_set_ids': [measurement_set_id]
}
print('Starting simulation...')
response = requests.post(
api_base_url + '/simulations',
json=simulation_start_data,
headers={'x-api-key': ''}
)
# Store the ID of the result set
simulation_id = response.json()['id']
print('Simulation started: ', simulation_id)
# Get simulation results
# Ensure that the correct number of results are returned
# We should get a result for every timestep we submitted measurements for
simulation_state_url = api_base_url + '/simulations/' + simulation_id
simulation_results_url = api_base_url + '/results?simulation_id=' + simulation_id
results = None
attempts = 0
while attempts < 10:
# Get the results
# First get the simulation state, to see the result count
print('Getting simulation state...')
simulation_state = requests.get(
simulation_state_url,
headers={'x-api-key': ''}
)
n_results = simulation_state.json()['result_count']
if n_results == 1:
# We have our result - get the results and break out of the loop
print('Results ready - getting results')
get_result = requests.get(
simulation_results_url,
headers={'x-api-key': ''}
)
results = get_result.json()
break
# The results aren't ready yet - sleep for 0.1 seconds and try again
attempts += 1
print('Attempts made: ', attempts)
time.sleep(5)
# Raise an exception if the results were not returned from the API
if results is None:
raise Exception('Error loading WakeBlaster results')
# Print the results
pprint(results)
Submits a measurement to the API in CSV format, then gets the result.
A clean measurement is submitted, so no processing needs to take place before the measurement is submitted to the simulation.
A timestamp is specified in order to ensure that only the data we want to retrieve is returned.
Written and tested using Python 3.5.
# Import some modules from the standard python distribution
from datetime import datetime # datetime for generating timestamps for the measurements
import time # time for sleeping between API request attempts
from pprint import pprint # pprint for pretty-printing data
import requests # use the `requests` library (install using `pip install requests`).
# More info: http://docs.python-requests.org
api_base_url = 'https://app.wakeblaster.net/api'
# Create some csv text to submit - this can be read from a file
measurements_csv = 'signal_id,instance_id,value,flow_case_id\n'
measurements_csv += 'WMET_WindSpeed1_avg,Lidar,8,flow_case_1\n'
measurements_csv += 'WMET_WindDirection1_avg,Lidar,60,flow_case_1\n'
# Specify the farm that the measurement belongs to
farm_id = 'DemoFarm_SingleTurbine'
# Create the measurement data object
measurement_data = {
'farm_id': farm_id,
'measurements_csv': measurements_csv
}
# Call the measurements endpoint to submit the measurements
print('Submitting measurements...')
response = requests.post(
api_base_url + '/measurement-sets',
json=measurement_data,
headers={'x-api-key': ''}
)
# Store the ID of the measurement set
measurement_set_id = response.json()['id']
print('Measurement submitted: ', measurement_set_id)
# Start the simulation
simulation_start_data = {
'simulation_config': {
'measurements': {
'wind_conditions_inference': 'ReferenceBased'
},
'wake_model': {
'type': 'Park'
}
},
'measurement_set_ids': [measurement_set_id]
}
print('Starting simulation...')
response = requests.post(
api_base_url + '/simulations',
json=simulation_start_data,
headers={'x-api-key': ''}
)
# Store the ID of the result set
simulation_id = response.json()['id']
print('Simulation started: ', simulation_id)
# Get simulation results
# Ensure that the correct number of results are returned
# We should get a result for every timestep we submitted measurements for
simulation_state_url = api_base_url + '/simulations/' + simulation_id
simulation_results_url = api_base_url + '/results?simulation_id=' + simulation_id
results = None
attempts = 0
while attempts < 10:
# Get the results
# First get the simulation state, to see the result count
print('Getting simulation state...')
simulation_state = requests.get(
simulation_state_url,
headers={'x-api-key': ''}
)
n_results = simulation_state.json()['result_count']
if n_results == 1:
# We have our result - get the results and break out of the loop
print('Results ready - getting results')
get_result = requests.get(
simulation_results_url,
headers={'x-api-key': ''}
)
results = get_result.json()
break
# The results aren't ready yet - sleep for 0.1 seconds and try again
attempts += 1
print('Attempts made: ', attempts)
time.sleep(5)
# Raise an exception if the results were not returned from the API
if results is None:
raise Exception('Error loading WakeBlaster results')
# Print the results
pprint(results)
Uploads an asset (a wind farm description) to the WakeBlaster application.
Performs the following steps:
1) Confirms that the wind farm description is not already present
2) Uploads the wind farm description
3) Confirms that the wind farm description was correctly uploaded
Written and tested using Python 3.5.
# Import some modules from the standard python distribution
import json # json for creating json-formatted data
from pprint import pprint # pprint for pretty-printing data
import requests # use the `requests` library (install using `pip install requests`).
# More info: http://docs.python-requests.org
api_base_url = 'https://app.wakeblaster.net/api'
asset_id = 'DemoFarm_SingleTurbine_CSV'
# Upload the wind farm description
wind_farm_description = "id,type,design_id,northing,easting,elevation\n"
wind_farm_description += "A01,turbine,demo_turbine_design,6157991.0,411582.5,0\n"
wind_farm_description += "Lidar,met_mast,demo_met_mast_design,6162408.5,413210.3,0\n"
print('Uploading wind farm description...')
response = requests.put(
api_base_url + '/assets/' + asset_id,
json={'wind_farm_description_csv': wind_farm_description},
headers={'x-api-key': ''}
)
# If we don't get a 201 CREATED response, something has gone wrong
if response.status_code != 201:
raise Exception('Something went wrong uploading the wind farm description, error code: %d', response.status_code)
print('Wind farm description uploaded!')
# Our wind farm description has been loaded - check that it is now accessible
print('Getting assets...')
response = requests.get(
api_base_url + '/assets',
headers={'x-api-key': ''}
)
assets = response.json()
# Confirm that our wind farm description is now present
if not any(map(lambda a: a['asset_id'] == 'DemoFarm_SingleTurbine_CSV', assets)):
raise Exception('Asset has not been uploaded!')
# Our wind farm description has been uploaded now - great!
print('Wind farm description has been uploaded successfully!')
pprint(assets)
Upload Wind Farm Description - Python
Uploads an asset (a wind farm description) to the WakeBlaster application.
Performs the following steps:
1) Confirms that the wind farm description is not already present
2) Uploads the wind farm description
3) Confirms that the wind farm description was correctly uploaded
Written and tested using Python 3.5.
# Import some modules from the standard python distribution
import json # json for creating json-formatted data
from pprint import pprint # pprint for pretty-printing data
import requests # use the `requests` library (install using `pip install requests`).
# More info: http://docs.python-requests.org
api_base_url = 'https://app.wakeblaster.net/api'
asset_id = 'DemoFarm_SingleTurbine'
# Upload the wind farm description
wind_farm_description = {
"turbine_instances": [
{
"id": "A01",
"northing": 6157991.0,
"elevation": 0,
"design_id": "demo_turbine_design",
"easting": 411582.5
}
],
"met_mast_instances": [
{
"elevation": 0,
"easting": 413210.3,
"design_id": "demo_met_mast_design",
"id": "Lidar",
"northing": 6162408.5
}
]
}
print('Uploading wind farm description...')
response = requests.put(
api_base_url + '/assets/' + asset_id,
json={'wind_farm_description': wind_farm_description},
headers={'x-api-key': ''}
)
# If we don't get a 201 CREATED response, something has gone wrong
if response.status_code != 201:
raise Exception('Something went wrong uploading the wind farm description, error code: %d', response.status_code)
print('Wind farm description uploaded!')
# Our wind farm description has been loaded - check that it is now accessible
print('Getting assets...')
response = requests.get(
api_base_url + '/assets',
headers={'x-api-key': ''}
)
assets = response.json()
# Confirm that our wind farm description is now present
if not any(map(lambda a: a['asset_id'] == 'DemoFarm_SingleTurbine', assets)):
raise Exception('Asset has not been uploaded!')
# Our wind farm description has been uploaded now - great!
print('Wind farm description has been uploaded successfully!')
pprint(assets)
Submit a Measurement, Errors In Setup - Python
Uploads a wind resource grid description to the API for the demo farm.
The wind resource grid file has errors in so the simulation will produce errors when a measurement is submitted. Get these errors from the API and return.
Written and tested using Python 3.5.
# Import some modules from the standard python distribution
from datetime import datetime # datetime for generating timestamps for the measurements
import time # time for sleeping between API request attempts
from pprint import pprint # pprint for pretty-printing data
import requests # use the `requests` library (install using `pip install requests`).
# More info: http://docs.python-requests.org
api_base_url = 'https://app.wakeblaster.net/api'
# Specify the farm that the measurement belongs to
asset_id = 'DemoFarm_SingleTurbine_Invalid'
# Specify the wind farm description
wind_farm_description = {
"turbine_instances": [
{
"id": "A01",
"northing": 6157991.0,
"elevation": 0,
"design_id": "demo_turbine_design",
"easting": 411582.5
}
],
"met_mast_instances": [
{
"elevation": 0,
"easting": 413210.3,
"design_id": "demo_met_mast_design",
"id": "Lidar",
"northing": 6162408.5
}
]
}
# Specify a wind resource grid with only one site that doesn't match either of the instances
wind_resource_grid_file = ' site 001 431250.0 6149500.0 0 70.0 9.91 2.240 713.132 12 86 87 219 46 74 183 78 93 204 76 97 234 82 99 241 57 92 217 76 99 207 94 109 242 127 110 262 95 105 235 111 96 222 73 107 238'
print('Uploading wind farm description...')
response = requests.put(
api_base_url + '/assets/' + asset_id,
json={
'wind_farm_description': wind_farm_description,
'wind_resource_grid_file': wind_resource_grid_file
},
headers={'x-api-key': ''}
)
# Create a measurement to submit
# Initialise the timestamp in ISO 8601 format
timestamp = datetime.now().isoformat()
wind_speed_measurement = {
'signal_id': 'WMET_WindSpeed1_avg', # Signal ID for this measurement
'instance_id': 'Lidar', # Instance ID for this measurement
'value': 8, # Value for this measurement
'timestamp': timestamp # Timestamp for this measurement
}
wind_direction_measurement = {
'signal_id': 'WMET_WindDirection1_avg', # Signal ID for this measurement
'instance_id': 'Lidar', # Instance ID for this measurement
'value': 60, # Value for this measurement
'timestamp': timestamp # Timestamp for this measurement
}
# Create the measurement data object
measurement_data = {
'farm_id': asset_id,
'measurements': [
wind_speed_measurement,
wind_direction_measurement
] # This is an array of measurements
}
# Call the measurements endpoint to submit the measurements
print('Submitting measurements...')
response = requests.post(
api_base_url + '/measurement-sets',
json=measurement_data,
headers={'x-api-key': ''}
)
# Store the ID of the measurement set
measurement_set_id = response.json()['id']
print('Measurement submitted: ', measurement_set_id)
# Start the simulation
simulation_start_data = {
'simulation_config': {
'measurements': {
'wind_conditions_inference': 'ReferenceBased'
},
'wake_model': {
'type': 'Park'
}
},
'measurement_set_ids': [measurement_set_id]
}
print('Starting simulation...')
response = requests.post(
api_base_url + '/simulations',
json=simulation_start_data,
headers={'x-api-key': ''}
)
# Store the ID of the result set
simulation_id = response.json()['id']
print('Simulation started: ', simulation_id)
# Get simulation results
# Ensure that the correct number of results are returned
# We should get a result for every timestep we submitted measurements for
simulation_state_url = api_base_url + '/simulations/' + simulation_id
simulation_errors_url = api_base_url + '/errors?simulation_id=' + simulation_id
errors = None
attempts = 0
while attempts < 10:
# Get the results
# First get the simulation state, to see the error count
print('Getting simulation state...')
simulation_state = requests.get(
simulation_state_url,
headers={'x-api-key': ''}
)
n_errors = simulation_state.json()['error_count']
if n_errors == 1:
# We have our error - get the errors and break out of the loop
print('Errors ready - getting results')
get_error = requests.get(
simulation_errors_url,
headers={'x-api-key': ''}
)
errors = get_error.json()
break
# The results aren't ready yet - sleep for 0.1 seconds and try again
attempts += 1
print('Attempts made: ', attempts)
time.sleep(5)
# Raise an exception if the results were not returned from the API
if errors is None:
raise Exception('Error loading WakeBlaster results')
# Print the results
pprint(errors)
Upload Turbine Design - Python
Uploads a turbine design to the WakeBlaster application.
Performs the following steps:
1) Confirms that the turbine and met mast designs are not already present
2) Uploads the turbine design
3) Uploads the met mast design
4) Confirms that the turbine and met mast designs were correctly uploaded
Written and tested using Python 3.5.
# Import some modules from the standard python distribution
import json # json for creating json-formatted data
from pprint import pprint # pprint for pretty-printing data
import requests # use the `requests` library (install using `pip install requests`).
# More info: http://docs.python-requests.org
api_base_url = 'https://app.wakeblaster.net/api'
turbine_design_id = 'demo_turbine_design'
met_mast_design_id = 'demo_met_mast_design'
# Upload the turbine design
print('Uploading turbine design...')
with open('/files/demo_turbine_design.wtg') as fp:
turbine_design = fp.read()
response = requests.put(
api_base_url + '/designs/' + turbine_design_id,
json={'wtg_file': turbine_design},
headers={'x-api-key': ''}
)
# If we don't get a 201 CREATED response, something has gone wrong
if response.status_code != 201:
raise Exception('Something went wrong uploading the turbine design, error code: %d', response.status_code)
# Upload the met mast design
print('Uploading met_mast design...')
with open('/files/demo_met_mast_design.json') as fp:
met_mast_design = json.load(fp)
response = requests.put(
api_base_url + '/designs/' + met_mast_design_id,
json={'met_mast_design': met_mast_design},
headers={'x-api-key': ''}
)
# If we don't get a 201 CREATED response, something has gone wrong
if response.status_code != 201:
raise Exception('Something went wrong uploading the turbine design, error code: %d', response.status_code)
print('Designs uploaded!')
# Our wind farm description has been loaded - check that it is now accessible
print('Getting designs...')
response = requests.get(
api_base_url + '/designs',
headers={'x-api-key': ''}
)
designs = response.json()
# Confirm that our designs are now present
if not any(map(lambda d: d['design_id'] == 'demo_turbine_design', designs)):
raise Exception('Turbine design has not uploaded successfully!')
if not any(map(lambda d: d['design_id'] == 'demo_met_mast_design', designs)):
raise Exception('Metmast design has not uploaded successfully!')
# Our wind farm description has been uploaded now - great!
print('Designs have been uploaded successfully!')
pprint(designs)