#!/usr/bin/env python # coding: utf-8 # In[1]: from datetime import datetime import dask.diagnostics import rioxarray import xarray as xr import numpy as np import pandas as pd import geopandas as gpd #import geojson import json from datetime import datetime from shapely.geometry import mapping #import zarr import netCDF4 import os import lxml get_ipython().run_line_magic('matplotlib', 'inline') import sys import dask import datacube import matplotlib.pyplot as plt from dask.distributed import Client sys.path.append("../Scripts") from dea_plotting import display_map from dea_dask import create_local_dask_cluster # In[ ]: create_local_dask_cluster() # In[2]: #!conda install netCDF4 --yes os.environ['GDAL_DISABLE_READDIR_ON_OPEN']='EMPTY_DIR' #This is KEY! otherwise we send a bunch of HTTP GET requests to test for common sidecar metadata os.environ['AWS_NO_SIGN_REQUEST']='YES' #Since this is a public bucket, we don't need authentication os.environ['GDAL_MAX_RAW_BLOCK_CACHE_SIZE']='200000000' #200MB: Want this to be greater than size of uncompressed raster to overcome a 10 MB limit in the GeoTIFF driver for range request merging. os.environ['GDAL_SWATH_SIZE']='200000000' #also increase this if increasing MAX_RAW_BLOCK_CACHE_SIZE os.environ['VSI_CURL_CACHE_SIZE']='200000000' #also increase this if increasing MAX_RAW_BLOCK_CACHE_SIZE # Others? # In[3]: #!conda install lxml --yes #!conda install -c conda-forge rtree=0.9.3 --yes fixes geopandas lib spatial index dll error filelisting_netcdf = 'https://s3-ap-southeast-2.amazonaws.com/silo-open-data/annual/index.html' # In[4]: oz = xr.open_rasterio(f'https://s3-ap-southeast-2.amazonaws.com/silo-open-data/annual/rh_tmax/2020.rh_tmax.nc', chunks=(1,1024,1024)) # In[5]: oz # In[11]: with dask.diagnostics.ProgressBar(): oz = oz.where(oz > -32767.0, drop=True) # In[12]: oz.min() # In[13]: oz[74].mean().compute() # In[14]: oz[200].mean().compute() # In[15]: oz[365].plot(robust=True) # In[16]: oz[200].shape # In[17]: np.unique(oz[200].values, return_counts=True) # In[18]: oz[200].plot() # In[ ]: oz.rio.to_raster(r'humid.tif') # In[ ]: