示例#1
0
def model_id(filename):
    """ 

    """
    from anynetcdf import ncf
    rep='no_model'
    clogger.debug("opening "+filename)
    f=ncf(filename, 'r') 
    if 'model_id' in dir(f) : rep=f.model_id
    f.close()
    return(rep)
示例#2
0
def model_id(filename):
    """ 

    """
    from anynetcdf import ncf
    rep = 'no_model'
    clogger.debug("opening " + filename)
    f = ncf(filename, 'r')
    if 'model_id' in dir(f): rep = f.model_id
    f.close()
    return (rep)
示例#3
0
def dimsOfFile(filename):
    """
    returns the list of dimensions of the netcdf file filename
    """
    from anynetcdf import ncf
    rep = False
    clogger.debug("opening " + filename + " for checking the dimensions")
    fileobj = ncf(filename)
    dims = fileobj.dimensions
    if isinstance(dims, dict): dims = dims.keys()
    fileobj.close()
    return (dims)
示例#4
0
def fileHasVar(filename,varname):
    """ 
    returns True if FILENAME has variable VARNAME
    """
    from anynetcdf import ncf
    rep=False
    clogger.debug("opening "+filename+" for checkin if has variable"+varname)
    fileobj=ncf(filename)
    vars=fileobj.variables
    if isinstance(vars,dict ) : vars=vars.keys()
    for filevar in vars :
        if filevar == varname :
            rep=True
            break
    fileobj.close()
    return(rep)
示例#5
0
def fileHasVar(filename,varname):
    """ 
    returns True if FILENAME has variable VARNAME
    """
    from anynetcdf import ncf
    rep=False
    clogger.debug("opening "+filename+" for checkin if has variable"+varname)
    fileobj=ncf(filename)
    vars=fileobj.variables
    if isinstance(vars,dict ) : vars=vars.keys()
    for filevar in vars :
        if filevar == varname :
            rep=True
            break
    fileobj.close()
    return(rep)
示例#6
0
def timeLimits(filename) :
    #
    try :
        import netcdftime
    except :
        raise Climaf_Netcdf_Error("Netcdf time handling is yet available only with module netcdftime")
    #
    from anynetcdf import ncf
    f=ncf(filename) 
    if 'time_bnds' in f.variables :
        tim=f.variables['time_bnds']
        start=tim[0,0] ; end=tim[-1,1] 
        ct=netcdftime.utime(tim.units, calendar=tim.calendar)
        f.close()
        return cperiod(ct.num2date(start),ct.num2date(end))
    else:
        f.close()
        return None
示例#7
0
def fileHasDim(filename, dimname):
    """
    returns True if FILENAME has dimension dimname
    """
    from anynetcdf import ncf
    rep = False
    clogger.debug("opening " + filename + " for checkin if has dimension " +
                  dimname)
    fileobj = ncf(filename)
    dims = fileobj.dimensions
    vars = fileobj.variables
    if isinstance(dims, dict): dims = dims.keys()
    if isinstance(vars, dict): vars = vars.keys()
    dims = dims + vars
    for filedim in dims:
        if filedim == dimname:
            rep = True
            break
    fileobj.close()
    return (rep)
示例#8
0
def timeLimits(filename) :
    #
    try :
        import netcdftime
    except :
        raise Climaf_Netcdf_Error("Netcdf time handling is yet available only with module netcdftime")
    #
    from anynetcdf import ncf
    rep=None
    f=ncf(filename) 
    if 'time_bnds' in f.variables :
        tim=f.variables['time_bnds']
        if 'units' in dir(tim) :
            start=tim[0,0] ; end=tim[-1,1] 
            ct=netcdftime.utime(tim.units, calendar=tim.calendar)
            return cperiod(ct.num2date(start),ct.num2date(end))
    f.close()
    return rep
    #raise Climaf_Netcdf_Error("No time bounds in file %s, and no guess method yet developped (TBD)"%filename)
        
示例#9
0
def varsOfFile(filename):
    """ 
    returns the list of non-dimensions variable in NetCDF file FILENAME
    """
    from anynetcdf import ncf
    lvars = []
    fileobj = ncf(filename, 'r')
    vars = fileobj.variables
    if isinstance(vars, dict): vars = vars.keys()
    for filevar in vars:
        if ((filevar not in fileobj.dimensions)
                and not re.findall("^lat", filevar)
                and not re.findall("^lon", filevar)
                and not re.findall("^LAT", filevar)
                and not re.findall("^LON", filevar)
                and not re.findall("nav_lat", filevar)
                and not re.findall("nav_lon", filevar)
                and not re.findall("^time_", filevar)
                and not re.findall("_bnds$", filevar)):
            lvars.append(filevar)
    fileobj.close()
    return (lvars)
示例#10
0
def varsOfFile(filename) :
    """ 
    returns the list of non-dimensions variable in NetCDF file FILENAME
    """
    from anynetcdf import ncf
    lvars=[]
    fileobj=ncf(filename, 'r') 
    vars=fileobj.variables
    if isinstance(vars,dict ) : vars=vars.keys()
    for filevar in vars :
        if ((filevar not in fileobj.dimensions) and
            not re.findall("^lat",filevar) and
            not re.findall("^lon",filevar) and
            not re.findall("^LAT",filevar) and
            not re.findall("^LON",filevar) and
            not re.findall("nav_lat",filevar) and
            not re.findall("nav_lon",filevar) and
            not re.findall("^time_",filevar) and
            not re.findall("_bnds$",filevar) ):
            lvars.append(filevar)
    fileobj.close()
    return(lvars)