Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wind speed and wind speed informed variables use cffdrs #3123

Merged
merged 31 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c69daae
Have wind speed and wind speed informed variables use cffdrs
conbrad Sep 18, 2023
ec43fb5
Merge branch 'main' into task/consistent-critical-hours
conbrad Sep 18, 2023
da292d3
Merge branch 'main' into task/consistent-critical-hours
conbrad Sep 19, 2023
db72fc2
Round indices, calculate bui, shuffle tests around for c1
conbrad Sep 19, 2023
b33ea73
Merge branch 'main' into task/consistent-critical-hours
conbrad Sep 19, 2023
b2ecf02
Fix wind speed test
conbrad Sep 19, 2023
19dd2b9
c2 to c5
conbrad Sep 19, 2023
9ab07f4
c6 and c7
conbrad Sep 19, 2023
a6030ee
d1 and c7 test name fix
conbrad Sep 19, 2023
cdae173
m1 50 and 75
conbrad Sep 20, 2023
981a865
M1 and M2
conbrad Sep 20, 2023
216142a
M3
conbrad Sep 20, 2023
aac8f59
m3 file rename, m4
conbrad Sep 20, 2023
4b79596
01a
conbrad Sep 20, 2023
10c5d0b
01b
conbrad Sep 20, 2023
56cce39
undo rounding, use tolerance based tests
conbrad Sep 21, 2023
815227c
c1 to c3
conbrad Sep 21, 2023
770507c
01a
conbrad Sep 21, 2023
ae32242
01b
conbrad Sep 21, 2023
c19fe87
c4, c5
conbrad Sep 21, 2023
349f06f
Merge branch 'main' into task/consistent-critical-hours
conbrad Sep 21, 2023
e3a0745
Ignore duplicate code in fba tests
conbrad Sep 21, 2023
a05f67c
c6, c7, d1
conbrad Sep 22, 2023
d76c6ae
s1 to s3, remove bdd test suite
conbrad Sep 22, 2023
2756903
adjust wind speed test
conbrad Sep 22, 2023
671c40a
Delete json fixtures
conbrad Sep 22, 2023
027ba8f
switch to main loop
conbrad Sep 22, 2023
732cb0e
Undo last, try to get event loop
conbrad Sep 22, 2023
9351e21
set new event loop
conbrad Sep 22, 2023
fec4260
try setting event loop in the fixtures
conbrad Sep 22, 2023
7ef70b6
Merge branch 'main' into task/consistent-critical-hours
conbrad Sep 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .sonarcloud.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ sonar.exclusions=**/Makefile, **/*.Dockerfile, api/app/data/**, api/alembic/vers
sonar.test.exclusions=*.feature
sonar.tests.inclusions=**/*.test.tsx

# Exclude duplication in fba tests due to many similar calculation numbers
sonar.cpd.exclusions=api/app/tests/fba_calc/*.py

# Encoding of the source code. Default is default system encoding
sonar.sourceEncoding=UTF-8
33 changes: 33 additions & 0 deletions api/app/fire_behaviour/wind_speed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@


from app.fire_behaviour import cffdrs
from app.schemas.fba_calc import StationRequest, WindResult

"""
If user has not specified wind speed, use the values retrieved from WFWX, always re-calculate FFMC & ISI
"""


def calculate_wind_speed_result(requested_station: StationRequest, yesterday: dict, raw_daily: dict) -> WindResult:
# extract variable from wf1 that we need to calculate the fire behaviour advisory.
bui = cffdrs.bui_calc(raw_daily.get('duffMoistureCode', None), raw_daily.get('droughtCode', None))
temperature = raw_daily.get('temperature', None)
relative_humidity = raw_daily.get('relativeHumidity', None)
precipitation = raw_daily.get('precipitation', None)

wind_speed = raw_daily.get('windSpeed', None)
status = raw_daily.get('recordType').get('id')

if requested_station.wind_speed is not None:
wind_speed = requested_station.wind_speed
status = 'ADJUSTED'

Check warning on line 23 in api/app/fire_behaviour/wind_speed.py

View check run for this annotation

Codecov / codecov/patch

api/app/fire_behaviour/wind_speed.py#L22-L23

Added lines #L22 - L23 were not covered by tests

ffmc = cffdrs.fine_fuel_moisture_code(
yesterday.get('fineFuelMoistureCode', None),
temperature,
relative_humidity,
precipitation,
wind_speed)
isi = cffdrs.initial_spread_index(ffmc, wind_speed)
fwi = cffdrs.fire_weather_index(isi, bui)
return WindResult(ffmc=ffmc, isi=isi, bui=bui, wind_speed=wind_speed, fwi=fwi, status=status)
38 changes: 8 additions & 30 deletions api/app/routers/fba_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from app.auth import authentication_required, audit
from app.fire_behaviour.advisory import (FBACalculatorWeatherStation, FireBehaviourAdvisory,
calculate_fire_behaviour_advisory)
from app.fire_behaviour.wind_speed import calculate_wind_speed_result
from app.hourlies import get_hourly_readings_in_time_interval
from app.schemas.fba_calc import (StationListRequest, StationRequest,
StationsListResponse, StationResponse)
from app.fire_behaviour import cffdrs
from app.utils.time import get_hour_20_from_date
from app.wildfire_one.schema_parsers import WFWXWeatherStation
from app.wildfire_one.wfwx_api import (get_auth_header,
Expand Down Expand Up @@ -102,41 +102,19 @@ async def process_request(
last_observed_morning_rh_values = build_hourly_rh_dict(raw_observations.values)

# extract variable from wf1 that we need to calculate the fire behaviour advisory.
bui = raw_daily.get('buildUpIndex', None)
temperature = raw_daily.get('temperature', None)
relative_humidity = raw_daily.get('relativeHumidity', None)
precipitation = raw_daily.get('precipitation', None)
wind_direction = raw_daily.get('windDirection', None)
# if user has not specified wind speed as part of StationRequest, use the
# values retrieved from WFWX in raw_daily
if requested_station.wind_speed is None:
ffmc = raw_daily.get('fineFuelMoistureCode', None)
isi = raw_daily.get('initialSpreadIndex', None)
wind_speed = raw_daily.get('windSpeed', None)
fwi = raw_daily.get('fireWeatherIndex', None)
status = raw_daily.get('recordType').get('id')
# if user has specified wind speed as part of StationRequest, will need to
# re-calculate FFMC & ISI with modified value of wind speed
else:
wind_speed = requested_station.wind_speed
status = 'ADJUSTED'

ffmc = cffdrs.fine_fuel_moisture_code(
yesterday.get('fineFuelMoistureCode', None),
temperature,
relative_humidity,
precipitation,
wind_speed)
isi = cffdrs.initial_spread_index(ffmc, wind_speed)
fwi = cffdrs.fire_weather_index(isi, bui)
wind_result = calculate_wind_speed_result(requested_station, yesterday, raw_daily)

# Prepare the inputs for the fire behaviour advisory calculation.
# This is a combination of inputs from the front end, information about the station from wf1
# and the daily values (observations/forecasts).
fba_station = FBACalculatorWeatherStation(
elevation=wfwx_station.elevation,
fuel_type=requested_station.fuel_type,
status=status,
status=wind_result.status,
time_of_interest=time_of_interest,
percentage_conifer=requested_station.percentage_conifer,
percentage_dead_balsam_fir=requested_station.percentage_dead_balsam_fir,
Expand All @@ -145,12 +123,12 @@ async def process_request(
crown_fuel_load=requested_station.crown_fuel_load,
lat=wfwx_station.lat,
long=wfwx_station.long,
bui=bui,
ffmc=ffmc,
isi=isi,
fwi=fwi,
bui=wind_result.bui,
ffmc=wind_result.ffmc,
isi=wind_result.isi,
fwi=wind_result.fwi,
prev_day_daily_ffmc=yesterday.get('fineFuelMoistureCode', None),
wind_speed=wind_speed,
wind_speed=wind_result.wind_speed,
wind_direction=wind_direction,
temperature=temperature,
relative_humidity=relative_humidity,
Expand Down
9 changes: 9 additions & 0 deletions api/app/schemas/fba_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,12 @@ class StationsListResponse(BaseModel):
""" Response for all weather stations, in a list """
date: date
stations: List[StationResponse]


class WindResult(BaseModel):
ffmc: float
bui: float
isi: float
wind_speed: float
fwi: float
status: str
12 changes: 0 additions & 12 deletions api/app/tests/fba_calc/c1_request.json

This file was deleted.

11 changes: 0 additions & 11 deletions api/app/tests/fba_calc/c1_request_forecast.json

This file was deleted.

23 changes: 0 additions & 23 deletions api/app/tests/fba_calc/c1_request_multiple.json

This file was deleted.

11 changes: 0 additions & 11 deletions api/app/tests/fba_calc/c1_request_no_daily_data.json

This file was deleted.

13 changes: 0 additions & 13 deletions api/app/tests/fba_calc/c1_request_ws_override.json

This file was deleted.

35 changes: 0 additions & 35 deletions api/app/tests/fba_calc/c1_response.json

This file was deleted.

35 changes: 0 additions & 35 deletions api/app/tests/fba_calc/c1_response_forecast.json

This file was deleted.

101 changes: 0 additions & 101 deletions api/app/tests/fba_calc/c1_response_multiple.json

This file was deleted.

Loading
Loading