Exemplo n.º 1
0
def addfile_surfer(fname, getfn=True):
    '''
    Add a Surfer ASCII grid data file.
    
    :param fname: (*string*) The Surfer ASCII grid file name.
    :param getfn: (*string*) If run ``__getfilename`` function or not. Default is ``True``.
    
    :returns: (*DimDataFile*) Opened file object.
    '''
    if getfn:
        fname, isweb = __getfilename(fname)
    meteodata = MeteoDataInfo()
    meteodata.openSurferGridData(fname)
    datafile = DimDataFile(meteodata)
    return datafile
Exemplo n.º 2
0
def addfile_micaps(fname, getfn=True):
    '''
    Add a MICAPS data file (Data formats from CMA).
    
    :param fname: (*string*) The MICAPS file name.
    :param getfn: (*string*) If run ``__getfilename`` function or not. Default is ``True``.
    
    :returns: (*DimDataFile*) Opened file object.
    '''
    if getfn:
        fname, isweb = __getfilename(fname)
    meteodata = MeteoDataInfo()
    meteodata.openMICAPSData(fname)
    datafile = DimDataFile(meteodata)
    return datafile
Exemplo n.º 3
0
def addfile_nc(fname, getfn=True):
    '''
    Add a netCDF data file.
    
    :param fname: (*string*) The netCDF file name.
    :param getfn: (*string*) If run ``__getfilename`` function or not. Default is ``True``.
    
    :returns: (*DimDataFile*) Opened file object.
    '''
    if getfn:
        fname, isweb = __getfilename(fname)
    meteodata = MeteoDataInfo()
    meteodata.openNetCDFData(fname)
    datafile = DimDataFile(meteodata)
    return datafile
Exemplo n.º 4
0
def addfile_grads(fname, getfn=True):
    '''
    Add a GrADS data file. use this function is GrADS control file has no ``.ctl`` suffix, otherwise use
    ``addfile`` function.
    
    :param fname: (*string*) GrADS control file name.
    :param getfn: (*string*) If run ``__getfilename`` function or not. Default is ``True``.
    
    :returns: (*DimDataFile*) Opened file object.
    '''
    if getfn:
        fname, isweb = __getfilename(fname)
    meteodata = MeteoDataInfo()
    meteodata.openGrADSData(fname)
    datafile = DimDataFile(meteodata)
    return datafile
Exemplo n.º 5
0
def addfile_lonlat(fname, getfn=True, missingv=-9999.0):
    '''
    Add a Lon/Lat ASCII data file.
    
    :param fname: (*string*) The Lon/Lat ASCII file name.
    :param getfn: (*string*) If run ``__getfilename`` function or not. Default is ``True``.
    
    :returns: (*DimDataFile*) Opened file object.
    '''
    if getfn:
        fname, isweb = __getfilename(fname)
    meteodata = MeteoDataInfo()
    meteodata.openLonLatData(fname)
    meteodata.getDataInfo().setMissingValue(missingv)
    datafile = DimDataFile(meteodata)
    return datafile
Exemplo n.º 6
0
def addfile_ascii_grid(fname, getfn=True):
    '''
    Add a ESRI ASCII grid data file.
    
    :param fname: (*string*) The ESRI ASCII grid file name.
    :param getfn: (*string*) If run ``__getfilename`` function or not. Default is ``True``.
    
    :returns: (*DimDataFile*) Opened file object.
    '''
    if getfn:
        fname, isweb = __getfilename(fname)
    if not os.path.exists(fname):
        raise IOError('No such file: ' + fname)
    meteodata = MeteoDataInfo()
    meteodata.openASCIIGridData(fname)
    datafile = DimDataFile(meteodata)
    return datafile
Exemplo n.º 7
0
def addfile_awx(fname, getfn=True):
    '''
    Add a AWX data file (Satellite data file format from CMA). use this function is the file has no ``.awx`` 
    suffix, otherwise use ``addfile`` function.
    
    :param fname: (*string*) The AWX file name.
    :param getfn: (*string*) If run ``__getfilename`` function or not. Default is ``True``.
    
    :returns: (*DimDataFile*) Opened file object.
    '''
    if getfn:
        fname, isweb = __getfilename(fname)
    if not os.path.exists(fname):
        raise IOError('No such file: ' + fname)
    meteodata = MeteoDataInfo()
    meteodata.openAWXData(fname)
    datafile = DimDataFile(meteodata)
    return datafile
Exemplo n.º 8
0
def addfile_hytraj(fname, getfn=True):
    '''
    Add a HYSPLIT trajectory endpoint data file.
    
    :param fname: (*string*) The HYSPLIT trajectory endpoint file name.
    :param getfn: (*string*) If run ``__getfilename`` function or not. Default is ``True``.
    
    :returns: (*DimDataFile*) Opened file object.
    '''
    if isinstance(fname, basestring):
        if getfn:
            fname, isweb = __getfilename(fname)
    if not os.path.exists(fname):
        raise IOError('No such file: ' + fname)
    meteodata = MeteoDataInfo()
    meteodata.openHYSPLITTrajData(fname)
    datafile = DimDataFile(meteodata)
    return datafile
Exemplo n.º 9
0
def addfile_hyconc(fname, getfn=True, big_endian=True):
    '''
    Add a HYSPLIT concentration data file.
    
    :param fname: (*string*) The HYSPLIT concentration file name.
    :param getfn: (*string*) If run ``__getfilename`` function or not. Default is ``True``.
    :param big_endian: (*boolean*) Big_endian or little_endian.
    
    :returns: (*DimDataFile*) Opened file object.
    '''
    if getfn:
        fname, isweb = __getfilename(fname)
    if not os.path.exists(fname):
        raise IOError('No such file: ' + fname)
    meteodata = MeteoDataInfo()
    meteodata.openHYSPLITConcData(fname, big_endian)
    datafile = DimDataFile(meteodata)
    return datafile
Exemplo n.º 10
0
def addfile_mm5(fname, getfn=True, reffile=None):
    '''
    Add a MM5 data file.
    
    :param fname: (*string*) The MM5 file name.
    :param getfn: (*string*) If run ``__getfilename`` function or not. Default is ``True``.
    
    :returns: (*DimDataFile*) Opened file object.
    '''
    if getfn:
        fname, isweb = __getfilename(fname)
    meteodata = MeteoDataInfo()
    if reffile is None:
        meteodata.openMM5Data(fname)
    else:
        meteodata.openMM5Data(fname, reffile)
    datafile = DimDataFile(meteodata)
    return datafile
Exemplo n.º 11
0
def addfile_grib(fname, getfn=True, version=None):
    '''
    Add a GRIB data file.
    
    :param fname: (*string*) The GRIB file name.
    :param getfn: (*string*) If run ``__getfilename`` function or not. Default is ``True``.
    :param version: (*int*) None, GRIB-1 or GRIB-2. Default is None, the version will be read from data.
    
    :returns: (*DimDataFile*) Opened file object.
    '''
    if getfn:
        fname, isweb = __getfilename(fname)
    meteodata = MeteoDataInfo()
    if version is None:
        meteodata.openNetCDFData(fname)
    else:
        meteodata.openGRIBData(fname, version)
    datafile = DimDataFile(meteodata)
    return datafile
Exemplo n.º 12
0
def addfile_mm5(fname, getfn=True, reffile=None):
    '''
    Add a MM5 data file.
    
    :param fname: (*string*) The MM5 file name.
    :param getfn: (*string*) If run ``__getfilename`` function or not. Default is ``True``.
    :param reffile: (*string*) Reference file, for the mm5 file lacking header part.
    
    :returns: (*DimDataFile*) Opened file object.
    '''
    if getfn:
        fname, isweb = __getfilename(fname)
    meteodata = MeteoDataInfo()
    if reffile is None:
        meteodata.openMM5Data(fname)
    else:
        meteodata.openMM5Data(fname, reffile)
    datafile = DimDataFile(meteodata)
    return datafile
Exemplo n.º 13
0
def addfile_grib(fname, getfn=True, version=None):
    '''
    Add a GRIB data file.
    
    :param fname: (*string*) The GRIB file name.
    :param getfn: (*string*) If run ``__getfilename`` function or not. Default is ``True``.
    :param version: (*int*) None, GRIB-1 or GRIB-2. Default is None, the version will be read from data.
    
    :returns: (*DimDataFile*) Opened file object.
    '''
    if getfn:
        fname, isweb = __getfilename(fname)
    meteodata = MeteoDataInfo()
    if version is None:
        meteodata.openNetCDFData(fname)
    else:
        meteodata.openGRIBData(fname, version)
    datafile = DimDataFile(meteodata)
    return datafile
Exemplo n.º 14
0
mapDir = 'c:/share/map'

#---- Create MapLayout object
mapLayout = MapLayout()
mapFrame = mapLayout.getActiveMapFrame()
 
#---- Load country layer
print 'Load country layer...'
countryLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'poly_region.shp'))
lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
lb.setDrawFill(False)
lb.setOutlineColor(Color.blue)
mapFrame.addLayer(countryLayer)
 
#---- Create MeteoDataInfo object
mdi = MeteoDataInfo()
 
#---- Open a GrADS data file
# fn = os.path.join(dataDir, 'GrADS/model.ctl')
# mdi.openGrADSData(fn)
 
#---- Get grid data
#mdi.setTimeIndex(2)
#mdi.setLevelIndex(3)
#gdata = mdi.getGridData('Z')
#gdata.extendToGlobal()

 

#---- Create a grid point and determine grid points are in or out of Tibet
nLayer = VectorLayer(ShapeTypes.Point)
Exemplo n.º 15
0
import org.meteoinfo.map.MapView
from org.meteoinfo.projection import ProjectionInfo
from calendar import monthrange
from calendar import month_abbr
import os.path
import sys
import os
import re

dirIn = sys.argv[1]
dirOut = sys.argv[2]
wantVars = sys.argv[3:]

takeOffDict = {'TPP3': 5, 'V10M': 5, 'T02M': 4}

Met = MeteoDataInfo()

yearstr = re.findall('\d{4}', dirIn)[0]
metType = os.path.split(dirIn)[1]

months = 12
shYear = str(int(yearstr) - 2000)

dirOut = (dirOut + '/' + yearstr + '/')


def zstr(num):
    #return the string of the number including a zero at beg
    if num < 10:
        val = "0" + str(num)
    else:
Exemplo n.º 16
0
from org.meteoinfo.data.meteodata import MeteoDataInfo
from org.meteoinfo.data.meteodata import Dimension
from org.meteoinfo.data.meteodata import DimensionType
from org.meteoinfo.data.meteodata import DrawMeteoData
from org.meteoinfo.legend import LegendScheme
from org.meteoinfo.shape import ShapeTypes
from ucar.nc2 import NetcdfFile
import os.path
import jarray

#Set data directory
dataDir = 'D:/Temp/toMingJing/AOD'
outDir = 'D:/Temp'

#Create MeteoDataInfo object
mdi = MeteoDataInfo()

#Read hdf data file
fn = os.path.join(
    dataDir,
    'MOD08_M3.A2000061.051.2010273213159.pscs_000500501908.Optical_Depth_Land_And_Ocean_Mean_Mean.G3.HDF'
)
if os.path.isfile(fn):
    print fn
    mdi.openNetCDFData(fn)
    dataInfo = mdi.getDataInfo()
    #print mdi.getInfoText()
    xmin = -180.0
    ymin = -90.0
    xnum = 360
    ynum = 180
Exemplo n.º 17
0
#---- Create MapLayout object
mapLayout = MapLayout()
mapFrame = mapLayout.getActiveMapFrame()
ps = PaperSize('Custum', 500, 1000)
mapLayout.setPaperSize(ps)

#---- Load country layer
print 'Load country layer...'
countryLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'country1.shp'))
lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
lb.setDrawFill(False)
lb.setOutlineColor(Color.black)
mapFrame.addLayer(countryLayer)

#---- Create MeteoDataInfo object
mdi = MeteoDataInfo()

#---- Open a MICAPS data file
fn = os.path.join(dataDir, 'MICAPS/10101414.000')
mdi.openMICAPSData(fn)

#---- Get station data
sdata = mdi.getStationData('WeatherNow')

#---- Create station weather layer from the station data
layer = DrawMeteoData.createWeatherSymbolLayer(sdata, 'All Weather', 'WeatherSymbole')
#weathers = [5,10,11,12,40,41,42,43,44,45,46,47,48,49]
#layer = DrawMeteoData.createWeatherSymbolLayer(sdata, weathers, 'WeatherSymbole')

#---- Add layer
mapFrame.addLayer(layer)
Exemplo n.º 18
0
# coding=utf-8
#-----------------------------------------------------
# Author: Yaqiang Wang
# Date: 2014-11-30
# Purpose: Open a NetCDF data file and show data information
# Note: Sample
#-----------------------------------------------------
#---- Import classes
print 'Import classes...'
from org.meteoinfo.data.meteodata import MeteoDataInfo
import os

#---- Set directories
print 'Set directories...'
baseDir = 'D:/MyProgram/Distribution/java/MeteoInfo/MeteoInfo'
dataDir = os.path.join(baseDir, 'sample')

#---- Create MeteoDataInfo object
mdi = MeteoDataInfo()

#---- Open a NetCDF data file
fn = os.path.join(dataDir, 'NetCDF/air.mon.ltm.nc')
mdi.openNetCDFData(fn)

#---- Show data information
print mdi.getInfoText()

print 'Finished!'
Exemplo n.º 19
0
# Purpose: Convert GRIB data to ARL data  
# Note: Sample                                                   
#-----------------------------------------------------------
from org.meteoinfo.data.meteodata import MeteoDataInfo
from org.meteoinfo.data.meteodata.arl import ARLDataInfo
from org.meteoinfo.data.meteodata.arl import DataLabel
import os

#---- Set directories
dataDir = "D:/Temp"

#---- Set output data file
outFile = os.path.join(dataDir, 'arl/test2.arl')

#---- Read a GRIB data file
mydata = MeteoDataInfo()
infile = os.path.join(dataDir, 'grib/201001011800.pgbh06.gdas.20100101-20100105.grb2')
print infile
mydata.openNetCDFData(infile)
print 'GRIB file has been opened...'

#---- Set output ARL data info
arlDI = ARLDataInfo()

#---- Set variable and level list
gvars = ['Pressure_surface','Temperature_height_above_ground',\
	'u-component_of_wind_height_above_ground','v-component_of_wind_height_above_ground',\
	'Geopotential_height_isobaric','Temperature_isobaric',\
	'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']
mapDir = os.path.join(baseDir, 'map')

#---- Create MapLayout object
mapLayout = MapLayout()
mapFrame = mapLayout.getActiveMapFrame()

#---- Load country layer
print 'Load country layer...'
countryLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'country1.shp'))
lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
lb.setDrawFill(False)
lb.setOutlineColor(Color.blue)
mapFrame.addLayer(countryLayer)

#---- Create MeteoDataInfo object
mdi = MeteoDataInfo()

#---- Open a MICAPS data file
fn = os.path.join(dataDir, 'MICAPS/10101414.000')
mdi.openMICAPSData(fn)

#---- Get station model data
smdata = mdi.getStationModelData()

#---- Create station info layer from the station model data
layer = DrawMeteoData.createStationModelLayer(smdata, 'StationModel')

#---- Add layer
mapFrame.addLayer(layer)

#--- Move layer to bottom
Exemplo n.º 21
0
mapDir = os.path.join(baseDir, 'map')

#---- Create MapLayout object
mapLayout = MapLayout()
mapFrame = mapLayout.getActiveMapFrame()

#---- Load country layer
print 'Load country layer...'
countryLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'country1.shp'))
lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
lb.setDrawFill(False)
lb.setOutlineColor(Color.blue)
mapFrame.addLayer(countryLayer)

#---- Create MeteoDataInfo object
mdi = MeteoDataInfo()

#---- Open a MICAPS data file
fn = os.path.join(dataDir, 'MICAPS/10101414.000')
mdi.openMICAPSData(fn)

#---- Get station data
sdata = mdi.getStationData('Visibility')

#---- Create station point layer from the grid data
layer = DrawMeteoData.createSTPointLayer(sdata, 'Visibility_STPoint', 'Visibility')

#---- Add layer
mapFrame.addLayer(layer)

#--- Move layer to bottom
#---- Create MapLayout object
mapLayout = MapLayout()
mapFrame = mapLayout.getActiveMapFrame()
layoutMap = mapLayout.getActiveLayoutMap()

#---- Load country layer
print 'Load country layer...'
countryLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'country1.shp'))
lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
lb.setDrawFill(False)
lb.setOutlineColor(Color.blue)
mapFrame.addLayer(countryLayer)

#---- Open netCDF data files
print 'Open netCDF data files...'
dataAir = MeteoDataInfo()
dataUwnd = MeteoDataInfo()
dataVwnd = MeteoDataInfo()
dataRhum = MeteoDataInfo()
dataAir.openNetCDFData(os.path.join(dataDir, 'air.2011.nc'))
dataUwnd.openNetCDFData(os.path.join(dataDir, 'uwnd.2011.nc'))
dataVwnd.openNetCDFData(os.path.join(dataDir, 'vwnd.2011.nc'))
dataRhum.openNetCDFData(os.path.join(dataDir, 'rhum.2011.nc'))

#---- Calculation
#---- Set date to June 23
#tIdx = 171
tIdx = 173
dataAir.setTimeIndex(tIdx);
dataUwnd.setTimeIndex(tIdx);
dataVwnd.setTimeIndex(tIdx);
Exemplo n.º 23
0
import org.meteoinfo.map.MapView
from org.meteoinfo.projection import ProjectionInfo
from calendar import monthrange
from calendar import month_abbr
import os.path
import sys
import os
import re

dirIn = sys.argv[1]
dirOut = sys.argv[2]
wantVars = sys.argv[3:]

takeOffDict = {'TPP3': 5, 'V10M': 5, 'T02M': 4}

Met = MeteoDataInfo()

yearstr = re.findall('\d{4}',dirIn)[0]
metType = os.path.split(dirIn)[1]

months = 12 
shYear = str(int(yearstr)-2000)

dirOut = (dirOut + '/' + yearstr + '/')

def zstr(num):
	#return the string of the number including a zero at beg
	if num<10:
		val = "0" + str(num)
	else:
		val = str(num)
Exemplo n.º 24
0
from org.meteoinfo.data.meteodata import MeteoDataInfo
from org.meteoinfo.data.meteodata import Dimension
from org.meteoinfo.data.meteodata import DimensionType
from org.meteoinfo.data.meteodata import DrawMeteoData
from org.meteoinfo.legend import LegendType
from org.meteoinfo.legend import LegendManage
from org.meteoinfo.shape import ShapeTypes
from ucar.nc2 import NetcdfFile
import os.path
import jarray

#Set data directory
dataDir = 'D:/Temp/hdf'

#Create MeteoDataInfo object
mdi = MeteoDataInfo()

#Read hdf data file
fn = os.path.join(dataDir, '3B43.19980101.7.HDF')
if os.path.isfile(fn):
    print fn
    mdi.openNetCDFData(fn)
    dataInfo = mdi.getDataInfo()
    #print mdi.getInfoText()
    xmin = -180.0
    ymin = -50.0
    xnum = 1440
    ynum = 400
    xdelt = 0.25
    ydelt = 0.25
    xlist = []
Exemplo n.º 25
0
            else:
                varList = [strVar]

            lvVarDict.update({lv: varList})
            tupAdd = (lv, varDict[va])
            if va in ncDict:
                idList = ncDict[va]
                idList += [tupAdd]
            else:
                idList = [tupAdd]
            ncDict.update({va: idList})

junk = ncDict.pop('x')
junk = lvVarDict.pop('x')

Met = MeteoDataInfo()

rightFullLvls = sorted(lvVarDict.keys(), reverse=True)
rightFullLvls = [rightFullLvls[-1]] + rightFullLvls[0:-1]

lvDict = dict(zip(range(len(rightFullLvls)), rightFullLvls))
hg2lvDict = dict(zip(rightFullLvls, range(len(rightFullLvls))))

Met = MeteoDataInfo()
exmPath = exampleNcSlice
Met.openNetCDFData(exmPath)
proj = Met.getProjectionInfo()
NCDI = Met.getDataInfo()

xs = NCDI.getXDimension()
ys = NCDI.getYDimension()
#---- Set directories
print 'Set directories...'
baseDir = 'D:/MyProgram/Distribution/java/MeteoInfo/MeteoInfo'
dataDir = os.path.join(baseDir, 'sample/MICAPS')
mapDir = os.path.join(baseDir, 'map')

#---- Create MapLayout object
mapLayout = MapLayout()

#---- Load project file (*.mip)
pfn = 'D:/Temp/mip/rain.mip'
mapLayout.loadProjectFile(pfn)
mapFrame = mapLayout.getActiveMapFrame()

#---- Create MeteoDataInfo object
mdi = MeteoDataInfo()

#---- Set start/end time
stime = datetime(2010,10,14,14)
etime = datetime(2010,10,14,20)

#---- Loop
print 'Get sum station data...'
sdata = StationData()
atime = stime
i = 0
while atime < etime:
	#---- Open a MICAPS data file
	fn = os.path.join(dataDir, stime.strftime('%y%m%d%H') + '.000')
	mdi.openMICAPSData(fn)
mapLayout.addElement(aLayoutMap)
aMapFrame.addLayer(bou1Layer_1)
aProjInfo = ProjectionInfo("+proj=lcc+lat_1=25+lat_2=47+lon_0=105")
aMapFrame.getMapView().projectLayers(aProjInfo)
aMapFrame.getMapView().zoomToExtentLonLatEx(Extent(106.5,122.5,1,23))

#---- Project mapview
print 'Project mapview...'
projStr = '+proj=lcc+lat_1=25+lat_2=47+lon_0=105'
projInfo = ProjectionInfo(projStr)
mapView.projectLayers(projInfo)
extent = Extent(78,130,15,53)
mapView.zoomToExtentLonLatEx(extent)

#---- Create MeteoDataInfo object
mdi = MeteoDataInfo()

#---- Set start/end time
stime = datetime(2010,10,14,14)
etime = datetime(2010,10,14,20)

#---- Loop
print 'Get sum station data...'
sdata = StationData()
atime = stime
i = 0
while atime < etime:
	#---- Open a MICAPS data file
	fn = os.path.join(dataDir, stime.strftime('%y%m%d%H') + '.000')
	mdi.openMICAPSData(fn)
Exemplo n.º 28
0
#---- Create MapLayout object
mapLayout = MapLayout()
mapFrame = mapLayout.getActiveMapFrame()

#---- Load country layer
print 'Load country layer...'
countryLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'country1.shp'))
lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
lb.setDrawFill(False)
lb.setOutlineColor(Color.blue)
mapFrame.addLayer(countryLayer)

#---- Open GrADS data
print 'Open GrADS data...'
mdi = MeteoDataInfo()
mdi.openGrADSData(os.path.join(dataDir, 'model.ctl'))

#---- Set time index
mdi.setTimeIndex(2)

#---- Get pressure grid data
gdata = mdi.getGridData('PS')
gdata.extendToGlobal()

#---- Create pressure shaded layer
print 'Create pressure shaded layer...'
pressLayer = DrawMeteoData.createShadedLayer(gdata, 'Pressure', 'PS', True)

#---- Add layer
mapFrame.addLayer(pressLayer)
mapDir = os.path.join(baseDir, 'map')

#---- Create MapLayout object
mapLayout = MapLayout()
mapFrame = mapLayout.getActiveMapFrame()

#---- Load country layer
print 'Load country layer...'
countryLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'country1.shp'))
lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
lb.setDrawFill(False)
lb.setOutlineColor(Color.black)
mapFrame.addLayer(countryLayer)

#---- Create MeteoDataInfo object
mdi = MeteoDataInfo()

#---- Open a MICAPS data file
fn = os.path.join(dataDir, 'MICAPS/10101414.000')
mdi.openMICAPSData(fn)

#---- Get wind direction/speed station data
windDir = mdi.getStationData('WindDirection')
windSpeed = mdi.getStationData('WindSpeed')

#---- Create barb and vector wind layers
bLayer = DrawMeteoData.createSTBarbLayer(windDir, windSpeed, 'WindBarb_Point', False)
vLayer = DrawMeteoData.createSTVectorLayer(windDir, windSpeed, 'WindVector_Point', False)

#---- Add layers
mapFrame.addLayer(bLayer)
Exemplo n.º 30
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.º 31
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.º 32
0
mapDir = os.path.join(baseDir, 'map')

#---- Create MapLayout object
mapLayout = MapLayout()
mapFrame = mapLayout.getActiveMapFrame()

#---- Load country layer
print 'Load country layer...'
countryLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'country1.shp'))
lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
lb.setDrawFill(False)
lb.setOutlineColor(Color.blue)
mapFrame.addLayer(countryLayer)

#---- Create MeteoDataInfo object
mdi = MeteoDataInfo()

#---- Open a MICAPS data file
fn = os.path.join(dataDir, 'MICAPS/10101414.000')
mdi.openMICAPSData(fn)

#---- Get station info data
sidata = mdi.getStationInfoData()

#---- Create station info layer from the station info data
ls = LegendScheme(ShapeTypes.Point)
ls.setLegendType(LegendType.SingleSymbol)
lbs = ls.getLegendBreaks()
lb = PointBreak()
lb.setSize(16)
lb.setColor(Color.blue)
Exemplo n.º 33
0
# Purpose: Convert GRIB data to ARL data
# Note: Sample
#-----------------------------------------------------------
from org.meteoinfo.data.meteodata import MeteoDataInfo
from org.meteoinfo.data.meteodata.arl import ARLDataInfo
from org.meteoinfo.data.meteodata.arl import DataLabel
import os

#---- Set directories
dataDir = "D:/Temp"

#---- Set output data file
outFile = os.path.join(dataDir, 'arl/test2.arl')

#---- Read a GRIB data file
mydata = MeteoDataInfo()
infile = os.path.join(dataDir,
                      'grib/201001011800.pgbh06.gdas.20100101-20100105.grb2')
print infile
mydata.openNetCDFData(infile)
print 'GRIB file has been opened...'

#---- Set output ARL data info
arlDI = ARLDataInfo()

#---- Set variable and level list
gvars = ['Pressure_surface','Temperature_height_above_ground',\
 'u-component_of_wind_height_above_ground','v-component_of_wind_height_above_ground',\
 'Geopotential_height_isobaric','Temperature_isobaric',\
 'u-component_of_wind_isobaric','v-component_of_wind_isobaric','Vertical_velocity_pressure_isobaric',\
 'Relative_humidity_isobaric']
Exemplo n.º 34
0
mapDir = os.path.join(baseDir, 'map')

#---- Create MapLayout object
mapLayout = MapLayout()
mapFrame = mapLayout.getActiveMapFrame()

#---- Load country layer
print 'Load country layer...'
countryLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'country1.shp'))
lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
lb.setDrawFill(False)
lb.setOutlineColor(Color.black)
mapFrame.addLayer(countryLayer)

#---- Create MeteoDataInfo object
mdi = MeteoDataInfo()

#---- Open a GrADS data file
fn = os.path.join(dataDir, 'GrADS/model.ctl')
mdi.openGrADSData(fn)

#---- Get U/V grid data
mdi.setTimeIndex(2)
mdi.setLevelIndex(3)
udata = mdi.getGridData('U')
vdata = mdi.getGridData('V')

#---- Create wind vector layer from the U/V grid data
layer = DrawMeteoData.createGridVectorLayer(udata, vdata,  'UV_Vector', True)
#layer = DrawMeteoData.createGridBarbLayer(udata, vdata,  'UV_Barb', True)
#layer = DrawMeteoData.createStreamlineLayer(udata, vdata, 'Z_Streamline', True)
Exemplo n.º 35
0
#---- Create MapLayout object
mapLayout = MapLayout()
mapFrame = mapLayout.getActiveMapFrame()
ps = PaperSize('Custum', 650, 640)
mapLayout.setPaperSize(ps)

#---- Load country layer
print 'Load country layer...'
countryLayer = MapDataManage.loadLayer(os.path.join(mapDir, 'country1.shp'))
lb = countryLayer.getLegendScheme().getLegendBreaks().get(0)
lb.setOutlineColor(Color.black)
lb.setOutlineSize(2)
mapFrame.addLayer(countryLayer)

#---- Create MeteoDataInfo object
mdi = MeteoDataInfo()

#---- Open a trajectory data file
print 'Open trajectory data file...'
fn = os.path.join(dataDir, 'HYSPLIT/tdump')
mdi.openHYSPLITTrajData(fn)
dataInfo = mdi.getDataInfo()

#---- Create trajectory layers
print 'Create trajectory layers...'
trajLayer = dataInfo.createTrajLineLayer()
startLayer = dataInfo.createTrajStartPointLayer()
lb = startLayer.getLegendScheme().getLegendBreaks().get(0)
lb.setStyle(PointStyle.Star)

#---- Add layer
Exemplo n.º 36
0
				varList = [strVar]
	
			lvVarDict.update({lv:varList})
			tupAdd = (lv, varDict[va])
			if va in ncDict:
				idList = ncDict[va]
				idList += [tupAdd]
			else:
				idList = [tupAdd]
			ncDict.update({va:idList})

junk = ncDict.pop('x')
junk = lvVarDict.pop('x')


Met = MeteoDataInfo()

rightFullLvls = sorted(lvVarDict.keys(), reverse=True)
rightFullLvls = [rightFullLvls[-1]] + rightFullLvls[0:-1]

lvDict = dict(zip(range(len(rightFullLvls)), rightFullLvls))
hg2lvDict = dict(zip(rightFullLvls, range(len(rightFullLvls))))

Met = MeteoDataInfo()
exmPath = exampleNcSlice
Met.openNetCDFData(exmPath)
proj = Met.getProjectionInfo()
NCDI = Met.getDataInfo()

xs = NCDI.getXDimension()
ys = NCDI.getYDimension()
Exemplo n.º 37
0
from org.meteoinfo.data.meteodata import MeteoDataInfo
from org.meteoinfo.data.meteodata import Dimension
from org.meteoinfo.data.meteodata import DimensionType
from org.meteoinfo.data.meteodata import DrawMeteoData
from org.meteoinfo.legend import LegendType
from org.meteoinfo.legend import LegendManage
from org.meteoinfo.shape import ShapeTypes
from ucar.nc2 import NetcdfFile
import os.path
import jarray

#Set data directory
dataDir = 'D:/Temp/hdf'

#Create MeteoDataInfo object
mdi = MeteoDataInfo()

#Read hdf data file
fn = os.path.join(dataDir, '3B43.19980101.7.HDF')
if os.path.isfile(fn):
	print fn
	mdi.openNetCDFData(fn)
	dataInfo = mdi.getDataInfo()
	#print mdi.getInfoText()
	xmin = -180.0
	ymin = -50.0
	xnum = 1440
	ynum = 400
	xdelt = 0.25
	ydelt = 0.25
	xlist = []