Created
December 21, 2023 18:08
-
-
Save cboettig/f3b273b7bba875a38d4a1c8f8dd0be5a to your computer and use it in GitHub Desktop.
xarray GDAL VSI vs fsspec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xarray as xr | |
import rasterio | |
import rioxarray | |
import earthaccess | |
import os | |
from timebudget import timebudget | |
from pathlib import Path | |
# assumes we have a ~/.netrc created | |
cookies = os.path.expanduser("~/.urs_cookies") | |
Path(cookies).touch() | |
results = earthaccess.search_data( | |
short_name="MUR-JPL-L4-GLOB-v4.1", | |
temporal=("2019-01-01", "2019-01-31"), | |
) | |
data_links = [granule.data_links(access="external") for granule in results] | |
url_links = [f'{link[0]}' for link in data_links] | |
@timebudget | |
def via_gdalvsi(): | |
with rasterio.Env(GDAL_HTTP_COOKIEFILE=cookies, | |
GDAL_HTTP_COOKIEJAR=cookies, | |
GDAL_HTTP_NETRC=True): | |
ds = xr.open_mfdataset(url_links, engine = "rasterio", decode_times=False, parallel=True) | |
return(ds) | |
@timebudget | |
def via_earthaccess(): | |
files = earthaccess.open(results) | |
ds = xr.open_mfdataset(files, engine = "rasterio", decode_times=False, parallel=True) | |
return(ds) | |
# And here we go! | |
ds = via_gdalvsi() | |
ds2 = via_earthaccess() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment