Page 1 of 1

Query and download PACE or VIIRS data from EarthData

Posted: Wed May 01, 2024 5:05 am
by quinten
I have implemented a simple query and download function for the EarthData API to get VIIRS and OCI L1B data.

To use the EarthData portal please make an account at https://urs.earthdata.nasa.gov/ and put your credentials in your .netrc file:

Code: Select all

machine urs.earthdata.nasa.gov
login YOUR_LOGIN
password YOUR_PASSWORD
Make sure your .netrc file has no group or world read access, i.e. -rw-------. You can set this for example by:

Code: Select all

chmod 600 ~/.netrc
Alternatively you can provide the credentials in a more unsafe manner by setting them in your operating system variables or ACOLITE config.txt file. See the GitHub ReadMe for details.

Before using the functions shown below, make sure you import the acolite distribution in your Python code, for example:

Code: Select all

import sys, os
user_home = os.path.expanduser("~")
sys.path.append(user_home+'/git/acolite')
import acolite as ac

Re: Query and download PACE or VIIRS data from EarthData

Posted: Wed May 01, 2024 5:08 am
by quinten
This post shows some examples of query and download of PACE_OCI data.

You can query based on a sensor, date and location. Currently only querying for a single lon/lat point is supported. This function will return the urls and scene names. Note that start_date and end_date can be specified with/without time. If you specify start_date and end_date without time, and provide the same date for both, the search will be performed between midnight and midnight the next day:

Code: Select all

## PACE query La Plata
sensor = 'PACE_OCI'
lon =  -57.55411154916672
lat = -34.803384076441866
start_date = '2024-04-28T16:00:00'
end_date = '2024-04-28T17:00:00'

urls, scenes = ac.api.earthdata.query(sensor, lon = lon, lat = lat, 
                       start_date = start_date, end_date = end_date)
The same function can be used to download, by setting download = True and a download path. If a local copy of the file exists, the download will be skipped unless override = True. Now this function returns the local paths of the files.

Code: Select all

## PACE query La Plata 
sensor = 'PACE_OCI'
lon =  -57.55411154916672
lat = -34.803384076441866
start_date = '2024-04-28T16:00:00'
end_date = '2024-04-28T17:00:00'

## download scenes
download = True
local_directory = '../Input/LaPlata/PACE'

local_scenes = ac.api.earthdata.query(sensor, lon = lon, lat = lat, 
                       start_date = start_date, end_date = end_date,
 		      download = download, local_directory = local_directory)
If you know the scene name you can directly download the scene. This is currently only supported for PACE:

Code: Select all

## PACE download La Plata scene
sensor = 'PACE_OCI'
scene = 'PACE_OCI.20240428T163152.L1B.nc'
download = True
local_directory = '../Input/LaPlata/PACE'

local_scenes = ac.api.earthdata.query(sensor, scene = scene,
 		      download = download, local_directory = local_directory)
[Edit] I have now added support for downloading L2 data, by setting pace_oci_level = 'L2' and specifying level2_type one of AOP (default), BGC, IOP, or PAR. For example:

Code: Select all

## PACE query La Plata
sensor = 'PACE_OCI'
lon =  -57.55411154916672
lat = -34.803384076441866
start_date = '2024-04-28T16:00:00'
end_date = '2024-04-28T17:00:00'

urls, scenes = ac.api.earthdata.query(sensor, lon = lon, lat = lat, 
                       start_date = start_date, end_date = end_date, pace_oci_level = 'L2', level2_type = 'AOP')
[Edit2] Updated L2 download example from level2 = True to pace_oci_level = 'L2'. Different versions of the data download are now supported. By default pace_oci_version = 'v2.0' is used.

Re: Query and download PACE or VIIRS data from EarthData

Posted: Wed May 01, 2024 5:22 am
by quinten
This post shows some examples of query and download of VIIRS data.

VIIRS data are distributed as L1B and GEO files that can be directly processed by ACOLITE. The function will download both geometry and radiance data files for both I (375 m) and M (750 m) bands that can be used in ACOLITE processing. An individual sensor can be specified (i.e. SUOMI-NPP_VIIRS, JPSS1_VIIRS, or JPSS2_VIIRS, or their EarthData aliases VNP, VJ1, or VJ2), or a generic VIIRS sensor can be specified which will return scenes for all operational sensors. It is recommended to query per day and add daytime hours to the start_date and end_date to avoid obtaining nighttime VIIRS overpasses. Currently there is no option to query multiple days while specifying daytime hours (i.e. the query will return all overpasses between start_date and end_date).

The query function will return a list of urls and scenes. An example query for daytime data for all VIIRS sensors:

Code: Select all

## generic VIIRS query La Plata between 15 and 20 UTC
sensor = 'VIIRS'
lon =  -57.55411154916672
lat = -34.803384076441866
start_date = '2024-04-28T15:00:00'
end_date = '2024-04-28T20:00:00'

urls, scenes = ac.api.earthdata.query(sensor, lon = lon, lat = lat, 
                       start_date = start_date, end_date = end_date)
An example query for daytime data for a specific VIIRS sensor:

Code: Select all

## sensor specific VIIRS query La Plata
sensor = 'SUOMI-NPP_VIIRS'
lon =  -57.55411154916672
lat = -34.803384076441866
start_date = '2024-04-28T15:00:00'
end_date = '2024-04-28T20:00:00'

urls, scenes = ac.api.earthdata.query(sensor, lon = lon, lat = lat, 
                       start_date = start_date, end_date = end_date)
The same function can be used to download, by setting download = True and a download path. If a local copy of the file exists, the download will be skipped unless override = True. Now this function returns the local paths of the files.

An example query and download for daytime data for a specific VIIRS sensor:

Code: Select all

## sensor specific VIIRS query La Plata
sensor = 'SUOMI-NPP_VIIRS'
lon =  -57.55411154916672
lat = -34.803384076441866
start_date = '2024-04-28T15:00:00'
end_date = '2024-04-28T20:00:00'

download = True
local_directory = '../Input/LaPlata/VIIRS'

local_scenes = ac.api.earthdata.query(sensor, lon = lon, lat = lat, 
                       start_date = start_date, end_date = end_date,
                       download = download, local_directory = local_dir)
Specific scene download is currently not supported for VIIRS.