Skip to content

Commit

Permalink
Templating Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
tobin-ford committed Aug 1, 2024
1 parent bc0d354 commit 89fc000
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 798 deletions.
12 changes: 12 additions & 0 deletions contributors/tobin-ford.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
2024-08-01

I hereby agree to the terms of the Contributors License Agreement,
version 1.0, with MD5 checksum 46ea45f996295bdb0652333d516a6d0a.

I furthermore declare that I am authorized and able to make this
agreement and sign this declaration.

Signed,

Tobin Ford https://github.com/tobin-ford

2 changes: 2 additions & 0 deletions pvdeg/geospatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ def output_template(


# we should be able to get rid of this with the new autotemplating function and decorator
# this is helpful for users so we should move it to a section in the documenation,
# discuss with group
def template_parameters(func):
"""
Output parameters for xarray template.
Expand Down
30 changes: 30 additions & 0 deletions pvdeg/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Callable
import inspect
import math
import xarray as xr


def gid_downsampling(meta, n):
Expand Down Expand Up @@ -471,3 +472,32 @@ def tilt_azimuth_scan(
print("\r ", end="")
print("\r", end="")
return tilt_azimuth_series

def compare_templates(ds1: xr.Dataset, ds2: xr.Dataset, atol=1e-10, consider_nan_equal=True) -> bool:
"""Compare loaded datasets with "empty-like" values"""

if ds1.dims != ds2.dims:
return False

if set(ds1.coords.keys()) != set(ds2.coords.keys()):
return False

for coord in ds1.coords:
if ds1.coords[coord].dtype.kind in {'i', 'f'}:
if not np.allclose(ds1.coords[coord], ds2.coords[coord], atol=atol): # Use np.allclose for numeric coordinates
return False
elif ds1.coords[coord].dtype.kind == 'M': # datetime64
if not np.array_equal(ds1.coords[coord], ds2.coords[coord]): # Use array equality for datetime coordinates
return False
else:
if not np.array_equal(ds1.coords[coord], ds2.coords[coord]):
return False

if set(ds1.data_vars.keys()) != set(ds2.data_vars.keys()):
return False

for dim in ds1.dims:
if not ds1.indexes[dim].equals(ds2.indexes[dim]):
return False

return True
Binary file added tests/data/humidity_template.nc
Binary file not shown.
Loading

0 comments on commit 89fc000

Please sign in to comment.