Coverage for toardb/stationmeta/models_global.py: 100%
37 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-03 20:32 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-03 20:32 +0000
1# SPDX-FileCopyrightText: 2021 Forschungszentrum Jülich GmbH
2# SPDX-License-Identifier: MIT
4"""
5class StationmetaGlobal (Base)
6==============================
7"""
8from sqlalchemy import Column, DateTime, Float, ForeignKey, Integer, String, \
9 Text, text, CheckConstraint, Sequence
10from sqlalchemy.orm import relationship
11from sqlalchemy.dialects.postgresql import JSONB, ARRAY
12from .models_core import StationmetaCore
13from toardb.base import Base
15STATIONMETA_GLOBAL_ID_SEQ = Sequence('stationmeta_global_id_seq') # define sequence explicitly
16class StationmetaGlobal(Base):
17 """
18 Table "public.stationmeta_global"
20 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
21 | Column | Type | Collation | Nullable | Default |
22 +=======================================+========================+===========+==========+================================================+
23 | id | integer | | not null | nextval('stationmeta_global_id_seq'::regclass) |
24 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
25 | mean_topography_srtm_alt_90m_year1994 | double precision | | not null | '-999.0'::numeric |
26 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
27 | mean_topography_srtm_alt_1km_year1994 | double precision | | not null | '-999.0'::numeric |
28 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
29 | max_topography_srtm_relative_alt_5km_year1994 | double precision | | not null | '-999.0'::numeric |
30 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
31 | min_topography_srtm_relative_alt_5km_year1994 | double precision | | not null | '-999.0'::numeric |
32 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
33 | stddev_topography_srtm_relative_alt_5km_year1994 | double precision | | not null | '-999.0'::numeric |
34 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
35 | climatic_zone_year2016 | integer | | not null | '-1'::integer |
36 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
37 | htap_region_tier1_year2010 | integer | | not null | '-1'::integer |
38 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
39 | dominant_landcover_year2012 | integer | | not null | '-1'::integer |
40 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
41 | landcover_description_25km_year2012 | character varying(400) | | not null | ''::character varying |
42 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
43 | dominant_ecoregion_year2017 | integer | | not null | '-1'::integer |
44 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
45 | ecoregion_description_25km_year2017 | character varying(400) | | not null | ''::character varying |
46 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
47 | distance_to_major_road_year2020 | double precision | | not null | '-999.0'::numeric |
48 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
49 | mean_stable_nightlights_1km_year2013 | double precision | | not null | '-999.0'::numeric |
50 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
51 | mean_stable_nightlights_5km_year2013 | double precision | | not null | '-999.0'::numeric |
52 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
53 | max_stable_nightlights_25km_year2013 | double precision | | not null | '-999.0'::numeric |
54 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
55 | max_stable_nightlights_25km_year1992 | double precision | | not null | '-999.0'::numeric |
56 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
57 | mean_population_density_250m_year2015 | double precision | | not null | '-999.0'::numeric |
58 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
59 | mean_population_density_5km_year2015 | double precision | | not null | '-999.0'::numeric |
60 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
61 | max_population_density_25km_year2015 | double precision | | not null | '-999.0'::numeric |
62 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
63 | mean_population_density_250m_year1990 | double precision | | not null | '-999.0'::numeric |
64 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
65 | mean_population_density_5km_year1990 | double precision | | not null | '-999.0'::numeric |
66 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
67 | max_population_density_25km_year1990 | double precision | | not null | '-999.0'::numeric |
68 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
69 | mean_nox_emissions_10km_year2015 | double precision | | not null | '-999.0'::numeric |
70 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
71 | mean_nox_emissions_10km_year2000 | double precision | | not null | '-999.0'::numeric |
72 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
73 | toar1_category | integer | | not null | '-1'::integer |
74 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
75 | toar2_category | integer | | not null | '0'::integer |
76 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
77 | station_id | integer | | not null | |
78 +--------------------------------------------------+------------------------+-----------+----------+------------------------------------------------+
80 Indexes:
81 "stationmeta_global_pkey" PRIMARY KEY, btree (id)
82 "stationmeta_global_station_id_key" UNIQUE CONSTRAINT, btree (station_id)
83 Check constraints:
84 "stationmeta_global_climatic_zone_check" CHECK (climatic_zone_year2016 >= 0)
85 "stationmeta_global_dominant_landcover_year2012_check" CHECK (dominant_landcover_year2012 >= 0)
86 "stationmeta_global_htap_region_tier1_check" CHECK (htap_region_tier1_year2010 >= 0)
87 Foreign-key constraints:
88 "stationmeta_global_station_id_29ff53dd_fk_stationmeta_core_id" FOREIGN KEY (station_id) REFERENCES stationmeta_core(id) DEFERRABLE INITIALLY DEFERRED
89 "stationmeta_glob_dominant_ecoregion_year2017_fk_er_voc_enum_val" FOREIGN KEY (dominant_ecoregion_year2017) REFERENCES er_vocabulary(enum_val)
90 "stationmeta_glob_dominant_landcover_year2012_fk_lc_voc_enum_val" FOREIGN KEY (dominant_landcover_year2012) REFERENCES lc_vocabulary(enum_val)
91 "stationmeta_global_climatic_zone_fk_cz_at_vocabulary_enum_val" FOREIGN KEY (climatic_zone_year2016) REFERENCES cz_vocabulary(enum_val)
92 "stationmeta_global_htap_region_tier1_fk_tr_vocabulary_enum_val" FOREIGN KEY (htap_region_tier1_year2010) REFERENCES tr_vocabulary(enum_val)
93 "stationmeta_global_toar1_category_fk_tc_vocabulary_enum_val" FOREIGN KEY (toar1_category) REFERENCES tc_vocabulary(enum_val)
94 "stationmeta_global_toar2_category_fk_tc_vocabulary_enum_val" FOREIGN KEY (toar2_category) REFERENCES ta_vocabulary(enum_val)
95 """
96 __tablename__ = 'stationmeta_global'
97# Default values do not fit CheckConstraints == > Check, how both can be done!!
98# __table_args__ = (
99# CheckConstraint('climatic_zone_year2016 >= 0'),
100# CheckConstraint('dominant_landcover_year2012 >= 0'),
101# CheckConstraint('htap_region_tier1_year2010 >= 0'),
102# )
104 id = Column(Integer, STATIONMETA_GLOBAL_ID_SEQ, primary_key=True, server_default=STATIONMETA_GLOBAL_ID_SEQ.next_value())
105 mean_topography_srtm_alt_90m_year1994 = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
106 mean_topography_srtm_alt_1km_year1994 = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
107 max_topography_srtm_relative_alt_5km_year1994 = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
108 min_topography_srtm_relative_alt_5km_year1994 = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
109 stddev_topography_srtm_relative_alt_5km_year1994 = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
110 climatic_zone_year2016 = Column(ForeignKey('cz_vocabulary.enum_val'), nullable=False, server_default=text("'-1'::integer"))
111 htap_region_tier1_year2010 = Column(ForeignKey('tr_vocabulary.enum_val'), nullable=False, server_default=text("'-1'::integer"))
112 dominant_landcover_year2012 = Column(ForeignKey('lc_vocabulary.enum_val'), nullable=False, server_default=text("'-1'::integer"))
113 landcover_description_25km_year2012 = Column(String(400), nullable=False, server_default=text("''::character varying"))
114 dominant_ecoregion_year2017 = Column(ForeignKey('er_vocabulary.enum_val'), nullable=False, server_default=text("'-1'::integer"))
115 ecoregion_description_25km_year2017 = Column(String(400), nullable=False, server_default=text("''::character varying"))
116 distance_to_major_road_year2020 = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
117 mean_stable_nightlights_1km_year2013 = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
118 mean_stable_nightlights_5km_year2013 = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
119 max_stable_nightlights_25km_year2013 = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
120 max_stable_nightlights_25km_year1992 = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
121 mean_population_density_250m_year2015 = Column(Integer, nullable=False, server_default=text("'-999.0'::numeric"))
122 mean_population_density_5km_year2015 = Column(Integer, nullable=False, server_default=text("'-999.0'::numeric"))
123 max_population_density_25km_year2015 = Column(Integer, nullable=False, server_default=text("'-999.0'::numeric"))
124 mean_population_density_250m_year1990 = Column(Integer, nullable=False, server_default=text("'-999.0'::numeric"))
125 mean_population_density_5km_year1990 = Column(Integer, nullable=False, server_default=text("'-999.0'::numeric"))
126 max_population_density_25km_year1990 = Column(Integer, nullable=False, server_default=text("'-999.0'::numeric"))
127 mean_nox_emissions_10km_year2015 = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
128 mean_nox_emissions_10km_year2000 = Column(Float(53), nullable=False, server_default=text("'-999.0'::numeric"))
129 toar1_category = Column(ForeignKey('tc_vocabulary.enum_val'), nullable=False, server_default=text("'-1'::integer"))
130 toar2_category = Column(ForeignKey('ta_vocabulary.enum_val'), nullable=False, server_default=text("'0'::integer"))
131# do not use string declaration here (not working for pytest)
132# use the explicit class name here,
133# see: https://groups.google.com/forum/#!topic/sqlalchemy/YjGhE4d6K4U
134# station_id = Column(ForeignKey('stationmeta_core.id', deferrable=True, initially='DEFERRED'), nullable=False, unique=True)
135 station_id = Column(ForeignKey(StationmetaCore.id))
137 #uselist=False ==> 1:1 relationship
138# station = relationship('StationmetaCore', uselist=False)
139 station = relationship('StationmetaCore', back_populates='globalmeta')
141# cz_vocabulary = relationship('CzVocabulary')
142# lc_vocabulary = relationship('LcVocabulary')
143# er_vocabulary = relationship('ErVocabulary')
144# tr_vocabulary = relationship('TrVocabulary')
145# tc_vocabulary = relationship('TcVocabulary')