In [1]:
import numpy as np
import xray
import os
import re
from matplotlib import pyplot as plt
%matplotlib inline

In [2]:
ddir = '/data/scratch/rpa/channel_moc/GCM/run'

In [3]:
def parse_available_diagnostics(fname):
    all_diags = {}
    with open(fname) as f:
        # will automatically skip first four header lines
        for l in f:
            c = re.split('\|',l)
            if len(c)==7 and c[0].strip()!='Num':
                key = c[1].strip()
                levs = int(c[2].strip())
                mate = c[3].strip()
                if mate: mate = int(mate) 
                code = c[4]
                units = c[5].strip()
                desc = c[6].strip()
                all_diags[key] = MITgcmDiagnosticDescription(
                    key, code, units, desc, levs, mate)
    return all_diags
            
class MITgcmDiagnosticDescription(object):
    
    def __init__(self, key, code, units=None, desc=None, levs=None, mate=None):
        self.key = key
        self.levs = levs
        self.mate = mate
        self.code = code
        self.units = units
        self.desc = desc
    
    def coords(self):
        """Parse code to determine coordinates."""
        hpoint = self.code[1]
        rpoint = self.code[8]
        rlev = self.code[9]
        xcoords = {'U': 'XG', 'V': 'XC', 'M': 'XC', 'Z': 'XG'}
        ycoords = {'U': 'YC', 'V': 'YG', 'M': 'YC', 'Z': 'YG'}
        rcoords = {'M': 'RC', 'U': 'RFu', 'L': 'RFl'}
        if rlev=='1':
            return (ycoords[hpoint], xcoords[hpoint])
        elif rlev=='R':
            return (rcoords[rpoint], ycoords[hpoint], xcoords[hpoint])
        else:
            raise ValueError("Don't know what to do with rlev = " + rlev)

In [68]:
all_diags = parse_available_diagnostics(os.path.join(ddir, 'available_diagnostics.log'))

In [71]:
diag = all_diags['UDIAG9']

In [72]:
diag.coords()


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-72-eeaf5d2f2c3f> in <module>()
----> 1 diag.coords()

<ipython-input-3-889c6ea8f91b> in coords(self)
     40             return (rcoords[rpoint], ycoords[hpoint], xcoords[hpoint])
     41         else:
---> 42             raise ValueError("Don't know what to do with rlev = " + rlev)
     43 
     44 

ValueError: Don't know what to do with rlev = L

In [5]:
print all_diags['PHIBOT'].coords()
print all_diags['PHIBOT'].code


('YC', 'XC')
SM      M1

In [6]:
def parse_meta(fname):
    flds = {}
    basename = re.match('(^\w+)', os.path.basename(fname)).groups()[0]
    flds['basename'] = basename
    with open(fname) as f:
        text = f.read()
    # split into items
    for item in re.split(';', text):
        # remove whitespace at beginning
        item = re.sub('^\s+', '', item)
        #match = re.match('(\w+) = ', item)
        match = re.match('(\w+) = (\[|\{)(.*)(\]|\})', item, re.DOTALL)
        if match:
            key, _, value, _ = match.groups()
            # remove more whitespace
            value = re.sub('^\s+', '', value)
            value = re.sub('\s+$', '', value)
            #print key,':', value
            flds[key] = value
    # now check the needed things are there
    needed_keys = ['dimList','nDims','nrecords','dataprec']
    for k in needed_keys:
        assert flds.has_key(k)
    # transform datatypes
    #print flds
    flds['nDims'] = int(flds['nDims'])
    flds['nrecords'] = int(flds['nrecords'])
    # use big endian always
    flds['dataprec'] = np.dtype(re.sub("'",'',flds['dataprec'])).newbyteorder('>')
    flds['dimList'] = [[int(h) for h in
                       re.split(',', g)] for g in
                       re.split(',\n',flds['dimList'])]
    if flds.has_key('fldList'):
        flds['fldList'] = [re.match("'*(\w+)",g).groups()[0] for g in
                           re.split("' '",flds['fldList'])]
        assert flds['nrecords'] == len(flds['fldList'])
    return flds

In [7]:
def read_mds(fname, iternum=None, use_mmap=True,
             force_dict=False, convert_big_endian=False):
    if iternum is None:
        istr = ''
    else:
        assert isinstance(iternum, int)
        istr = '.%010d' % iternum
    datafile = fname + istr + '.data'
    metafile = fname + istr + '.meta'
    
    # get metadata
    meta = parse_meta(metafile)
    # why does the .meta file contain so much repeated info?
    # just get the part we need
    # and reverse order (numpy uses C order, mds is fortran)
    shape = [g[0] for g in meta['dimList']][::-1]
    assert len(shape) == meta['nDims']
    # now add an extra for number of recs
    nrecs = meta['nrecords']
    shape.insert(0, nrecs)
    
    # load and shape data
    if use_mmap:
        d = np.memmap(datafile, meta['dataprec'], 'r')
    else:
        d = np.fromfile(datafile, meta['dataprec'])
    if convert_big_endian:
        dtnew = d.dtype.newbyteorder('=')
        d = d.astype(dtnew)
        
    d.shape = shape
    
    if nrecs == 1:
        if meta.has_key('fldList'):
            name = meta['fldList'][0]
        else:
            name = meta['basename']
        if force_dict:
            return {name: d[0]}
        else:
            return d[0]
    else:
        # need record names
        out = {}
        for n, name in enumerate(meta['fldList']):
            out[name] = d[n]
        return out

In [8]:
ds = xray.Dataset()

grid_files = ['XC','XG','YG','YG','RC','RF']
geom_files = ['DXC','DXG','DYC','DYG','DRF','DRF','RAC','RAS','RAW','RAZ','hFacC','hFacS','hFacW']

def grid_path(vname):
    return os.path.join(ddir, vname)

# 1D orthogonal dimensions
# This is valid for cartesian geometry only!
# ( and maybe spherical polar grid)
ds.coords['XC'] = ('XC', read_mds(grid_path('XC'))[0,:])
ds.coords['XG'] = ('XG', read_mds(grid_path('XG'))[0,:])
ds.coords['YC'] = ('YC', read_mds(grid_path('YC'))[:,0])
ds.coords['YG'] = ('YG', read_mds(grid_path('YG'))[:,0])
ds.coords['RC'] = ('RC', read_mds(grid_path('RC'))[:,0,0])
ds.coords['RF'] = ('RF', read_mds(grid_path('RF'))[:,0,0])
# these are for actual variables
ds.coords['RFl'] = ('RFl', read_mds(grid_path('RF'))[:-1,0,0])
ds.coords['RFu'] = ('RFu', read_mds(grid_path('RF'))[1:,0,0])

# 2D and 3D grid variables
ds.coords['RAC'] = (('YC','XC'), read_mds(grid_path('RAC')))
ds.coords['RAZ'] = (('YG','XG'), read_mds(grid_path('RAC')))
# what about RAS and RAW?

ds.coords['HFACC'] = (('RC','YC','XC'), read_mds(grid_path('hFacC')))
ds.coords['HFACS'] = (('RC','YG','XC'), read_mds(grid_path('hFacS')))
ds.coords['HFACW'] = (('RC','YC','XG'), read_mds(grid_path('hFacW')))


ds


Out[8]:
<xray.Dataset>
Dimensions:  (RC: 40, RF: 41, RFl: 40, RFu: 40, XC: 200, XG: 200, YC: 400, YG: 400)
Coordinates:
  * XC       (XC) >f4 2500.0 7500.0 12500.0 17500.0 22500.0 27500.0 32500.0 ...
  * XG       (XG) >f4 0.0 5000.0 10000.0 15000.0 20000.0 25000.0 30000.0 ...
  * YC       (YC) >f4 2500.0 7500.0 12500.0 17500.0 22500.0 27500.0 32500.0 ...
  * YG       (YG) >f4 0.0 5000.0 10000.0 15000.0 20000.0 25000.0 30000.0 ...
  * RC       (RC) >f4 -5.0 -15.0 -25.0 -36.0 -49.0 -64.0 -81.5 -102.0 -126.0 ...
  * RF       (RF) >f4 0.0 -10.0 -20.0 -30.0 -42.0 -56.0 -72.0 -91.0 -113.0 ...
  * RFl      (RFl) >f4 0.0 -10.0 -20.0 -30.0 -42.0 -56.0 -72.0 -91.0 -113.0 ...
  * RFu      (RFu) >f4 -10.0 -20.0 -30.0 -42.0 -56.0 -72.0 -91.0 -113.0 ...
    RAC      (YC, XC) >f4 2.5e+07 2.5e+07 2.5e+07 2.5e+07 2.5e+07 2.5e+07 ...
    RAZ      (YG, XG) >f4 2.5e+07 2.5e+07 2.5e+07 2.5e+07 2.5e+07 2.5e+07 ...
    HFACC    (RC, YC, XC) >f4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    HFACS    (RC, YG, XC) >f4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    HFACW    (RC, YC, XG) >f4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Data variables:
    *empty*

In [22]:
ls /data/scratch/rpa/channel_moc/GCM/run


available_diagnostics.log         STDOUT.0011
bathyFile.bin                     STDOUT.0012
channel.e25947                    STDOUT.0013
channel.e25956                    STDOUT.0014
channel.e25975                    STDOUT.0015
channel.e42286                    STDOUT.0016
channel.e44034                    STDOUT.0017
channel.e49731                    STDOUT.0018
channel.e50368                    STDOUT.0019
channel.e618856                   STDOUT.0020
channel.e618861                   STDOUT.0021
channel.e618862                   STDOUT.0022
channel.e618863                   STDOUT.0023
channel.e618865                   STDOUT.0024
channel.e618866                   STDOUT.0025
channel.e618868                   STDOUT.0026
channel.e618873                   STDOUT.0027
channel.o25947                    STDOUT.0028
channel.o25956                    STDOUT.0029
channel.o25975                    STDOUT.0030
channel.o42286                    STDOUT.0031
channel.o44034                    STDOUT.0032
channel.o49731                    STDOUT.0033
channel.o50368                    STDOUT.0034
channel.o618856                   STDOUT.0035
channel.o618861                   STDOUT.0036
channel.o618862                   STDOUT.0037
channel.o618863                   STDOUT.0038
channel.o618865                   STDOUT.0039
channel.o618866                   STDOUT.0040
channel.o618868                   STDOUT.0041
channel.o618873                   STDOUT.0042
Convtave.0000115200.data          STDOUT.0043
Convtave.0000115200.meta          STDOUT.0044
Convtave.0000345600.data          STDOUT.0045
Convtave.0000345600.meta          STDOUT.0046
Convtave.0000691200.data          STDOUT.0047
Convtave.0000691200.meta          STDOUT.0048
Convtave.0001036800.data          STDOUT.0049
Convtave.0001036800.meta          STDOUT.0050
Convtave.0001382400.data          STDOUT.0051
Convtave.0001382400.meta          STDOUT.0052
Convtave.0001728000.data          STDOUT.0053
Convtave.0001728000.meta          STDOUT.0054
data                              STDOUT.0055
data.bak                          STDOUT.0056
data.diagnostics                  STDOUT.0057
data.diagnostics.layers           STDOUT.0058
data.diagnostics.tracer           STDOUT.0059
data.kpp                          STDOUT.0060
data.layers                       STDOUT.0061
data.mnc                          STDOUT.0062
data.pkg                          STDOUT.0063
data.ptracers                     STDOUT.0064
data.ptracers.reset               STDOUT.0065
data.rbcs                         STDOUT.0066
data.rbcs.tracer                  STDOUT.0067
Depth.data                        STDOUT.0068
Depth.meta                        STDOUT.0069
DiagLAYERS-trend.0001728000.data  STDOUT.0070
DiagLAYERS-trend.0001728000.meta  STDOUT.0071
DRC.data                          STDOUT.0072
DRC.meta                          STDOUT.0073
DRF.data                          STDOUT.0074
DRF.meta                          STDOUT.0075
DXC.data                          STDOUT.0076
DXC.meta                          STDOUT.0077
DXG.data                          STDOUT.0078
DXG.meta                          STDOUT.0079
DYC.data                          STDOUT.0080
DYC.meta                          STDOUT.0081
DYG.data                          STDOUT.0082
DYG.meta                          STDOUT.0083
eedata                            STDOUT.0084
Eta.0000000000.data               STDOUT.0085
Eta.0000000000.meta               STDOUT.0086
Eta.0000115200.data               STDOUT.0087
Eta.0000115200.meta               STDOUT.0088
Eta.0000460800.data               STDOUT.0089
Eta.0000460800.meta               STDOUT.0090
Eta.0000691200.data               STDOUT.0091
Eta.0000691200.meta               STDOUT.0092
Eta.0000806400.data               STDOUT.0093
Eta.0000806400.meta               STDOUT.0094
Eta.0001036800.data               STDOUT.0095
Eta.0001036800.meta               STDOUT.0096
Eta.0001382400.data               STDOUT.0097
Eta.0001382400.meta               STDOUT.0098
Eta.0001728000.data               STDOUT.0099
Eta.0001728000.meta               STDOUT.0100
Eta2tave.0000115200.data          STDOUT.0101
Eta2tave.0000115200.meta          STDOUT.0102
Eta2tave.0000345600.data          STDOUT.0103
Eta2tave.0000345600.meta          STDOUT.0104
Eta2tave.0000691200.data          STDOUT.0105
Eta2tave.0000691200.meta          STDOUT.0106
Eta2tave.0001036800.data          STDOUT.0107
Eta2tave.0001036800.meta          STDOUT.0108
Eta2tave.0001382400.data          STDOUT.0109
Eta2tave.0001382400.meta          STDOUT.0110
Eta2tave.0001728000.data          STDOUT.0111
Eta2tave.0001728000.meta          STDOUT.0112
ETAtave.0000115200.data           STDOUT.0113
ETAtave.0000115200.meta           STDOUT.0114
ETAtave.0000345600.data           STDOUT.0115
ETAtave.0000345600.meta           STDOUT.0116
ETAtave.0000691200.data           STDOUT.0117
ETAtave.0000691200.meta           STDOUT.0118
ETAtave.0001036800.data           STDOUT.0119
ETAtave.0001036800.meta           STDOUT.0120
ETAtave.0001382400.data           STDOUT.0121
ETAtave.0001382400.meta           STDOUT.0122
ETAtave.0001728000.data           STDOUT.0123
ETAtave.0001728000.meta           STDOUT.0124
hFacC.data                        STDOUT.0125
hFacC.meta                        STDOUT.0126
hFacS.data                        STDOUT.0127
hFacS.meta                        surfQfile.bin
hFacW.data                        T.0000000000.data
hFacW.meta                        T.0000000000.meta
layers1TH.data                    T.0000115200.data
layers1TH.meta                    T.0000115200.meta
mitgcmuv*                         T.0000460800.data
mitgcmuv.mnc*                     T.0000460800.meta
mitgcmuv.mynetcdf*                T.0000691200.data
mitgcmuv.nomnc*                   T.0000691200.meta
monitor.0000000000.t001.nc        T.0000806400.data
monitor.0000460800.t001.nc        T.0000806400.meta
monitor.0000691200.t001.nc        T.0001036800.data
monitor.0001036800.t001.nc        T.0001036800.meta
monitor.0001382400.t001.nc        T.0001382400.data
monitor_grid.0000000000.t001.nc   T.0001382400.meta
monitor_grid.0000460800.t001.nc   T.0001728000.data
monitor_grid.0000691200.t001.nc   T.0001728000.meta
monitor_grid.0001036800.t001.nc   Tdiftave.0000115200.data
monitor_grid.0001382400.t001.nc   Tdiftave.0000115200.meta
PBS_run_script_yeti               Tdiftave.0000345600.data
PBS_run_script_yeti_netcdf        Tdiftave.0000345600.meta
PH.0000115200.data                Tdiftave.0000691200.data
PH.0000115200.meta                Tdiftave.0000691200.meta
PH.0000460800.data                Tdiftave.0001036800.data
PH.0000460800.meta                Tdiftave.0001036800.meta
PH.0000806400.data                Tdiftave.0001382400.data
PH.0000806400.meta                Tdiftave.0001382400.meta
PH.0001036800.data                Tdiftave.0001728000.data
PH.0001036800.meta                Tdiftave.0001728000.meta
PH.0001382400.data                Temp_init_40l.bin
PH.0001382400.meta                tFluxtave.0000115200.data
PH.0001728000.data                tFluxtave.0000115200.meta
PH.0001728000.meta                tFluxtave.0000345600.data
PhHytave.0000115200.data          tFluxtave.0000345600.meta
PhHytave.0000115200.meta          tFluxtave.0000691200.data
PhHytave.0000345600.data          tFluxtave.0000691200.meta
PhHytave.0000345600.meta          tFluxtave.0001036800.data
PhHytave.0000691200.data          tFluxtave.0001036800.meta
PhHytave.0000691200.meta          tFluxtave.0001382400.data
PhHytave.0001036800.data          tFluxtave.0001382400.meta
PhHytave.0001036800.meta          tFluxtave.0001728000.data
PhHytave.0001382400.data          tFluxtave.0001728000.meta
PhHytave.0001382400.meta          thetaClimFile_lin.bin
PhHytave.0001728000.data          tr01.bin
PhHytave.0001728000.meta          tr02.bin
PHL.0000115200.data               tr03.bin
PHL.0000115200.meta               tr04.bin
PHL.0000460800.data               tr05.bin
PHL.0000460800.meta               tr06.bin
PHL.0000806400.data               Ttave.0000115200.data
PHL.0000806400.meta               Ttave.0000115200.meta
PHL.0001036800.data               Ttave.0000345600.data
PHL.0001036800.meta               Ttave.0000345600.meta
PHL.0001382400.data               Ttave.0000691200.data
PHL.0001382400.meta               Ttave.0000691200.meta
PHL.0001728000.data               Ttave.0001036800.data
PHL.0001728000.meta               Ttave.0001036800.meta
PHL2tave.0000115200.data          Ttave.0001382400.data
PHL2tave.0000115200.meta          Ttave.0001382400.meta
PHL2tave.0000345600.data          Ttave.0001728000.data
PHL2tave.0000345600.meta          Ttave.0001728000.meta
PHL2tave.0000691200.data          TTtave.0000115200.data
PHL2tave.0000691200.meta          TTtave.0000115200.meta
PHL2tave.0001036800.data          TTtave.0000345600.data
PHL2tave.0001036800.meta          TTtave.0000345600.meta
PHL2tave.0001382400.data          TTtave.0000691200.data
PHL2tave.0001382400.meta          TTtave.0000691200.meta
PHL2tave.0001728000.data          TTtave.0001036800.data
PHL2tave.0001728000.meta          TTtave.0001036800.meta
PHLtave.0000115200.data           TTtave.0001382400.data
PHLtave.0000115200.meta           TTtave.0001382400.meta
PHLtave.0000345600.data           TTtave.0001728000.data
PHLtave.0000345600.meta           TTtave.0001728000.meta
PHLtave.0000691200.data           U.0000000000.data
PHLtave.0000691200.meta           U.0000000000.meta
PHLtave.0001036800.data           U.0000115200.data
PHLtave.0001036800.meta           U.0000115200.meta
PHLtave.0001382400.data           U.0000460800.data
PHLtave.0001382400.meta           U.0000460800.meta
PHLtave.0001728000.data           U.0000691200.data
PHLtave.0001728000.meta           U.0000691200.meta
PHrefC.data                       U.0000806400.data
PHrefC.meta                       U.0000806400.meta
PHrefF.data                       U.0001036800.data
PHrefF.meta                       U.0001036800.meta
pickup.0000115200.data            U.0001382400.data
pickup.0000115200.meta            U.0001382400.meta
pickup.0000345600.data            U.0001728000.data
pickup.0000345600.meta            U.0001728000.meta
pickup.0000691200.data            uFluxtave.0000115200.data
pickup.0000691200.meta            uFluxtave.0000115200.meta
pickup.0001036800.data            uFluxtave.0000345600.data
pickup.0001036800.meta            uFluxtave.0000345600.meta
pickup.0001382400.data            uFluxtave.0000691200.data
pickup.0001382400.meta            uFluxtave.0000691200.meta
pickup.0001728000.data            uFluxtave.0001036800.data
pickup.0001728000.meta            uFluxtave.0001036800.meta
pickup.ckptA.data                 uFluxtave.0001382400.data
pickup.ckptA.meta                 uFluxtave.0001382400.meta
pickup_somT.0000115200.data       uFluxtave.0001728000.data
pickup_somT.0000115200.meta       uFluxtave.0001728000.meta
pickup_somT.0000345600.data       UStave.0000115200.data
pickup_somT.0000345600.meta       UStave.0000115200.meta
pickup_somT.0000691200.data       UStave.0000345600.data
pickup_somT.0000691200.meta       UStave.0000345600.meta
pickup_somT.0001036800.data       UStave.0000691200.data
pickup_somT.0001036800.meta       UStave.0000691200.meta
pickup_somT.0001382400.data       UStave.0001036800.data
pickup_somT.0001382400.meta       UStave.0001036800.meta
pickup_somT.0001728000.data       UStave.0001382400.data
pickup_somT.0001728000.meta       UStave.0001382400.meta
pickup_somT.ckptA.data            UStave.0001728000.data
pickup_somT.ckptA.meta            UStave.0001728000.meta
RAC.data                          UTtave.0000115200.data
RAC.meta                          UTtave.0000115200.meta
RAS.data                          UTtave.0000345600.data
RAS.meta                          UTtave.0000345600.meta
RAW.data                          UTtave.0000691200.data
RAW.meta                          UTtave.0000691200.meta
RAZ.data                          UTtave.0001036800.data
RAZ.meta                          UTtave.0001036800.meta
RC.data                           UTtave.0001382400.data
RC.meta                           UTtave.0001382400.meta
relaxMaskFile_40l.bin             UTtave.0001728000.data
relaxMaskFile.bin                 UTtave.0001728000.meta
relaxMaskUFile.bin                UUtave.0000115200.data
relaxTfile_1000_40l.bin           UUtave.0000115200.meta
relaxTfile_1000.bin               UUtave.0000345600.data
RF.data                           UUtave.0000345600.meta
RF.meta                           UUtave.0000691200.data
RhoRef.data                       UUtave.0000691200.meta
RhoRef.meta                       UUtave.0001036800.data
S.0000000000.data                 UUtave.0001036800.meta
S.0000000000.meta                 UUtave.0001382400.data
S.0000115200.data                 UUtave.0001382400.meta
S.0000115200.meta                 UUtave.0001728000.data
S.0000460800.data                 UUtave.0001728000.meta
S.0000460800.meta                 uVeltave.0000115200.data
S.0000691200.data                 uVeltave.0000115200.meta
S.0000691200.meta                 uVeltave.0000345600.data
S.0000806400.data                 uVeltave.0000345600.meta
S.0000806400.meta                 uVeltave.0000691200.data
S.0001036800.data                 uVeltave.0000691200.meta
S.0001036800.meta                 uVeltave.0001036800.data
S.0001382400.data                 uVeltave.0001036800.meta
S.0001382400.meta                 uVeltave.0001382400.data
S.0001728000.data                 uVeltave.0001382400.meta
S.0001728000.meta                 uVeltave.0001728000.data
sFluxtave.0000115200.data         uVeltave.0001728000.meta
sFluxtave.0000115200.meta         UVtave.0000115200.data
sFluxtave.0000345600.data         UVtave.0000115200.meta
sFluxtave.0000345600.meta         UVtave.0000345600.data
sFluxtave.0000691200.data         UVtave.0000345600.meta
sFluxtave.0000691200.meta         UVtave.0000691200.data
sFluxtave.0001036800.data         UVtave.0000691200.meta
sFluxtave.0001036800.meta         UVtave.0001036800.data
sFluxtave.0001382400.data         UVtave.0001036800.meta
sFluxtave.0001382400.meta         UVtave.0001382400.data
sFluxtave.0001728000.data         UVtave.0001382400.meta
sFluxtave.0001728000.meta         UVtave.0001728000.data
SOSE.e1385821                     UVtave.0001728000.meta
SOSE.o1385821                     V.0000000000.data
Stave.0000115200.data             V.0000000000.meta
Stave.0000115200.meta             V.0000115200.data
Stave.0000345600.data             V.0000115200.meta
Stave.0000345600.meta             V.0000460800.data
Stave.0000691200.data             V.0000460800.meta
Stave.0000691200.meta             V.0000691200.data
Stave.0001036800.data             V.0000691200.meta
Stave.0001036800.meta             V.0000806400.data
Stave.0001382400.data             V.0000806400.meta
Stave.0001382400.meta             V.0001036800.data
Stave.0001728000.data             V.0001036800.meta
Stave.0001728000.meta             V.0001382400.data
STDERR.0000                       V.0001382400.meta
STDERR.0001                       V.0001728000.data
STDERR.0002                       V.0001728000.meta
STDERR.0003                       vFluxtave.0000115200.data
STDERR.0004                       vFluxtave.0000115200.meta
STDERR.0005                       vFluxtave.0000345600.data
STDERR.0006                       vFluxtave.0000345600.meta
STDERR.0007                       vFluxtave.0000691200.data
STDERR.0008                       vFluxtave.0000691200.meta
STDERR.0009                       vFluxtave.0001036800.data
STDERR.0010                       vFluxtave.0001036800.meta
STDERR.0011                       vFluxtave.0001382400.data
STDERR.0012                       vFluxtave.0001382400.meta
STDERR.0013                       vFluxtave.0001728000.data
STDERR.0014                       vFluxtave.0001728000.meta
STDERR.0015                       VStave.0000115200.data
STDERR.0016                       VStave.0000115200.meta
STDERR.0017                       VStave.0000345600.data
STDERR.0018                       VStave.0000345600.meta
STDERR.0019                       VStave.0000691200.data
STDERR.0020                       VStave.0000691200.meta
STDERR.0021                       VStave.0001036800.data
STDERR.0022                       VStave.0001036800.meta
STDERR.0023                       VStave.0001382400.data
STDERR.0024                       VStave.0001382400.meta
STDERR.0025                       VStave.0001728000.data
STDERR.0026                       VStave.0001728000.meta
STDERR.0027                       VTtave.0000115200.data
STDERR.0028                       VTtave.0000115200.meta
STDERR.0029                       VTtave.0000345600.data
STDERR.0030                       VTtave.0000345600.meta
STDERR.0031                       VTtave.0000691200.data
STDERR.0032                       VTtave.0000691200.meta
STDERR.0033                       VTtave.0001036800.data
STDERR.0034                       VTtave.0001036800.meta
STDERR.0035                       VTtave.0001382400.data
STDERR.0036                       VTtave.0001382400.meta
STDERR.0037                       VTtave.0001728000.data
STDERR.0038                       VTtave.0001728000.meta
STDERR.0039                       vVeltave.0000115200.data
STDERR.0040                       vVeltave.0000115200.meta
STDERR.0041                       vVeltave.0000345600.data
STDERR.0042                       vVeltave.0000345600.meta
STDERR.0043                       vVeltave.0000691200.data
STDERR.0044                       vVeltave.0000691200.meta
STDERR.0045                       vVeltave.0001036800.data
STDERR.0046                       vVeltave.0001036800.meta
STDERR.0047                       vVeltave.0001382400.data
STDERR.0048                       vVeltave.0001382400.meta
STDERR.0049                       vVeltave.0001728000.data
STDERR.0050                       vVeltave.0001728000.meta
STDERR.0051                       VVtave.0000115200.data
STDERR.0052                       VVtave.0000115200.meta
STDERR.0053                       VVtave.0000345600.data
STDERR.0054                       VVtave.0000345600.meta
STDERR.0055                       VVtave.0000691200.data
STDERR.0056                       VVtave.0000691200.meta
STDERR.0057                       VVtave.0001036800.data
STDERR.0058                       VVtave.0001036800.meta
STDERR.0059                       VVtave.0001382400.data
STDERR.0060                       VVtave.0001382400.meta
STDERR.0061                       VVtave.0001728000.data
STDERR.0062                       VVtave.0001728000.meta
STDERR.0063                       W.0000000000.data
STDERR.0064                       W.0000000000.meta
STDERR.0065                       W.0000115200.data
STDERR.0066                       W.0000115200.meta
STDERR.0067                       W.0000460800.data
STDERR.0068                       W.0000460800.meta
STDERR.0069                       W.0000691200.data
STDERR.0070                       W.0000691200.meta
STDERR.0071                       W.0000806400.data
STDERR.0072                       W.0000806400.meta
STDERR.0073                       W.0001036800.data
STDERR.0074                       W.0001036800.meta
STDERR.0075                       W.0001382400.data
STDERR.0076                       W.0001382400.meta
STDERR.0077                       W.0001728000.data
STDERR.0078                       W.0001728000.meta
STDERR.0079                       WStave.0000115200.data
STDERR.0080                       WStave.0000115200.meta
STDERR.0081                       WStave.0000345600.data
STDERR.0082                       WStave.0000345600.meta
STDERR.0083                       WStave.0000691200.data
STDERR.0084                       WStave.0000691200.meta
STDERR.0085                       WStave.0001036800.data
STDERR.0086                       WStave.0001036800.meta
STDERR.0087                       WStave.0001382400.data
STDERR.0088                       WStave.0001382400.meta
STDERR.0089                       WStave.0001728000.data
STDERR.0090                       WStave.0001728000.meta
STDERR.0091                       WTtave.0000115200.data
STDERR.0092                       WTtave.0000115200.meta
STDERR.0093                       WTtave.0000345600.data
STDERR.0094                       WTtave.0000345600.meta
STDERR.0095                       WTtave.0000691200.data
STDERR.0096                       WTtave.0000691200.meta
STDERR.0097                       WTtave.0001036800.data
STDERR.0098                       WTtave.0001036800.meta
STDERR.0099                       WTtave.0001382400.data
STDERR.0100                       WTtave.0001382400.meta
STDERR.0101                       WTtave.0001728000.data
STDERR.0102                       WTtave.0001728000.meta
STDERR.0103                       wVeltave.0000115200.data
STDERR.0104                       wVeltave.0000115200.meta
STDERR.0105                       wVeltave.0000345600.data
STDERR.0106                       wVeltave.0000345600.meta
STDERR.0107                       wVeltave.0000691200.data
STDERR.0108                       wVeltave.0000691200.meta
STDERR.0109                       wVeltave.0001036800.data
STDERR.0110                       wVeltave.0001036800.meta
STDERR.0111                       wVeltave.0001382400.data
STDERR.0112                       wVeltave.0001382400.meta
STDERR.0113                       wVeltave.0001728000.data
STDERR.0114                       wVeltave.0001728000.meta
STDERR.0115                       XC.data
STDERR.0116                       XC.meta
STDERR.0117                       XG.data
STDERR.0118                       XG.meta
STDERR.0119                       YC.data
STDERR.0120                       YC.meta
STDERR.0121                       YG.data
STDERR.0122                       YG.meta
STDERR.0123                       zonalWindFile_tau-0.050.bin
STDERR.0124                       zonalWindFile_tau-0.05.bin
STDERR.0125                       zonalWindFile_tau-0.100.bin
STDERR.0126                       zonalWindFile_tau-0.10.bin
STDERR.0127                       zonalWindFile_tau-0.125.bin
STDOUT.0000                       zonalWindFile_tau-0.150.bin
STDOUT.0001                       zonalWindFile_tau-0.15.bin
STDOUT.0002                       zonalWindFile_tau-0.175.bin
STDOUT.0003                       zonalWindFile_tau-0.200.bin
STDOUT.0004                       zonalWindFile_tau-0.20.bin
STDOUT.0005                       zonalWindFile_tau-0.225.bin
STDOUT.0006                       zonalWindFile_tau-0.250.bin
STDOUT.0007                       zonalWindFile_tau-0.275.bin
STDOUT.0008                       zonalWindFile_tau-0.300.bin
STDOUT.0009                       zonalWindFile_tau-0.400.bin
STDOUT.0010

Diagnostic Parsing Array

Array Value Description
1 S Scalar Diagnostic
U U-vector component Diagnostic
V V-vector component Diagnostic
2 U C-Grid U-Point
V C-Grid V-Point
M C-Grid Mass Point
Z C-Grid Vorticity (Corner) Point
3 Used for Level Integrated output: cumulate levels
r same but cumulate product by model level thickness
R same but cumulate product by hFac & level thickness
4 P Positive Definite Diagnostic
5 C with Counter array
P post-processed (not filled up) from other diags
D Disabled Diagnostic for output
6-8 retired, formerly: 3-digit mate number
9 U model-level plus 1/2
M model-level middle
L model-level minus 1/2
10 0 levels = 0
1 levels = 1
R levels = Nr
L levels = MAX(Nr,NrPhys)
M levels = MAX(Nr,NrPhys) - 1
G levels = Ground_level Number
I levels = sea-Ice_level Number
X free levels option (need to be set explicitly)

In [9]:
state_vars = {
    'U': MITgcmDiagnosticDescription(
         'U', 'UUR     MR', 'm/s', 'Zonal Component of Velocity (m/s)'),
    'V': MITgcmDiagnosticDescription(
         'V', 'VVR     MR', 'm/s', 'Meridional Component of Velocity (m/s)'),
    'W': MITgcmDiagnosticDescription(
         'W', 'WM      LR', 'm/s', 'Vertical Component of Velocity (r_units/s)'),
    'T': MITgcmDiagnosticDescription(
         'T', 'SMR     MR', 'degC', 'Potential Temperature'),
    'S': MITgcmDiagnosticDescription(
         'S', 'SMR     MR', 'psu', 'Salinity'),
    'PH': MITgcmDiagnosticDescription(
          'PH', 'SMR     MR', 'm^2/s^2', 'Hydrostatic Pressure Pot.(p/rho) Anomaly'),
    'PHL': MITgcmDiagnosticDescription(
          'PHL', 'SM      M1', 'm^2/s^2', 'Bottom Pressure Pot.(p/rho) Anomaly'),
    'Eta': MITgcmDiagnosticDescription(
          'Eta', 'SM      M1', 'm', 'Surface Height Anomaly'),
}

In [10]:
iternum = 1728000
for k, v in state_vars.iteritems():
    data = read_mds(grid_path(k), iternum)
    ds[k] = (v.coords(), data)
    ds[k].attrs = {'description': v.desc, 'units': v.units}

In [11]:
ds


Out[11]:
<xray.Dataset>
Dimensions:  (RC: 40, RF: 41, RFl: 40, RFu: 40, XC: 200, XG: 200, YC: 400, YG: 400)
Coordinates:
  * XC       (XC) >f4 2500.0 7500.0 12500.0 17500.0 22500.0 27500.0 32500.0 ...
  * XG       (XG) >f4 0.0 5000.0 10000.0 15000.0 20000.0 25000.0 30000.0 ...
  * YC       (YC) >f4 2500.0 7500.0 12500.0 17500.0 22500.0 27500.0 32500.0 ...
  * YG       (YG) >f4 0.0 5000.0 10000.0 15000.0 20000.0 25000.0 30000.0 ...
  * RC       (RC) >f4 -5.0 -15.0 -25.0 -36.0 -49.0 -64.0 -81.5 -102.0 -126.0 ...
  * RF       (RF) >f4 0.0 -10.0 -20.0 -30.0 -42.0 -56.0 -72.0 -91.0 -113.0 ...
  * RFl      (RFl) >f4 0.0 -10.0 -20.0 -30.0 -42.0 -56.0 -72.0 -91.0 -113.0 ...
  * RFu      (RFu) >f4 -10.0 -20.0 -30.0 -42.0 -56.0 -72.0 -91.0 -113.0 ...
    RAC      (YC, XC) >f4 2.5e+07 2.5e+07 2.5e+07 2.5e+07 2.5e+07 2.5e+07 ...
    RAZ      (YG, XG) >f4 2.5e+07 2.5e+07 2.5e+07 2.5e+07 2.5e+07 2.5e+07 ...
    HFACC    (RC, YC, XC) >f4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    HFACS    (RC, YG, XC) >f4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    HFACW    (RC, YC, XG) >f4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Data variables:
    S        (RC, YC, XC) >f4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    Eta      (YC, XC) >f4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    U        (RC, YC, XG) >f4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    T        (RC, YC, XC) >f4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    W        (RFl, YC, XC) >f4 -0.0 -0.0 -0.0 -0.0 -0.0 -0.0 -0.0 -0.0 -0.0 ...
    V        (RC, YG, XC) >f4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    PH       (RC, YC, XC) >f4 0.07848 0.07848 0.07848 0.07848 0.07848 ...
    PHL      (YC, XC) >f4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...

Time-average variables

Convtave
Eta2tave
ETAtave
PhHytave
PHL2tave
PHLtave
sFluxtave
Stave
Tdiftave
tFluxtave
Ttave
TTtave
uFluxtave
UStave
UTtave
UUtave
uVeltave
UVtave
vFluxtave
VStave
VTtave
vVeltave
VVtave
WStave
WTtave
wVeltave

In [26]:
ds['T'] * ds['PH']


Out[26]:
<xray.DataArray (RC: 40, YC: 400, XC: 200)>
array([[[  0.00000000e+00,   0.00000000e+00,   0.00000000e+00, ...,
           0.00000000e+00,   0.00000000e+00,   0.00000000e+00],
        [ -4.77954578e+00,  -4.76554441e+00,  -4.78610754e+00, ...,
          -4.81507158e+00,  -4.79722786e+00,  -4.78228283e+00],
        [ -4.84008884e+00,  -4.74809980e+00,  -4.76202965e+00, ...,
          -7.01163149e+00,  -6.23767376e+00,  -5.15652132e+00],
        ..., 
        [  7.88622284e+01,   7.88518372e+01,   7.88433609e+01, ...,
           7.89076462e+01,   7.88900146e+01,   7.88750000e+01],
        [  7.90084534e+01,   7.90063934e+01,   7.90049820e+01, ...,
           7.90169601e+01,   7.90140305e+01,   7.90109100e+01],
        [  0.00000000e+00,   0.00000000e+00,   0.00000000e+00, ...,
           0.00000000e+00,   0.00000000e+00,   0.00000000e+00]],

       [[  0.00000000e+00,   0.00000000e+00,   0.00000000e+00, ...,
           0.00000000e+00,   0.00000000e+00,   0.00000000e+00],
        [ -4.70402813e+00,  -4.69037580e+00,  -4.71059179e+00, ...,
          -4.73656559e+00,  -4.72162533e+00,  -4.70718622e+00],
        [ -4.76395369e+00,  -4.67326212e+00,  -4.68685198e+00, ...,
          -6.87989426e+00,  -6.11580706e+00,  -5.06198263e+00],
        ..., 
        [  7.88372421e+01,   7.88263168e+01,   7.88171844e+01, ...,
           7.88823013e+01,   7.88654175e+01,   7.88503799e+01],
        [  7.89598999e+01,   7.89579163e+01,   7.89564590e+01, ...,
           7.89680939e+01,   7.89652023e+01,   7.89622726e+01],
        [  0.00000000e+00,   0.00000000e+00,   0.00000000e+00, ...,
           0.00000000e+00,   0.00000000e+00,   0.00000000e+00]],

       [[  0.00000000e+00,   0.00000000e+00,   0.00000000e+00, ...,
           0.00000000e+00,   0.00000000e+00,   0.00000000e+00],
        [ -4.62617254e+00,  -4.61280870e+00,  -4.63270998e+00, ...,
          -4.65684462e+00,  -4.64363575e+00,  -4.62971544e+00],
        [ -4.68478870e+00,  -4.59596825e+00,  -4.60926914e+00, ...,
          -6.71431398e+00,  -5.98041058e+00,  -4.97413731e+00],
        ..., 
        [  7.87436752e+01,   7.87318573e+01,   7.87223969e+01, ...,
           7.87905731e+01,   7.87739105e+01,   7.87579041e+01],
        [  7.88031845e+01,   7.88010178e+01,   7.87989273e+01, ...,
           7.88122406e+01,   7.88087616e+01,   7.88057327e+01],
        [  0.00000000e+00,   0.00000000e+00,   0.00000000e+00, ...,
           0.00000000e+00,   0.00000000e+00,   0.00000000e+00]],

       ..., 
       [[  0.00000000e+00,   0.00000000e+00,   0.00000000e+00, ...,
           0.00000000e+00,   0.00000000e+00,   0.00000000e+00],
        [ -5.49522758e-01,  -5.49538314e-01,  -5.49297988e-01, ...,
          -5.48723638e-01,  -5.49084425e-01,  -5.49357951e-01],
        [ -5.49706221e-01,  -5.49396753e-01,  -5.49250007e-01, ...,
          -5.50280750e-01,  -5.50223410e-01,  -5.50021589e-01],
        ..., 
        [  1.27322543e+00,   1.28011799e+00,   1.28743327e+00, ...,
           1.25563633e+00,   1.26098597e+00,   1.26683569e+00],
        [  1.22055733e+00,   1.23105276e+00,   1.24242187e+00, ...,
           1.19352865e+00,   1.20180440e+00,   1.21079826e+00],
        [  0.00000000e+00,   0.00000000e+00,   0.00000000e+00, ...,
           0.00000000e+00,   0.00000000e+00,   0.00000000e+00]],

       [[  0.00000000e+00,   0.00000000e+00,   0.00000000e+00, ...,
           0.00000000e+00,   0.00000000e+00,   0.00000000e+00],
        [ -5.87408245e-01,  -5.87776661e-01,  -5.88092566e-01, ...,
          -5.86124361e-01,  -5.86576104e-01,  -5.87012768e-01],
        [ -5.87459147e-01,  -5.87311268e-01,  -5.87128162e-01, ...,
          -5.87723255e-01,  -5.87653220e-01,  -5.87562680e-01],
        ..., 
        [  1.19670361e-01,   1.28179953e-01,   1.36988804e-01, ...,
           9.60824043e-02,   1.03641696e-01,   1.11483656e-01],
        [  9.72040519e-02,   1.12956479e-01,   1.29979491e-01, ...,
           5.97366504e-02,   7.07756132e-02,   8.32114145e-02],
        [  0.00000000e+00,   0.00000000e+00,   0.00000000e+00, ...,
           0.00000000e+00,   0.00000000e+00,   0.00000000e+00]],

       [[  0.00000000e+00,   0.00000000e+00,   0.00000000e+00, ...,
           0.00000000e+00,   0.00000000e+00,   0.00000000e+00],
        [ -6.39803410e-01,  -6.39623702e-01,  -6.39999568e-01, ...,
          -6.41295969e-01,  -6.40908420e-01,  -6.40336871e-01],
        [ -6.28509998e-01,  -6.27041936e-01,  -6.26198769e-01, ...,
          -6.30635738e-01,  -6.30224049e-01,  -6.29624546e-01],
        ..., 
        [ -9.60336149e-01,  -9.57557559e-01,  -9.54341173e-01, ...,
          -9.66210485e-01,  -9.64584291e-01,  -9.62640941e-01],
        [ -9.63418245e-01,  -9.51610923e-01,  -9.40269053e-01, ...,
          -1.00342333e+00,  -9.89886761e-01,  -9.76355195e-01],
        [  0.00000000e+00,   0.00000000e+00,   0.00000000e+00, ...,
           0.00000000e+00,   0.00000000e+00,   0.00000000e+00]]], dtype=float32)
Coordinates:
    HFACC    (RC, YC, XC) >f4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
  * XC       (XC) >f4 2500.0 7500.0 12500.0 17500.0 22500.0 27500.0 32500.0 ...
  * YC       (YC) >f4 2500.0 7500.0 12500.0 17500.0 22500.0 27500.0 32500.0 ...
    RAC      (YC, XC) >f4 2.5e+07 2.5e+07 2.5e+07 2.5e+07 2.5e+07 2.5e+07 ...
  * RC       (RC) >f4 -5.0 -15.0 -25.0 -36.0 -49.0 -64.0 -81.5 -102.0 -126.0 ...

In [27]:
plt.imshow(ds['T'].mean(dim='XC'))


Out[27]:
<matplotlib.image.AxesImage at 0x7f6f1e448ed0>

In [356]:
x = xray.DataArray( np.ones(10, dtype='>f4'))
print float(x.sum()), x.data.sum()


4.60060298822e-40 10.0

In [355]:
np.ones(10)#, dtype='>4f')


Out[355]:
array([ 1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.])

In [7]:
dt = np.dtype('>f4')
dt


Out[7]:
dtype('>f4')

In [28]:
type(ds['T'].data)


Out[28]:
numpy.ndarray

In [9]:
dtnew


Out[9]:
dtype('float32')

In [30]:
import bottleneck as bn
bn.bench()


Bottleneck performance benchmark
    Bottleneck  1.0.0
    Numpy (np)  1.9.2
    Speed is NumPy time divided by Bottleneck time
    NaN means approx one-third NaNs; float64 and axis=-1 are used

                 no NaN     no NaN      NaN        NaN    
                   (10,)   (1000,1000)   (10,)   (1000,1000)
    nansum         39.8        2.7       39.5        6.6
    nanmean       151.0        3.9      151.0        8.1
    nanstd        271.8        2.8      271.5        6.7
    nanvar        257.6        2.8      256.9        6.7
    nanmin         33.1        1.0       32.9        1.4
    nanmax         33.1        1.0       32.9        2.1
    median         38.3        0.8       40.2        1.0
    nanmedian      48.2        3.8       55.3       10.9
    ss             14.8        1.3       14.8        1.3
    nanargmin      63.5        3.6       63.7        8.8
    nanargmax      64.4        3.5       64.8        9.8
    anynan         14.6        0.5       14.8       46.2
    allnan         15.1       53.4       14.7       48.6
    rankdata       50.5        1.4       51.6        2.1
    nanrankdata    64.2       32.5       58.9       46.7
    partsort        6.7        0.9        6.8        1.3
    argpartsort     3.2        0.7        3.3        0.5
    replace         8.7        1.0        8.8        1.0
    move_sum      379.2      154.0      379.2      424.0
    move_mean     911.8      174.8      941.5      552.4
    move_std     1407.5       61.8     1512.8      982.5
    move_min      273.2       22.3      278.3       50.4
    move_max      263.1       23.4      269.1      105.4
    move_median   505.1       42.4      488.5      182.0

In [282]:
import mdsxray
reload(mdsxray)


Out[282]:
<module 'mdsxray' from 'mdsxray.py'>

In [289]:
#iters = range(1036800, 2073600,345600)
iters = range(2073840, 2384880, 480)
store = mdsxray.MDSDataStore(ddir, iters, deltaT=900)
ds = xray.Dataset.load_store(store)
ds


---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-289-37822f1dbc1c> in <module>()
      1 #iters = range(1036800, 2073600,345600)
      2 iters = range(2073840, 2384880, 480)
----> 3 store = mdsxray.MDSDataStore(ddir, iters, deltaT=900)
      4 ds = xray.Dataset.load_store(store)
      5 ds

/home/rpa/mitgcm-xray/mdsxray.py in __init__(self, dirname, iters, deltaT, ignore_pickup, geometry)

/home/rpa/mitgcm-xray/mdsxray.py in _read_mds(fname, iternum, use_mmap, force_dict, convert_big_endian)

/usr/local/anaconda/lib/python2.7/site-packages/numpy/core/memmap.pyc in __new__(subtype, filename, dtype, mode, offset, shape, order)

error: [Errno 24] Too many open files

In [272]:
#ds.set_coords(dsc.variables.keys(), inplace=True)
#dsc = ds.chunk({'X': 100, 'Y':100})
#dsc


Convtave ('time', 'Zl', 'Y', 'X') (3, 40, 400, 200)
ETAtave ('time', 'Y', 'X') (3, 400, 200)
TTtave ('time', 'Z', 'Y', 'X') (3, 40, 400, 200)
vFluxtave ('time', 'Yp1', 'X') (3, 400, 200)
PhHytave ('time', 'Z', 'Y', 'X') (3, 40, 400, 200)
VVtave ('time', 'Z', 'Yp1', 'X') (3, 40, 400, 200)
S ('time', 'Z', 'Y', 'X') (3, 40, 400, 200)
uFluxtave ('time', 'Y', 'Xp1') (3, 400, 200)
UTtave ('time', 'Z', 'Y', 'Xp1') (3, 40, 400, 200)
UStave ('time', 'Z', 'Y', 'Xp1') (3, 40, 400, 200)
PHLtave ('time', 'Y', 'X') (3, 400, 200)
uVeltave ('time', 'Z', 'Y', 'Xp1') (3, 40, 400, 200)
PH ('time', 'Z', 'Y', 'X') (3, 40, 400, 200)
UVtave ('time', 'Z', 'Yp1', 'Xp1') (3, 40, 400, 200)
PHL2tave ('time', 'Y', 'X') (3, 400, 200)
sFluxtave ('time', 'Y', 'X') (3, 400, 200)
PHL ('time', 'Y', 'X') (3, 400, 200)
T ('time', 'Z', 'Y', 'X') (3, 40, 400, 200)
VTtave ('time', 'Z', 'Yp1', 'X') (3, 40, 400, 200)
U ('time', 'Z', 'Y', 'Xp1') (3, 40, 400, 200)
VStave ('time', 'Z', 'Yp1', 'X') (3, 40, 400, 200)
Eta2tave ('time', 'Y', 'X') (3, 400, 200)
Tdiftave ('time', 'Zl', 'Y', 'X') (3, 40, 400, 200)
Eta ('time', 'Y', 'X') (3, 400, 200)
vVeltave ('time', 'Z', 'Yp1', 'X') (3, 40, 400, 200)
V ('time', 'Z', 'Yp1', 'X') (3, 40, 400, 200)
UUtave ('time', 'Z', 'Y', 'Xp1') (3, 40, 400, 200)
Stave ('time', 'Z', 'Y', 'X') (3, 40, 400, 200)
W ('time', 'Zl', 'Y', 'X') (3, 40, 400, 200)
Ttave ('time', 'Z', 'Y', 'X') (3, 40, 400, 200)
wVeltave ('time', 'Zl', 'Y', 'X') (3, 40, 400, 200)
WStave ('time', 'Zl', 'Y', 'X') (3, 40, 400, 200)
tFluxtave ('time', 'Y', 'X') (3, 400, 200)
WTtave ('time', 'Zl', 'Y', 'X') (3, 40, 400, 200)
Out[272]:
<xray.Dataset>
Dimensions:    (X: 200, Xp1: 200, Y: 400, Yp1: 400, Z: 40, Zl: 40, Zp1: 41, Zu: 39, time: 3)
Coordinates:
    YC         (Y, X) >f4 2500.0 2500.0 2500.0 2500.0 2500.0 2500.0 2500.0 ...
    YG         (Yp1, Xp1) >f4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    rA         (Y, X) >f4 2.5e+07 2.5e+07 2.5e+07 2.5e+07 2.5e+07 2.5e+07 ...
  * Xp1        (Xp1) >f4 0.0 5000.0 10000.0 15000.0 20000.0 25000.0 30000.0 ...
    dxG        (Yp1, X) >f4 5000.0 5000.0 5000.0 5000.0 5000.0 5000.0 5000.0 ...
    dxC        (Y, Xp1) >f4 5000.0 5000.0 5000.0 5000.0 5000.0 5000.0 5000.0 ...
  * Zl         (Zl) >f4 0.0 -10.0 -20.0 -30.0 -42.0 -56.0 -72.0 -91.0 -113.0 ...
  * Yp1        (Yp1) >f4 0.0 5000.0 10000.0 15000.0 20000.0 25000.0 30000.0 ...
  * Zp1        (Zp1) >f4 0.0 -10.0 -20.0 -30.0 -42.0 -56.0 -72.0 -91.0 ...
    XC         (Y, X) >f4 2500.0 7500.0 12500.0 17500.0 22500.0 27500.0 ...
    XG         (Yp1, Xp1) >f4 0.0 5000.0 10000.0 15000.0 20000.0 25000.0 ...
    Depth      (Y, X) >f4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
  * Y          (Y) >f4 2500.0 7500.0 12500.0 17500.0 22500.0 27500.0 32500.0 ...
  * X          (X) >f4 2500.0 7500.0 12500.0 17500.0 22500.0 27500.0 32500.0 ...
    drC        (Zp1) >f4 5.0 10.0 10.0 11.0 13.0 15.0 17.5 20.5 24.0 28.0 ...
  * Z          (Z) >f4 -5.0 -15.0 -25.0 -36.0 -49.0 -64.0 -81.5 -102.0 ...
    drF        (Z) >f4 10.0 10.0 10.0 12.0 14.0 16.0 19.0 22.0 26.0 30.0 ...
    HFacS      (Z, Yp1, X) >f4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    HFacW      (Z, Y, Xp1) >f4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    HFacC      (Z, Y, X) >f4 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    rAw        (Y, Xp1) >f4 2.5e+07 2.5e+07 2.5e+07 2.5e+07 2.5e+07 2.5e+07 ...
    rAs        (Yp1, X) >f4 2.5e+07 2.5e+07 2.5e+07 2.5e+07 2.5e+07 2.5e+07 ...
  * Zu         (Zu) >f4 -15.0 -25.0 -36.0 -49.0 -64.0 -81.5 -102.0 -126.0 ...
    dyG        (Y, Xp1) >f4 5000.0 5000.0 5000.0 5000.0 5000.0 5000.0 5000.0 ...
    rAz        (Yp1, Xp1) >f4 2.5e+07 2.5e+07 2.5e+07 2.5e+07 2.5e+07 ...
    dyC        (Yp1, X) >f4 5000.0 5000.0 5000.0 5000.0 5000.0 5000.0 5000.0 ...
  * time       (time) int64 933120000 1244160000 1555200000
Data variables:
    Convtave   (time, Zl, Y, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    ETAtave    (time, Y, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    TTtave     (time, Z, Y, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    vFluxtave  (time, Yp1, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    PhHytave   (time, Z, Y, X) float32 0.07848 0.07848 0.07848 0.07848 ...
    VVtave     (time, Z, Yp1, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    S          (time, Z, Y, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    uFluxtave  (time, Y, Xp1) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    UTtave     (time, Z, Y, Xp1) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    UStave     (time, Z, Y, Xp1) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    PHLtave    (time, Y, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    uVeltave   (time, Z, Y, Xp1) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    PH         (time, Z, Y, X) float32 0.07848 0.07848 0.07848 0.07848 ...
    UVtave     (time, Z, Yp1, Xp1) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    PHL2tave   (time, Y, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    sFluxtave  (time, Y, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    PHL        (time, Y, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    T          (time, Z, Y, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    VTtave     (time, Z, Yp1, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    U          (time, Z, Y, Xp1) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    VStave     (time, Z, Yp1, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    Eta2tave   (time, Y, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    Tdiftave   (time, Zl, Y, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    Eta        (time, Y, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    vVeltave   (time, Z, Yp1, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    V          (time, Z, Yp1, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    UUtave     (time, Z, Y, Xp1) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    Stave      (time, Z, Y, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    W          (time, Zl, Y, X) float32 -0.0 -0.0 -0.0 -0.0 -0.0 -0.0 -0.0 ...
    Ttave      (time, Z, Y, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    wVeltave   (time, Zl, Y, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    WStave     (time, Zl, Y, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
    tFluxtave  (time, Y, X) float32 -9.99931 -9.99931 -9.99931 -9.99931 ...
    WTtave     (time, Zl, Y, X) float32 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 ...
Attributes:
    history: Some made up attribute

In [284]:
u = ds['U']

In [287]:
type(u.data)


Out[287]:
dask.array.core.Array

In [61]:
xc = read_mds(grid_path('XC'))
xg = read_mds(grid_path('XG'))
yc = read_mds(grid_path('YC'))
xcd = da.from_array(xc, xc.shape)
xgd = da.from_array(xg, xg.shape)
ycd = da.from_array(yc, yc.shape)

In [54]:
import dask.array as da

In [63]:
dstacked = da.stack([xcd, xgd, ycd])

In [64]:
dstacked


Out[64]:
dask.array<stack-1, shape=(3, 400, 200), chunks=((1, 1, 1), (400,), (200,)), dtype=float32>

In [136]:
type(np.asarray(xc))


Out[136]:
numpy.ndarray

In [143]:
from xray.backends import ScipyDataStore

In [144]:
sds = ScipyDataStore('/data/scratch/rpa/aviso/ftp.aviso.altimetry.fr/global/delayed-time/grids/msla/all-sat-merged/uv/all-monthly/dt_global_allsat_msla_uv_2014-12.nc')

In [149]:
sds.get_variables()['lat_bnds']


Out[149]:
<xray.Variable (lat: 720, nv: 2)>
array([[-89.75, -90.  ],
       [-89.5 , -89.75],
       [-89.25, -89.5 ],
       ..., 
       [ 89.5 ,  89.25],
       [ 89.75,  89.5 ],
       [ 90.  ,  89.75]], dtype=float32)

In [197]:
varnames = ['a', 'b']
vardata = {}
[vardata[k] = [] for k in varnames]


  File "<ipython-input-197-90cb719f797a>", line 3
    [vardata[k] = [] for k in varnames]
                ^
SyntaxError: invalid syntax

In [199]:
dims = ('Y','X')
('time',) + dims


Out[199]:
('time', 'Y', 'X')

In [220]:
m = re.match('pickup', '/pickup.0001036800.meta')

In [223]:
if re.match('pickup', '/pickuP.0001036800.meta'):
    print 'ok'
else:
    print 'no match'


no match

In [236]:
f = 'DiagLAYERS-diapycnal.0002073600.meta'

In [243]:
re.match('(^.+?)\..+', f).groups()[0]


Out[243]:
'DiagLAYERS-diapycnal'

In [246]:
vardata = ['a', 'b']

In [247]:
vardata.remove('a')

In [248]:
vardata


Out[248]:
['b']

In [288]:
2074320 - 2073840


Out[288]:
480

In [ ]: