This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### This works ##### | |
FILEPATTERN = '...' | |
def func(ds): | |
var = next(var for var in ds) | |
fp = ds[var].encoding['source'] | |
coordds = ds.assign_coords(path=fp) | |
dimds = coordds.expand_dims('path') | |
return dimds | |
fs = fsspec.filesystem('gs') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from yaml import load, dump, Loader | |
fp = '/Users/emile/Desktop/testyaml.yaml' | |
out = { | |
'a': 1 | |
} | |
with open(fp, 'w') as f: | |
dump(out, f) | |
with open(fp, 'r') as f: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xarray as xr | |
import numpy as np | |
### Fake data ### | |
def spatio_temporal_gcm_factory( | |
x=np.random.rand(1, 361, 721), | |
start_date="1995-01-01", | |
lat=np.arange(-90, 90.5, 0.5), | |
lon=np.arange(-180, 180.5, 0.5), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def censor(x): | |
if x < 1: | |
return np.random.uniform(low=0.5, high=1) | |
else: | |
return x | |
vcensor = np.vectorize(censor) | |
ds_corrected = xr.apply_ufunc(vcensor, ds, dask='parallelized') # rather, should we load the data before hand ? | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import xarray as xr | |
from xclim import sdba | |
def _datafactory( | |
x, start_time="1950-01-01", variable_name="fakevariable", lon=1.0, lat=1.0 | |
): | |
"""Populate xr.Dataset with synthetic data for testing""" | |
start_time = str(start_time) | |
if x.ndim != 1: |
NewerOlder