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

Class ArrayWriter

xarray/backends/common.py:390–432  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

388
389
390class ArrayWriter:
391 __slots__ = ("lock", "regions", "sources", "targets")
392
393 def __init__(self, lock=None):
394 self.sources = []
395 self.targets = []
396 self.regions = []
397 self.lock = lock
398
399 def add(self, source, target, region=None):
400 if is_chunked_array(source):
401 self.sources.append(source)
402 self.targets.append(target)
403 self.regions.append(region)
404 elif region:
405 target[region] = source
406 else:
407 target[...] = source
408
409 def sync(self, compute=True, chunkmanager_store_kwargs=None):
410 if self.sources:
411 chunkmanager = get_chunked_array_type(*self.sources)
412
413 # TODO: consider wrapping targets with dask.delayed, if this makes
414 # for any discernible difference in performance, e.g.,
415 # targets = [dask.delayed(t) for t in self.targets]
416
417 if chunkmanager_store_kwargs is None:
418 chunkmanager_store_kwargs = {}
419
420 delayed_store = chunkmanager.store(
421 self.sources,
422 self.targets,
423 lock=self.lock,
424 compute=compute,
425 flush=True,
426 regions=self.regions,
427 **chunkmanager_store_kwargs,
428 )
429 self.sources = []
430 self.targets = []
431 self.regions = []
432 return delayed_store
433
434
435class AbstractWritableDataStore(AbstractDataStore):

Callers 6

to_netcdfFunction · 0.90
dump_to_storeFunction · 0.90
to_zarrFunction · 0.90
_datatree_to_netcdfFunction · 0.90
_datatree_to_zarrFunction · 0.90
storeMethod · 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…