Skip to content

Commit

Permalink
format notebookns
Browse files Browse the repository at this point in the history
  • Loading branch information
pgzmnk committed Mar 29, 2024
1 parent 6503f93 commit b2daa73
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 56 deletions.
3 changes: 1 addition & 2 deletions docs/basics/out/http.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,10 @@
}
],
"source": [
"\n",
"!\\\n",
" export GEOJSON_ENCODED=$(printf '{\"type\": \"FeatureCollection\", \"features\": [{\"id\": \"0\", \"type\": \"Feature\", \"properties\": {\"x\": 11243, \"y\": 26163, \"z\": 16}, \"geometry\": {\"type\": \"Polygon\", \"coordinates\": [[[-118.23486328125, 34.075412438417395], [-118.23486328125, 34.070862323766306], [-118.2403564453125, 34.070862323766306], [-118.2403564453125, 34.075412438417395], [-118.23486328125, 34.075412438417395]]]}}]}' | jq --slurp --raw-input --raw-output @uri) && \\\n",
" echo $GEOJSON_ENCODED && \\\n",
" curl -L -XGET \"https://www.fused.io/server/v1/realtime-shared/55ffe996fc2bd635cde3beda7e2632005e228798a1ef333297240b86af7d12a4/run/file?dtype_out_vector=geojson&bbox=${GEOJSON_ENCODED}\"\n"
" curl -L -XGET \"https://www.fused.io/server/v1/realtime-shared/55ffe996fc2bd635cde3beda7e2632005e228798a1ef333297240b86af7d12a4/run/file?dtype_out_vector=geojson&bbox=${GEOJSON_ENCODED}\""
]
},
{
Expand Down
2 changes: 0 additions & 2 deletions docs/basics/out/http/Http.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,10 @@ The following example shows how to encode a GeoJSON with `jq` to ensure that the
remains valid.

```python

!\
export GEOJSON_ENCODED=$(printf '{"type": "FeatureCollection", "features": [{"id": "0", "type": "Feature", "properties": {"x": 11243, "y": 26163, "z": 16}, "geometry": {"type": "Polygon", "coordinates": [[[-118.23486328125, 34.075412438417395], [-118.23486328125, 34.070862323766306], [-118.2403564453125, 34.070862323766306], [-118.2403564453125, 34.075412438417395], [-118.23486328125, 34.075412438417395]]]}}]}' | jq --slurp --raw-input --raw-output @uri) && \
echo $GEOJSON_ENCODED && \
curl -L -XGET "https://www.fused.io/server/v1/realtime-shared/55ffe996fc2bd635cde3beda7e2632005e228798a1ef333297240b86af7d12a4/run/file?dtype_out_vector=geojson&bbox=${GEOJSON_ENCODED}"

```

<CellOutput>
Expand Down
17 changes: 11 additions & 6 deletions docs/basics/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@
"source": [
"import fused\n",
"\n",
"\n",
"@fused.udf\n",
"def udf():\n",
" return 42\n",
"\n",
"fused.run(udf, engine='local')"
"\n",
"fused.run(udf, engine=\"local\")"
]
},
{
Expand Down Expand Up @@ -500,8 +502,8 @@
"\n",
" # Calculate convex hull\n",
" gdf[\"convex_hull\"] = gdf.convex_hull\n",
" \n",
" return gdf[['GEOID', 'area', 'centroid', 'buffered', 'convex_hull']].head()\n",
"\n",
" return gdf[[\"GEOID\", \"area\", \"centroid\", \"buffered\", \"convex_hull\"]].head()\n",
"\n",
"\n",
"gdf = fused.run(udf=udf, engine=\"local\")\n",
Expand Down Expand Up @@ -535,7 +537,7 @@
}
],
"source": [
"gdf.buffered.plot()\n"
"gdf.buffered.plot()"
]
},
{
Expand Down Expand Up @@ -628,13 +630,16 @@
"source": [
"@fused.udf\n",
"def udf(bbox):\n",
" table_path=\"s3://fused-asset/infra/building_msft_us\"\n",
" utils = fused.load(\"https://github.com/fusedio/udfs/tree/f928ee1/public/common/\").utils\n",
" table_path = \"s3://fused-asset/infra/building_msft_us\"\n",
" utils = fused.load(\n",
" \"https://github.com/fusedio/udfs/tree/f928ee1/public/common/\"\n",
" ).utils\n",
" gdf = utils.table_to_tile(bbox, table=table_path)\n",
"\n",
" # Calculate buffer\n",
" return gdf.buffer(0.0001)\n",
"\n",
"\n",
"gdf = fused.run(udf=udf, x=9648, y=12320, z=15, engine=\"realtime\")\n",
"gdf.head()"
]
Expand Down
38 changes: 20 additions & 18 deletions docs/basics/transform/raster.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -445,49 +445,51 @@
"source": [
"import fused\n",
"\n",
"\n",
"@fused.udf\n",
"def udf(bbox: fused.types.Bbox=None, var = \"DEM\"):\n",
"def udf(bbox: fused.types.Bbox = None, var=\"DEM\"):\n",
" import geopandas as gpd\n",
" import numpy as np\n",
"\n",
" # Utility functions\n",
" utils = fused.load(\n",
" \"https://github.com/fusedio/udfs/tree/main/public/common/\"\n",
" ).utils\n",
" utils = fused.load(\"https://github.com/fusedio/udfs/tree/main/public/common/\").utils\n",
"\n",
" # Fetch USGS datasets\n",
" matching_items = utils.bbox_stac_items(bbox, table='s3://fused-asset/dem/usgs30m/')\n",
" matching_items = utils.bbox_stac_items(bbox, table=\"s3://fused-asset/dem/usgs30m/\")\n",
"\n",
" # GeoDataFrame of Tile\n",
" tile_bbox_gdf = gpd.GeoDataFrame({'geometry': [bbox]}, crs='EPSG:4326')\n",
" tile_bbox_gdf = gpd.GeoDataFrame({\"geometry\": [bbox]}, crs=\"EPSG:4326\")\n",
"\n",
" # Load tiff data\n",
" a=[]\n",
" a = []\n",
" for i in range(len(matching_items)):\n",
" input_tiff_path = matching_items.iloc[i].assets['data']['href']\n",
" a.append(utils.read_tiff(tile_bbox_gdf, input_tiff_path, 0, output_shape=(256,256)))\n",
" if len(a)==1:\n",
" data=a[0]\n",
" input_tiff_path = matching_items.iloc[i].assets[\"data\"][\"href\"]\n",
" a.append(\n",
" utils.read_tiff(tile_bbox_gdf, input_tiff_path, 0, output_shape=(256, 256))\n",
" )\n",
" if len(a) == 1:\n",
" data = a[0]\n",
" else:\n",
" data = np.maximum.reduce(a)[0]\n",
"\n",
" if var=='DEM':\n",
" if var == \"DEM\":\n",
" # Calculate DEM\n",
" data[data<0]=0\n",
" data =np.sqrt(data)\n",
" data = (data*8).astype('uint8')\n",
" data[data < 0] = 0\n",
" data = np.sqrt(data)\n",
" data = (data * 8).astype(\"uint8\")\n",
" return utils.arr_to_plasma(data)\n",
"\n",
" elif var=='SLOPE':\n",
" elif var == \"SLOPE\":\n",
" # Calculate Slope\n",
" slope_x, slope_y = np.gradient(data)\n",
" data = np.sqrt(slope_x**2 + slope_y**2)\n",
" data = (data*10).astype('uint8')\n",
" data = (data * 10).astype(\"uint8\")\n",
" return utils.arr_to_plasma(data)\n",
"\n",
" return utils.arr_to_plasma(data)\n",
"\n",
"arr = fused.run(udf=udf, x= 6073, y=3435, z=13, engine=\"realtime\")\n",
"\n",
"arr = fused.run(udf=udf, x=6073, y=3435, z=13, engine=\"realtime\")\n",
"arr"
]
},
Expand Down
38 changes: 20 additions & 18 deletions docs/basics/transform/raster/Raster.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -31,49 +31,51 @@ This sample UDF calculates Digital Elevation and slope from tiffs loaded from th
```python
import fused


@fused.udf
def udf(bbox: fused.types.Bbox=None, var = "DEM"):
def udf(bbox: fused.types.Bbox = None, var="DEM"):
import geopandas as gpd
import numpy as np

# Utility functions
utils = fused.load(
"https://github.com/fusedio/udfs/tree/main/public/common/"
).utils
utils = fused.load("https://github.com/fusedio/udfs/tree/main/public/common/").utils

# Fetch USGS datasets
matching_items = utils.bbox_stac_items(bbox, table='s3://fused-asset/dem/usgs30m/')
matching_items = utils.bbox_stac_items(bbox, table="s3://fused-asset/dem/usgs30m/")

# GeoDataFrame of Tile
tile_bbox_gdf = gpd.GeoDataFrame({'geometry': [bbox]}, crs='EPSG:4326')
tile_bbox_gdf = gpd.GeoDataFrame({"geometry": [bbox]}, crs="EPSG:4326")

# Load tiff data
a=[]
a = []
for i in range(len(matching_items)):
input_tiff_path = matching_items.iloc[i].assets['data']['href']
a.append(utils.read_tiff(tile_bbox_gdf, input_tiff_path, 0, output_shape=(256,256)))
if len(a)==1:
data=a[0]
input_tiff_path = matching_items.iloc[i].assets["data"]["href"]
a.append(
utils.read_tiff(tile_bbox_gdf, input_tiff_path, 0, output_shape=(256, 256))
)
if len(a) == 1:
data = a[0]
else:
data = np.maximum.reduce(a)[0]

if var=='DEM':
if var == "DEM":
# Calculate DEM
data[data<0]=0
data =np.sqrt(data)
data = (data*8).astype('uint8')
data[data < 0] = 0
data = np.sqrt(data)
data = (data * 8).astype("uint8")
return utils.arr_to_plasma(data)

elif var=='SLOPE':
elif var == "SLOPE":
# Calculate Slope
slope_x, slope_y = np.gradient(data)
data = np.sqrt(slope_x**2 + slope_y**2)
data = (data*10).astype('uint8')
data = (data * 10).astype("uint8")
return utils.arr_to_plasma(data)

return utils.arr_to_plasma(data)

arr = fused.run(udf=udf, x= 6073, y=3435, z=13, engine="realtime")

arr = fused.run(udf=udf, x=6073, y=3435, z=13, engine="realtime")
arr
```

Expand Down
29 changes: 24 additions & 5 deletions docs/basics/transform/vector.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,41 @@
"def udf(bbox):\n",
" import fused\n",
"\n",
" utils = fused.load(\"https://github.com/fusedio/udfs/tree/f928ee1/public/common/\").utils\n",
" utils = fused.load(\n",
" \"https://github.com/fusedio/udfs/tree/f928ee1/public/common/\"\n",
" ).utils\n",
"\n",
" # Load Census Block Group (CBG) table\n",
" table_path_cbg = \"s3://fused-asset/infra/census_block_us/\"\n",
" gdf_cbg=utils.table_to_tile(bbox, table=table_path_cbg, use_columns=['STATEFP20', 'COUNTYFP20', 'TRACTCE20', 'BLOCKCE20', 'GEOID20', 'NAME20','geometry']) \n",
" gdf_cbg = utils.table_to_tile(\n",
" bbox,\n",
" table=table_path_cbg,\n",
" use_columns=[\n",
" \"STATEFP20\",\n",
" \"COUNTYFP20\",\n",
" \"TRACTCE20\",\n",
" \"BLOCKCE20\",\n",
" \"GEOID20\",\n",
" \"NAME20\",\n",
" \"geometry\",\n",
" ],\n",
" )\n",
"\n",
" # Load Buildings (BLD) table\n",
" table_path_bld=\"s3://fused-asset/infra/building_msft_us\" \n",
" gdf_bld=utils.table_to_tile(bbox, table=table_path_bld, use_columns=['release', 'capture_dates_range', 'geometry']) \n",
" table_path_bld = \"s3://fused-asset/infra/building_msft_us\"\n",
" gdf_bld = utils.table_to_tile(\n",
" bbox,\n",
" table=table_path_bld,\n",
" use_columns=[\"release\", \"capture_dates_range\", \"geometry\"],\n",
" )\n",
"\n",
" # Spatial JOIN between CBG with BLD\n",
" # Determine CBG of each buildings\n",
" gdf_joined = gdf_bld.sjoin(gdf_cbg, how='left', predicate='intersects')\n",
" gdf_joined = gdf_bld.sjoin(gdf_cbg, how=\"left\", predicate=\"intersects\")\n",
"\n",
" return gdf_joined\n",
"\n",
"\n",
"gdf = fused.run(udf=udf, x=5239, y=12664, z=15, engine=\"realtime\")\n",
"gdf.head()"
]
Expand Down
29 changes: 24 additions & 5 deletions docs/basics/transform/vector/Vector.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,41 @@ import fused
def udf(bbox):
import fused

utils = fused.load("https://github.com/fusedio/udfs/tree/f928ee1/public/common/").utils
utils = fused.load(
"https://github.com/fusedio/udfs/tree/f928ee1/public/common/"
).utils

# Load Census Block Group (CBG) table
table_path_cbg = "s3://fused-asset/infra/census_block_us/"
gdf_cbg=utils.table_to_tile(bbox, table=table_path_cbg, use_columns=['STATEFP20', 'COUNTYFP20', 'TRACTCE20', 'BLOCKCE20', 'GEOID20', 'NAME20','geometry'])
gdf_cbg = utils.table_to_tile(
bbox,
table=table_path_cbg,
use_columns=[
"STATEFP20",
"COUNTYFP20",
"TRACTCE20",
"BLOCKCE20",
"GEOID20",
"NAME20",
"geometry",
],
)

# Load Buildings (BLD) table
table_path_bld="s3://fused-asset/infra/building_msft_us"
gdf_bld=utils.table_to_tile(bbox, table=table_path_bld, use_columns=['release', 'capture_dates_range', 'geometry'])
table_path_bld = "s3://fused-asset/infra/building_msft_us"
gdf_bld = utils.table_to_tile(
bbox,
table=table_path_bld,
use_columns=["release", "capture_dates_range", "geometry"],
)

# Spatial JOIN between CBG with BLD
# Determine CBG of each buildings
gdf_joined = gdf_bld.sjoin(gdf_cbg, how='left', predicate='intersects')
gdf_joined = gdf_bld.sjoin(gdf_cbg, how="left", predicate="intersects")

return gdf_joined


gdf = fused.run(udf=udf, x=5239, y=12664, z=15, engine="realtime")
gdf.head()
```
Expand Down

0 comments on commit b2daa73

Please sign in to comment.