{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Prepare lake bounds shapefile\n", "---\n", "### This notebook writes a shapefile to use to create a mask around Lake Mead\n", "\n", "We will use this shapefile to create a mask with the time slider and other visualizations in this repository." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# notebook dependencies\n", "import geopandas as gpd\n", "import rasterio as rio\n", "import xarray as xr\n", "import pyproj\n", "from rasterio.mask import mask" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We use a [2003 USGS shapefile of the shores of Lake Mead](https://pubs.usgs.gov/of/2009/1150/gis/basemap/lakebndsmeta.htm). This is located in `aux_files/lakebnds`. We will write a new shapefile `aux_files/bufferlakebnds.shp`. We also load in one DSWx GeoTIFF as a reference image." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "shapepath = 'aux_files/lakebnds/lakebnds.shp'\n", "bufferpath = 'aux_files/bufferlakebnds/bufferlakebnds.shp'\n", "filepath = 's3://opera-pst-rs-pop1/products/OPERA_L3_DSWx-HLS_T11SQA_20201002T180918Z_20230118T203131Z_L8_30_v0.0/OPERA_L3_DSWx-HLS_T11SQA_20201002T180918Z_20230118T203131Z_L8_30_v0.0_B01_WTR.tif'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We reproject the shapefile to the same coordinate system as DSWx, create a 500 pixel buffer, and write to a new shapefile." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = gpd.read_file(shapepath)\n", "df_new = gpd.GeoDataFrame(columns=['BNDTYPE', 'geometry'], geometry='geometry')\n", "f = xr.open_rasterio(filepath)\n", "df_new['BNDTYPE'] = df['BNDTYPE']\n", "df_new['geometry'] = df.geometry.to_crs(pyproj.CRS.to_epsg(pyproj.CRS.from_proj4(f.crs))).buffer(4000,join_style=2)\n", "df_new.to_file(bufferpath)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The new shapefile `aux_files/bufferlakebnds.shp` is already provided as part of this repository." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13" }, "vscode": { "interpreter": { "hash": "5d751f0bf54b38837c679b9bb741ac2e77b1c14d35b41d9e176906b1359cbeef" } } }, "nbformat": 4, "nbformat_minor": 2 }