Skip to content

Commit

Permalink
Added data_precision as a new property to coverage configurations (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogsilva authored Oct 17, 2024
1 parent 5d61eca commit 03b97b2
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 1 deletion.
31 changes: 31 additions & 0 deletions arpav_ppcv/bootstrapper/coverage_configurations/forecast/pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
_DISPLAY_NAME_ITALIAN = "Precipitazione"
_DESCRIPTION_ENGLISH = "Daily precipitation near the ground"
_DESCRIPTION_ITALIAN = "Precipitazioni giornaliere in prossimità del suolo"
_DATA_PRECISION = 0


def generate_configurations(
Expand All @@ -30,6 +31,7 @@ def generate_configurations(
palette="default/div-BrBG",
color_scale_min=-40,
color_scale_max=40,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -106,6 +108,7 @@ def generate_configurations(
palette="default/div-BrBG",
color_scale_min=-40,
color_scale_max=40,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -185,6 +188,7 @@ def generate_configurations(
palette="default/div-BrBG",
color_scale_min=-40,
color_scale_max=40,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -264,6 +268,7 @@ def generate_configurations(
palette="default/div-BrBG",
color_scale_min=-40,
color_scale_max=40,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -340,6 +345,7 @@ def generate_configurations(
palette="default/div-BrBG",
color_scale_min=-40,
color_scale_max=40,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -419,6 +425,7 @@ def generate_configurations(
palette="default/div-BrBG",
color_scale_min=-40,
color_scale_max=40,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -498,6 +505,7 @@ def generate_configurations(
palette="default/seq-YlOrRd",
color_scale_min=0,
color_scale_max=0,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -579,6 +587,7 @@ def generate_configurations(
palette="default/seq-YlOrRd",
color_scale_min=0,
color_scale_max=0,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -660,6 +669,7 @@ def generate_configurations(
palette="default/seq-BuYl-inv",
color_scale_min=0,
color_scale_max=800,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -740,6 +750,7 @@ def generate_configurations(
palette="default/seq-BuYl-inv",
color_scale_min=0,
color_scale_max=3200,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -805,6 +816,7 @@ def generate_configurations(
palette="default/seq-BuYl-inv",
color_scale_min=0,
color_scale_max=800,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -888,6 +900,7 @@ def generate_configurations(
palette="default/seq-BuYl-inv",
color_scale_min=0,
color_scale_max=800,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -956,6 +969,7 @@ def generate_configurations(
palette="default/seq-BuYl-inv",
color_scale_min=0,
color_scale_max=800,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -1039,6 +1053,7 @@ def generate_configurations(
palette="default/seq-BuYl-inv",
color_scale_min=0,
color_scale_max=3200,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -1107,6 +1122,7 @@ def generate_configurations(
palette="default/seq-BuYl-inv",
color_scale_min=0,
color_scale_max=800,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -1187,6 +1203,7 @@ def generate_configurations(
palette="default/seq-BuYl-inv",
color_scale_min=0,
color_scale_max=3200,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -1252,6 +1269,7 @@ def generate_configurations(
palette="default/seq-BuYl-inv",
color_scale_min=0,
color_scale_max=800,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -1335,6 +1353,7 @@ def generate_configurations(
palette="default/seq-BuYl-inv",
color_scale_min=0,
color_scale_max=3200,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -1403,6 +1422,7 @@ def generate_configurations(
palette="default/seq-BuYl-inv",
color_scale_min=0,
color_scale_max=800,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -1486,6 +1506,7 @@ def generate_configurations(
palette="default/seq-BuYl-inv",
color_scale_min=0,
color_scale_max=3200,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -1554,6 +1575,7 @@ def generate_configurations(
palette="default/seq-BuYl-inv",
color_scale_min=0,
color_scale_max=800,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -1635,6 +1657,7 @@ def generate_configurations(
palette="default/seq-BuYl-inv",
color_scale_min=0,
color_scale_max=800,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -1716,6 +1739,7 @@ def generate_configurations(
palette="default/seq-BuYl-inv",
color_scale_min=0,
color_scale_max=3200,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -1782,6 +1806,7 @@ def generate_configurations(
palette="default/seq-BuYl-inv",
color_scale_min=0,
color_scale_max=3200,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -1849,6 +1874,7 @@ def generate_configurations(
palette="uncert-stippled/div-BrBG",
color_scale_min=-40,
color_scale_max=40,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -1935,6 +1961,7 @@ def generate_configurations(
palette="default/div-BrBG",
color_scale_min=-40,
color_scale_max=40,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -2024,6 +2051,7 @@ def generate_configurations(
palette="default/div-BrBG",
color_scale_min=-40,
color_scale_max=40,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -2113,6 +2141,7 @@ def generate_configurations(
palette="default/div-BrBG",
color_scale_min=-40,
color_scale_max=40,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -2199,6 +2228,7 @@ def generate_configurations(
palette="default/div-BrBG",
color_scale_min=-40,
color_scale_max=40,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -2288,6 +2318,7 @@ def generate_configurations(
palette="default/div-BrBG",
color_scale_min=-40,
color_scale_max=40,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
_UNIT = "mm"
_COLOR_SCALE_MIN = 300
_COLOR_SCALE_MAX = 1300
_DATA_PRECISION = 0
_RELATED_OBSERVATION_VARIABLE_NAME = "PRCPTOT"


Expand Down Expand Up @@ -162,6 +163,7 @@ def generate_configurations(
palette="default/seq-YlOrRd",
color_scale_min=_COLOR_SCALE_MIN,
color_scale_max=_COLOR_SCALE_MAX,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -209,6 +211,7 @@ def generate_configurations(
palette="default/seq-YlOrRd",
color_scale_min=_COLOR_SCALE_MIN,
color_scale_max=_COLOR_SCALE_MAX,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down Expand Up @@ -271,6 +274,7 @@ def generate_configurations(
palette="default/seq-YlOrRd",
color_scale_min=_COLOR_SCALE_MIN,
color_scale_max=_COLOR_SCALE_MAX,
data_precision=_DATA_PRECISION,
possible_values=[
ConfigurationParameterPossibleValueCreate(
configuration_parameter_value_id=conf_param_values[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""added precision to cov conf
Revision ID: 4df282a0319d
Revises: c6f618a7f88f
Create Date: 2024-10-16 13:39:58.363787
"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
import sqlmodel
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
_table_name = "coverageconfiguration"
_column_name = "data_precision"

class CoverageConfiguration(Base):
__tablename__ = _table_name

id = sa.Column(sa.UUID, primary_key=True)
data_precision = sa.Column(sa.Integer, nullable=True)


# revision identifiers, used by Alembic.
revision: str = "4df282a0319d"
down_revision: Union[str, None] = "c6f618a7f88f"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
bind = op.get_bind()
op.add_column(
_table_name,
sa.Column(_column_name, sa.Integer(), nullable=True)
)
session = sa.orm.Session(bind=bind)
for cov_conf in session.query(CoverageConfiguration):
cov_conf.data_precision = 3
session.commit()
op.alter_column(_table_name, _column_name, nullable=False)


def downgrade() -> None:
op.drop_column('coverageconfiguration', 'data_precision')
3 changes: 3 additions & 0 deletions arpav_ppcv/schemas/coverages.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class CoverageConfiguration(sqlmodel.SQLModel, table=True):
palette: str
color_scale_min: float = 0.0
color_scale_max: float = 1.0
data_precision: int = 3
observation_variable_id: Optional[uuid.UUID] = sqlmodel.Field(
default=None, foreign_key="variable.id"
)
Expand Down Expand Up @@ -444,6 +445,7 @@ class CoverageConfigurationCreate(sqlmodel.SQLModel):
palette: str
color_scale_min: float
color_scale_max: float
data_precision: int = 3
possible_values: list["ConfigurationParameterPossibleValueCreate"]
observation_variable_id: Optional[uuid.UUID] = None
observation_variable_aggregation_type: Optional[
Expand Down Expand Up @@ -479,6 +481,7 @@ class CoverageConfigurationUpdate(sqlmodel.SQLModel):
palette: Optional[str] = None
color_scale_min: Optional[float] = None
color_scale_max: Optional[float] = None
data_precision: Optional[int] = None
observation_variable_id: Optional[uuid.UUID] = None
observation_variable_aggregation_type: Optional[
base.ObservationAggregationType
Expand Down
1 change: 1 addition & 0 deletions arpav_ppcv/webapp/admin/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class CoverageConfigurationRead(sqlmodel.SQLModel):
palette: str
color_scale_min: float
color_scale_max: float
data_precision: int
possible_values: list[ConfigurationParameterPossibleValueRead]
observation_variable_aggregation_type: ObservationAggregationType
observation_variable: Optional["ObservationVariableRead"]
Expand Down
Loading

0 comments on commit 03b97b2

Please sign in to comment.