How to create an interactive map of AERONET Sites with Python and Folium ?

Published: August 28, 2024

Tags: AERONET; Python;

DMCA.com Protection Status

Introduction

Creating interactive maps is an effective way to visualize spatial data, and Python's Folium library makes it straightforward to achieve this. In this article, we'll walk through the process of creating an interactive map of AERONET (Aerosol Robotic Network) sites using Python and Folium. This guide will help you display the geographical locations of AERONET sites on a map, which can be valuable for data analysis, presentation, and more.

Related Notes: Jupyter Notebook; AERONET Project

Prerequisites

Before we start, ensure you have the following libraries installed:
- pandas: For handling and processing CSV data.
- folium: For creating interactive maps.
- glob: For file pattern matching.

You can install these libraries using pip if you haven't already:

1
pip install pandas folium

Step-by-Step Guide

1 -Setup Your Environment

Begin by importing the necessary libraries:

1
2
3
import pandas as pd
import folium
import glob

2 - Define the Path to Your Data

Set the path where your AERONET data files are stored. In this example, the files are located in the ./inputs/AOD_Level20_Daily_V3/AOD/AOD20/DAILY/ directory:

1
inputs_path = './inputs/AOD_Level20_Daily_V3/AOD/AOD20/DAILY/'

3 -List the AERONET Site Files

Use glob to create a list of filenames that match the pattern *lev20 in the specified directory:

1
aeronet_site_list = [f.split('/')[-1] for f in glob.glob(inputs_path + '*lev20')]

This line of code generates a list of file names, which will be used to extract location data for each AERONET site.

4 - Initialize the Interactive Map

Create a Folium map object centered at latitude 0 and longitude 0 with an initial zoom level of 2:

1
m = folium.Map([0,0], zoom_start=2)

Add a tile layer to the map using Esri's satellite imagery for better visualization:

1
2
3
4
5
6
7
folium.TileLayer(
    tiles='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',
    attr='Esri',
    name='Esri Satellite',
    overlay=False,
    control=True
).add_to(m)

5 - Add Markers for Each AERONET Site

Loop through each file in the aeronet_site_list, read the CSV data, extract latitude and longitude, and add a marker to the map:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
for aeronet_site in aeronet_site_list:   
    # Read the CSV file for the current AERONET site
    filename = aeronet_site
    df = pd.read_csv(inputs_path + filename, skiprows=6, low_memory=False, encoding="utf-8")

    # Extract latitude and longitude from the specified columns
    cols = ['Site_Latitude(Degrees)', 'Site_Longitude(Degrees)']
    lat = df[cols].iloc[0,0]
    long = df[cols].iloc[0,1]

    # Add a marker to the map for the current AERONET site
    folium.Marker(
        location=[lat, long],
        popup="AERONET Site",
    ).add_to(m)

This loop reads each CSV file, extracts the coordinates, and places a marker on the map at the specified location.

5 - Display the Map

Finally, display the interactive map:

1
m

If you're using a Jupyter notebook, the map will be rendered inline. For other environments, you might need to save the map as an HTML file and open it in a web browser:

1
m.save('aeronet_sites_map.html')

How to create an interactive map of AERONET Sites with Python and Folium ?
How to create an interactive map of AERONET Sites with Python and Folium ?

Conclusion

By following these steps, you can create an interactive map of AERONET sites using Python and Folium. This map will allow you to visualize the distribution of AERONET sites globally, enhancing your ability to analyze and present atmospheric aerosol data. The combination of Python's data handling capabilities and Folium's mapping features provides a powerful tool for data scientists and researchers working with geographical and environmental datasets.

References

Links Site
folium - icons folium
aeronet aeronet.gsfc.nasa.gov
download_all_v3_aod aeronet.gsfc.nasa.gov
Image

of