VIIRS
# Install AerEO and any required plugins for this notebook (Google Colab)
!pip install -q "aereo[swath,viz]" aereo-read-satpy
# Download config files and AOIs from the GitHub repository so this
# notebook can run outside the repo (e.g. Google Colab).
import os
import urllib.request
GITHUB_RAW = "https://raw.githubusercontent.com/frandorr/aereo/main"
os.makedirs("config/aoi", exist_ok=True)
# Config files
urllib.request.urlretrieve(
f"{GITHUB_RAW}/examples/config/job_viirs.yaml",
"config/job_viirs.yaml",
)
# AOI files
urllib.request.urlretrieve(
f"{GITHUB_RAW}/examples/config/aoi/chocon.geojson",
"config/aoi/chocon.geojson",
)
NASA Earthdata authentication¶
The NASA notebooks need a valid ~/.netrc file. Run this cell once in Colab to create it from your credentials:
import os
from getpass import getpass
# Get Earthdata credentials from the user
earthdata_username = getpass("Earthdata username: ")
earthdata_password = getpass("Earthdata password: ")
# Define the path for the .netrc file in the user's home directory
netrc_path = os.path.expanduser("~/.netrc")
# Create the .netrc file with the provided credentials
with open(netrc_path, "w") as f:
f.write("machine urs.earthdata.nasa.gov login {username} password {password}\n".format(
username=earthdata_username,
password=earthdata_password
))
# Set permissions for the .netrc file to be readable only by the owner
os.chmod(netrc_path, 0o600)
print(f"Successfully created {netrc_path} for Earthdata authentication.")
Config used in this notebook¶
This notebook loads the job from examples/config/job_viirs.yaml:
aoi_path: config/aoi/chocon.geojson
name: viirs_sample
grid_dist: 50_000
grid_cells_margin: 10
target_aoi: ${aoi_path}
output_uri: /tmp/aereo_extraction
overwrite: false
search:
_target_: aereo.builtins.search_earthaccess
_partial_: true
collections:
VJ202IMG: ["I04"]
VJ203IMG: []
intersects: ${aoi_path}
start_datetime: "2024-01-01T00:00:00Z"
end_datetime: "2024-01-02T23:59:59Z"
read:
_partial_: true
_target_: aereo.read_satpy.read_satpy
reader: viirs_l1b
wishlist: [I04]
downloader:
_target_: aereo.asset_downloader.core._download_with_earthaccess
_partial_: true
reproject:
_target_: aereo.builtins.reproject_swath
_partial_: true
reproject_mode: grid
resolution: 375
write:
_target_: aereo.builtins.write.write_geotiff
from aereo.cache import TaskResultCache
from aereo.executors import LocalExecutor
from aereo.pipeline import ExtractionJob
# Load the job from the Hydra config package.
job = ExtractionJob.load_from_config(
config_dir="config",
config_name="job_viirs",
)
assets = job.search() # Use the search method from the job object to get the assets.
tasks = job.build_tasks(assets)
len(tasks)
# now we create an Executor, in this case a LocalExecutor to run
# each ExtractionTask using Threads
local_exec = LocalExecutor(workers=2, use_threads=False, cache=TaskResultCache())
# Extract!
print("Extracting...")
artifacts = job.execute(tasks, executor=local_exec)
print(f"✓ Extracted {len(artifacts)} artifacts")
from aereo.viz import plot_artifact_patches
plot_artifact_patches(
artifacts,
ds_factor=1,
cmap="viridis",
stretch="percentile",
aoi=job.target_aoi,
aoi_edgecolor="blue",
)