<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Brian &quot;Owlzy&quot; Mubia on Medium]]></title>
        <description><![CDATA[Stories by Brian &quot;Owlzy&quot; Mubia on Medium]]></description>
        <link>https://medium.com/@monsieursapien?source=rss-495384a36414------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*oFPp0hYzhVr7994T4zQ3tg.jpeg</url>
            <title>Stories by Brian &amp;quot;Owlzy&amp;quot; Mubia on Medium</title>
            <link>https://medium.com/@monsieursapien?source=rss-495384a36414------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 00:41:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@monsieursapien/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Monitoring Water Quality Of Lake Victoria in Kenya Part 1: Data Collection]]></title>
            <link>https://medium.com/@monsieursapien/monitoring-water-quality-of-lake-victoria-in-kenya-part-1-data-collection-64191644cdd5?source=rss-495384a36414------2</link>
            <guid isPermaLink="false">https://medium.com/p/64191644cdd5</guid>
            <category><![CDATA[earth-observation]]></category>
            <category><![CDATA[remote-sensing]]></category>
            <category><![CDATA[spatialdatascience]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Brian "Owlzy" Mubia]]></dc:creator>
            <pubDate>Fri, 29 Nov 2024 12:41:15 GMT</pubDate>
            <atom:updated>2024-11-29T12:41:15.558Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*Lo2ewAnU86lBa0iq7M8Vcw.png" /><figcaption>Lake Victoria’s waters in Kenya</figcaption></figure><p>Being an enthusiastic learner in Data Science, I have recently developed an even stronger passion for problem solving using Data by connecting it with my interest in Geography. This eventually led me to the world of<strong> </strong><a href="https://eo-college.org/"><strong>Earth Observation</strong></a> and took courses on <strong>Remote Sensing</strong> ; the scanning of the earth by satellites or high flying aircraft in order to obtain information about it. As a milestone in my learning and fueled by news about the water hyacinth plague on the lake, I settled on developing a project that automates the data collection of water quality parameters and analyze them to get insights into the aquatic ecosystem of Kenya’s side of the Lake.</p><p>Let’s dive in, shall we? ;)</p><h3><strong>Data Source &amp; Parameters</strong></h3><p>The Water Quality Parameters I monitor in this project are:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*jfBFIZuFr0E3OyYpJozAaA.png" /><figcaption>Image of Chlorophyll-a on Lake Victoria</figcaption></figure><ol><li><strong>Normalized Difference Chlorophyll Index</strong> (NDCI): A spectral index used to estimate the relative concentration of chlorophyll in water bodies.</li><li><strong>Turbidity</strong>: Measures the cloudiness or haziness of water caused by large numbers of individual particles.</li><li><strong>Chlorophyll-a </strong>: Estimates the absolute concentration of chlorophyll-a in water bodies.</li><li><strong>Suspended Solids Concentration</strong> : Estimates the concentration of suspended sediments in water bodies.</li></ol><p>For my data source, I decided to go with the satellite that provided images dating as early as possible due to my interest in the historical changes of the water quality parameters over time. So I went with the <a href="https://developers.google.com/earth-engine/datasets/catalog/MODIS_061_MYD09GA">MODIS</a> satellite. The data is free to access on <a href="https://developers.google.com/earth-engine">Google Earth Engine</a>.</p><blockquote><strong>Note</strong>: To interact with the datasets, you will need a Google Cloud Project, which you will be guided on upon registering on the top right corner of their landing page.</blockquote><p>At the heart of the data collection process, we will leverage <a href="https://geemap.org/"><strong>geemap</strong></a>, which is a Python package for interactive geospatial analysis and visualization with Google Earth Engine.</p><p>To perform the computation using geemap’s <em>zonal_stats</em> function, we will need the raster image(the satellite image), the vector data (our region of interest, ROI) and the stat type(mean). The code below does just that!</p><h3>Step 1: Import Necessary Libraries</h3><p>First, import the required libraries:</p><pre>import ee<br>import geemap<br>import geopandas as gpd<br>import pandas as pd<br>import numpy as np<br>import seaborn as sns<br>import folium<br>import matplotlib.pyplot as plt</pre><h3>Step 2: Authenticate and Initialize Earth Engine</h3><p>Authenticate and initialize the Earth Engine API:</p><pre># Authenticate to the Earth Engine servers<br>ee.Authenticate()<br><br># Initialize Earth Engine<br>ee.Initialize()</pre><h3>Step 3: Define the Area of Interest</h3><p>Load the Geospatial files for Lake Victoria and Kenya, and find their intersection to define the study area:</p><pre># Load the lake geojson<br>lake = gpd.read_file(&#39;Lake_Victoria_Shapefile.geojson&#39;)<br><br># Load Kenya geojson<br>kenya = gpd.read_file(&#39;kenya.geojson&#39;)<br><br># Get the intersection of the lake and Kenya<br>study_area = gpd.overlay(kenya, lake, how=&#39;intersection&#39;)<br><br># Plot the study area<br>study_area.plot()</pre><h3>Step 4: Upload the Study Area as an Asset</h3><p>Export the study area to a shapefile and upload it to your GEE account for optimal performance. Note that you will have to zip the files in a single folder before uploading:</p><pre># Export the study area as a shapefile<br>study_area.to_file(&#39;study_area.shp&#39;)</pre><h3>Step 5: Load the Study Area Asset</h3><p>Load the study area asset from your GEE account:</p><pre># Load the study area asset uploaded to ee<br>lake_asset = &#39;projects/water-quality-441207/assets/lake_victoria_ke&#39;<br>lake = ee.FeatureCollection(lake_asset)</pre><h3>Step 6: Load the MODIS Image Collection</h3><p>Load the MODIS image collection and select the relevant bands:</p><pre># Load the MODIS image collection<br>dataset = ee.ImageCollection(&#39;MODIS/061/MYD09GA&#39;) \<br>            .filterDate(&#39;2002-07-04&#39;, &#39;2024-11-12&#39;) \<br>            .select([&#39;sur_refl_b01&#39;, &#39;sur_refl_b02&#39;, &#39;sur_refl_b03&#39;, <br>                     &#39;sur_refl_b04&#39;, &#39;sur_refl_b05&#39;, &#39;sur_refl_b06&#39;, &#39;sur_refl_b07&#39;])</pre><h3>Step 7: Calculate Spectral Indices</h3><p>Define a function to calculate the water quality indices:</p><pre># Calculate indices for water quality<br>def calculate_indices(image):<br>    ndci = image.normalizedDifference([&#39;sur_refl_b05&#39;, &#39;sur_refl_b04&#39;]).rename(&#39;NDCI&#39;)  # NIR and Red<br>    chl_a = image.expression(<br>        &#39;exp(0.15 * (B3 / B4))&#39;,  # Empirical formula with Blue (B3) and Green (B4)<br>        {&#39;B3&#39;: image.select(&#39;sur_refl_b03&#39;), &#39;B4&#39;: image.select(&#39;sur_refl_b04&#39;)}<br>    ).rename(&#39;Chlorophyll_a&#39;)<br>    ssc = image.expression(<br>        &#39;0.1 * pow(B3, 1.5)&#39;,  # Example SSC formula using Red (B3)<br>        {&#39;B3&#39;: image.select(&#39;sur_refl_b03&#39;)}<br>    ).rename(&#39;SSC&#39;)<br>    turbidity = image.expression(<br>        &#39;0.02 * pow(B3, 1.3)&#39;,  # Example Turbidity formula using Red (B3)<br>        {&#39;B3&#39;: image.select(&#39;sur_refl_b03&#39;)}<br>    ).rename(&#39;Turbidity&#39;)<br>    return image.addBands([ndci, chl_a, ssc, turbidity])<br><br># Apply index calculations to the dataset<br>processed_dataset = dataset.map(calculate_indices)</pre><h3>Step 8: Compute Monthly Averages</h3><p>Define functions to compute monthly averages for each water quality parameter:</p><pre># Define the function to compute monthly NDCI averages<br>def compute_monthly_ndci_averages(start_date, end_date, lake, scale=1000):<br>    start = ee.Date(start_date)<br>    end = ee.Date(end_date)<br>    months = pd.date_range(start_date, end_date, freq=&#39;MS&#39;).strftime(&quot;%Y-%m&quot;).tolist()<br>    all_stats = []<br><br>    for month in months:<br>        month_start = ee.Date(f&#39;{month}-01&#39;)<br>        month_end = month_start.advance(1, &#39;month&#39;)<br>        monthly_ndci = processed_dataset.filterDate(month_start, month_end).select(&#39;NDCI&#39;).mean()<br>        if monthly_ndci.bandNames().size().getInfo() == 0:<br>            print(f&quot;No data for {month}&quot;)<br>            continue<br>        stats = geemap.zonal_stats(monthly_ndci, lake, None, stat_type=&#39;MEAN&#39;, scale=scale, return_fc=True)<br>        df = geemap.ee_to_df(stats)<br>        df[&#39;month&#39;] = month<br>        all_stats.append(df)<br><br>    final_df = pd.concat(all_stats, ignore_index=True)<br>    final_output_file = &#39;monthly_ndci_averages.csv&#39;<br>    final_df.to_csv(final_output_file, index=False)<br>    return final_output_file<br><br># Compute the monthly NDCI averages<br>final_output_file = compute_monthly_ndci_averages(&#39;2002-07-04&#39;, &#39;2024-11-12&#39;, lake)<br>print(f&#39;Monthly NDCI averages saved to {final_output_file}&#39;)</pre><pre># Compute the monthly NDCI averages<br>final_output_file = compute_monthly_ndci_averages(start_date, end_date, lake)<br>print(f&#39;Monthly NDCI averages saved to {final_output_file}&#39;)</pre><p>This is an example of a function that computes a parameter of interest (NDCI). The rest of the code for the remaining parameters can be found in <a href="https://github.com/owlzyseyes/Water-Quality-Monitoring/blob/main/data_collection_notebooks/extraction.ipynb">this notebook</a>!</p><p>In the next article, I will cover the analysis of the parameters. Thank you for reading and hope you learned something in my very first article. Until then, cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64191644cdd5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>