Skip to content

Commit

Permalink
Install libudunits2-dev as dependency for cffdrs (#3427)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgboss authored Feb 23, 2024
1 parent ca1e215 commit f13eff8
Show file tree
Hide file tree
Showing 41 changed files with 288 additions and 275 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ jobs:
uses: actions/checkout@v4
- name: Install ubuntu pre-requisites (api)
# The python gdal and R component relies on libgdal-dev being installed.
# cffdrs requires libudunits2-dev
run: |
sudo apt-get update
sudo apt-get -y install libgdal-dev
sudo apt-get -y install libgdal-dev libudunits2-dev
- name: Setup Python ${{ matrix.python-version }} (api)
uses: actions/setup-python@v5
with:
Expand Down Expand Up @@ -88,10 +89,11 @@ jobs:
fetch-depth: 0
- name: Install ubuntu pre-requisites (api)
# The python gdal and R component relies on libgdal-dev being installed.
# cffdrs requires libudunits2-dev
# The api uses wkhtmltopdf to generate pdf's.
run: |
sudo apt-get update
sudo apt-get -y install libgdal-dev wkhtmltopdf
sudo apt-get -y install libgdal-dev wkhtmltopdf libudunits2-dev
- name: Setup Python ${{ matrix.python-version }} (api)
uses: actions/setup-python@v5
with:
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/post_merge_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ jobs:
uses: actions/checkout@v4
- name: Install ubuntu pre-requisites (api)
# The python gdal and R component relies on libgdal-dev being installed.
# cffdrs requires libudunits2-dev
run: |
sudo apt-get update
sudo apt-get -y install libgdal-dev
sudo apt-get -y install libgdal-dev libudunits2-dev
- name: Setup Python ${{ matrix.python-version }} (api)
uses: actions/setup-python@v5
with:
Expand Down Expand Up @@ -89,10 +90,11 @@ jobs:
fetch-depth: 0
- name: Install ubuntu pre-requisites (api)
# The python gdal and R component relies on libgdal-dev being installed.
# cffdrs requires libudunits2-dev
# The api uses wkhtmltopdf to generate pdf's.
run: |
sudo apt-get update
sudo apt-get -y install libgdal-dev wkhtmltopdf
sudo apt-get -y install libgdal-dev wkhtmltopdf libudunits2-dev
- name: Setup Python ${{ matrix.python-version }} (api)
uses: actions/setup-python@v5
with:
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile.vscode
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ RUN apt-get -y update
RUN apt-get -y install unixodbc-dev
# Install old (2.4.*; current debian) version of gdal
RUN apt-get -y install libgdal-dev
# Dependency required for installation of cffdrs
RUN apt-get -y install libudunits2-dev

# Install R
RUN apt-get update --fix-missing && apt-get -y install r-base
Expand Down
3 changes: 2 additions & 1 deletion api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get -y update
RUN apt-get -y install unixodbc-dev
# Install old (2.4.*; current debian) version of gdal
RUN apt-get -y install libgdal-dev
# cffdrs requires libudunits2-dev
RUN apt-get -y install libgdal-dev libudunits2-dev

# Install R
RUN apt-get update --fix-missing && apt-get -y install r-base
Expand Down
18 changes: 11 additions & 7 deletions api/app/fire_behaviour/cffdrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import math
from typing import Optional
import rpy2
import rpy2.robjects as robjs
from rpy2.robjects import pandas2ri
from rpy2.rinterface import NULL
Expand All @@ -11,6 +12,7 @@
from app.utils.singleton import Singleton
from app.schemas.fba_calc import FuelTypeEnum


logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -806,19 +808,21 @@ def hourly_fine_fuel_moisture_code(weatherstream: pd.DataFrame, ffmc_old: float,

# We have to change field names to exactly what the CFFDRS lib expects.
# This may need to be adjusted depending on the future data input model, which is currently unknown
column_name_map = {'temperature':'temp', 'relative_humidity': 'rh', 'wind_speed': 'ws', 'precipitation': 'prec'}
column_name_map = {'temperature':'temp', 'relative_humidity': 'rh', 'wind_speed': 'ws', 'precipitation': 'prec', 'datetime': 'hr'}
weatherstream = weatherstream.rename(columns=column_name_map)

r_weatherstream = pandas_to_r_converter(weatherstream)

result = CFFDRS.instance().cffdrs.hffmc(weatherstream=r_weatherstream,
try:
result = CFFDRS.instance().cffdrs.hffmc(r_weatherstream,
ffmc_old=ffmc_old, time_step=time_step, calc_step=calc_step,
batch=batch, hourlyFWI=hourly_fwi)

if isinstance(result, robjs.vectors.FloatVector):
weatherstream['hffmc'] = list(result)
return weatherstream
raise CFFDRSException("Failed to calculate hffmc")
if isinstance(result, robjs.vectors.FloatVector):
weatherstream['hffmc'] = list(result)
return weatherstream
except rpy2.rinterface_lib.embedded.RRuntimeError as e:
logger.error(f"An error occurred when calculating hourly ffmc: {e}")
raise CFFDRSException("Failed to calculate hffmc")


def get_ffmc_for_target_hfi(
Expand Down
6 changes: 3 additions & 3 deletions api/app/tests/fba_calc/test_01a_0curing_firebat.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ async def test_01a_0curing_request_response(anyio_backend, async_client: AsyncCl
assert response.json()['stations'][0]['fuel_type'] == 'O1A'
assert response.json()['stations'][0]['grass_cure'] == 0.0

assert math.isclose(response.json()['stations'][0]['fine_fuel_moisture_code'], 93.305, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['fine_fuel_moisture_code'], 93.258, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['drought_code'], 340.544, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['initial_spread_index'], 10.88, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['initial_spread_index'], 10.810, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['build_up_index'], 117.899, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['duff_moisture_code'], 103.923, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['fire_weather_index'], 35.793, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['fire_weather_index'], 35.640, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['head_fire_intensity'], 0.0001, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['rate_of_spread'], 1e-06, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['percentage_crown_fraction_burned'], 0.0, abs_tol=0.001)
Expand Down
14 changes: 7 additions & 7 deletions api/app/tests/fba_calc/test_01a_30curing_firebat.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ async def test_01a_30curing_request_response(anyio_backend, async_client: AsyncC
assert response.json()['stations'][0]['fuel_type'] == 'O1A'
assert response.json()['stations'][0]['grass_cure'] == 30.0

assert math.isclose(response.json()['stations'][0]['fine_fuel_moisture_code'], 93.305, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['fine_fuel_moisture_code'], 93.258, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['drought_code'], 340.544, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['initial_spread_index'], 10.88, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['initial_spread_index'], 10.810, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['build_up_index'], 117.899, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['duff_moisture_code'], 103.923, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['fire_weather_index'], 35.793, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['head_fire_intensity'], 90.634, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['rate_of_spread'], 0.863, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['fire_weather_index'], 35.640, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['head_fire_intensity'], 89.942, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['rate_of_spread'], 0.857, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['percentage_crown_fraction_burned'], 0.0, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['flame_length'], 0.55, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['sixty_minute_fire_size'], 0.0863, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['flame_length'], 0.548, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['sixty_minute_fire_size'], 0.085, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['thirty_minute_fire_size'], 0.016, abs_tol=0.001)

assert response.json()['stations'][0]['fire_type'] == 'SUR'
Expand Down
16 changes: 8 additions & 8 deletions api/app/tests/fba_calc/test_01a_90curing_firebat.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ async def test_01a_90curing_request_response(anyio_backend, async_client: AsyncC
assert response.json()['stations'][0]['fuel_type'] == 'O1A'
assert response.json()['stations'][0]['grass_cure'] == 90.0

assert math.isclose(response.json()['stations'][0]['fine_fuel_moisture_code'], 93.305, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['fine_fuel_moisture_code'], 93.258, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['drought_code'], 340.544, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['initial_spread_index'], 10.88, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['initial_spread_index'], 10.810, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['build_up_index'], 117.899, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['duff_moisture_code'], 103.923, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['fire_weather_index'], 35.793, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['head_fire_intensity'], 2770.676, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['rate_of_spread'], 26.387, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['fire_weather_index'], 35.640, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['head_fire_intensity'], 2749.522, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['rate_of_spread'], 26.186, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['percentage_crown_fraction_burned'], 0.0, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['flame_length'], 3.039, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['sixty_minute_fire_size'], 80.668, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['thirty_minute_fire_size'], 14.571, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['flame_length'], 3.027, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['sixty_minute_fire_size'], 79.408, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['thirty_minute_fire_size'], 14.343, abs_tol=0.001)

assert response.json()['stations'][0]['fire_type'] == 'SUR'
assert response.json()['stations'][0]['critical_hours_hfi_4000'] is None
Expand Down
6 changes: 3 additions & 3 deletions api/app/tests/fba_calc/test_01b_0curing_firebat.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ async def test_01b_0curing_request_response(anyio_backend, async_client: AsyncCl
assert response.json()['stations'][0]['fuel_type'] == 'O1B'
assert response.json()['stations'][0]['grass_cure'] == 0.0

assert math.isclose(response.json()['stations'][0]['fine_fuel_moisture_code'], 93.305, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['fine_fuel_moisture_code'], 93.258, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['drought_code'], 340.544, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['initial_spread_index'], 10.88, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['initial_spread_index'], 10.810, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['build_up_index'], 117.899, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['duff_moisture_code'], 103.923, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['fire_weather_index'], 35.793, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['fire_weather_index'], 35.640, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['head_fire_intensity'], 0.0001, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['rate_of_spread'], 1e-06, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['percentage_crown_fraction_burned'], 0.0, abs_tol=0.001)
Expand Down
14 changes: 7 additions & 7 deletions api/app/tests/fba_calc/test_01b_30curing_firebat.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ async def test_01b_30curing_request_response(anyio_backend, async_client: AsyncC
assert response.json()['stations'][0]['fuel_type'] == 'O1B'
assert response.json()['stations'][0]['grass_cure'] == 30.0

assert math.isclose(response.json()['stations'][0]['fine_fuel_moisture_code'], 93.305, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['fine_fuel_moisture_code'], 93.258, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['drought_code'], 340.544, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['initial_spread_index'], 10.88, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['initial_spread_index'], 10.810, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['build_up_index'], 117.899, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['duff_moisture_code'], 103.923, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['fire_weather_index'], 35.793, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['head_fire_intensity'], 97.279, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['rate_of_spread'], 0.926, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['fire_weather_index'], 35.640, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['head_fire_intensity'], 96.398, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['rate_of_spread'], 0.918, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['percentage_crown_fraction_burned'], 0.0, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['flame_length'], 0.569, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['sixty_minute_fire_size'], 0.08999, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['flame_length'], 0.567, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['sixty_minute_fire_size'], 0.088, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['thirty_minute_fire_size'], 0.016, abs_tol=0.001)

assert response.json()['stations'][0]['fire_type'] == 'SUR'
Expand Down
16 changes: 8 additions & 8 deletions api/app/tests/fba_calc/test_01b_90curing_firebat.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ async def test_01b_90curing_request_response(anyio_backend, async_client: AsyncC
assert response.json()['stations'][0]['fuel_type'] == 'O1B'
assert response.json()['stations'][0]['grass_cure'] == 90.0

assert math.isclose(response.json()['stations'][0]['fine_fuel_moisture_code'], 93.305, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['fine_fuel_moisture_code'], 93.258, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['drought_code'], 340.544, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['initial_spread_index'], 10.88, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['initial_spread_index'], 10.810, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['build_up_index'], 117.899, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['duff_moisture_code'], 103.923, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['fire_weather_index'], 35.793, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['head_fire_intensity'], 2973.81, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['rate_of_spread'], 28.322, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['fire_weather_index'], 35.640, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['head_fire_intensity'], 2946.886, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['rate_of_spread'], 28.066, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['percentage_crown_fraction_burned'], 0.0, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['flame_length'], 3.149, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['sixty_minute_fire_size'], 84.103, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['thirty_minute_fire_size'], 15.191, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['flame_length'], 3.134, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['sixty_minute_fire_size'], 82.549, abs_tol=0.001)
assert math.isclose(response.json()['stations'][0]['thirty_minute_fire_size'], 14.910, abs_tol=0.001)

assert response.json()['stations'][0]['fire_type'] == 'SUR'
assert response.json()['stations'][0]['critical_hours_hfi_4000'] is None
Expand Down
Loading

0 comments on commit f13eff8

Please sign in to comment.