示例#1
0
oFile1 = "var_sub1.nc"
oFile2 = "var_sub2.nc"
oFile3 = "var_sub3.nc"

## variable of interest
varName = "o3"

## subset domain, needs to be a list of tuples x,y order
domainLL = [(-92,35), (-82, 42)]   ## Lon, Lat in degrees
domainXY = [(-450000, -950000), (20000, 340000)] ## Xlon, Ylat in meters
domainCR = [(2, 5), (55, 61)]  ## col, row, 0-based

##------------------------------------------------------------##

## open input file for reading
f = ioT.open(iFile)

## read  variable
var = f(varName)

## print some diagnostics
print var

## get Latitude and Longitude axes, print diagnostics
## units are in meters, Xlon, Ylat
print var.getLatitude()
print var.getLongitude()
print ""

## Subset the variable using lat, lon domain
var_sub1 = var.IOsubset(domainLL)
示例#2
0
## input file
iFile = "CCTM_ACONC.D1.001"
iFile = os.path.join(cdat_info.get_prefix(), 'sample_data/' + iFile)

oFile1 = "var_newdate.ioapi"

## variable of interest
varName = "o3"

## new date
dateNew = D.DateTime(2006, 7, 10, 12)

##------------------------------------------------------------##

## open input file for reading
f = ioT.open(iFile)

## read  variable
var = f(varName)
f.close()

## Make a copy of the variable so that you don't change
## original variables dates
var2 = var.IOclone()

## change the date of var2, could use DateTime object, cdtime object
## or a date string
var2.IOchangeDate(dateNew)

## print some diagnostics
print "original date values:"
示例#3
0
## could be multiple coordinates
coordLL = [(-92, 35)]  ## Lon, Lat in degrees
coordXY = [(-450000, 340000), (20000, 340000)]  ## Xlon, Ylat in meters
coordCR = [(55, 61)]  ## col, row, 0-based

## coordinate Outside the domain in lon,lat
outsideLL = (24.32, 34.68)

## date inside and outside temporal domain
dateIn = "2001-06-01 22:00"
dateOut = "2001-05-03 12:00"

##------------------------------------------------------------##

## open input file for reading
f = ioT.open(iFile)

## read  variable
var = f(varName)
f.close()

## lon/lat --> proj
## Note, the 3rd element is the vertical coordinate, ignore
## this is 0 for all values
coordOutLst = var.IOcoordConv(coordLL)
print "lon/lat --> proj:"
print "\t%s  -->  %s" % (coordLL, coordOutLst)

## lon/lat --> col,row
coordOutLst = var.IOcoordConv(coordLL, ioT.ll2crFlag)
print "lon/lat --> col/row:"
示例#4
0
iFile = "CCTM_ACONC.D1.001"
iFile = os.path.join (cdat_info.get_prefix(),'sample_data/' + iFile)

oFile1 = "var_newdate.ioapi"

## variable of interest
varName = "o3"

## new date
dateNew = D.DateTime(2006,7,10,12)


##------------------------------------------------------------##

## open input file for reading
f = ioT.open(iFile)

## read  variable
var = f(varName)
f.close()

## Make a copy of the variable so that you don't change
## original variables dates
var2 = var.IOclone()

## change the date of var2, could use DateTime object, cdtime object
## or a date string
var2.IOchangeDate(dateNew)


## print some diagnostics
示例#5
0
## output files
oFile1 = "var1.ioapi"
oFile2 = "multvar1.ioapi"
oFile3 = "multvar2.ioapi"

## variable of interest
varName = "o3"

## logfile for ioapi log info
logName = "ioapi.log"

##------------------------------------------------------------##


## open input file for reading
f = ioT.open(iFile)

## read 1 variable
var1 = f(varName)

## print some diagnostics
print "Read %s from infile: %s" %(varName, iFile)
print "Writing to ioapi file: %s" %oFile1

## open an output file for writing (CF netCDF format)
## write the single variable to an output file
## send ioapi stdout to a log (optional)
## all subsequent ioapi writes will be written to this logFile
## do NOT include in future open commands
g = ioT.open(oFile1, "w", ioT.iofileFlag, logFile=logName)
g.write(var1)
示例#6
0
## print some diagnostics
print fs

## Extract the variable
print "Extracting %s ..." % varName
var = fs(varName)

## To average over time, you need to setup
## the time axis' bounds
cdutil.setTimeBoundsDaily(var.getTime(), frequency=24)

## average over the 0th axis, ie. time
var_average = ioT.binAverager(var, 0)

## change metadata
varDesc = "%s variable -- daily average" % varName
var_average.IOmodVar(desc=varDesc)

## print time axes
print "original data time axis:"
print var.getTime()

print "average data time axis:"
print var_average.getTime()

## write to a netCDF file
print "writing average variable to %s" % oFile1
g = ioT.open(oFile1, "w")
g.write(var_average)
g.close()
示例#7
0
## Setup
## input file
iFile = "CCTM_CONC.D1.001"
iFile = os.path.join(sys.prefix, 'sample_data/' + iFile)

gridFile = "GRIDCRO2D_D1.001"
gridFile = os.path.join(sys.prefix, 'sample_data/' + gridFile)

## output file
oFile1 = "o3_masked.nc"

##------------------------------------------------------------##

## open input files for reading
f = ioT.open(iFile)
grid = ioT.open(gridFile)

## read  o3 and landuse variables
o3 = f("o3")
landuse = grid("dluse")
f.close()
grid.close()

## Mask o3 variable
## Future versions of ioapiTools will make this easier

## Need to have landuse data same shape as o3
## landuse data has shape (1,1,nrows,ncols)
## o3 data has shape (ntime,nlev,nrows, ncols)
## so repeat landuse in time and level dimensions
示例#8
0
文件: scan_var.py 项目: AZed/uvcdat
## output files
oFile1 = "var_multiday.nc"

## variable of interest
varName = "o3"

##------------------------------------------------------------##


## scan the files from the search string for date range
## returns an iofilescan object
fs = ioT.scan(searchStr, date1, date2)

## print some diagnostics
print fs

## Extract the variable
print "Extracting %s ..." %varName
var = fs(varName)

## write to a file
g = ioT.open(oFile1, "w")
g.write(var)
g.close()

## close iofilescan object
fs.close()



示例#9
0
oFile1 = "var_sub1.nc"
oFile2 = "var_sub2.nc"
oFile3 = "var_sub3.nc"

## variable of interest
varName = "o3"

## subset domain, needs to be a list of tuples x,y order
domainLL = [(-92,35), (-82, 42)]   ## Lon, Lat in degrees
domainXY = [(-450000, -950000), (20000, 340000)] ## Xlon, Ylat in meters
domainCR = [(2, 5), (55, 61)]  ## col, row, 0-based

##------------------------------------------------------------##

## open input file for reading
f = ioT.open(iFile)

## read  variable
var = f(varName)

## print some diagnostics
print var

## get Latitude and Longitude axes, print diagnostics
## units are in meters, Xlon, Ylat
print var.getLatitude()
print var.getLongitude()
print ""

## Subset the variable using lat, lon domain
var_sub1 = var.IOsubset(domainLL)
示例#10
0
## output files
oFile1 = "var1.ioapi"
oFile2 = "multvar1.ioapi"
oFile3 = "multvar2.ioapi"

## variable of interest
varName = "o3"

## logfile for ioapi log info
logName = "ioapi.log"

##------------------------------------------------------------##

## open input file for reading
f = ioT.open(iFile)

## read 1 variable
var1 = f(varName)

## print some diagnostics
print "Read %s from infile: %s" % (varName, iFile)
print "Writing to ioapi file: %s" % oFile1

## open an output file for writing (CF netCDF format)
## write the single variable to an output file
## send ioapi stdout to a log (optional)
## all subsequent ioapi writes will be written to this logFile
## do NOT include in future open commands
g = ioT.open(oFile1, "w", ioT.iofileFlag, logFile=logName)
g.write(var1)
示例#11
0
## input file
iFile = "CCTM_ACONC.D1.001"
iFile = os.path.join (sys.prefix,'sample_data/' + iFile)

## output files
oFile1 = "var1.nc"
oFile2 = "multvar.nc"

## variable of interest
varName = "o3"

##------------------------------------------------------------##


## open input file for reading
f = ioT.open(iFile)

## read 1 variable
var1 = f(varName)

## print some diagnostics
print "Read %s from infile: %s" %(varName, iFile)
print "Writing to CF netCDF file: %s" %oFile1

## open an output file for writing (CF netCDF format)
## write the single variable to an output file
g = ioT.open(oFile1, "w")
g.write(var1)
g.close()

## Reading all the variables in a file
示例#12
0
## input file
iFile = "CCTM_ACONC.D1.001"
iFile = os.path.join(sys.prefix, 'sample_data/' + iFile)

## output files
oFile1 = "var1.nc"
oFile2 = "multvar.nc"

## variable of interest
varName = "o3"

##------------------------------------------------------------##

## open input file for reading
f = ioT.open(iFile)

## read 1 variable
var1 = f(varName)

## print some diagnostics
print "Read %s from infile: %s" % (varName, iFile)
print "Writing to CF netCDF file: %s" % oFile1

## open an output file for writing (CF netCDF format)
## write the single variable to an output file
g = ioT.open(oFile1, "w")
g.write(var1)
g.close()

## Reading all the variables in a file
示例#13
0
文件: adv_subset.py 项目: AZed/uvcdat
## Setup
## input file
iFile = "CCTM_ACONC.D1.001"
iFile = os.path.join (sys.prefix,'sample_data/' + iFile)

## variable of interest
varName = "o3"

## subset domain in col, row. needs to be a list of lists x,y order
domainCR = [[2, 5], [55, 61]] ## col, row, 0-based

##------------------------------------------------------------##

## open input file for reading
f = ioT.open(iFile)

## read  variable
var = f(varName)
f.close()

## convert the domain into Xlon, Ylat
domainXY = var.IOcoordConv(domainCR, ioT.cr2projFlag)

## print equivalency
print "col/row --> proj:"
print "%s --> %s" %(domainCR, domainXY)

## Calculate the cell size
## get the bounds, ie the extent of the first cell
## diff is the cell size, in both x and y in my case.
示例#14
0
## Setup
## input file
iFile = "CCTM_CONC.D1.001"
iFile = os.path.join (cdat_info.get_prefix(),'sample_data/' + iFile)

gridFile = "GRIDCRO2D_D1.001"
gridFile = os.path.join (cdat_info.get_prefix(),'sample_data/' + gridFile)

## output file
oFile1 = "o3_masked.nc"

##------------------------------------------------------------##

## open input files for reading
f = ioT.open(iFile)
grid = ioT.open(gridFile)

## read  o3 and landuse variables
o3 = f("o3")
landuse = grid("dluse")
f.close()
grid.close()

## Mask o3 variable
## Future versions of ioapiTools will make this easier

## Need to have landuse data same shape as o3
## landuse data has shape (1,1,nrows,ncols)
## o3 data has shape (ntime,nlev,nrows, ncols)
## so repeat landuse in time and level dimensions