Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/Basics_of_H3_in_Fused/collection.json

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions public/Basics_of_H3_in_Fused/copdem_elevation/README.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
<!--fused:preview-->
<p align="center"><img src="fused_uploaded_preview" width="600" alt="UDF preview image"></p>

<!--fused:readme-->
Reading H3 Ingested Copernicus 30m DEM dataset
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def udf(bounds: fused.types.Bounds = [-125, 32, -114, 42]):
# Run all months in parallel
pool = monthly_udf.map([{
'month': m,
'bounds': list(bounds)
'bounds': bounds
} for m in months])
df = pool.df()

Expand Down
2 changes: 1 addition & 1 deletion public/Basics_of_H3_in_Fused/era5_full_year/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"fused:udfType": "auto"
},
"code": "@fused.udf\ndef udf(bounds: fused.types.Bounds = [-125, 32, -114, 42]):\n import pandas as pd\n\n monthly_udf = fused.load('era5_temp_monthly_average')\n\n # All months from 2019 to 2024\n months = [f'{y}-{m:02d}' for y in range(2019, 2025) for m in range(1, 13)]\n\n # Run all months in parallel\n pool = monthly_udf.map([{\n 'month': m,\n 'bounds': list(bounds)\n } for m in months])\n df = pool.df()\n\n df = df.reset_index(drop=True).sort_values('date').reset_index(drop=True)\n\n print(f\"{df.shape=}\")\n print(df.head())\n\n return df",
"code": "@fused.udf\ndef udf(bounds: fused.types.Bounds = [-125, 32, -114, 42]):\n import pandas as pd\n\n monthly_udf = fused.load('era5_temp_monthly_average')\n\n # All months from 2019 to 2024\n months = [f'{y}-{m:02d}' for y in range(2019, 2025) for m in range(1, 13)]\n\n # Run all months in parallel\n pool = monthly_udf.map([{\n 'month': m,\n 'bounds': bounds\n } for m in months])\n df = pool.df()\n\n df = df.reset_index(drop=True).sort_values('date').reset_index(drop=True)\n\n print(f\"{df.shape=}\")\n print(df.head())\n\n return df",
"headers": []
}
}
Expand Down
4 changes: 1 addition & 3 deletions public/Basics_of_H3_in_Fused/era5_hex_temp/era5_hex_temp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
def udf():
map_utils = fused.load("https://github.com/fusedio/udfs/tree/3eb82cb/community/milind/map_utils/")

import h3
import geopandas as gpd
from shapely.geometry import Point

hex_data = fused.load("era5_monthly_mean")
data = hex_data()

# We can't visualize hex 15 hexagons, so turning to small points to visualixe
# We can't visualize hex 15 hexagons, so turning to small points to visualise
gdf = data.copy()
common = fused.load("https://github.com/fusedio/udfs/tree/9bad664/public/common/")
con = common.duckdb_connect()
Expand Down
2 changes: 1 addition & 1 deletion public/Basics_of_H3_in_Fused/era5_hex_temp/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"fused:udfType": "auto"
},
"code": "@fused.udf\ndef udf():\n map_utils = fused.load(\"https://github.com/fusedio/udfs/tree/3eb82cb/community/milind/map_utils/\")\n\n import h3\n import geopandas as gpd\n from shapely.geometry import Point\n\n hex_data = fused.load(\"era5_monthly_mean\")\n data = hex_data()\n\n # We can't visualize hex 15 hexagons, so turning to small points to visualixe\n gdf = data.copy()\n common = fused.load(\"https://github.com/fusedio/udfs/tree/9bad664/public/common/\")\n con = common.duckdb_connect()\n gdf = con.sql(\"\"\"\n SELECT *, \n h3_cell_to_latlng(CAST(hex AS UBIGINT)) AS latlng\n FROM gdf\n \"\"\").df()\n gdf['geometry'] = gpd.points_from_xy(\n gdf['latlng'].apply(lambda x: x[1]),\n gdf['latlng'].apply(lambda x: x[0])\n )\n gdf = gpd.GeoDataFrame(gdf.drop(columns=['latlng']), geometry='geometry', crs='EPSG:4326')\n \n print(f\"{data.T=}\")\n\n val_min = data['monthly_mean_temp'].min()\n val_max = data['monthly_mean_temp'].max()\n\n # Layer config for Census population data\n config_census = {\n \"style\": {\n \"fillColor\": {\n \"type\": \"continuous\",\n \"attr\": \"monthly_mean_temp\",\n \"domain\": [val_min, val_max],\n \"steps\": 20,\n \"palette\": \"DarkMint\",\n },\n \"filled\": True,\n \"stroked\": False,\n \"opacity\": 0.9,\n \"pointRadius\": 1,\n },\n \"tooltip\": [\"hex\", \"monthly_mean_temp\"],\n }\n\n widgets = {\n \"controls\": \"bottom-right\",\n \"scale\": \"bottom-left\",\n \"basemap\": \"bottom-right\",\n \"layers\": {\"position\": \"top-right\", \"expanded\": False},\n \"legend\": {\"position\": \"top-right\", \"expanded\": True},\n }\n\n html = map_utils.deckgl_layers(\n layers=[\n {\n \"type\": \"vector\",\n \"data\": gdf,\n \"config\": config_census,\n \"visible\": True,\n \"name\": \"Hex 15 Temperature\",\n }\n ],\n basemap=\"dark\",\n theme=\"dark\",\n initialViewState=None,\n widgets=widgets,\n \n )\n return html",
"code": "@fused.udf\ndef udf():\n map_utils = fused.load(\"https://github.com/fusedio/udfs/tree/3eb82cb/community/milind/map_utils/\")\n\n import geopandas as gpd\n\n hex_data = fused.load(\"era5_monthly_mean\")\n data = hex_data()\n\n # We can't visualize hex 15 hexagons, so turning to small points to visualise\n gdf = data.copy()\n common = fused.load(\"https://github.com/fusedio/udfs/tree/9bad664/public/common/\")\n con = common.duckdb_connect()\n gdf = con.sql(\"\"\"\n SELECT *, \n h3_cell_to_latlng(CAST(hex AS UBIGINT)) AS latlng\n FROM gdf\n \"\"\").df()\n gdf['geometry'] = gpd.points_from_xy(\n gdf['latlng'].apply(lambda x: x[1]),\n gdf['latlng'].apply(lambda x: x[0])\n )\n gdf = gpd.GeoDataFrame(gdf.drop(columns=['latlng']), geometry='geometry', crs='EPSG:4326')\n \n print(f\"{data.T=}\")\n\n val_min = data['monthly_mean_temp'].min()\n val_max = data['monthly_mean_temp'].max()\n\n # Layer config for Census population data\n config_census = {\n \"style\": {\n \"fillColor\": {\n \"type\": \"continuous\",\n \"attr\": \"monthly_mean_temp\",\n \"domain\": [val_min, val_max],\n \"steps\": 20,\n \"palette\": \"DarkMint\",\n },\n \"filled\": True,\n \"stroked\": False,\n \"opacity\": 0.9,\n \"pointRadius\": 1,\n },\n \"tooltip\": [\"hex\", \"monthly_mean_temp\"],\n }\n\n widgets = {\n \"controls\": \"bottom-right\",\n \"scale\": \"bottom-left\",\n \"basemap\": \"bottom-right\",\n \"layers\": {\"position\": \"top-right\", \"expanded\": False},\n \"legend\": {\"position\": \"top-right\", \"expanded\": True},\n }\n\n html = map_utils.deckgl_layers(\n layers=[\n {\n \"type\": \"vector\",\n \"data\": gdf,\n \"config\": config_census,\n \"visible\": True,\n \"name\": \"Hex 15 Temperature\",\n }\n ],\n basemap=\"dark\",\n theme=\"dark\",\n initialViewState=None,\n widgets=widgets,\n \n )\n return html",
"headers": []
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@fused.udf
def udf(month='2024-05',
bounds:list=[-130, 25, -60, 50]
bounds:fused.types.Bounds=[-130, 25, -60, 50]
):
path = f's3://fused-asset/data/era5/t2m_daily_mean_v4_1000/month={month}/0.parquet'

Expand Down
2 changes: 1 addition & 1 deletion public/Basics_of_H3_in_Fused/era5_monthly_mean/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
},
"fused:udfType": "auto"
},
"code": "@fused.udf\ndef udf(month='2024-05',\n bounds:list=[-130, 25, -60, 50]\n):\n path = f's3://fused-asset/data/era5/t2m_daily_mean_v4_1000/month={month}/0.parquet'\n \n common = fused.load(\"https://github.com/fusedio/udfs/tree/56ec615/public/common/\")\n con = common.duckdb_connect() \n\n query = f\"\"\"\n SELECT \n hex, \n avg(daily_mean) - 273.15 as monthly_mean_temp\n FROM read_parquet('{path}')\n WHERE 1=1\n AND h3_cell_to_lng(hex) between {bounds[0]} and {bounds[2]} \n AND h3_cell_to_lat(hex) between {bounds[1]} and {bounds[3]} \n GROUP BY 1\n \"\"\" \n\n data = con.execute(query).df()\n\n print(f\"{data.T=}\")\n\n return data",
"code": "@fused.udf\ndef udf(month='2024-05',\n bounds:fused.types.Bounds=[-130, 25, -60, 50]\n):\n path = f's3://fused-asset/data/era5/t2m_daily_mean_v4_1000/month={month}/0.parquet'\n \n common = fused.load(\"https://github.com/fusedio/udfs/tree/56ec615/public/common/\")\n con = common.duckdb_connect() \n\n query = f\"\"\"\n SELECT \n hex, \n avg(daily_mean) - 273.15 as monthly_mean_temp\n FROM read_parquet('{path}')\n WHERE 1=1\n AND h3_cell_to_lng(hex) between {bounds[0]} and {bounds[2]} \n AND h3_cell_to_lat(hex) between {bounds[1]} and {bounds[3]} \n GROUP BY 1\n \"\"\" \n\n data = con.execute(query).df()\n\n print(f\"{data.T=}\")\n\n return data",
"headers": []
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@fused.udf(cache_max_age=0)
def udf(bounds:list=[-130,-50,-35,50]):
def udf(bounds:fused.types.Bounds=[-130,-50,-35,50]):
map_utils = fused.load("https://github.com/fusedio/udfs/tree/5c526cc/community/milind/map_utils/")

era5_udf = fused.load("era5_temp_month_hex4")
Expand Down
2 changes: 1 addition & 1 deletion public/Basics_of_H3_in_Fused/era5_temp_map_hex4/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"fused:udfType": "auto"
},
"code": "@fused.udf(cache_max_age=0)\ndef udf(bounds:list=[-130,-50,-35,50]):\n map_utils = fused.load(\"https://github.com/fusedio/udfs/tree/5c526cc/community/milind/map_utils/\")\n\n era5_udf = fused.load(\"era5_temp_month_hex4\")\n data = era5_udf(month='2025-03', hex_res=4)\n \n val_min = float(data[\"monthly_mean_temp\"].min())\n val_max = float(data[\"monthly_mean_temp\"].max())\n\n # Layer config for Census population data\n config_census = {\n \"style\": {\n \"fillColor\": {\n \"type\": \"continuous\",\n \"attr\": \"monthly_mean_temp\",\n \"domain\": [val_min, val_max],\n \"steps\": 20,\n \"palette\": \"DarkMint\",\n },\n \"filled\": True,\n \"stroked\": False,\n \"opacity\": 0.9,\n },\n \"tooltip\": [\"hex\", \"monthly_mean_temp\"],\n }\n\n widgets = {\n \"controls\": \"bottom-right\",\n \"scale\": \"bottom-left\",\n \"basemap\": \"bottom-right\",\n \"layers\": {\"position\": \"top-right\", \"expanded\": False},\n \"legend\": {\"position\": \"top-right\", \"expanded\": True},\n }\n\n html = map_utils.deckgl_layers(\n layers=[\n {\n \"type\": \"hex\",\n \"data\": data,\n \"config\": config_census,\n \"visible\": True,\n \"name\": \"Hex 4 Temperature\",\n }\n ],\n basemap=\"dark\",\n theme=\"dark\",\n initialViewState=None,\n widgets=widgets,\n debug=False,\n )\n return html",
"code": "@fused.udf(cache_max_age=0)\ndef udf(bounds:fused.types.Bounds=[-130,-50,-35,50]):\n map_utils = fused.load(\"https://github.com/fusedio/udfs/tree/5c526cc/community/milind/map_utils/\")\n\n era5_udf = fused.load(\"era5_temp_month_hex4\")\n data = era5_udf(month='2025-03', hex_res=4)\n \n val_min = float(data[\"monthly_mean_temp\"].min())\n val_max = float(data[\"monthly_mean_temp\"].max())\n\n # Layer config for Census population data\n config_census = {\n \"style\": {\n \"fillColor\": {\n \"type\": \"continuous\",\n \"attr\": \"monthly_mean_temp\",\n \"domain\": [val_min, val_max],\n \"steps\": 20,\n \"palette\": \"DarkMint\",\n },\n \"filled\": True,\n \"stroked\": False,\n \"opacity\": 0.9,\n },\n \"tooltip\": [\"hex\", \"monthly_mean_temp\"],\n }\n\n widgets = {\n \"controls\": \"bottom-right\",\n \"scale\": \"bottom-left\",\n \"basemap\": \"bottom-right\",\n \"layers\": {\"position\": \"top-right\", \"expanded\": False},\n \"legend\": {\"position\": \"top-right\", \"expanded\": True},\n }\n\n html = map_utils.deckgl_layers(\n layers=[\n {\n \"type\": \"hex\",\n \"data\": data,\n \"config\": config_census,\n \"visible\": True,\n \"name\": \"Hex 4 Temperature\",\n }\n ],\n basemap=\"dark\",\n theme=\"dark\",\n initialViewState=None,\n widgets=widgets,\n debug=False,\n )\n return html",
"headers": []
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@fused.udf(cache_max_age=0)
def udf(bounds:list=[-130,-50,-35,50]):
def udf(bounds:fused.types.Bounds=[-130,-50,-35,50]):
map_utils = fused.load("https://github.com/fusedio/udfs/tree/5c526cc/community/milind/map_utils/")

era5_udf = fused.load("era5_temp_month_hex4")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"fused:udfType": "auto"
},
"code": "@fused.udf(cache_max_age=0)\ndef udf(bounds:list=[-130,-50,-35,50]):\n map_utils = fused.load(\"https://github.com/fusedio/udfs/tree/5c526cc/community/milind/map_utils/\")\n\n era5_udf = fused.load(\"era5_temp_month_hex4\")\n data = era5_udf(month='2025-03', hex_res=2)\n \n val_min = float(data[\"monthly_mean_temp\"].min())\n val_max = float(data[\"monthly_mean_temp\"].max())\n\n # Layer config for Census population data\n config_census = {\n \"style\": {\n \"fillColor\": {\n \"type\": \"continuous\",\n \"attr\": \"monthly_mean_temp\",\n \"domain\": [val_min, val_max],\n \"steps\": 20,\n \"palette\": \"DarkMint\",\n },\n \"filled\": True,\n \"stroked\": False,\n \"opacity\": 0.9,\n },\n \"tooltip\": [\"hex\", \"monthly_mean_temp\"],\n }\n\n widgets = {\n \"controls\": \"bottom-right\",\n \"scale\": \"bottom-left\",\n \"basemap\": \"bottom-right\",\n \"layers\": {\"position\": \"top-right\", \"expanded\": False},\n \"legend\": {\"position\": \"top-right\", \"expanded\": True},\n }\n\n html = map_utils.deckgl_layers(\n layers=[\n {\n \"type\": \"hex\",\n \"data\": data,\n \"config\": config_census,\n \"visible\": True,\n \"name\": \"Hex 4 Temperature\",\n }\n ],\n basemap=\"dark\",\n theme=\"dark\",\n initialViewState=None,\n widgets=widgets,\n debug=False,\n )\n return html",
"code": "@fused.udf(cache_max_age=0)\ndef udf(bounds:fused.types.Bounds=[-130,-50,-35,50]):\n map_utils = fused.load(\"https://github.com/fusedio/udfs/tree/5c526cc/community/milind/map_utils/\")\n\n era5_udf = fused.load(\"era5_temp_month_hex4\")\n data = era5_udf(month='2025-03', hex_res=2)\n \n val_min = float(data[\"monthly_mean_temp\"].min())\n val_max = float(data[\"monthly_mean_temp\"].max())\n\n # Layer config for Census population data\n config_census = {\n \"style\": {\n \"fillColor\": {\n \"type\": \"continuous\",\n \"attr\": \"monthly_mean_temp\",\n \"domain\": [val_min, val_max],\n \"steps\": 20,\n \"palette\": \"DarkMint\",\n },\n \"filled\": True,\n \"stroked\": False,\n \"opacity\": 0.9,\n },\n \"tooltip\": [\"hex\", \"monthly_mean_temp\"],\n }\n\n widgets = {\n \"controls\": \"bottom-right\",\n \"scale\": \"bottom-left\",\n \"basemap\": \"bottom-right\",\n \"layers\": {\"position\": \"top-right\", \"expanded\": False},\n \"legend\": {\"position\": \"top-right\", \"expanded\": True},\n }\n\n html = map_utils.deckgl_layers(\n layers=[\n {\n \"type\": \"hex\",\n \"data\": data,\n \"config\": config_census,\n \"visible\": True,\n \"name\": \"Hex 4 Temperature\",\n }\n ],\n basemap=\"dark\",\n theme=\"dark\",\n initialViewState=None,\n widgets=widgets,\n debug=False,\n )\n return html",
"headers": []
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@fused.udf
def udf(month='2024-05',
bounds:list=[-130, 25, -60, 50],
bounds:fused.types.Bounds=[-130, 25, -60, 50],
hex_res: int = 4
):
path = f's3://fused-asset/data/era5/t2m_daily_mean_v4_1000/month={month}/0.parquet'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"fused:udfType": "auto"
},
"code": "@fused.udf\ndef udf(month='2024-05',\n bounds:list=[-130, 25, -60, 50],\n hex_res: int = 4\n):\n path = f's3://fused-asset/data/era5/t2m_daily_mean_v4_1000/month={month}/0.parquet'\n\n # This loads DuckDB with the spatial & H3 extensions directly\n common = fused.load(\"https://github.com/fusedio/udfs/tree/56ec615/public/common/\")\n con = common.duckdb_connect() \n\n query = f\"\"\"\n SELECT \n h3_cell_to_parent(hex, {hex_res}) as hex,\n round(avg(daily_mean) - 273.15, 2) as monthly_mean_temp\n FROM read_parquet('{path}')\n WHERE 1=1\n AND h3_cell_to_lng(hex) between {bounds[0]} and {bounds[2]}\n AND h3_cell_to_lat(hex) between {bounds[1]} and {bounds[3]} \n GROUP BY 1\n \"\"\" \n\n data = con.execute(query).df()\n\n print(f\"{data.T=}\")\n\n return data\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n ",
"code": "@fused.udf\ndef udf(month='2024-05',\n bounds:fused.types.Bounds=[-130, 25, -60, 50],\n hex_res: int = 4\n):\n path = f's3://fused-asset/data/era5/t2m_daily_mean_v4_1000/month={month}/0.parquet'\n\n # This loads DuckDB with the spatial & H3 extensions directly\n common = fused.load(\"https://github.com/fusedio/udfs/tree/56ec615/public/common/\")\n con = common.duckdb_connect() \n\n query = f\"\"\"\n SELECT \n h3_cell_to_parent(hex, {hex_res}) as hex,\n round(avg(daily_mean) - 273.15, 2) as monthly_mean_temp\n FROM read_parquet('{path}')\n WHERE 1=1\n AND h3_cell_to_lng(hex) between {bounds[0]} and {bounds[2]}\n AND h3_cell_to_lat(hex) between {bounds[1]} and {bounds[3]} \n GROUP BY 1\n \"\"\" \n\n data = con.execute(query).df()\n\n print(f\"{data.T=}\")\n\n return data\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n ",
"headers": []
}
}
Expand Down
Loading
Loading