Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def fetch_bedmap2():
downloader = pooch.HTTPDownloader(progressbar=True)
filenames = bedmap2.fetch(
'bedmap2_tiff.zip', processor=pooch.Unzip(), downloader=downloader
)
return [f for f in filenames if os.path.splitext(f)[1] == '.tif']
if zone not in ZONES:
raise ValueError(
"Passed zone '{}' is not a valid GRAV-D zone.".format(zone)
)
blocks = tuple(b for b in ZONES[zone])
if block is not None:
if block not in BLOCKS:
raise ValueError(
"Passed block '{}' is not a valid GRAV-D block.".format(block)
)
blocks = (block,)
fnames = list(
fname
for b in blocks
for fname in REGISTRY.fetch(
"NGS_GRAVD_Block_{}_BETA1.zip".format(b), processor=Unzip()
)
)
if not load:
return fnames
frames = [_load_block_file(b, fnames) for b in blocks]
if len(frames) > 1:
frame = pd.concat(frames, ignore_index=True)
else:
frame = frames[0]
return frame
**kwargs
Extra parameters passed to the :func:`xarray.open_rasterio` function.
Returns
-------
grid : :class:`xarray.Dataset`
The loaded Bedmap2 datasets.
"""
if isinstance(datasets, str):
datasets = [datasets]
if not set(datasets).issubset(DATASETS.keys()):
raise ValueError(
"Invalid datasets: {}".format(set(datasets).difference(DATASETS.keys()))
)
fnames = REGISTRY.fetch("bedmap2_tiff.zip", processor=Unzip())
if not load:
return [get_fname(dataset, fnames) for dataset in datasets]
arrays = []
for dataset in datasets:
array = xr.open_rasterio(get_fname(dataset, fnames), chunks=chunks, **kwargs)
# Replace no data values with nans
array = array.where(array != array.nodatavals)
# Remove "band" dimension and coordinate
array = array.squeeze("band", drop=True)
array.name = dataset
array.x.attrs["units"] = "meters"
array.y.attrs["units"] = "meters"
array.attrs["long_name"] = DATASETS[dataset]["name"]
if "units" in DATASETS[dataset]:
array.attrs["units"] = DATASETS[dataset]["units"]
arrays.append(array)