Skip to content

Commit d78a527

Browse files
committed
Added warning to netcdf_monitor.py for mismatch in precision settings
1 parent 8d68884 commit d78a527

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

ndsl/monitor/netcdf_monitor.py

+6-15
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import os
22
from pathlib import Path
33
from typing import Any, Dict, List, Optional, Set
4+
from warnings import warn
45

56
import fsspec
67
import numpy as np
78

89
from ndsl.comm.communicator import Communicator
9-
from ndsl.dsl.typing import Float
10+
from ndsl.dsl.typing import Float, get_precision
1011
from ndsl.filesystem import get_fs
1112
from ndsl.logging import ndsl_log
1213
from ndsl.monitor.convert import to_numpy
@@ -132,20 +133,10 @@ def __init__(
132133
self._time_chunk_size = time_chunk_size
133134
self.__writer: Optional[_ChunkedNetCDFWriter] = None
134135
self._expected_vars: Optional[Set[str]] = None
135-
if precision == Float:
136-
self._transfer_type = Float
137-
elif precision == np.float32:
138-
self._transfer_type = np.float32
139-
elif precision == np.float64:
140-
if np.float32 == Float:
141-
raise ValueError(
142-
f"Cannot output float64 with PACE_FLOAT_PRECISION set to {Float}"
143-
)
144-
self._transfer_type = np.float64
145-
else:
146-
raise ValueError(
147-
"precision must be set to one of 'Float', 'float32', or 'float64"
148-
f"got {precision}"
136+
self._transfer_type = precision
137+
if self._transfer_type == np.float32 and get_precision() > 32:
138+
warn(
139+
"NetCDF save: requested 32-bit float but precision of NDSL is {get_precision()}, cast will occur with possible loss of precision"
149140
)
150141

151142
@property

0 commit comments

Comments
 (0)