Last active
March 9, 2018 16:25
-
-
Save rabernat/e54755e7de4eb5a93cc4e7f9f903e3cc to your computer and use it in GitHub Desktop.
writable MDS store for dask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
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
Hi Ryan:
This function "works" for me, but each chunk overwrites the next, so that I only get the last chunk on disk. Since
tofile
doesn't do any fancy indexing, I'm not surprised by this. If you haven't done something else, I'll work on a version that usesf.seek
andf.write
to create a file with the write gaps etc...Thanks, Jody