Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Mar 25, 2024
1 parent bcd8215 commit 80c948c
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions docs/patch_level_cloud_cover.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
"epsg = items_L2A[0].properties[\"proj:epsg\"]\n",
"\n",
"# Convert point from lon/lat to UTM projection\n",
"poidf = gpd.GeoDataFrame(crs=\"OGC:CRS84\", \n",
"poidf = gpd.GeoDataFrame(crs=\"OGC:CRS84\",\n",
" geometry=[area_of_interest.centroid]).to_crs(epsg)\n",
"geom = poidf.iloc[0].geometry\n",
"\n",
Expand Down Expand Up @@ -217,13 +217,13 @@
" # Write tile to output dir, whilst dropping the SCL band in the process\n",
" for tile in stack_L2A.sel(band=[\"red\", \"green\", \"blue\"]):\n",
" date = str(tile.time.values)[:10]\n",
" \n",
"\n",
" name = \"{dir}/claytile_{date}.tif\".format(\n",
" dir=outdir,\n",
" date=date.replace(\"-\", \"\"),\n",
" )\n",
" tile.rio.to_raster(name, compress=\"deflate\")\n",
" \n",
"\n",
" with rasterio.open(name, \"r+\") as rst:\n",
" rst.update_tags(date=date)"
]
Expand Down Expand Up @@ -282,14 +282,14 @@
"transform = ds_chunked_L2A.attrs['transform']\n",
"crs = ds_chunked_L2A.attrs['crs']\n",
"\n",
"for x in range((ds_chunked_L2A.sizes['x'] // chunk_size['x'])): # + 1):\n",
" for y in range((ds_chunked_L2A.sizes['y'] // chunk_size['y'])): # + 1):\n",
"for x in range(ds_chunked_L2A.sizes['x'] // chunk_size['x']): # + 1):\n",
" for y in range(ds_chunked_L2A.sizes['y'] // chunk_size['y']): # + 1):\n",
" # Compute chunk coordinates\n",
" x_start = x * chunk_size['x']\n",
" y_start = y * chunk_size['y']\n",
" x_end = min(x_start + chunk_size['x'], ds_chunked_L2A.sizes['x'])\n",
" y_end = min(y_start + chunk_size['y'], ds_chunked_L2A.sizes['y'])\n",
" \n",
"\n",
" # Compute chunk geospatial bounds\n",
" lon_start, lat_start = transform * (x_start, y_start)\n",
" lon_end, lat_end = transform * (x_end, y_end)\n",
Expand All @@ -303,10 +303,10 @@
"\n",
" # Extract the subset of the SCL band\n",
" subset_scl = ds_chunked_L2A.sel(band=\"scl\")[:, y_start:y_end, x_start:x_end]\n",
" \n",
"\n",
" # Count the cloud pixels in the subset\n",
" cloud_pct = count_cloud_pixels(subset_scl, SCL_CLOUD_LABELS)\n",
" \n",
"\n",
" # Store the cloud percent for this chunk\n",
" cloud_pcts[(x, y)] = int(100 * (cloud_pct / 1024))\n",
"\n",
Expand Down Expand Up @@ -414,7 +414,7 @@
"outputs": [],
"source": [
"# remove date and lat/lon and reshape to disaggregated patches\n",
"embeddings_patch = embeddings[0][:, :-2, :].reshape([1,16,16,768]) "
"embeddings_patch = embeddings[0][:, :-2, :].reshape([1,16,16,768])"
]
},
{
Expand Down Expand Up @@ -490,20 +490,20 @@
" date = batch[\"date\"]\n",
" data = {\n",
" \"source_url\": batch[\"source_url\"][0],\n",
" \"date\": pd.to_datetime(arg=date, \n",
" \"date\": pd.to_datetime(arg=date,\n",
" format=\"%Y-%m-%d\").astype(dtype=\"date32[day][pyarrow]\"),\n",
" \"embeddings\": [numpy.ascontiguousarray(embeddings_output_patch)],\n",
" \"cloud_cover\": cloud_pct_[0][1]\n",
" }\n",
" \n",
"\n",
" # Define the bounding box as a Polygon (xmin, ymin, xmax, ymax)\n",
" # The box_ list is encoded as \n",
" # The box_ list is encoded as\n",
" # [bottom left x, bottom left y, top right x, top right y]\n",
" box_emb = shapely.geometry.box(box_[0], box_[1], box_[2], box_[3])\n",
" \n",
"\n",
" # Create the GeoDataFrame\n",
" gdf = gpd.GeoDataFrame(data, geometry=[box_emb], crs=f\"EPSG:{epsg}\")\n",
" \n",
"\n",
" # Reproject to WGS84 (lon/lat coordinates)\n",
" gdf = gdf.to_crs(epsg=4326)\n",
"\n",
Expand Down Expand Up @@ -554,7 +554,7 @@
" gdf[\"idx\"] = '_'.join(emb.split(\"/\")[-1].split(\"_\")[2:]).replace('.gpq', '')\n",
" gdf[\"box\"] = [box(*geom.bounds) for geom in gdf.geometry]\n",
" gdfs.append(gdf)\n",
" \n",
"\n",
" for _,row in gdf.iterrows():\n",
" data.append({\n",
" \"vector\": row[\"embeddings\"],\n",
Expand Down Expand Up @@ -612,7 +612,7 @@
"epsg = items_L2A[0].properties[\"proj:epsg\"]\n",
"\n",
"# Convert point from lon/lat to UTM projection\n",
"box_embedding = gpd.GeoDataFrame(crs=\"OGC:CRS84\", \n",
"box_embedding = gpd.GeoDataFrame(crs=\"OGC:CRS84\",\n",
" geometry=[area_of_interest_embedding]).to_crs(epsg)\n",
"geom_embedding = box_embedding.iloc[0].geometry\n",
"\n",
Expand Down Expand Up @@ -823,23 +823,23 @@
" for row in range(0, height, window_size[1]):\n",
" # Define the window\n",
" window = ((row, row + window_size[1]), (col, col + window_size[0]))\n",
" \n",
"\n",
" # Read the data within the window\n",
" data = chip.read(window=window)\n",
" \n",
"\n",
" # Get the index of the window\n",
" index = (col // window_size[0], row // window_size[1])\n",
" \n",
"\n",
" # Process the window data here\n",
" # For example, print the index and the shape of the window data\n",
" #print(\"Index:\", index)\n",
" #print(\"Window Shape:\", data.shape)\n",
"\n",
" idxs_windows['idx'].append('_'.join(map(str, index)))\n",
" idxs_windows['window'].append(data)\n",
" \n",
"\n",
" #print(idxs_windows)\n",
" \n",
"\n",
" for ax, (_, row) in zip(axs.flatten(), df.iterrows()):\n",
" idx = row[\"idx\"]\n",
" # Find the corresponding window based on the idx\n",
Expand Down Expand Up @@ -908,13 +908,13 @@
"# Make geodataframe of the search results\n",
"# cloudy\n",
"result_cloudy_boxes = [\n",
" Polygon([(bbox[0], bbox[1]), (bbox[2], bbox[1]), (bbox[2], bbox[3]), (bbox[0], bbox[3])]) \n",
" Polygon([(bbox[0], bbox[1]), (bbox[2], bbox[1]), (bbox[2], bbox[3]), (bbox[0], bbox[3])])\n",
" for bbox in result_cloudy['box']]\n",
"result_cloudy_gdf = gpd.GeoDataFrame(result_cloudy, geometry=result_cloudy_boxes)\n",
"result_cloudy_gdf.crs = \"EPSG:4326\"\n",
"# non-cloudy\n",
"result_non_cloudy_boxes = [\n",
" Polygon([(bbox[0], bbox[1]), (bbox[2], bbox[1]), (bbox[2], bbox[3]), (bbox[0], bbox[3])]) \n",
" Polygon([(bbox[0], bbox[1]), (bbox[2], bbox[1]), (bbox[2], bbox[3]), (bbox[0], bbox[3])])\n",
" for bbox in result_non_cloudy['box']]\n",
"result_non_cloudy_gdf = gpd.GeoDataFrame(\n",
" result_non_cloudy, geometry=result_non_cloudy_boxes)\n",
Expand Down

0 comments on commit 80c948c

Please sign in to comment.