Exemplo n.º 1
0
		os.remove(fileOut)


	while not mns[tind-1] == mn:
		tind += 1
	startInd = tind

	ARLDI = ARLDataInfo()
	ARLDI.X = xs.getValues()
	ARLDI.Y = ys.getValues()
	
	for lind in range(len(rightFullLvls)):
		ARLDI.levels.add(lvDict[lind])
		ARLDI.LevelVarList.add(lvVarDict[lvDict[lind]])
		
	ARLDI.createDataFile(fileOut)

	while tind <= len(mns) and mns[tind-1] == mn:
		dataHead = ARLDI.getDataHead(proj, 'NRCP', 2)
		ARLDI.writeIndexRecord(ts[tind], dataHead)
		for hg in rightFullLvls:
			for arlV in lvVarDict[hg]:
				arlV = str(arlV)
				ncV = arl2ncDict[arlV]
				
				fileName = str(yrWant) + "Time"+ zstr(tind, 4) + ".asc"
				indvPath = os.path.join(dirIn, ncV, str(hg), fileName)
				Met.openASCIIGridData(indvPath)
				asData = Met.getGridData()
				
				if ncV in unAvgableVars:
Exemplo n.º 2
0
    if os.path.isfile(fileOut):
        os.remove(fileOut)

    while not mns[tind - 1] == mn:
        tind += 1
    startInd = tind

    ARLDI = ARLDataInfo()
    ARLDI.X = xs.getValues()
    ARLDI.Y = ys.getValues()

    for lind in range(len(rightFullLvls)):
        ARLDI.levels.add(lvDict[lind])
        ARLDI.LevelVarList.add(lvVarDict[lvDict[lind]])

    ARLDI.createDataFile(fileOut)

    while tind <= len(mns) and mns[tind - 1] == mn:
        dataHead = ARLDI.getDataHead(proj, 'NRCP', 2)
        ARLDI.writeIndexRecord(ts[tind], dataHead)
        for hg in rightFullLvls:
            for arlV in lvVarDict[hg]:
                arlV = str(arlV)
                ncV = arl2ncDict[arlV]

                fileName = str(yrWant) + "Time" + zstr(tind, 4) + ".asc"
                indvPath = os.path.join(dirIn, ncV, str(hg), fileName)
                Met.openASCIIGridData(indvPath)
                asData = Met.getGridData()

                if ncV in unAvgableVars:
Exemplo n.º 3
0
def addfile(fname, access='r', dtype='netcdf', keepopen=False, **kwargs):
    """
    Opens a data file that is written in a supported file format.
    
    :param fname: (*string*) The full or relative path of the data file to load.
    :param access: (*string*) The access right setting to the data file. Default is ``r``.
    :param dtype: (*string*) The data type of the data file. Default is ``netcdf``.
    :param keepopen: (*boolean*) If the file keep open after this function. Default is ``False``. The
        file need to be closed later if ``keepopen`` is ``True``.
    
    :returns: (*DimDataFile*) Opened file object.
    """
    if access == 'r':
        fname = fname.strip()
        fname, isweb = __getfilename(fname)
        if fname is None:
            raise IOError(fname)

        if isweb:
            return addfile_nc(fname, False)
        
        if not os.path.exists(fname):
            raise IOError(fname)
        
        fsufix = os.path.splitext(fname)[1].lower()
        if fsufix == '.ctl':
            return addfile_grads(fname, False)
        elif fsufix == '.tif':
            return addfile_geotiff(fname, False)
        elif fsufix == '.awx':
            return addfile_awx(fname, False)
        elif fsufix == '.bil':
            return addfile_bil(fname, False)
        
        meteodata = MeteoDataInfo()
        meteodata.openData(fname, keepopen)
        datafile = DimDataFile(meteodata, access=access)
        return datafile
    elif access == 'c':
        if dtype == 'arl':
            arldata = ARLDataInfo()
            arldata.createDataFile(fname)
            datafile = DimDataFile(arldata=arldata)
        elif dtype == 'bufr':
            bufrdata = BufrDataInfo()
            if os.path.exists(fname):
                try:
                    os.remove(fname)
                except:   
                    info=sys.exc_info()   
                    print info[0],":",info[1]
            bufrdata.createDataFile(fname)
            datafile = DimDataFile(bufrdata=bufrdata)
        else:
            version = kwargs.pop('version', 'netcdf3')
            if version == 'netcdf3':
                version = NetcdfFileWriter.Version.netcdf3
            else:
                version = NetcdfFileWriter.Version.netcdf4
            ncfile = NetcdfFileWriter.createNew(version, fname)
            largefile = kwargs.pop('largefile', None)
            if not largefile is None:
                ncfile.setLargeFile(largefile)
            datafile = DimDataFile(access=access, ncfile=ncfile)
        return datafile
    elif access == 'w':
        fname = fname.strip()
        fname, isweb = __getfilename(fname)
        if fname is None:
            raise IOError(fname)
            meteodata = MeteoDataInfo()
        ncfile = NetcdfFileWriter.openExisting(fname)
        meteodata = MeteoDataInfo()
        meteodata.openData(ncfile.getNetcdfFile(), True)  
        datafile = DimDataFile(dataset=meteodata, access=access, ncfile=ncfile)
        return datafile
    else:
        return None
Exemplo n.º 4
0
	'u-component_of_wind_isobaric','v-component_of_wind_isobaric','Vertical_velocity_pressure_isobaric',\
	'Relative_humidity_isobaric']
avars = ['PRSS','T02M','U10M','V10M','HGTS','TEMP','UWND','VWND','WWND','RELH']
levels = [0,1000,975,950,925,900,875,850,825,800,775,750,700,\
	650,600,550,500,450,400,350,300,250,225,200,175,150,\
	125,100,70,50,30,20,10,7,5,3,2,1]
for l in levels:
	arlDI.levels.add(l)
	if l == 0:
		arlDI.LevelVarList.add(['PRSS','T02M','U10M','V10M'])
	else:
		arlDI.LevelVarList.add(['HGTS','TEMP','UWND','VWND','WWND','RELH'])

#---- Write ARL data file
dataInfo = mydata.getDataInfo()
arlDI.createDataFile(outFile)
arlDI.X = dataInfo.getXDimension().getValues()
arlDI.Y = dataInfo.getYDimension().getValues()
variables = dataInfo.getVariables()
tNum = dataInfo.getTimeNum()
for t in range(0, tNum):
	mydata.setTimeIndex(t)
	atime = dataInfo.getTimes().get(t)
	aDH = arlDI.getDataHead(mydata.getProjectionInfo(), 'FNL1', 2)
	arlDI.writeIndexRecord(atime, aDH)
	lidx = 0
	for l in arlDI.levels:
		print l
		for v in arlDI.LevelVarList[lidx]:
			vName = gvars[avars.index(v)]
			print vName
Exemplo n.º 5
0
    'RELH'
]
levels = [0,1000,975,950,925,900,875,850,825,800,775,750,700,\
 650,600,550,500,450,400,350,300,250,225,200,175,150,\
 125,100,70,50,30,20,10,7,5,3,2,1]
for l in levels:
    arlDI.levels.add(l)
    if l == 0:
        arlDI.LevelVarList.add(['PRSS', 'T02M', 'U10M', 'V10M'])
    else:
        arlDI.LevelVarList.add(
            ['HGTS', 'TEMP', 'UWND', 'VWND', 'WWND', 'RELH'])

#---- Write ARL data file
dataInfo = mydata.getDataInfo()
arlDI.createDataFile(outFile)
arlDI.X = dataInfo.getXDimension().getValues()
arlDI.Y = dataInfo.getYDimension().getValues()
variables = dataInfo.getVariables()
tNum = dataInfo.getTimeNum()
for t in range(0, tNum):
    mydata.setTimeIndex(t)
    atime = dataInfo.getTimes().get(t)
    aDH = arlDI.getDataHead(mydata.getProjectionInfo(), 'FNL1', 2)
    arlDI.writeIndexRecord(atime, aDH)
    lidx = 0
    for l in arlDI.levels:
        print l
        for v in arlDI.LevelVarList[lidx]:
            vName = gvars[avars.index(v)]
            print vName
Exemplo n.º 6
0
def addfile(fname, access='r', dtype='netcdf', keepopen=False, **kwargs):
    """
    Opens a data file that is written in a supported file format.
    
    :param fname: (*string*) The full or relative path of the data file to load.
    :param access: (*string*) The access right setting to the data file. Default is ``r``.
    :param dtype: (*string*) The data type of the data file. Default is ``netcdf``.
    :param keepopen: (*boolean*) If the file keep open after this function. Default is ``False``. The
        file need to be closed later if ``keepopen`` is ``True``.
    
    :returns: (*DimDataFile*) Opened file object.
    """
    if access == 'r':
        fname = fname.strip()
        fname, isweb = __getfilename(fname)
        if fname is None:
            raise IOError(fname)

        if isweb:
            return addfile_nc(fname, False)
        
        if not os.path.exists(fname):
            raise IOError(fname)
        
        fsufix = os.path.splitext(fname)[1].lower()
        if fsufix == '.ctl':
            return addfile_grads(fname, False)
        elif fsufix == '.tif':
            return addfile_geotiff(fname, False)
        elif fsufix == '.awx':
            return addfile_awx(fname, False)
        elif fsufix == '.bil':
            return addfile_bil(fname, False)
        
        meteodata = MeteoDataInfo()
        meteodata.openData(fname, keepopen)
        datafile = DimDataFile(meteodata, access=access)
        return datafile
    elif access == 'c':
        if dtype == 'arl':
            arldata = ARLDataInfo()
            arldata.createDataFile(fname)
            datafile = DimDataFile(arldata=arldata)
        elif dtype == 'bufr':
            bufrdata = BufrDataInfo()
            if os.path.exists(fname):
                try:
                    os.remove(fname)
                except:   
                    info=sys.exc_info()   
                    print info[0],":",info[1]
            bufrdata.createDataFile(fname)
            datafile = DimDataFile(bufrdata=bufrdata)
        else:
            version = kwargs.pop('version', 'netcdf3')
            if version == 'netcdf3':
                version = NetcdfFileWriter.Version.netcdf3
            else:
                version = NetcdfFileWriter.Version.netcdf4
            ncfile = NetcdfFileWriter.createNew(version, fname)
            largefile = kwargs.pop('largefile', None)
            if not largefile is None:
                ncfile.setLargeFile(largefile)
            datafile = DimDataFile(access=access, ncfile=ncfile)
        return datafile
    elif access == 'w':
        fname = fname.strip()
        fname, isweb = __getfilename(fname)
        if fname is None:
            raise IOError(fname)
            meteodata = MeteoDataInfo()
        ncfile = NetcdfFileWriter.openExisting(fname)
        meteodata = MeteoDataInfo()
        meteodata.openData(ncfile.getNetcdfFile(), True)  
        datafile = DimDataFile(dataset=meteodata, access=access, ncfile=ncfile)
        return datafile
    else:
        return None