How to use the xgcm.mdsxray.MemmapArrayWrapper function in xgcm

To help you get started, we’ve selected a few xgcm examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xgcm / xgcm / xgcm / mdsxray.py View on Github external
### read grid files
        for k in _grid_variables:
            dims, desc, units = _grid_variables[k]
            data = _read_and_shape_grid_data(k, dirname, endian=endian)
            if data is not None:
                self._variables[k] = Variable(
                    dims, MemmapArrayWrapper(data),
                    {'description': desc, 'units': units})
                self._dimensions.append(k)

        ## check for layers
        Nlayers = None
        for varname, dims, desc, units, data in \
                _get_layers_grid_variables(dirname, endian=endian):
            self._variables[varname] = Variable(
                    dims, MemmapArrayWrapper(data),
                    {'description': desc, 'units': units})
            self._dimensions.append(varname)
            # if there are multiple layers coordinates, they all have the same
            # size, so this works (although it is sloppy)
            if varname[-7:]=='_bounds':
                Nlayers = len(data)

        ## load metadata for all possible diagnostics
        diag_meta = _parse_available_diagnostics(
                os.path.join(dirname, 'available_diagnostics.log'),
                Nlayers=Nlayers)

        # now get variables from our iters
        if iters is not None:

            # create iteration array
github xgcm / xgcm / xgcm / mdsxray.py View on Github external
except ValueError:
                    pass

            # read data as dask arrays (should be an option)
            vardata = {}
            for k in varnames:
                vardata[k] = []
            for i in iters:
                for f in fnames:
                    try:
                        data = _read_mds(f, i, force_dict=True, endian=endian)
                        # this can screw up if the same variable appears in
                        # multiple diagnostic files
                        for k in data:
                            if k in varnames:
                                mwrap = MemmapArrayWrapper(data[k])
                                # for some reason, da.from_array does not
                                # necessarily give a unique name
                                # need to specify array name
                                myda = da.from_array(mwrap, mwrap.shape,
                                        name='%s_%010d' % (k, i))
                                vardata[k].append(myda)
                    except IOError:
                        # couldn't find the variable, remove it from the list
                        #print 'Removing %s from list (iter %g)' % (k, i)
                        varnames.remove(k)

            # final loop to create Variable objects
            for k in varnames:
                try:
                    dims, desc, units = _state_variables[k]
                except KeyError: