1.Extract_HLS_L30 .R
1.Extract_HLS_L30 .R | 1.Extract_HLS_L30 .py |
---|---|
library(dplyr)
library(terra)
library(sf)
library(exactextractr)
library(glue) | import pandas as pd
import rasterio
import geopandas as gpd
import os
import glob
import numpy as np
from rasterstats import zonal_stats |
Syntax is easy. Knowing which libraries to use – not so much! Here’s a quick description of each Python library used for this program:
| |
process_shapefile <- function(sensor, NIR_band) { | |
Defines a function that takes the | |
Changes to the base directory and gets a list of the tiles. |
|
Creates a dataframe with the number of rows in fields but with no columns. Note the simple syntax in Python. The single colon | |
Creates a loop to iterate through the tiles. Note that the Python code could be written as | |
Changes to the directory of the current tile. | |
Grabs the files that match the pattern Python’s f strings work similarly to R’s glue function. | |
Creates a loop to iterate through each tile's scenes. | |
Shows the current processing status. | |
Changes to the scene/date folder. | |
Grabs the filenames of the NIR and B04 bands. Note how Python’s | |
Loads the raster stack of the B04 and NIR bands. | |
Sets the names of the raster stack based on file names. | |
| |
The R code creates references to This is an optimization technique, which prevents R from copying data that might not change. However, the data does change in the following code. When that happens, R will automatically change the references to copies of The Python code makes this explicit by creating copies of | |
Sets values not matching the conditions to NaN. | |
Merges the cloud mask layers for 0, 64, and 128. | |
Applies the cloud mask to the raster stack | |
CONTINUE FROM HERE | |
| |
| |
Reads the buffered shapefile. | |
Plots the shapefile.
|