Skip to content

Commit

Permalink
Merge 138944d into 909b8a7
Browse files Browse the repository at this point in the history
  • Loading branch information
raybellwaves committed Sep 26, 2020
2 parents 909b8a7 + 138944d commit 295cfb9
Show file tree
Hide file tree
Showing 72 changed files with 1,123 additions and 1,092 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Internal Changes
~~~~~~~~~~~~~~~~
- Added Python 3.7 and Python 3.8 to the CI. Use the latest version of Python 3
for development. (:issue:`21`, :pr:`189`). `Aaron Spring`_
- Lint with the latest black. (:issue:`179`, :pr:`191`). `Ray Bell`_


xskillscore v0.0.18 (2020-09-23)
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
xskillscore's contributor guidelines
[can be found in our online documentation](https://xskillscore.readthedocs.io/en/stable/contributing.html)
[can be found in our online documentation](https://xskillscore.readthedocs.io/en/stable/contributing.html)
74 changes: 37 additions & 37 deletions asv_bench/benchmarks/deterministic.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,31 @@ def make_ds(self, nmember, nx, ny):

lons = xr.DataArray(
np.linspace(0, 360, self.nx),
dims=('lon',),
attrs={'units': 'degrees east', 'long_name': 'longitude'},
dims=("lon",),
attrs={"units": "degrees east", "long_name": "longitude"},
)
lats = xr.DataArray(
np.linspace(-90, 90, self.ny),
dims=('lat',),
attrs={'units': 'degrees north', 'long_name': 'latitude'},
dims=("lat",),
attrs={"units": "degrees north", "long_name": "latitude"},
)
self.ds['tos'] = xr.DataArray(
self.ds["tos"] = xr.DataArray(
randn((self.nmember, self.nx, self.ny), frac_nan=frac_nan),
coords={'member': members, 'lon': lons, 'lat': lats},
dims=('member', 'lon', 'lat'),
name='tos',
coords={"member": members, "lon": lons, "lat": lats},
dims=("member", "lon", "lat"),
name="tos",
encoding=None,
attrs={'units': 'foo units', 'description': 'a description'},
attrs={"units": "foo units", "description": "a description"},
)
self.ds['sos'] = xr.DataArray(
self.ds["sos"] = xr.DataArray(
randn((self.nmember, self.nx, self.ny), frac_nan=frac_nan),
coords={'member': members, 'lon': lons, 'lat': lats},
dims=('member', 'lon', 'lat'),
name='sos',
coords={"member": members, "lon": lons, "lat": lats},
dims=("member", "lon", "lat"),
name="sos",
encoding=None,
attrs={'units': 'foo units', 'description': 'a description'},
attrs={"units": "foo units", "description": "a description"},
)
self.ds.attrs = {'history': 'created for xarray benchmarking'}
self.ds.attrs = {"history": "created for xarray benchmarking"}

# set nans for land sea mask
self.ds = self.ds.where(
Expand All @@ -77,17 +77,17 @@ class Compute_small(Generate):
def setup(self, *args, **kwargs):
self.make_ds(nmember, 90, 45) # 4 degree grid

@parameterized('metric', DETERMINISTIC_METRICS)
@parameterized("metric", DETERMINISTIC_METRICS)
def time_xskillscore_metric_small(self, metric):
"""Take time for xskillscore.metric."""
dim = 'member'
metric(self.ds['tos'], self.ds['sos'], dim=dim)
dim = "member"
metric(self.ds["tos"], self.ds["sos"], dim=dim)

@parameterized('metric', DETERMINISTIC_METRICS)
@parameterized("metric", DETERMINISTIC_METRICS)
def peakmem_xskillscore_metric_small(self, metric):
dim = 'member'
dim = "member"
"""Take memory peak for xskillscore.metric."""
metric(self.ds['tos'], self.ds['sos'], dim=dim)
metric(self.ds["tos"], self.ds["sos"], dim=dim)


class Compute_large(Generate):
Expand All @@ -96,22 +96,22 @@ class Compute_large(Generate):

def setup_cache(self, *args, **kwargs):
self.make_ds(nmember, large_lon_lat, large_lon_lat)
self.ds.to_netcdf('large.nc')
self.ds.to_netcdf("large.nc")

def setup(self, *args, **kwargs):
self.ds = xr.open_dataset('large.nc')
self.ds = xr.open_dataset("large.nc")

@parameterized('metric', DETERMINISTIC_METRICS)
@parameterized("metric", DETERMINISTIC_METRICS)
def time_xskillscore_metric_large(self, metric):
"""Take time for xskillscore.metric."""
dim = 'member'
metric(self.ds['tos'], self.ds['sos'], dim=dim)
dim = "member"
metric(self.ds["tos"], self.ds["sos"], dim=dim)

@parameterized('metric', DETERMINISTIC_METRICS)
@parameterized("metric", DETERMINISTIC_METRICS)
def peakmem_xskillscore_metric_large(self, metric):
dim = 'member'
dim = "member"
"""Take memory peak for xskillscore.metric."""
metric(self.ds['tos'], self.ds['sos'], dim=dim)
metric(self.ds["tos"], self.ds["sos"], dim=dim)


class Compute_large_dask(Generate):
Expand All @@ -121,19 +121,19 @@ class Compute_large_dask(Generate):
def setup_cache(self, *args, **kwargs):
requires_dask()
self.make_ds(nmember, large_lon_lat, large_lon_lat)
self.ds.to_netcdf('large.nc')
self.ds.to_netcdf("large.nc")

def setup(self, *args, **kwargs):
self.ds = xr.open_dataset('large.nc', chunks={'lon': large_lon_lat_chunksize})
self.ds = xr.open_dataset("large.nc", chunks={"lon": large_lon_lat_chunksize})

@parameterized('metric', DETERMINISTIC_METRICS)
@parameterized("metric", DETERMINISTIC_METRICS)
def time_xskillscore_metric_large_dask(self, metric):
"""Take time for xskillscore.metric."""
dim = 'member'
metric(self.ds['tos'], self.ds['sos'], dim=dim).compute()
dim = "member"
metric(self.ds["tos"], self.ds["sos"], dim=dim).compute()

@parameterized('metric', DETERMINISTIC_METRICS)
@parameterized("metric", DETERMINISTIC_METRICS)
def peakmem_xskillscore_metric_large_dask(self, metric):
dim = 'member'
dim = "member"
"""Take memory peak for xskillscore.metric."""
metric(self.ds['tos'], self.ds['sos'], dim=dim).compute()
metric(self.ds["tos"], self.ds["sos"], dim=dim).compute()
108 changes: 54 additions & 54 deletions asv_bench/benchmarks/probabilistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,33 @@ def make_ds(self, nmember, nx, ny):

lons = xr.DataArray(
np.linspace(0, 360, self.nx),
dims=('lon',),
attrs={'units': 'degrees east', 'long_name': 'longitude'},
dims=("lon",),
attrs={"units": "degrees east", "long_name": "longitude"},
)
lats = xr.DataArray(
np.linspace(-90, 90, self.ny),
dims=('lat',),
attrs={'units': 'degrees north', 'long_name': 'latitude'},
dims=("lat",),
attrs={"units": "degrees north", "long_name": "latitude"},
)
self.fct['tos'] = xr.DataArray(
self.fct["tos"] = xr.DataArray(
randn((self.nmember, self.nx, self.ny), frac_nan=frac_nan),
coords={'member': members, 'lon': lons, 'lat': lats},
dims=('member', 'lon', 'lat'),
name='tos',
coords={"member": members, "lon": lons, "lat": lats},
dims=("member", "lon", "lat"),
name="tos",
encoding=None,
attrs={'units': 'foo units', 'description': 'a description'},
attrs={"units": "foo units", "description": "a description"},
)
self.obs['tos'] = xr.DataArray(
self.obs["tos"] = xr.DataArray(
randn((self.nx, self.ny), frac_nan=frac_nan),
coords={'lon': lons, 'lat': lats},
dims=('lon', 'lat'),
name='tos',
coords={"lon": lons, "lat": lats},
dims=("lon", "lat"),
name="tos",
encoding=None,
attrs={'units': 'foo units', 'description': 'a description'},
attrs={"units": "foo units", "description": "a description"},
)

self.fct.attrs = {'history': 'created for xarray benchmarking'}
self.obs.attrs = {'history': 'created for xarray benchmarking'}
self.fct.attrs = {"history": "created for xarray benchmarking"}
self.obs.attrs = {"history": "created for xarray benchmarking"}

# set nans for land sea mask
self.fct = self.fct.where(
Expand All @@ -98,49 +98,49 @@ class Compute_small(Generate):
def setup(self, *args, **kwargs):
self.make_ds(nmember, 90, 45) # 4 degree grid

@parameterized('metric', PROBABILISTIC_METRICS)
@parameterized("metric", PROBABILISTIC_METRICS)
def time_xskillscore_probabilistic_small(self, metric):
"""Take time for xskillscore.metric."""
if metric is crps_gaussian:
mu = 0.5
sig = 0.2
metric(self.obs['tos'], mu, sig)
metric(self.obs["tos"], mu, sig)
elif metric is crps_quadrature:
if not including_crps_quadrature:
pass
else:
xmin, xmax, tol = -10, 10, 1e-6
cdf_or_dist = norm
metric(self.obs['tos'], cdf_or_dist, xmin, xmax, tol)
metric(self.obs["tos"], cdf_or_dist, xmin, xmax, tol)
elif metric is crps_ensemble:
metric(self.obs['tos'], self.fct['tos'])
metric(self.obs["tos"], self.fct["tos"])
elif metric is threshold_brier_score:
threshold = 0.5
metric(self.obs['tos'], self.fct['tos'], threshold)
metric(self.obs["tos"], self.fct["tos"], threshold)
elif metric is brier_score:
metric(self.obs['tos'] > 0.5, (self.fct['tos'] > 0.5).mean('member'))
metric(self.obs["tos"] > 0.5, (self.fct["tos"] > 0.5).mean("member"))

@parameterized('metric', PROBABILISTIC_METRICS)
@parameterized("metric", PROBABILISTIC_METRICS)
def peakmem_xskillscore_probabilistic_small(self, metric):
"""Take time for xskillscore.metric."""
if metric is crps_gaussian:
mu = 0.5
sig = 0.2
metric(self.obs['tos'], mu, sig)
metric(self.obs["tos"], mu, sig)
elif metric is crps_quadrature:
if not including_crps_quadrature:
pass
else:
xmin, xmax, tol = -10, 10, 1e-6
cdf_or_dist = norm
metric(self.obs['tos'], cdf_or_dist, xmin, xmax, tol)
metric(self.obs["tos"], cdf_or_dist, xmin, xmax, tol)
elif metric is crps_ensemble:
metric(self.obs['tos'], self.fct['tos'])
metric(self.obs["tos"], self.fct["tos"])
elif metric is threshold_brier_score:
threshold = 0.5
metric(self.obs['tos'], self.fct['tos'], threshold)
metric(self.obs["tos"], self.fct["tos"], threshold)
elif metric is brier_score:
metric(self.obs['tos'] > 0.5, (self.fct['tos'] > 0.5).mean('member'))
metric(self.obs["tos"] > 0.5, (self.fct["tos"] > 0.5).mean("member"))


class Compute_large(Generate):
Expand All @@ -150,49 +150,49 @@ class Compute_large(Generate):
def setup(self, *args, **kwargs):
self.make_ds(nmember, large_lon_lat, large_lon_lat)

@parameterized('metric', PROBABILISTIC_METRICS)
@parameterized("metric", PROBABILISTIC_METRICS)
def time_xskillscore_probabilistic_large(self, metric):
"""Take time for xskillscore.metric."""
if metric is crps_gaussian:
mu = 0.5
sig = 0.2
metric(self.obs['tos'], mu, sig)
metric(self.obs["tos"], mu, sig)
elif metric is crps_quadrature:
if not including_crps_quadrature:
pass
else:
xmin, xmax, tol = -10, 10, 1e-6
cdf_or_dist = norm
metric(self.obs['tos'], cdf_or_dist, xmin, xmax, tol)
metric(self.obs["tos"], cdf_or_dist, xmin, xmax, tol)
elif metric is crps_ensemble:
metric(self.obs['tos'], self.fct['tos'])
metric(self.obs["tos"], self.fct["tos"])
elif metric is threshold_brier_score:
threshold = 0.5
metric(self.obs['tos'], self.fct['tos'], threshold)
metric(self.obs["tos"], self.fct["tos"], threshold)
elif metric is brier_score:
metric(self.obs['tos'] > 0.5, (self.fct['tos'] > 0.5).mean('member'))
metric(self.obs["tos"] > 0.5, (self.fct["tos"] > 0.5).mean("member"))

@parameterized('metric', PROBABILISTIC_METRICS)
@parameterized("metric", PROBABILISTIC_METRICS)
def peakmem_xskillscore_probabilistic_large(self, metric):
"""Take time for xskillscore.metric."""
if metric is crps_gaussian:
mu = 0.5
sig = 0.2
metric(self.obs['tos'], mu, sig)
metric(self.obs["tos"], mu, sig)
elif metric is crps_quadrature:
if not including_crps_quadrature:
pass
else:
xmin, xmax, tol = -10, 10, 1e-6
cdf_or_dist = norm
metric(self.obs['tos'], cdf_or_dist, xmin, xmax, tol)
metric(self.obs["tos"], cdf_or_dist, xmin, xmax, tol)
elif metric is crps_ensemble:
metric(self.obs['tos'], self.fct['tos'])
metric(self.obs["tos"], self.fct["tos"])
elif metric is threshold_brier_score:
threshold = 0.5
metric(self.obs['tos'], self.fct['tos'], threshold)
metric(self.obs["tos"], self.fct["tos"], threshold)
elif metric is brier_score:
metric(self.obs['tos'] > 0.5, (self.fct['tos'] > 0.5).mean('member'))
metric(self.obs["tos"] > 0.5, (self.fct["tos"] > 0.5).mean("member"))


class Compute_large_dask(Generate):
Expand All @@ -203,56 +203,56 @@ def setup(self, *args, **kwargs):
requires_dask()
self.make_ds(nmember, large_lon_lat, large_lon_lat)
self.obs = self.obs.chunk(
{'lon': large_lon_lat_chunksize, 'lat': large_lon_lat_chunksize}
{"lon": large_lon_lat_chunksize, "lat": large_lon_lat_chunksize}
)
self.fct = self.fct.chunk(
{'lon': large_lon_lat_chunksize, 'lat': large_lon_lat_chunksize}
{"lon": large_lon_lat_chunksize, "lat": large_lon_lat_chunksize}
)

@parameterized('metric', PROBABILISTIC_METRICS)
@parameterized("metric", PROBABILISTIC_METRICS)
def time_xskillscore_probabilistic_large_dask(self, metric):
"""Take time for xskillscore.metric."""
if metric is crps_gaussian:
mu = 0.5
sig = 0.2
metric(self.obs['tos'], mu, sig).compute()
metric(self.obs["tos"], mu, sig).compute()
elif metric is crps_quadrature:
if not including_crps_quadrature:
pass
else:
xmin, xmax, tol = -10, 10, 1e-6
cdf_or_dist = norm
metric(self.obs['tos'], cdf_or_dist, xmin, xmax, tol).compute()
metric(self.obs["tos"], cdf_or_dist, xmin, xmax, tol).compute()
elif metric is crps_ensemble:
metric(self.obs['tos'], self.fct['tos']).compute()
metric(self.obs["tos"], self.fct["tos"]).compute()
elif metric is threshold_brier_score:
threshold = 0.5
metric(self.obs['tos'], self.fct['tos'], threshold).compute()
metric(self.obs["tos"], self.fct["tos"], threshold).compute()
elif metric is brier_score:
metric(
self.obs['tos'] > 0.5, (self.fct['tos'] > 0.5).mean('member')
self.obs["tos"] > 0.5, (self.fct["tos"] > 0.5).mean("member")
).compute()

@parameterized('metric', PROBABILISTIC_METRICS)
@parameterized("metric", PROBABILISTIC_METRICS)
def peakmem_xskillscore_probabilistic_large_dask(self, metric):
"""Take time for xskillscore.metric."""
if metric is crps_gaussian:
mu = 0.5
sig = 0.2
metric(self.obs['tos'], mu, sig).compute()
metric(self.obs["tos"], mu, sig).compute()
elif metric is crps_quadrature:
if not including_crps_quadrature:
pass
else:
xmin, xmax, tol = -10, 10, 1e-6
cdf_or_dist = norm
metric(self.obs['tos'], cdf_or_dist, xmin, xmax, tol).compute()
metric(self.obs["tos"], cdf_or_dist, xmin, xmax, tol).compute()
elif metric is crps_ensemble:
metric(self.obs['tos'], self.fct['tos']).compute()
metric(self.obs["tos"], self.fct["tos"]).compute()
elif metric is threshold_brier_score:
threshold = 0.5
metric(self.obs['tos'], self.fct['tos'], threshold).compute()
metric(self.obs["tos"], self.fct["tos"], threshold).compute()
elif metric is brier_score:
metric(
self.obs['tos'] > 0.5, (self.fct['tos'] > 0.5).mean('member')
self.obs["tos"] > 0.5, (self.fct["tos"] > 0.5).mean("member")
).compute()

0 comments on commit 295cfb9

Please sign in to comment.