\documentclass[10pt]{article}

\usepackage{fullpage}
\usepackage{setspace}
\usepackage{parskip}
\usepackage{titlesec}
\usepackage[section]{placeins}
\usepackage{xcolor}
\usepackage{breakcites}
\usepackage{lineno}
\usepackage{hyphenat}





\PassOptionsToPackage{hyphens}{url}
\usepackage[colorlinks = true,
            linkcolor = blue,
            urlcolor  = blue,
            citecolor = blue,
            anchorcolor = blue]{hyperref}
\usepackage{etoolbox}
\makeatletter
\patchcmd\@combinedblfloats{\box\@outputbox}{\unvbox\@outputbox}{}{%
  \errmessage{\noexpand\@combinedblfloats could not be patched}%
}%
\makeatother


\usepackage{natbib}




\renewenvironment{abstract}
  {{\bfseries\noindent{\abstractname}\par\nobreak}\footnotesize}
  {\bigskip}

\titlespacing{\section}{0pt}{*3}{*1}
\titlespacing{\subsection}{0pt}{*2}{*0.5}
\titlespacing{\subsubsection}{0pt}{*1.5}{0pt}


\usepackage{authblk}


\usepackage{graphicx}
\usepackage[space]{grffile}
\usepackage{latexsym}
\usepackage{textcomp}
\usepackage{longtable}
\usepackage{tabulary}
\usepackage{booktabs,array,multirow}
\usepackage{amsfonts,amsmath,amssymb}
\providecommand\citet{\cite}
\providecommand\citep{\cite}
\providecommand\citealt{\cite}
% You can conditionalize code for latexml or normal latex using this.
\newif\iflatexml\latexmlfalse
\providecommand{\tightlist}{\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}%

\AtBeginDocument{\DeclareGraphicsExtensions{.pdf,.PDF,.eps,.EPS,.png,.PNG,.tif,.TIF,.jpg,.JPG,.jpeg,.JPEG}}

\usepackage[utf8]{inputenc}
\usepackage[english]{babel}



\usepackage{float}








\begin{document}

\title{Monitoring flood using Amazon SageMaker geospatial capabilities}



\author[1]{Ishneet Kaur Dua}%
\author[1]{Parth Girish Patel}%
\affil[1]{Affiliation not available}%


\vspace{-1em}



  
  \date{June 18, 2024}


\begingroup
\let\center\flushleft
\let\endcenter\endflushleft
\maketitle
\endgroup





\selectlanguage{english}
\begin{abstract}
Flood monitoring with satellite images is an effective method of
detecting and tracking floods. This approach involves the use of
satellite imagery to detect changes in water levels and identify flooded
areas.~To monitor floods using satellite images, the images are analyzed
to detect changes in water levels over time.~To detect changes in water
levels and identify flooded areas based on a set of predefined criteria,
we can train algorithms. Amazon SageMaker geospatial capabilities make
it easier for data scientists and machine learning (ML) engineers to
build, train, and deploy ML models using geospatial data. ~These
capabilities also provide pre-trained models. One of the pre-trained
models is~land cover segmentation model. This land cover segmentation
model can be run with a simple API call and can be leverage to~analyze
changes in the water level.%
\end{abstract}%



\sloppy


\section*{Introduction~}

{\label{monitoring-flood-using-amazon-sagemaker-geospatial-capabilities}}

Changes in global temperatures have resulted in more frequent and
intense rainfall events, which can lead to flooding in areas that are
not equipped to handle large amounts of water.~Deforestation can also
contribute to increased flooding. Trees and other vegetation play a key
role in regulating the flow of water, and their removal can result in
more water running off the surface and into rivers and streams.

Flood monitoring with satellite images is an effective method of
detecting and tracking floods. This approach involves the use of
satellite imagery to detect changes in water levels and identify flooded
areas.~To monitor floods using satellite images, the images are analyzed
to detect changes in water levels over time.~To detect changes in water
levels and identify flooded areas based on a set of predefined criteria,
we can train algorithms. Amazon SageMaker geospatial capabilities make
it easier for data scientists and machine learning (ML) engineers to
build, train, and deploy ML models using geospatial data. ~These
capabilities also provide pre-trained models. One of the pre-trained
models is~land cover segmentation model. This land cover segmentation
model can be run with a simple API call and can be leverage to~analyze
changes in the water level.

\subsection*{Solution Overview}

{\label{solution-overview}}

Let's further understand how SageMaker geospatial capabilities make it
easy to build, train, and deploy models using geospatial data.~For~flood
monitoring use case, we will be using Sentinel 2 data from ASDI - Amazon
Sustainability Data Initiative.~In this blog post, we will first show
you how to leverage new Sagemaker geospatial capabilities to visualize
geospatial images from Sentinel-2 and further process these images to
segment and classify the water coverage. This will help to analyze flood
in defined area

\subsection*{Prerequisites}

{\label{prerequisites}}

To get hands-on experience with all the features described in this post,
complete the following prerequisites:

Ensure that you have an AWS account, secure access to log in to the
account via the AWS Management Console, and AWS Identity and Access
Management (IAM) permissions to use Amazon SageMaker and Amazon Simple
Storage Service (Amazon S3) resources.

Onboard to a SageMaker domain and access Studio to use notebooks. For
instructions, refer to Onboard to Amazon SageMaker Domain. If you're
using existing Studio, upgrade to the latest version of Studio.

\subsubsection*{Solution walkthrough with Jupyter Notebook using
SageMaker Geospatial
API}

{\label{solution-walkthrough-with-jupyter-notebook-using-sagemaker-geospatial-api}}

\subsection*{Data access}

{\label{data-access}}

The new geospatial capabilities in SageMaker offer easy access to
geospatial data such as Sentinel-2 and Landsat 8. Built-in geospatial
dataset access saves weeks of effort otherwise lost to collecting data
from various data providers and vendors. ~First, we will use an Amazon
SageMaker Studio notebook with a SageMaker geospatial image by following
steps outlined in Getting Started with Amazon SageMaker geospatial
capabilities. We use a SageMaker Studio notebook with a SageMaker
geospatial image for our analysis.

The amazon-sagemaker-examples GitHub repository
\url{https://github.com/aws/amazon-sagemaker-examples/tree/main/sagemaker-geospatial/lake-mead-drought-monitoring}~contains
similar notebooks that served as the basis for this article.~ You can
easily query data using SageMaker geospatial capabilities. We initially
create a bounding box around the Mississippi river to represent an
AreaOfInterest (AOI). In order to choose data from June 2018 to June
2019, we use the TimeRangeFilter. Often~cloud~cover~can block our view
of the location. To obtain less cloudy images, we will select a subset
of photos by setting the upper bound for cloud coverage to 20\%.

\subsection*{Model inference}

{\label{model-inference}}

The next stage is to remove water bodies from the satellite images after
the data has been identified. Normally, in order to distinguish various
kinds of physical materials on the earth's surface, such as water
bodies, vegetation, snow, and so on, we would need to train a land cover
segmentation model from scratch. Starting from scratch to train a model
is time and resource intensive which includes data labeling, model
training, and deployment.~SageMaker geospatial capabilities provide a
pre-trained land cover segmentation model. This land cover segmentation
model can be run with a simple API call.

Rather than downloading the data to a local machine for inferences,
SageMaker does all the heavy lifting for you.~In an Earth Observation
Job(EOJ), we simply specify the data setup and model configuration.

The satellite image data for the EOJ is automatically downloaded by
SageMaker, and prepared for inference.~SageMaker then does model
inference for the EOJ automatically.~The EOJ can take several minutes to
many hours to complete, depending on the workload (the amount of images
ran through model inference).~You can monitor the job status using the
get\_earth\_observation\_job function.

Coordinates ={[} {]} daterange = \{ ''2018-06-01T00:00:00Z'',
''2019-06-01T23:59:59Z'',\} Perform land cover segmentation on images
returned from the sentinel dataset. eoj\_input\_config = \{ \}
eoj\_config = \{''LandCoverSegmentationConfig'': \{\}\} response =
sg\_client.start\_earth\_observation\_job( ) eoj\_arn =
response{[}''Arn''{]} job\_details =
sg\_client.get\_earth\_observation\_job(Arn=eoj\_arn) \{k: v for k, v in
job\_details.items() if k in {[}''Arn'', ''Status'',
''DurationInSeconds''{]}\}

\subsection*{Analysis ~}

{\label{analysis}}

The results of the EOJ can be exported to an Amazon Simple Storage
Service (Amazon S3) bucket using the export earth observation job
function.~The data in Amazon S3 will be used for a subsequent analysis
in order to determine the water surface area.~SageMaker also simplifies
dataset management. The handling of datasets is made simpler with
SageMaker.~Instead of crawling thousands of files in the S3 bucket, we
can just share the EOJ results using the job ARN.~Each EOJ becomes an
asset in the data catalog, as results can be grouped by the job ARN.

sagemaker\_session = sagemaker.Session() s3\_bucket\_name =
sagemaker\_session.default\_bucket() ~\# Replace with your own bucket if
needed s3\_bucket = session.resource(''s3'').Bucket(s3\_bucket\_name)
prefix = ''eoj\_flood\_detection'' ~\# Replace with the S3 prefix
desired export\_bucket\_and\_key =
f''s3://\{s3\_bucket\_name\}/\{prefix\}/'' eoj\_output\_config =
\{''S3Data'': \{''S3Uri'': export\_bucket\_and\_key\}\} export\_response
= sg\_client.export\_earth\_observation\_job( )

Next, we analyze changes in the water level in Mississippi river. We
download the land cover masks to our local instance to calculate water
surface area using open-source libraries. SageMaker saves the model
outputs in Cloud Optimized GeoTiff (COG) format.

import os from glob import glob import cv2 import numpy as np import
tifffile import matplotlib.pyplot as plt from urllib.parse import
urlparse from botocore import UNSIGNED from botocore.config import
Config \# Download land cover masks os.makedirs(mask\_dir,
exist\_ok=True) image\_paths = {[}{]} for s3\_object in
s3\_bucket.objects.filter(Prefix=prefix).all(): path, filename =
os.path.split(s3\_object.key) if ''output'' in path: mask\_name =
mask\_dir + ''/'' + filename s3\_bucket.download\_file(s3\_object.key,
mask\_name) print(''Downloaded mask: '' + mask\_name) \# Download source
images for visualization for tci\_url in tci\_urls: url\_parts =
urlparse(tci\_url) img\_id = url\_parts.path.split(''/''){[}-2{]}
tci\_download\_path = image\_dir + ''/'' + img\_id + ''\_TCI.tif''
cogs\_bucket = session.resource( ''s3'',
config=Config(signature\_version=UNSIGNED, region\_name=''us-west-2'')
).Bucket(url\_parts.hostname.split(''.''){[}0{]})
cogs\_bucket.download\_file(url\_parts.path{[}1:{]}, tci\_download\_path
+ ''.1'') print(''Downloaded image: '' + img\_id) print(''Downloads
complete.'')

\par\null\par\null

Each pixel in the land cover mask has a value between 0-11. Each value
corresponds to a particular class of land cover. Water's class index is
6. We can use this class index to extract the water mask. First, we
count the number of pixels that are marked as water. Next, we multiply
that number by the area that each pixel covers to get the surface area
of the water. Depending on the bands, the spatial resolution of a
Sentinel-2 L2A image is 10\emph{m} , 20\emph{m} , or 60\emph{m} . All
bands are downsampled to a spatial resolution of 60 meters for the land
cover segmentation model inference. As a result, each pixel in the land
cover mask represents a ground area of 3600 \emph{m} 2, or 0.0036
\emph{km} 2.

os.makedirs(overlay\_dir, exist\_ok=True) lake\_areas = {[}{]}
mask\_dates = {[}{]} for image\_file, mask\_file in zip(image\_files,
mask\_files): image\_file.split(''/''){[}-1{]}.split(''\_TCI''){[}0{]}
mask\_file.split(''/''){[}-1{]}.split(''.tif''){[}0{]}
mask\_id.split(''\_''){[}2{]} f''\{image\_id\}\{mask\_id\}''
tifffile.imread(image\_file) 1830), interpolation=cv2.INTER\_LINEAR)
{[}6{]}).astype(np.uint8) ~\# water has a class index 6 60 / (1000 *
1000) ~\# calculate the surface area cv2.findContours(water\_mask,
cv2.RETR\_TREE, cv2.CHAIN\_APPROX\_SIMPLE) contour, -1, (255, 0, 0), 4)
mask\_date + ''.png'' cv2.cvtColor(lake\_crop, cv2.COLOR\_RGB2BGR))

We plot the water surface area over time in the following figure. The
water surface area clearly increased between June 2018 and June 2019.\selectlanguage{english}
\begin{figure}[H]
\begin{center}
\includegraphics[width=0.70\columnwidth]{figures/image1/image1}

\end{center}
\end{figure}

We can also extract the river boundaries and superimpose them over the
satellite images to better visualize the changes in river water body. As
shown in the following animation, In some months, the surface area has
increases by more than 50\% from the previous year.\selectlanguage{english}
\begin{figure}[H]
\begin{center}
\includegraphics[width=0.70\columnwidth]{figures/image2/Picture1}

\end{center}
\end{figure}

\subsection*{Conclusion:~}

{\label{conclusion}}

Flood monitoring with satellite imagery from Planet Labs , Amazon
Sagemaker Geospatial capabilities and ASDI has several advantages over
traditional methods of flood monitoring, including its ability to
provide data much faster then traditional methods and its ability to
cover large areas quickly. This makes it a valuable tool for disaster
management agencies, researchers and other organizations involved in
flood response and relief efforts.~SageMaker now supports geospatial
machine learning (ML), making it easier for data scientists and ML
engineers to build, train, and deploy models using geospatial data. In
this post, we showed how to utilize data, perform~analysis and
~visualize the changes in water level with SageMaker geospatial
capabilities.~See the Amazon SageMaker geospatial~documentation~~to
learn more.

{\textbf{References:~}}

{\url{https://aws.amazon.com/blogs/machine-learning/monitoring-lake-mead-drought-using-the-new-amazon-sagemaker-geospatial-capabilities/}}

https://earthobservatory.nasa.gov/images/145029/flooding-continues-along-the-mississippi

Data Source: Sentinel Tiff
arn:aws:sagemaker-geospatial:us-west-2:378778860802:raster-data-collection/public/nmqj48dcu3g7ayw8

Studio notebook
-~https://d-3o0hpfuqdd0k.studio.us-west-2.sagemaker.aws/jupyter/default/lab?

Earth observation job docs
-~https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sagemaker-geospatial/client/get\_earth\_observation\_job.html

\selectlanguage{english}
\FloatBarrier
\end{document}

