Skip to content

Commit

Permalink
Merge pull request #277 from observingClouds/fix_276
Browse files Browse the repository at this point in the history
adjust tests to new xarray cfscale return dtype algorithm
  • Loading branch information
observingClouds authored Apr 6, 2024
2 parents c7a8c6a + 5203675 commit 876a3d1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions tests/test_bitround.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,26 @@ def test_bitround_along_dim(air_temperature):
ds, info_per_bit, dim="lon", inflevels=[1.0, 0.9999, 0.99, 0.975]
)

assert ds_bitrounded_along_lon.air.dtype == "float32"
assert ds_bitrounded_along_lon.air.dtype == "float64"
assert ds_bitrounded_along_lon.lon.size == ds.lon.size
assert ds_bitrounded_along_lon.lat.size == ds.lat.size
assert ds_bitrounded_along_lon.time.size == ds.time.size
assert ds.air.values.dtype == ds_bitrounded_along_lon.air.values.dtype

assert (ds - ds_bitrounded_along_lon).air.mean() < 0.001
assert (ds - ds_bitrounded_along_lon).air.mean() < 0.01

# test for keepbits
ds_bitrounded_along_lon = bi.bitround_along_dim(
ds, info_per_bit, dim="lon", inflevels=None, keepbits=2
)

assert ds_bitrounded_along_lon.air.dtype == "float32"
assert ds_bitrounded_along_lon.air.dtype == "float64"
assert ds_bitrounded_along_lon.lon.size == ds.lon.size
assert ds_bitrounded_along_lon.lat.size == ds.lat.size
assert ds_bitrounded_along_lon.time.size == ds.time.size
assert ds.air.values.dtype == ds_bitrounded_along_lon.air.values.dtype

assert (ds - ds_bitrounded_along_lon).air.mean() < 0.001
assert (ds - ds_bitrounded_along_lon).air.mean() < 0.01

# Test error when both keepbits and inflevels are provided
with pytest.raises(ValueError):
Expand Down
24 changes: 12 additions & 12 deletions xbitinfo/xbitinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,13 @@ def get_bitinformation( # noqa: C901
-------
>>> ds = xr.tutorial.load_dataset("air_temperature")
>>> xb.get_bitinformation(ds, dim="lon") # doctest: +ELLIPSIS
<xarray.Dataset> Size: 652B
Dimensions: (bitfloat32: 32)
<xarray.Dataset> Size: 1kB
Dimensions: (bitfloat64: 64)
Coordinates:
* bitfloat32 (bitfloat32) <U3 384B '±' 'e1' 'e2' 'e3' ... 'm21' 'm22' 'm23'
* bitfloat64 (bitfloat64) <U3 768B '±' 'e1' 'e2' 'e3' ... 'm50' 'm51' 'm52'
dim <U3 12B 'lon'
Data variables:
air (bitfloat32) float64 256B 0.0 0.0 0.0 ... 3.953e-05 0.0006889
air (bitfloat64) float64 512B 0.0 0.0 0.0 ... 0.002847 0.0 0.0005092
Attributes:
xbitinfo_description: bitinformation calculated by xbitinfo.get_bit...
python_repository: https://github.com/observingClouds/xbitinfo
Expand All @@ -167,13 +167,13 @@ def get_bitinformation( # noqa: C901
xbitinfo_version: ...
BitInformation.jl_version: ...
>>> xb.get_bitinformation(ds)
<xarray.Dataset> Size: 1kB
Dimensions: (bitfloat32: 32, dim: 3)
<xarray.Dataset> Size: 2kB
Dimensions: (bitfloat64: 64, dim: 3)
Coordinates:
* bitfloat32 (bitfloat32) <U3 384B '±' 'e1' 'e2' 'e3' ... 'm21' 'm22' 'm23'
* bitfloat64 (bitfloat64) <U3 768B '±' 'e1' 'e2' 'e3' ... 'm50' 'm51' 'm52'
* dim (dim) <U4 48B 'lat' 'lon' 'time'
Data variables:
air (dim, bitfloat32) float64 768B 0.0 0.0 ... 6.327e-06 0.0004285
air (dim, bitfloat64) float64 2kB 0.0 0.0 0.0 ... 0.0 0.0004498
Attributes:
xbitinfo_description: bitinformation calculated by xbitinfo.get_bit...
python_repository: https://github.com/observingClouds/xbitinfo
Expand Down Expand Up @@ -411,23 +411,23 @@ def get_keepbits(info_per_bit, inflevel=0.99):
dim <U3 12B 'lon'
* inflevel (inflevel) float64 8B 0.99
Data variables:
air (inflevel) int64 8B 7
air (inflevel) int64 8B 6
>>> xb.get_keepbits(info_per_bit, inflevel=0.99999999)
<xarray.Dataset> Size: 28B
Dimensions: (inflevel: 1)
Coordinates:
dim <U3 12B 'lon'
* inflevel (inflevel) float64 8B 1.0
Data variables:
air (inflevel) int64 8B 14
air (inflevel) int64 8B 7
>>> xb.get_keepbits(info_per_bit, inflevel=1.0)
<xarray.Dataset> Size: 28B
Dimensions: (inflevel: 1)
Coordinates:
dim <U3 12B 'lon'
* inflevel (inflevel) float64 8B 1.0
Data variables:
air (inflevel) int64 8B 23
air (inflevel) int64 8B 52
>>> info_per_bit = xb.get_bitinformation(ds)
>>> xb.get_keepbits(info_per_bit)
<xarray.Dataset> Size: 80B
Expand All @@ -436,7 +436,7 @@ def get_keepbits(info_per_bit, inflevel=0.99):
* dim (dim) <U4 48B 'lat' 'lon' 'time'
* inflevel (inflevel) float64 8B 0.99
Data variables:
air (dim, inflevel) int64 24B 5 7 6
air (dim, inflevel) int64 24B 5 6 6
"""
if not isinstance(inflevel, list):
inflevel = [inflevel]
Expand Down

0 comments on commit 876a3d1

Please sign in to comment.