Skip to content

Commit

Permalink
Added bootstrap command for observation series configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogsilva committed Jan 9, 2025
1 parent 5797509 commit 150b4ea
Show file tree
Hide file tree
Showing 19 changed files with 959 additions and 800 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,22 +236,28 @@ dev environment is located at individual devs machine(s). In order to get a work
Build the docker image by running this command:

```shell
docker build --tag ghcr.io/geobeyond/arpav-ppcv-backend/arpav-ppcv-backend
docker build \
--tag ghcr.io/geobeyond/arpav-ppcv-backend/arpav-ppcv-backend \
--file docker/Dockerfile \
.
```

If you want to build an image for the current branch, such as when you added a new third-party dependency as part of
an ongoing task, add the branch name to the build image:

```shell
docker build --tag ghcr.io/geobeyond/arpav-ppcv-backend/arpav-ppcv-backend:$(git branch --show-current)
docker build
--tag ghcr.io/geobeyond/arpav-ppcv-backend/arpav-ppcv-backend:$(git branch --show-current) \
--file docker/Dockerfile \
.
```

In order to use this custom named image on your local development, set the `CURRENT_GIT_BRANCH` env variable before
launching the docker compose stack, _i.e._:

```shell
export CURRENT_GIT_BRANCH=$(git branch --show-current)
docker compose -f docker/compose.yaml -f docker/compose.dev.yaml up -d
docker compose -f docker/compose.yaml -f docker/compose.dev.yaml up -d --force-recreate
```


Expand Down
25 changes: 25 additions & 0 deletions arpav_ppcv/bootstrapper/cliapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
tasmin as tasmin_climatic_indicators,
tr as tr_climatic_indicators,
)
from .observation_series_configurations import (
generate_observation_series_configurations,
)

from .configurationparameters import generate_configuration_parameters

Expand Down Expand Up @@ -250,6 +253,28 @@ def bootstrap_climatic_indicators(
session.rollback()


@app.command("observation-series-configurations")
def bootstrap_observation_series_configurations(ctx: typer.Context):
"""Create initial observation series configurations."""
with sqlmodel.Session(ctx.obj["engine"]) as session:
all_climatic_indicators = database.collect_all_climatic_indicators(session)
to_generate = generate_observation_series_configurations(
{ind.identifier: ind for ind in all_climatic_indicators}
)
for obs_series_create in to_generate:
try:
db_series_conf = database.create_observation_series_configuration(
session, obs_series_create
)
print(
f"Created observation series "
f"configuration {db_series_conf.identifier!r}"
)
except IntegrityError as err:
print(f"Could not create observation series {to_generate!r}: {err}")
session.rollback()


@app.command("coverage-configuration-parameters")
def bootstrap_coverage_configuration_parameters(
ctx: typer.Context,
Expand Down
12 changes: 11 additions & 1 deletion arpav_ppcv/bootstrapper/climaticindicators/cdds.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from ...schemas.static import (
AggregationPeriod,
MeasureType,
ObservationStationManager,
)
from ...schemas.climaticindicators import (
ClimaticIndicatorCreate,
ClimaticIndicatorObservationNameCreate,
)
from ...schemas.climaticindicators import ClimaticIndicatorCreate


def generate_climatic_indicators() -> list[ClimaticIndicatorCreate]:
Expand All @@ -28,6 +32,12 @@ def generate_climatic_indicators() -> list[ClimaticIndicatorCreate]:
color_scale_max=1000,
data_precision=0,
sort_order=8,
observation_names=[
ClimaticIndicatorObservationNameCreate(
observation_station_manager=ObservationStationManager.ARPAV,
indicator_observation_name="CDD_jrc",
)
],
),
ClimaticIndicatorCreate(
name="cdds",
Expand Down
12 changes: 11 additions & 1 deletion arpav_ppcv/bootstrapper/climaticindicators/fd.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from ...schemas.static import (
AggregationPeriod,
MeasureType,
ObservationStationManager,
)
from ...schemas.climaticindicators import (
ClimaticIndicatorCreate,
ClimaticIndicatorObservationNameCreate,
)
from ...schemas.climaticindicators import ClimaticIndicatorCreate


def generate_climatic_indicators() -> list[ClimaticIndicatorCreate]:
Expand All @@ -26,6 +30,12 @@ def generate_climatic_indicators() -> list[ClimaticIndicatorCreate]:
color_scale_max=200,
data_precision=0,
sort_order=5,
observation_names=[
ClimaticIndicatorObservationNameCreate(
observation_station_manager=ObservationStationManager.ARPAV,
indicator_observation_name="FD",
)
],
),
ClimaticIndicatorCreate(
name="fd",
Expand Down
12 changes: 11 additions & 1 deletion arpav_ppcv/bootstrapper/climaticindicators/hdds.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from ...schemas.static import (
AggregationPeriod,
MeasureType,
ObservationStationManager,
)
from ...schemas.climaticindicators import (
ClimaticIndicatorCreate,
ClimaticIndicatorObservationNameCreate,
)
from ...schemas.climaticindicators import ClimaticIndicatorCreate


def generate_climatic_indicators() -> list[ClimaticIndicatorCreate]:
Expand All @@ -28,6 +32,12 @@ def generate_climatic_indicators() -> list[ClimaticIndicatorCreate]:
color_scale_max=7000,
data_precision=0,
sort_order=7,
observation_names=[
ClimaticIndicatorObservationNameCreate(
observation_station_manager=ObservationStationManager.ARPAV,
indicator_observation_name="HDD_it",
),
],
),
ClimaticIndicatorCreate(
name="hdds",
Expand Down
12 changes: 11 additions & 1 deletion arpav_ppcv/bootstrapper/climaticindicators/pr.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from ...schemas.static import (
AggregationPeriod,
MeasureType,
ObservationStationManager,
)
from ...schemas.climaticindicators import (
ClimaticIndicatorCreate,
ClimaticIndicatorObservationNameCreate,
)
from ...schemas.climaticindicators import ClimaticIndicatorCreate


def generate_climatic_indicators() -> list[ClimaticIndicatorCreate]:
Expand Down Expand Up @@ -54,6 +58,12 @@ def generate_climatic_indicators() -> list[ClimaticIndicatorCreate]:
color_scale_max=800,
data_precision=0,
sort_order=9,
observation_names=[
ClimaticIndicatorObservationNameCreate(
observation_station_manager=ObservationStationManager.ARPAV,
indicator_observation_name="PRCPTOT",
)
],
),
ClimaticIndicatorCreate(
name="pr",
Expand Down
12 changes: 11 additions & 1 deletion arpav_ppcv/bootstrapper/climaticindicators/su30.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from ...schemas.static import (
AggregationPeriod,
MeasureType,
ObservationStationManager,
)
from ...schemas.climaticindicators import (
ClimaticIndicatorCreate,
ClimaticIndicatorObservationNameCreate,
)
from ...schemas.climaticindicators import ClimaticIndicatorCreate


def generate_climatic_indicators() -> list[ClimaticIndicatorCreate]:
Expand All @@ -26,6 +30,12 @@ def generate_climatic_indicators() -> list[ClimaticIndicatorCreate]:
color_scale_max=100,
data_precision=0,
sort_order=4,
observation_names=[
ClimaticIndicatorObservationNameCreate(
observation_station_manager=ObservationStationManager.ARPAV,
indicator_observation_name="SU30",
)
],
),
ClimaticIndicatorCreate(
name="su30",
Expand Down
12 changes: 11 additions & 1 deletion arpav_ppcv/bootstrapper/climaticindicators/tas.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from ...schemas.static import (
AggregationPeriod,
MeasureType,
ObservationStationManager,
)
from ...schemas.climaticindicators import (
ClimaticIndicatorCreate,
ClimaticIndicatorObservationNameCreate,
)
from ...schemas.climaticindicators import ClimaticIndicatorCreate


def generate_climatic_indicators() -> list[ClimaticIndicatorCreate]:
Expand All @@ -22,6 +26,12 @@ def generate_climatic_indicators() -> list[ClimaticIndicatorCreate]:
color_scale_max=32,
data_precision=1,
sort_order=0,
observation_names=[
ClimaticIndicatorObservationNameCreate(
observation_station_manager=ObservationStationManager.ARPAV,
indicator_observation_name="TDd",
)
],
),
ClimaticIndicatorCreate(
name="tas",
Expand Down
12 changes: 11 additions & 1 deletion arpav_ppcv/bootstrapper/climaticindicators/tasmax.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from ...schemas.static import (
AggregationPeriod,
MeasureType,
ObservationStationManager,
)
from ...schemas.climaticindicators import (
ClimaticIndicatorCreate,
ClimaticIndicatorObservationNameCreate,
)
from ...schemas.climaticindicators import ClimaticIndicatorCreate


def generate_climatic_indicators() -> list[ClimaticIndicatorCreate]:
Expand All @@ -24,6 +28,12 @@ def generate_climatic_indicators() -> list[ClimaticIndicatorCreate]:
color_scale_max=32,
data_precision=1,
sort_order=2,
observation_names=[
ClimaticIndicatorObservationNameCreate(
observation_station_manager=ObservationStationManager.ARPAV,
indicator_observation_name="TXd",
)
],
),
ClimaticIndicatorCreate(
name="tasmax",
Expand Down
12 changes: 11 additions & 1 deletion arpav_ppcv/bootstrapper/climaticindicators/tasmin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from ...schemas.static import (
AggregationPeriod,
MeasureType,
ObservationStationManager,
)
from ...schemas.climaticindicators import (
ClimaticIndicatorCreate,
ClimaticIndicatorObservationNameCreate,
)
from ...schemas.climaticindicators import ClimaticIndicatorCreate


def generate_climatic_indicators() -> list[ClimaticIndicatorCreate]:
Expand All @@ -24,6 +28,12 @@ def generate_climatic_indicators() -> list[ClimaticIndicatorCreate]:
color_scale_max=32,
data_precision=1,
sort_order=1,
observation_names=[
ClimaticIndicatorObservationNameCreate(
observation_station_manager=ObservationStationManager.ARPAV,
indicator_observation_name="TNd",
)
],
),
ClimaticIndicatorCreate(
name="tasmin",
Expand Down
12 changes: 11 additions & 1 deletion arpav_ppcv/bootstrapper/climaticindicators/tr.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from ...schemas.static import (
AggregationPeriod,
MeasureType,
ObservationStationManager,
)
from ...schemas.climaticindicators import (
ClimaticIndicatorCreate,
ClimaticIndicatorObservationNameCreate,
)
from ...schemas.climaticindicators import ClimaticIndicatorCreate


def generate_climatic_indicators() -> list[ClimaticIndicatorCreate]:
Expand All @@ -26,6 +30,12 @@ def generate_climatic_indicators() -> list[ClimaticIndicatorCreate]:
color_scale_max=120,
data_precision=1,
sort_order=3,
observation_names=[
ClimaticIndicatorObservationNameCreate(
observation_station_manager=ObservationStationManager.ARPAV,
indicator_observation_name="TR",
)
],
),
ClimaticIndicatorCreate(
name="tr",
Expand Down
78 changes: 78 additions & 0 deletions arpav_ppcv/bootstrapper/observation_series_configurations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from ..schemas.climaticindicators import ClimaticIndicator
from ..schemas.observations import ObservationSeriesConfigurationCreate
from ..schemas.static import (
MeasurementAggregationType,
ObservationStationManager,
)


def generate_observation_series_configurations(
indicators: dict[str, ClimaticIndicator],
) -> list[ObservationSeriesConfigurationCreate]:
return [
ObservationSeriesConfigurationCreate(
climatic_indicator_id=indicators["hdds-absolute-annual"].id,
measurement_aggregation_type=MeasurementAggregationType.YEARLY,
station_managers=[ObservationStationManager.ARPAV],
),
ObservationSeriesConfigurationCreate(
climatic_indicator_id=indicators["cdds-absolute-annual"].id,
measurement_aggregation_type=MeasurementAggregationType.YEARLY,
station_managers=[ObservationStationManager.ARPAV],
),
ObservationSeriesConfigurationCreate(
climatic_indicator_id=indicators["tas-absolute-annual"].id,
measurement_aggregation_type=MeasurementAggregationType.SEASONAL,
station_managers=[ObservationStationManager.ARPAV],
),
ObservationSeriesConfigurationCreate(
climatic_indicator_id=indicators["tas-absolute-annual"].id,
measurement_aggregation_type=MeasurementAggregationType.YEARLY,
station_managers=[ObservationStationManager.ARPAV],
),
ObservationSeriesConfigurationCreate(
climatic_indicator_id=indicators["tasmax-absolute-annual"].id,
measurement_aggregation_type=MeasurementAggregationType.SEASONAL,
station_managers=[ObservationStationManager.ARPAV],
),
ObservationSeriesConfigurationCreate(
climatic_indicator_id=indicators["tasmax-absolute-annual"].id,
measurement_aggregation_type=MeasurementAggregationType.YEARLY,
station_managers=[ObservationStationManager.ARPAV],
),
ObservationSeriesConfigurationCreate(
climatic_indicator_id=indicators["tasmin-absolute-annual"].id,
measurement_aggregation_type=MeasurementAggregationType.SEASONAL,
station_managers=[ObservationStationManager.ARPAV],
),
ObservationSeriesConfigurationCreate(
climatic_indicator_id=indicators["tasmin-absolute-annual"].id,
measurement_aggregation_type=MeasurementAggregationType.YEARLY,
station_managers=[ObservationStationManager.ARPAV],
),
ObservationSeriesConfigurationCreate(
climatic_indicator_id=indicators["pr-absolute-annual"].id,
measurement_aggregation_type=MeasurementAggregationType.SEASONAL,
station_managers=[ObservationStationManager.ARPAV],
),
ObservationSeriesConfigurationCreate(
climatic_indicator_id=indicators["pr-absolute-annual"].id,
measurement_aggregation_type=MeasurementAggregationType.YEARLY,
station_managers=[ObservationStationManager.ARPAV],
),
ObservationSeriesConfigurationCreate(
climatic_indicator_id=indicators["tr-absolute-annual"].id,
measurement_aggregation_type=MeasurementAggregationType.YEARLY,
station_managers=[ObservationStationManager.ARPAV],
),
ObservationSeriesConfigurationCreate(
climatic_indicator_id=indicators["su30-absolute-annual"].id,
measurement_aggregation_type=MeasurementAggregationType.YEARLY,
station_managers=[ObservationStationManager.ARPAV],
),
ObservationSeriesConfigurationCreate(
climatic_indicator_id=indicators["fd-absolute-annual"].id,
measurement_aggregation_type=MeasurementAggregationType.YEARLY,
station_managers=[ObservationStationManager.ARPAV],
),
]
Loading

0 comments on commit 150b4ea

Please sign in to comment.