move path into config
Browse files
climateqa/engine/talk_to_data/config.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Path configuration for climateqa project
|
2 |
+
|
3 |
+
# IPCC dataset path
|
4 |
+
IPCC_DATASET_URL = "hf://datasets/ekimetrics/ipcc-atlas"
|
5 |
+
|
6 |
+
# DRIAS dataset paths
|
7 |
+
DRIAS_DATASET_URL = "hf://datasets/timeki/drias_db"
|
8 |
+
|
9 |
+
# Table paths
|
10 |
+
DRIAS_MEAN_ANNUAL_TEMPERATURE_PATH = f"{DRIAS_DATASET_URL}/mean_annual_temperature.parquet"
|
11 |
+
IPCC_COORDINATES_PATH = f"{IPCC_DATASET_URL}/coordinates.parquet"
|
climateqa/engine/talk_to_data/drias/queries.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from typing import TypedDict
|
|
|
2 |
|
3 |
class IndicatorPerYearAtLocationQueryParams(TypedDict, total=False):
|
4 |
"""Parameters for querying an indicator's values over time at a location.
|
@@ -36,7 +37,7 @@ def indicator_per_year_at_location_query(
|
|
36 |
if indicator_column is None or latitude is None or longitude is None: # If one parameter is missing, returns an empty query
|
37 |
return ""
|
38 |
|
39 |
-
table = f"'
|
40 |
|
41 |
sql_query = f"SELECT year, {indicator_column}, model\nFROM {table}\nWHERE latitude = {latitude} \nAnd longitude = {longitude} \nOrder by Year"
|
42 |
|
@@ -76,7 +77,7 @@ def indicator_for_given_year_query(
|
|
76 |
if year is None or indicator_column is None: # If one parameter is missing, returns an empty query
|
77 |
return ""
|
78 |
|
79 |
-
table = f"'
|
80 |
|
81 |
sql_query = f"Select {indicator_column}, latitude, longitude, model\nFrom {table}\nWhere year = {year}"
|
82 |
return sql_query
|
|
|
1 |
from typing import TypedDict
|
2 |
+
from climateqa.engine.talk_to_data.config import DRIAS_DATASET_URL
|
3 |
|
4 |
class IndicatorPerYearAtLocationQueryParams(TypedDict, total=False):
|
5 |
"""Parameters for querying an indicator's values over time at a location.
|
|
|
37 |
if indicator_column is None or latitude is None or longitude is None: # If one parameter is missing, returns an empty query
|
38 |
return ""
|
39 |
|
40 |
+
table = f"'{DRIAS_DATASET_URL}/{table.lower()}.parquet'"
|
41 |
|
42 |
sql_query = f"SELECT year, {indicator_column}, model\nFROM {table}\nWHERE latitude = {latitude} \nAnd longitude = {longitude} \nOrder by Year"
|
43 |
|
|
|
77 |
if year is None or indicator_column is None: # If one parameter is missing, returns an empty query
|
78 |
return ""
|
79 |
|
80 |
+
table = f"'{DRIAS_DATASET_URL}/{table.lower()}.parquet'"
|
81 |
|
82 |
sql_query = f"Select {indicator_column}, latitude, longitude, model\nFrom {table}\nWhere year = {year}"
|
83 |
return sql_query
|
climateqa/engine/talk_to_data/input_processing.py
CHANGED
@@ -5,7 +5,7 @@ from geopy.geocoders import Nominatim
|
|
5 |
from climateqa.engine.llm import get_llm
|
6 |
import duckdb
|
7 |
import os
|
8 |
-
from climateqa.engine.talk_to_data.
|
9 |
from climateqa.engine.talk_to_data.objects.llm_outputs import ArrayOutput
|
10 |
from climateqa.engine.talk_to_data.objects.location import Location
|
11 |
from climateqa.engine.talk_to_data.objects.plot import Plot
|
@@ -78,12 +78,12 @@ def nearest_neighbour_sql(location: tuple, mode: Literal['DRIAS', 'IPCC']) -> tu
|
|
78 |
conn = duckdb.connect()
|
79 |
|
80 |
if mode == 'DRIAS':
|
81 |
-
table_path = f"'
|
82 |
results = conn.sql(
|
83 |
f"SELECT latitude, longitude FROM {table_path} WHERE latitude BETWEEN {lat - 0.3} AND {lat + 0.3} AND longitude BETWEEN {long - 0.3} AND {long + 0.3}"
|
84 |
).fetchdf()
|
85 |
else:
|
86 |
-
table_path = f"'{
|
87 |
results = conn.sql(
|
88 |
f"SELECT latitude, longitude, admin1 FROM {table_path} WHERE latitude BETWEEN {lat - 0.5} AND {lat + 0.5} AND longitude BETWEEN {long - 0.5} AND {long + 0.5}"
|
89 |
).fetchdf()
|
|
|
5 |
from climateqa.engine.llm import get_llm
|
6 |
import duckdb
|
7 |
import os
|
8 |
+
from climateqa.engine.talk_to_data.config import DRIAS_MEAN_ANNUAL_TEMPERATURE_PATH, IPCC_COORDINATES_PATH
|
9 |
from climateqa.engine.talk_to_data.objects.llm_outputs import ArrayOutput
|
10 |
from climateqa.engine.talk_to_data.objects.location import Location
|
11 |
from climateqa.engine.talk_to_data.objects.plot import Plot
|
|
|
78 |
conn = duckdb.connect()
|
79 |
|
80 |
if mode == 'DRIAS':
|
81 |
+
table_path = f"'{DRIAS_MEAN_ANNUAL_TEMPERATURE_PATH}'"
|
82 |
results = conn.sql(
|
83 |
f"SELECT latitude, longitude FROM {table_path} WHERE latitude BETWEEN {lat - 0.3} AND {lat + 0.3} AND longitude BETWEEN {long - 0.3} AND {long + 0.3}"
|
84 |
).fetchdf()
|
85 |
else:
|
86 |
+
table_path = f"'{IPCC_COORDINATES_PATH}'"
|
87 |
results = conn.sql(
|
88 |
f"SELECT latitude, longitude, admin1 FROM {table_path} WHERE latitude BETWEEN {lat - 0.5} AND {lat + 0.5} AND longitude BETWEEN {long - 0.5} AND {long + 0.5}"
|
89 |
).fetchdf()
|
climateqa/engine/talk_to_data/ipcc/config.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
from climateqa.engine.talk_to_data.ui_config import PRECIPITATION_COLORSCALE, TEMPERATURE_COLORSCALE
|
|
|
2 |
|
3 |
|
4 |
-
IPCC_DATASET_URL = "hf://datasets/ekimetrics/ipcc-atlas"
|
5 |
IPCC_TABLES = [
|
6 |
"mean_temperature",
|
7 |
"total_precipitation",
|
|
|
1 |
from climateqa.engine.talk_to_data.ui_config import PRECIPITATION_COLORSCALE, TEMPERATURE_COLORSCALE
|
2 |
+
from climateqa.engine.talk_to_data.config import IPCC_DATASET_URL
|
3 |
|
4 |
|
5 |
+
# IPCC_DATASET_URL = "hf://datasets/ekimetrics/ipcc-atlas"
|
6 |
IPCC_TABLES = [
|
7 |
"mean_temperature",
|
8 |
"total_precipitation",
|
climateqa/engine/talk_to_data/ipcc/queries.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
from typing import TypedDict, Optional
|
2 |
|
3 |
-
from climateqa.engine.talk_to_data.ipcc.config import HUGE_MACRO_COUNTRIES,
|
4 |
-
|
5 |
class IndicatorPerYearAtLocationQueryParams(TypedDict, total=False):
|
6 |
"""
|
7 |
Parameters for querying the evolution of an indicator per year at a specific location.
|
|
|
1 |
from typing import TypedDict, Optional
|
2 |
|
3 |
+
from climateqa.engine.talk_to_data.ipcc.config import HUGE_MACRO_COUNTRIES, MACRO_COUNTRIES
|
4 |
+
from climateqa.engine.talk_to_data.config import IPCC_DATASET_URL
|
5 |
class IndicatorPerYearAtLocationQueryParams(TypedDict, total=False):
|
6 |
"""
|
7 |
Parameters for querying the evolution of an indicator per year at a specific location.
|