Ejemplo n.º 1
0
class GCcreatefile(GCfile):
    """Creating a GC netCDF file."""
    def __init__(self, fname, append=False):
        """Initialise.

        fname: name of GC file.
        append: set to true if file should be open rw"""

        GCfile.__init__(self, fname)
        self.mapvarname = 'mapping'
        # get variable definitions
        try:
            vname = os.environ['GLIMMER_PREFIX']
        except KeyError:
            vname = os.path.expanduser(os.path.join('~', 'glimmer'))
        vname = os.path.join(vname, 'share', 'glimmer')
        if not os.path.exists(vname):
            raise RuntimeError, 'Cannot find ncdf_vars.def\nPlease set GLIMMER_HOME to where glimmer is installed'
        self.vars = GCVariableDef(glob.glob(vname + '/*.def'))

        if append:
            self.file = GCNetCDFFile(self.fname, 'a')
        else:
            self.file = GCNetCDFFile(self.fname, 'w')
        self.file.Conventions = "GC-1.0"

    def createDimension(self, name, length):
        """Create a dimension.

        Creates a new dimension with the given name and length.
        length must be a positive integer or None, which stands for
        the unlimited dimension. Note that there can be only one
        unlimited dimension in a file."""
        self.file.createDimension(name, length)

    def createVariable(self, name):
        """Create a GC variable.

        name: name of variable."""

        if name not in self.vars:
            raise KeyError, 'Cannot find definition for variable %s' % name
        v = self.vars[name]
        var = self.file.createVariable(
            name, 'f',
            tuple(string.replace(v['dimensions'], ' ', '').split(',')))
        for a in v:
            if a not in NOATTRIB:
                setattr(var, a, v[a])
        if self.mapvarname != '' and 'x' in v['dimensions'] and 'y' in v[
                'dimensions']:
            var.grid_mapping = self.mapvarname
        return var
class GCcreatefile(GCfile):
    """Creating a GC netCDF file."""

    def __init__(self,fname,append=False):
        """Initialise.

        fname: name of GC file.
        append: set to true if file should be open rw"""

        GCfile.__init__(self,fname)
        self.mapvarname = 'mapping'
        # get variable definitions
        try:
            vname=os.environ['GLIMMER_PREFIX']
        except KeyError:
            vname = os.path.expanduser(os.path.join('~','glimmer'))
        vname = os.path.join(vname,'share','glimmer')
        if not os.path.exists(vname):
            raise RuntimeError, 'Cannot find ncdf_vars.def\nPlease set GLIMMER_HOME to where glimmer is installed'
        self.vars = GCVariableDef(glob.glob(vname+'/*.def'))

        if append:
            self.file = GCNetCDFFile(self.fname,'a')
        else:
            self.file = GCNetCDFFile(self.fname,'w')
        self.file.Conventions = "GC-1.0"
        
    def createDimension(self,name, length):
        """Create a dimension.

        Creates a new dimension with the given name and length.
        length must be a positive integer or None, which stands for
        the unlimited dimension. Note that there can be only one
        unlimited dimension in a file."""
        self.file.createDimension(name,length)

    def createVariable(self,name):
        """Create a GC variable.

        name: name of variable."""

        if name not in self.vars:
            raise KeyError, 'Cannot find definition for variable %s'%name
        v = self.vars[name]
        var = self.file.createVariable(name,'f',tuple(string.replace(v['dimensions'],' ','').split(',')))
        for a in v:
            if a not in NOATTRIB:
                setattr(var,a,v[a])
        if self.mapvarname != '' and 'x' in v['dimensions'] and 'y' in v['dimensions']:
            var.grid_mapping = self.mapvarname
        return var
Ejemplo n.º 3
0
class GCcreatefile(GCfile):
    """Creating a GC netCDF file."""

    def __init__(self, fname, append=False):
        """Initialise.

        fname: name of GC file.
        append: set to true if file should be open rw"""

        GCfile.__init__(self, fname)
        self.mapvarname = "mapping"
        # get variable definitions
        try:
            vname = os.environ["GLIMMER_PREFIX"]
        except KeyError:
            vname = os.path.expanduser(os.path.join("~", "glimmer"))
        vname = os.path.join(vname, "share", "glimmer")
        if not os.path.exists(vname):
            raise RuntimeError, "Cannot find ncdf_vars.def\nPlease set GLIMMER_HOME to where glimmer is installed"
        self.vars = GCVariableDef(glob.glob(vname + "/*.def"))

        if append:
            self.file = GCNetCDFFile(self.fname, "a")
        else:
            self.file = GCNetCDFFile(self.fname, "w")
        self.file.Conventions = "GC-1.0"

    def createDimension(self, name, length):
        """Create a dimension.

        Creates a new dimension with the given name and length.
        length must be a positive integer or None, which stands for
        the unlimited dimension. Note that there can be only one
        unlimited dimension in a file."""
        self.file.createDimension(name, length)

    def createVariable(self, name):
        """Create a GC variable.

        name: name of variable."""

        if name not in self.vars:
            raise KeyError, "Cannot find definition for variable %s" % name
        v = self.vars[name]
        var = self.file.createVariable(name, "f", tuple(string.replace(v["dimensions"], " ", "").split(",")))
        for a in v:
            if a not in NOATTRIB:
                setattr(var, a, v[a])
        if self.mapvarname != "" and "x" in v["dimensions"] and "y" in v["dimensions"]:
            var.grid_mapping = self.mapvarname
        return var
Ejemplo n.º 4
0
    def __init__(self, fname, append=False):
        """Initialise.

        fname: name of GC file.
        append: set to true if file should be open rw"""

        GCfile.__init__(self, fname)
        self.mapvarname = 'mapping'
        # get variable definitions
        try:
            vname = os.environ['GLIMMER_PREFIX']
        except KeyError:
            vname = os.path.expanduser(os.path.join('~', 'glimmer'))
        vname = os.path.join(vname, 'share', 'glimmer')
        if not os.path.exists(vname):
            raise RuntimeError, 'Cannot find ncdf_vars.def\nPlease set GLIMMER_HOME to where glimmer is installed'
        self.vars = GCVariableDef(glob.glob(vname + '/*.def'))

        if append:
            self.file = GCNetCDFFile(self.fname, 'a')
        else:
            self.file = GCNetCDFFile(self.fname, 'w')
        self.file.Conventions = "GC-1.0"
    def __init__(self,fname,append=False):
        """Initialise.

        fname: name of GC file.
        append: set to true if file should be open rw"""

        GCfile.__init__(self,fname)
        self.mapvarname = 'mapping'
        # get variable definitions
        try:
            vname=os.environ['GLIMMER_PREFIX']
        except KeyError:
            vname = os.path.expanduser(os.path.join('~','glimmer'))
        vname = os.path.join(vname,'share','glimmer')
        if not os.path.exists(vname):
            raise RuntimeError, 'Cannot find ncdf_vars.def\nPlease set GLIMMER_HOME to where glimmer is installed'
        self.vars = GCVariableDef(glob.glob(vname+'/*.def'))

        if append:
            self.file = GCNetCDFFile(self.fname,'a')
        else:
            self.file = GCNetCDFFile(self.fname,'w')
        self.file.Conventions = "GC-1.0"
Ejemplo n.º 6
0
    def __init__(self, fname, append=False):
        """Initialise.

        fname: name of GC file.
        append: set to true if file should be open rw"""

        GCfile.__init__(self, fname)
        self.mapvarname = "mapping"
        # get variable definitions
        try:
            vname = os.environ["GLIMMER_PREFIX"]
        except KeyError:
            vname = os.path.expanduser(os.path.join("~", "glimmer"))
        vname = os.path.join(vname, "share", "glimmer")
        if not os.path.exists(vname):
            raise RuntimeError, "Cannot find ncdf_vars.def\nPlease set GLIMMER_HOME to where glimmer is installed"
        self.vars = GCVariableDef(glob.glob(vname + "/*.def"))

        if append:
            self.file = GCNetCDFFile(self.fname, "a")
        else:
            self.file = GCNetCDFFile(self.fname, "w")
        self.file.Conventions = "GC-1.0"
Ejemplo n.º 7
0
    def __init__(self, fname):
        """Initialise.

        fname: name of CF file."""

        GCfile.__init__(self, fname)

        self.file = GCNetCDFFile(self.fname, 'r')

        self.timescale = 0.001
        # get mapping variable name
        for var in self.file.variables.keys():
            if hasattr(self.file.variables[var], 'grid_mapping_name'):
                self.mapvarname = var
                break
        self.reset_bb()
        # initialising variable dictionary
        self.__vars = {}
        # RSL residuals
        self.__rslres = {}