Skip to content

Instantly share code, notes, and snippets.

@rabernat
Last active March 9, 2018 16:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rabernat/e54755e7de4eb5a93cc4e7f9f903e3cc to your computer and use it in GitHub Desktop.
Save rabernat/e54755e7de4eb5a93cc4e7f9f903e3cc to your computer and use it in GitHub Desktop.
writable MDS store for dask
class writable_mds_store:
def __init__(self, prefix, iters, suffix='data', dtype='>f4'):
self.prefix = prefix
self.iters = iters
self.suffix = suffix
self.dtype = dtype
def __setitem__(self, idx, data):
# first slice should be the time index
tslice = idx[0]
# make sure it is just one single time slice
assert tslice.step is None
assert (tslice.stop - tslice.start) == 1
n = tslice.start
fname = '%s.%010d.%s' % (self.prefix, self.iters[n], self.suffix)
#print("Writing %s" % fname)
data.astype(self.dtype).tofile(fname)
# to use
# write all the data to disk
outdir = '/vega/physo/users/jb3210/offline_velocities/aviso_DUACS2014_daily_msla/div_corrected/'
uvel_store = writable_mds_store(outdir + 'uvelCorr', m.iter.values)
with ProgressBar():
m.UVEL_Psi.data.store(uvel_store)
@jklymak
Copy link

jklymak commented Jan 30, 2017

See my fork for a f.seek implimentation that is probably fragile, but works: https://gist.github.com/jklymak/282aa1fece49167af68997bdf2f95780

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment