Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- from requests import get
- from rasterio import open as rasopen
- req = get(url, verify=False, stream=True)
- if req.status_code != 200:
- raise ValueError('Bad response from NAIP API request.')
- temp = os.path.join(os.getcwd(), 'temp', 'tile.tif')
- with open(temp, 'wb') as f:
- f.write(req.content)
- with rasopen(temp, 'r') as src:
- array = src.read()
- profile = src.profile
- os.remove(temp)
- from xarray import open_dataset
- xray = open_dataset(url)
- variable = 'pr' # precipitation
- subset = xray.loc[dict(lat=slice(north, south),
- lon=slice(west,east))]
- arr = subset.variable.values
- with rasopen(url, 'r') as src:
- array = src.read()
Add Comment
Please, Sign In to add comment