MCPcopy Index your code
hub / github.com/pydata/xarray / ScipyDataStore

Class ScipyDataStore

xarray/backends/scipy_.py:210–363  ·  view source on GitHub ↗

Store for reading and writing data via scipy.io.netcdf_file. This store has the advantage of being able to be initialized with a StringIO object, allow for serialization without writing to disk. It only supports the NetCDF3 file-format.

Source from the content-addressed store, hash-verified

208
209
210class ScipyDataStore(WritableCFDataStore):
211 """Store for reading and writing data via scipy.io.netcdf_file.
212
213 This store has the advantage of being able to be initialized with a
214 StringIO object, allow for serialization without writing to disk.
215
216 It only supports the NetCDF3 file-format.
217 """
218
219 lock: Lock
220 _manager: FileManager[scipy.io.netcdf_file]
221
222 def __init__(
223 self,
224 filename_or_obj: T_PathFileOrDataStore,
225 mode: Literal["r", "w", "a"] = "r",
226 format: str | None = None,
227 group: str | None = None,
228 mmap: bool | None = None,
229 lock: Lock | Literal[False] | None = None,
230 ) -> None:
231 if group is not None:
232 raise ValueError("cannot save to a group with the scipy.io.netcdf backend")
233
234 version: Literal[1, 2]
235 if format is None or format == "NETCDF3_64BIT":
236 version = 2
237 elif format == "NETCDF3_CLASSIC":
238 version = 1
239 else:
240 raise ValueError(f"invalid format for scipy.io.netcdf backend: {format!r}")
241
242 if lock is None and mode != "r" and isinstance(filename_or_obj, str):
243 lock = get_write_lock(filename_or_obj)
244
245 self.lock = ensure_lock(lock)
246
247 if isinstance(filename_or_obj, BytesIOProxy):
248 source = filename_or_obj
249 filename_or_obj = io.BytesIO()
250 source.getvalue = filename_or_obj.getbuffer
251
252 manager: FileManager
253 if isinstance(filename_or_obj, str): # path
254 manager = CachingFileManager(
255 _open_scipy_netcdf,
256 filename_or_obj,
257 mode=mode,
258 lock=lock,
259 kwargs=dict(mmap=mmap, version=version),
260 )
261 elif hasattr(filename_or_obj, "seek"): # file object
262 # Note: checking for .seek matches the check for file objects
263 # in scipy.io.netcdf_file
264 scipy_dataset = _open_scipy_netcdf(
265 filename_or_obj, # type: ignore[arg-type] # unsupported cases are caught above
266 mode=mode,
267 mmap=mmap,

Callers 1

open_datasetMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…