MCPcopy
hub / github.com/google-deepmind/graphcast / normalize

Function normalize

graphcast/normalization.py:29–48  ·  view source on GitHub ↗

Normalize variables using the given scales and (optionally) locations.

(values: xarray.Dataset,
              scales: xarray.Dataset,
              locations: Optional[xarray.Dataset],
              )

Source from the content-addressed store, hash-verified

27
28
29def normalize(values: xarray.Dataset,
30 scales: xarray.Dataset,
31 locations: Optional[xarray.Dataset],
32 ) -> xarray.Dataset:
33 """Normalize variables using the given scales and (optionally) locations."""
34 def normalize_array(array):
35 if array.name is None:
36 raise ValueError(
37 "Can't look up normalization constants because array has no name.")
38 if locations is not None:
39 if array.name in locations:
40 array = array - locations[array.name].astype(array.dtype)
41 else:
42 logging.warning('No normalization location found for %s', array.name)
43 if array.name in scales:
44 array = array / scales[array.name].astype(array.dtype)
45 else:
46 logging.warning('No normalization scale found for %s', array.name)
47 return array
48 return xarray_tree.map_structure(normalize_array, values)
49
50
51def unnormalize(values: xarray.Dataset,

Callers 4

__call__Method · 0.85
lossMethod · 0.85
loss_and_predictionsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected