|
| 1 | +# Exploring NASA’s HLS Data on Microsoft Planetary Computer Using GitHub Copilot |
| 2 | + |
| 3 | +Use AI to query, visualize, and interact with NASA’s HLS data available in Microsoft's Planetary Computer |
| 4 | + |
| 5 | +## Description |
| 6 | +This tutorial introduces users to NASA’s Harmonized Landsat and Sentinel-2 (HLS) data through Microsoft’s Planetary Computer, using GitHub Copilot as a coding and AI assistant. The objective is to guide participants in interacting with the HLS Jupyter notebook, demonstrating how GitHub Copilot can simplify coding tasks, accelerate data exploration, promote open science, and increase accessibility through natural language prompts. By the end, users will be able to query, visualize, and analyze HLS data while gaining hands-on experience with AI-assisted development. |
| 7 | + |
| 8 | +## Objectives |
| 9 | +- Access HLS data from Microsoft’s Planetary Computer |
| 10 | +- Extract and visualize HLS data from an area and time of interest |
| 11 | +- Use GitHub Copilot to explore HLS data and modify code using natural language prompts |
| 12 | +- Generate an HLS-derived Normalized Difference Vegetation Index (NVID) plot and timelapse HLS gif |
| 13 | + |
| 14 | +## Prerequisites: |
| 15 | +1. Basic knowledge of Python and command-line usage |
| 16 | +2. Access to Microsoft Planetary Computer repository (https://github.com/microsoft/PlanetaryComputerExamples) |
| 17 | +3. GitHub account with Codespaces enabled (https://github.com/signup; https://github.com/settings/codespaces) |
| 18 | +4. GitHub Copilot (https://docs.github.com/en/copilot/get-started/plans) |
| 19 | + |
| 20 | +## Tutorial |
| 21 | + |
| 22 | +### 1. Setup your Environment |
| 23 | + |
| 24 | +1. Go to the Microsoft repo: https://github.com/microsoft/PlanetaryComputerExamples |
| 25 | +2. In the top-right corner, click **Fork**. |
| 26 | +3. Choose your account |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +Now you have your own copy under https://github.com/your-username/PlanetaryComputerExamples. |
| 31 | + |
| 32 | +4. In your fork, click the green **Code** button → **Open with Codespaces** |
| 33 | +5. Click **Create codespace on main**. |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +A cloud dev environment will spin up. Wait a few minutes to finish loading. |
| 38 | + |
| 39 | +6. In the left-hand Explorer sidebar, expand: **datasets → hls2 → hls2-example.ipynb** |
| 40 | +7. Click on the notebook to open it. |
| 41 | +8. If asked to select a kernel, pick the **default Python (e.g., “Python 3.x (Codespaces)”)**. |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +In this section, you prepared your environment by forking the Microsoft Planetary Computer Examples repository, opening it in GitHub Codespaces, and launching the HLS2 notebook. With this setup complete, you’re ready to test the notebook and start exploring HLS data. |
| 46 | + |
| 47 | +### 2. Test the Notebook |
| 48 | +1. At the top of the notebook, add a new cell. |
| 49 | +2. Copy and run this code: |
| 50 | + |
| 51 | +```bash |
| 52 | +%pip install -q pystac-client planetary-computer xarray rioxarray matplotlib geopandas folium rich odc-stac imageio pillow imageio-ffmpeg |
| 53 | +``` |
| 54 | + |
| 55 | +3. When it finishes, click **Restart → Restart Kernel** so everything reloads with the new packages. |
| 56 | +4. Edit this cell starting with _import pystac_client_, and add: |
| 57 | + |
| 58 | +```bash |
| 59 | +print("✅ Imports successful") |
| 60 | +``` |
| 61 | +5. Run the cell |
| 62 | + |
| 63 | +If you see ✅ Imports successful, everything is installed correctly. |
| 64 | + |
| 65 | +6. Now, modify the next cell in the Notebook to check connection with the Planetary Computer STAC: |
| 66 | + |
| 67 | +```bash |
| 68 | +print("STAC OK:", catalog is not None) |
| 69 | +``` |
| 70 | +7. Run the cell. |
| 71 | + |
| 72 | +If output is STAC OK: True, this confirms your notebook can talk to the Microsoft Planetary Computer catalog. |
| 73 | + |
| 74 | +8. Run the cells under the **Choose a region and time of interest** section in the notebook. |
| 75 | +9. The last cell should have HLS2 items returned, meaning you can fetch HLS data from the Microsoft Planetary Computer. |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | +In this section, you have checked that your environment works, verified that your notebook can talk to the Microsoft Planetary Computer and can access HLS data. |
| 80 | + |
| 81 | +Scroll through the rest of the notebook to inspect it. Do you see the area and time of interest? The NVDI plots? The visualizations from satellite imagery? We will use AI in the next section to dive deeper into these and modify the code, all using natural language commands. |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | +### 3. Use GitHub Copilot |
| 86 | + |
| 87 | +In this section, you’ll use GitHub Copilot, an AI coding assistant that suggests code, explains cells, and helps you adapt the your tools through natural language commands. We’ll walk through how to prompt Copilot to explain the notebook, customize searches, create visualizations, and perform simple analyses like NDVI. |
| 88 | + |
| 89 | +1. Open the Copilot Chat sidebar (icon on the top right) |
| 90 | +2. GitHub Copilot will open on the right-side of your window |
| 91 | +3. Set Copilot to Ask mode, and select a model like GPT-4o. |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | +Feel free to experiment with other models like GPT-5-mini, Claude, or others to see differences in Copilot engagement and responses. |
| 96 | + |
| 97 | +4. Ask Copilot, type: |
| 98 | + |
| 99 | +```bash |
| 100 | +"Explain what this notebook does at a high level” |
| 101 | +``` |
| 102 | +
|
| 103 | +Copilot will summarize how the notebook connects to the Planetary Computer, searches HLS data, and plots results. |
| 104 | +
|
| 105 | + |
| 106 | +
|
| 107 | +Try other prompts to explore the notebook further: |
| 108 | +
|
| 109 | +```bash |
| 110 | +"I’m new to HLS data, what can you tell me about it" |
| 111 | +"What is NDVI? Give me its definition and formula" |
| 112 | +``` |
| 113 | +
|
| 114 | +Now we will use Copilot in Agent mode to modify the code. |
| 115 | +
|
| 116 | +Please note that the default notebook focuses on Orange County, California and calculates the Normalized Vegetation Index (NDVI) in this area from October 2022 to April 2025. We will use Copilot to change the code to a different region and time of interest. |
| 117 | +
|
| 118 | +5. Click the cell with the area of iterest. |
| 119 | +6. Click <img width="100" height="20" alt="image" src=images/GitHub3.png />, which will open Copilot inside the notebook to allow us to modify the code. |
| 120 | +7. Type the following prompt: |
| 121 | +
|
| 122 | +```bash |
| 123 | +“Please replace the area of interest from Orange County, California to Washington D.C. Comment out the original code and insert the new code below" |
| 124 | +``` |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | +Copilot will insert a new cell with the updated coordinates for Washington D.C. |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | +Feel free to experiment with other areas around the world. |
| 134 | + |
| 135 | +Now we will do a similar process to change the timeline. |
| 136 | + |
| 137 | +8. Locate the Time of Interest cell. |
| 138 | +9. Click <img width="100" height="20" alt="image" src=assets/GitHub3.png />, to open Copilot inside the notebook. |
| 139 | +10. Type the following prompt: |
| 140 | + |
| 141 | +```bash |
| 142 | +“Please update the time of interest to be between April 2023 to January 2025" |
| 143 | +``` |
| 144 | +
|
| 145 | + |
| 146 | +
|
| 147 | +11. Click the **Run All** button, to run the entire notebook with the new area and time of interest. |
| 148 | +
|
| 149 | +See that the NVDI plot and visualizations represent Washington D.C. |
| 150 | +
|
| 151 | + |
| 152 | +
|
| 153 | +Can you see the Potomac River? |
| 154 | +
|
| 155 | +In this section, you used GitHub Copilot to go beyond simply running the notebook by turning it into an interactive learning experience. Copilot explained what the code was doing, helped you customize searches for new locations and dates, and generated code to visualize HLS data as RGB composites and NDVI maps. You also learned how to save your results and commit your work back to your GitHub fork, building a complete workflow from exploration to analysis to sharing. |
| 156 | +
|
| 157 | +## Additional Prompts for Copilot: |
| 158 | +
|
| 159 | +GitHub Copilot makes it easy to edit code. Here are a few additional prompts you can test in other parts of the notebook to explore what you can do with HLS data: |
| 160 | +
|
| 161 | +🔍 Explore More Data |
| 162 | +- “Change the search to look at Los Angeles, California for August 2022 .” |
| 163 | +- “Search for HLS scenes over the Amazon rainforest in June 2021 with less than 20% cloud cover.” |
| 164 | +
|
| 165 | +🖼️ Advanced Visualization |
| 166 | +- “Plot the Near Infrared (B08), Red (B04), and Green (B03) bands as a false-color composite to highlight vegetation.” |
| 167 | +- “Overlay the RGB image on top of the item’s footprint polygon with GeoPandas.” |
| 168 | +
|
| 169 | +🌱 Deeper Analysis |
| 170 | +- “Compute EVI (Enhanced Vegetation Index) using the Blue, Red, and NIR bands and plot it.” |
| 171 | +- “Calculate the average NDVI across the entire image and print the value.” |
| 172 | +- “Generate an NDVI histogram to see the distribution of values.” |
| 173 | +
|
| 174 | +📈 Time Series |
| 175 | +- “Loop through all items in the search results and plot NDVI over time as a line chart.” |
| 176 | +- “Make a small animation (GIF) of RGB composites over multiple dates to show change.” |
| 177 | +
|
| 178 | +🗺️ Mapping |
| 179 | +- “Put the RGB composite on an interactive Folium map centered on the search area.” |
| 180 | +- “Add NDVI as a semi-transparent layer on the Folium map with a legend.” |
| 181 | +
|
| 182 | +💾 Saving Results |
| 183 | +- “Save the RGB composite as a PNG file.” |
| 184 | +- “Export NDVI as a GeoTIFF with CRS and metadata preserved.” |
| 185 | +
|
| 186 | +
|
| 187 | +## Resources: |
| 188 | +- Learn more about Microsoft Planetary Computer: https://planetarycomputer.microsoft.com/ |
| 189 | +- For more information on NASA's HLS data: https://www.earthdata.nasa.gov/data/projects/hls |
| 190 | +- Continue learning about GitHub Copilot: https://learn.microsoft.com/en-us/training/modules/introduction-to-github-copilot/ |
| 191 | +
|
| 192 | +
|
0 commit comments