warnings.filterwarnings('ignore') account_key = os.environ.get('BLOB_ACCOUNT_KEY') gcms = [ ('CanESM5-CanOE', 'r3i1p2f1'), ('MIROC-ES2L', 'r1i1p1f2'), ('ACCESS-CM2', 'r1i1p1f1'), ('ACCESS-ESM1-5', 'r10i1p1f1'), ('MRI-ESM2-0', 'r1i1p1f1'), ('MPI-ESM1-2-LR', 'r10i1p1f1'), ] scenarios = ['ssp245', 'ssp370', 'ssp585'] website_mask = ( load.nlcd(store="az", year=2016).sel(band=[41, 42, 43, 90]).sum("band") > 0.5 ).astype("float") region_bboxes = { 'CONUS': {'x': slice(-3e6, 3e6), 'y': slice(4e6, 0)}, 'PNW': {'x': slice(-2.5e6, -1e6), 'y': slice(3.5e6, 2.4e6)}, 'Southwest': {'x': slice(-1.8e6, -0.9e6), 'y': slice(1.8e6, 0.9e6)}, 'California': {'x': slice(-2.3e6, -1.8e6), 'y': slice(2.5e6, 1.2e6)}, 'Southeast': { 'x': slice(0.6e6, 1.8e6), 'y': slice(1.6e6, 0.3e6), }, } def build_climate_cube(
print(f'[{dataset}] computing multi model mean') for scenario in scenarios: for target in targets: keys = list( filter( lambda x: x is not None, [ key if ((scenario in key) & (target in key)) else None for key in pf.columns ], )) pf[scenario + '_' + target] = pf[keys].mean(axis=1) print(f'[{dataset}] regridding predictions') nlcd = load.nlcd(store=store, year=2016, classes=[41, 42, 43, 90]) final_mask = nlcd.sum('band') final_mask.attrs['crs'] = nlcd.attrs['crs'] if 'biomass' in dataset: final_mask.values = final_mask.values * (final_mask.values > 0.5) else: final_mask.values = final_mask.values > 0.5 ds['historical'] = fit.interp(pf, final_mask, var='historical') for scenario in tqdm(scenarios): results = [] for target in targets: key = scenario + '_' + target gridded = fit.interp(pf, final_mask, var=key)
import xarray as xr from scipy.stats import binom from carbonplan_forest_risks import load from carbonplan_forest_risks.utils import get_store # flake8: noqa warnings.filterwarnings('ignore') impacts_to_process = ['fire'] account_key = os.environ.get('BLOB_ACCOUNT_KEY') rolling = True # specify the kind of mask you want to use mask_for_website = True website_mask = (load.nlcd(store="az", year=2016).sel( band=[41, 42, 43, 90]).sum("band") > 0.5).astype("float") gcms = [ ("ACCESS-CM2", "r1i1p1f1"), ("ACCESS-ESM1-5", "r10i1p1f1"), ("MRI-ESM2-0", "r1i1p1f1"), ("MIROC-ES2L", "r1i1p1f2"), ("MPI-ESM1-2-LR", "r10i1p1f1"), ("CanESM5-CanOE", "r3i1p2f1"), ] for impact in impacts_to_process: ds = xr.open_zarr( get_store( 'carbonplan-forests', 'risks/results/web/{}_cmip_high_res.zarr'.format(impact), account_key=account_key,
model = fit.hurdle(x, y, log=False) return score(x, y, model, da, method) def append(df, results): return df.append(results, ignore_index=True) coarsen = 4 tlim = (1984, 2018) variables = ["ppt", "tmean", "cwd"] store = "az" print('[stats] loading data') mask = (load.nlcd(store=store, year=2001).sel(band=[41, 42, 43, 90]).sum('band') > 0.25).astype( 'float' ) nftd = load.nftd(store=store, area_threshold=1500, coarsen=coarsen, mask=mask) climate = load.terraclim( store=store, tlim=(tlim[0] - 1, tlim[1]), coarsen=coarsen, variables=variables, mask=mask, sampling="monthly", ) mtbs = load.mtbs(store=store, coarsen=coarsen, tlim=tlim, mask=mask) prepend = climate.sel(time=slice('1983', '1983')) x, y = prepare.fire(
import os import rioxarray import xarray as xr from scipy.stats import binom from carbonplan_forest_risks import load from carbonplan_forest_risks.utils import get_store # flake8: noqa account_key = os.environ.get('BLOB_ACCOUNT_KEY') # this is only used to provide the x/y template for the insects/drought tifs grid_template = (load.nlcd(store="az", year=2016).sel( band=[41, 42, 43, 90]).sum("band") > 0.5).astype("float") # # by passing mask as none we don't mask out any values # # we'll pass a mask for when we do the webmap data prep cmip_insect_url_template = "https://carbonplan.blob.core.windows.net/carbonplan-scratch/from-bill-05-03-2021/InsectProjections_Maps_5-5-21/InsectModelProjection_{}.{}.{}-{}.{}-v18climate_05-05-2021.tif" da = load.impacts(cmip_insect_url_template, grid_template, mask=None) * 100 out_path = get_store('carbonplan-forests', 'risks/results/paper/insects_cmip_v5.zarr') ds = xr.Dataset() ds['probability'] = da.to_array(dim='vars').rename({'vars': 'gcm'}) ds.to_zarr(out_path, mode='w', consolidated=True) cmip_drought_url_template = "https://carbonplan.blob.core.windows.net/carbonplan-scratch/from-bill-05-03-2021/DroughtProjections_Maps_5-5-21/DroughtModelProjection_{}.{}.{}-{}.{}-v18climate_05-05-2021.tif" da = load.impacts(cmip_drought_url_template, grid_template, mask=None) * 100 out_path = get_store('carbonplan-forests',