From b2daa734157dbcb892529aa02f1fa8fa1219f708 Mon Sep 17 00:00:00 2001 From: pgzmnk Date: Fri, 29 Mar 2024 13:23:23 -0600 Subject: [PATCH] format notebookns --- docs/basics/out/http.ipynb | 3 +- docs/basics/out/http/Http.mdx | 2 -- docs/basics/quickstart.ipynb | 17 +++++++---- docs/basics/transform/raster.ipynb | 38 +++++++++++++------------ docs/basics/transform/raster/Raster.mdx | 38 +++++++++++++------------ docs/basics/transform/vector.ipynb | 29 +++++++++++++++---- docs/basics/transform/vector/Vector.mdx | 29 +++++++++++++++---- 7 files changed, 100 insertions(+), 56 deletions(-) diff --git a/docs/basics/out/http.ipynb b/docs/basics/out/http.ipynb index e8264d51..2b24e1d4 100644 --- a/docs/basics/out/http.ipynb +++ b/docs/basics/out/http.ipynb @@ -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}\"" ] }, { diff --git a/docs/basics/out/http/Http.mdx b/docs/basics/out/http/Http.mdx index d1b9b1dc..5c279ea0 100644 --- a/docs/basics/out/http/Http.mdx +++ b/docs/basics/out/http/Http.mdx @@ -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}" - ``` diff --git a/docs/basics/quickstart.ipynb b/docs/basics/quickstart.ipynb index e8722581..ea242012 100644 --- a/docs/basics/quickstart.ipynb +++ b/docs/basics/quickstart.ipynb @@ -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\")" ] }, { @@ -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", @@ -535,7 +537,7 @@ } ], "source": [ - "gdf.buffered.plot()\n" + "gdf.buffered.plot()" ] }, { @@ -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()" ] diff --git a/docs/basics/transform/raster.ipynb b/docs/basics/transform/raster.ipynb index 9780364a..6af1bf70 100644 --- a/docs/basics/transform/raster.ipynb +++ b/docs/basics/transform/raster.ipynb @@ -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" ] }, diff --git a/docs/basics/transform/raster/Raster.mdx b/docs/basics/transform/raster/Raster.mdx index 74e1ba06..02b8b5b3 100644 --- a/docs/basics/transform/raster/Raster.mdx +++ b/docs/basics/transform/raster/Raster.mdx @@ -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 ``` diff --git a/docs/basics/transform/vector.ipynb b/docs/basics/transform/vector.ipynb index 294f4450..96ad854b 100644 --- a/docs/basics/transform/vector.ipynb +++ b/docs/basics/transform/vector.ipynb @@ -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()" ] diff --git a/docs/basics/transform/vector/Vector.mdx b/docs/basics/transform/vector/Vector.mdx index 2f5abe10..d30ac580 100644 --- a/docs/basics/transform/vector/Vector.mdx +++ b/docs/basics/transform/vector/Vector.mdx @@ -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() ```