Guest User

Untitled

a guest
Mar 21st, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. import os
  2. from requests import get
  3. from rasterio import open as rasopen
  4.  
  5. req = get(url, verify=False, stream=True)
  6. if req.status_code != 200:
  7. raise ValueError('Bad response from NAIP API request.')
  8. temp = os.path.join(os.getcwd(), 'temp', 'tile.tif')
  9. with open(temp, 'wb') as f:
  10. f.write(req.content)
  11. with rasopen(temp, 'r') as src:
  12. array = src.read()
  13. profile = src.profile
  14. os.remove(temp)
  15.  
  16. from xarray import open_dataset
  17.  
  18. xray = open_dataset(url)
  19. variable = 'pr' # precipitation
  20. subset = xray.loc[dict(lat=slice(north, south),
  21. lon=slice(west,east))]
  22. arr = subset.variable.values
  23.  
  24. with rasopen(url, 'r') as src:
  25. array = src.read()
Add Comment
Please, Sign In to add comment