floris_design #7
@ -1,3 +1,4 @@
|
|||||||
|
import math
|
||||||
import os.path
|
import os.path
|
||||||
import sys
|
import sys
|
||||||
import uuid
|
import uuid
|
||||||
@ -54,14 +55,24 @@ class FlorisULSTU(FlorisModel):
|
|||||||
super().set(**kwargs)
|
super().set(**kwargs)
|
||||||
|
|
||||||
def visualisation(self):
|
def visualisation(self):
|
||||||
|
wind_dirs = self.core.flow_field.wind_directions
|
||||||
|
wind_speeds = self.core.flow_field.wind_speeds
|
||||||
|
|
||||||
|
experiment_counts = len(wind_dirs)
|
||||||
|
near_square = math.ceil(math.sqrt(experiment_counts))
|
||||||
|
fig, axarr = plt.subplots(near_square, near_square, figsize=(15,8))
|
||||||
|
axarr = axarr.flatten()
|
||||||
|
|
||||||
self.reset_operation()
|
for experiment_count in range(experiment_counts):
|
||||||
|
self.reset_operation()
|
||||||
horizontal_plane = self.calculate_horizontal_plane(height=90.0)
|
self.set(wind_speeds=[wind_speeds[0]], wind_directions=[wind_dirs[0]], turbulence_intensities=[0.05])
|
||||||
visualize_cut_plane(
|
ax = axarr[experiment_count]
|
||||||
horizontal_plane,
|
horizontal_plane = self.calculate_horizontal_plane(height=90.0)
|
||||||
)
|
visualize_cut_plane(
|
||||||
|
horizontal_plane,
|
||||||
|
ax=ax,
|
||||||
|
title=f"Wind flow day {experiment_count + 1}",
|
||||||
|
)
|
||||||
|
|
||||||
# plot_turbine_labels(self, axarr[0, 0])
|
# plot_turbine_labels(self, axarr[0, 0])
|
||||||
filename = str(uuid.uuid4()) + ".png"
|
filename = str(uuid.uuid4()) + ".png"
|
||||||
|
@ -17,7 +17,7 @@ class OpenMeteoClient:
|
|||||||
params = {
|
params = {
|
||||||
"latitude": latitude,
|
"latitude": latitude,
|
||||||
"longitude": longitude,
|
"longitude": longitude,
|
||||||
"hourly": ["wind_speed_10m", "wind_direction_10m"],
|
"daily": ["wind_speed_10m_max", "wind_direction_10m_dominant"],
|
||||||
"timezone": self.timezone,
|
"timezone": self.timezone,
|
||||||
"start_date": start_date,
|
"start_date": start_date,
|
||||||
"end_date": end_date
|
"end_date": end_date
|
||||||
@ -27,13 +27,13 @@ class OpenMeteoClient:
|
|||||||
|
|
||||||
def process_response(self, response):
|
def process_response(self, response):
|
||||||
# Process hourly data
|
# Process hourly data
|
||||||
hourly = response.Hourly()
|
daily = response.Daily()
|
||||||
hourly_wind_speed_10m = hourly.Variables(0).ValuesAsNumpy()
|
daily_wind_speed_10m = daily.Variables(0).ValuesAsNumpy()
|
||||||
hourly_wind_direction_10m = hourly.Variables(1).ValuesAsNumpy()
|
daily_wind_direction_10m = daily.Variables(1).ValuesAsNumpy()
|
||||||
|
|
||||||
return hourly_wind_speed_10m.tolist(), hourly_wind_direction_10m.tolist()
|
return daily_wind_speed_10m.tolist(), daily_wind_direction_10m.tolist()
|
||||||
|
|
||||||
def get_weather_info(self, latitude, longitude, start_date, end_date):
|
def get_weather_info(self, start_date, end_date, latitude=54.35119762746125, longitude=48.389356992149345):
|
||||||
responses = self.fetch_weather_data(latitude, longitude, start_date, end_date)
|
responses = self.fetch_weather_data(latitude, longitude, start_date, end_date)
|
||||||
response = responses[0]
|
response = responses[0]
|
||||||
self.process_response(response)
|
self.process_response(response)
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
from datetime import date
|
from datetime import date
|
||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
from fastapi import Query
|
from fastapi import Query
|
||||||
|
|
||||||
@ -19,4 +18,4 @@ class SFlorisInputParams(BaseModel):
|
|||||||
|
|
||||||
class SFlorisOutputData(BaseModel):
|
class SFlorisOutputData(BaseModel):
|
||||||
file_name: str
|
file_name: str
|
||||||
data: list[float]
|
data: object
|
@ -14,6 +14,7 @@ sys.path.append(str(Path(__file__).parent.parent.parent))
|
|||||||
from floris_module.src import FlorisULSTU
|
from floris_module.src import FlorisULSTU
|
||||||
from floris_module.src.OpenMeteoClient import OpenMeteoClient
|
from floris_module.src.OpenMeteoClient import OpenMeteoClient
|
||||||
|
|
||||||
|
|
||||||
FLORIS_IMAGES_PATH = Path(__file__).parent.parent.parent / "public" / "floris"
|
FLORIS_IMAGES_PATH = Path(__file__).parent.parent.parent / "public" / "floris"
|
||||||
|
|
||||||
router = APIRouter(
|
router = APIRouter(
|
||||||
@ -36,13 +37,9 @@ async def get_windmill_data(
|
|||||||
|
|
||||||
client = OpenMeteoClient()
|
client = OpenMeteoClient()
|
||||||
|
|
||||||
wind_directions = list()
|
climate_info = client.get_weather_info(data.date_start, data.date_end)
|
||||||
wind_speeds = list()
|
wind_speeds = climate_info[0]
|
||||||
|
wind_directions = climate_info[1]
|
||||||
for i in range(len(data.layout_x)):
|
|
||||||
i_result = client.get_weather_info(data.layout_x[i], data.layout_y[i], data.date_start, data.date_end)
|
|
||||||
wind_speeds.extend(i_result[0])
|
|
||||||
wind_directions.extend(i_result[1])
|
|
||||||
|
|
||||||
fmodel.set(
|
fmodel.set(
|
||||||
layout_x=data.layout_x,
|
layout_x=data.layout_x,
|
||||||
@ -54,12 +51,12 @@ async def get_windmill_data(
|
|||||||
|
|
||||||
fmodel.run()
|
fmodel.run()
|
||||||
|
|
||||||
data = fmodel.get_turbine_powers()[0].tolist()
|
res = fmodel.get_turbine_powers().tolist()
|
||||||
file_name = fmodel.visualisation()
|
file_name = fmodel.visualisation()
|
||||||
|
|
||||||
return SFlorisOutputData(
|
return SFlorisOutputData(
|
||||||
file_name=file_name,
|
file_name=file_name,
|
||||||
data=data
|
data=res
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user