示例#1
0
def iceData():
    # 获取ec数据信息(气温、降水、地温、湿度、积雪深度)
    ectime = ecmwf.ecreptime()
    fh = [i for i in range(12, 181, 3)]  # 20点的预报获取今天8:00的ec预报
    *_, dics = Writefile.readxml(glovar.trafficpath, 4)
    dicslist = dics.split(',')
    lonlatset, dataset = [], []
    for dic in dicslist:
        newdata = []
        lon, lat, data = Datainterface.micapsdata(ectime, dic, fh)
        lonlatset.append((lon, lat))
        for i in range(data.shape[0] - 1):
            if (np.isnan(data[i]).all() == True) and (i + 1 <= data.shape[0]):
                data[i] = data[i + 1] / 2
                data[i + 1] = data[i + 1] / 2
                newdata.append(
                    interp.interpolateGridData(data[i], lat, lon, glovar.lat,
                                               glovar.lon))
            else:
                newdata.append(
                    interp.interpolateGridData(data[i], lat, lon, glovar.lat,
                                               glovar.lon))
        newdata = np.array(newdata)
        # newdata[newdata<0] = 0                    # 保证数据正确性
        dataset.append(newdata)  # 保存插值后的数据集
    return np.array(dataset)
示例#2
0
def presnow():
    # 得到前一时刻积雪深度
    ectime = ecmwf.ecreptime()
    fh = [0]
    dic = 'ECMWF_HR/SNOD'
    lon, lat, data = Datainterface.micapsdata(ectime, dic, fh)
    return interp.interpolateGridData(data, lat, lon, glovar.lat, glovar.lon)
示例#3
0
文件: snow.py 项目: fourmia/learngit
def main():
    saltedata = saltedata(path)
    snowpre = np.random.randint(0, 1, size=(801 * 1381, 1))
    snow = SnowDepth()
    rep = ecmwf.ecreptime()
    fh = [i for i in range(12, 181, 3)]
    region = [
        float(i) for i in ','.join(
            Writefile.readxml(
                r'/home/cqkj/QHTraffic/Product/Traffic/SNOD/config.xml',
                0)).split(',')
    ]
    new_lon = np.arange(region[0], region[2], region[-1])
    new_lat = np.arange(region[1], region[3], region[-1])
    lonlatset, dataset = [], []
    # 提取数据及经纬度(双重循环,看能否改进)
    for dic in snow.dics:
        lon, lat, data = Datainterface.micapsdata(rep, dic, fh)
        lonlatset.append((lon, lat))
        for i in range(data.shape[0] - 1):
            if (np.isnan(data[i]).all() == True) and (i + 1 <= data.shape[0]):
                data[i] = data[i + 1] / 2
                data[i + 1] = data[i + 1] / 2
                interp.interpolateGridData(data, lat, lon, new_lat, new_lon)
            else:
                interp.interpolateGridData(data, lat, lon, new_lat, new_lon)
        dataset.append(data)  # 保存插值后的数据集
    depthgrid = snow.clcsd(dataset, new_lat, new_lon, saltedata, snowpre)
    snow.write(depthgrid, new_lat, new_lon)
    dangerindex = snow.clcindex(depthgrid, new_lat, new_lon)
    snow.write(dangerindex, type=1)
示例#4
0
def main():
    ice = Roadic()
    rep = ecmwf.ecreptime()
    fh = [i for i in range(12, 181, 3)]
    region = [float(i) for i in ','.join(Writefile.readxml(glovar.trafficpath, 0)).split(',')]
    new_lon = np.arange(region[0], region[2], region[-1])
    new_lat = np.arange(region[1], region[3], region[-1])
    lonlatset, dataset = [], []
    # 提取数据及经纬度(双重循环,看能否改进)
    for dic in ice.dics:
        lon, lat, data = Datainterface.micapsdata(rep, dic, fh)
        lonlatset.append((lon, lat))
        for i in range(data.shape[0] - 1):
            if (np.isnan(data[i]).all() == True) and (i + 1 <= data.shape[0]):
                data[i] = data[i + 1] / 2
                data[i+1] = data[i + 1] / 2
                interp.interpolateGridData(data,lat,lon,new_lat, new_lon)
            else:
                interp.interpolateGridData(data, lat, lon,new_lat, new_lon)
        dataset.append(data)                     # 保存插值后的数据集
    icgrid = ice.icegrid(dataset, new_lat, new_lon)
    savepath, indexpath = Writefile.readxml(glovar.trafficpath, 1)[2:]
    write(savepath, icgrid, 'Roadic', new_lat, new_lon)               # 先保存厚度网格数据
    iceroad = ice.depth2onezero(icgrid, new_lat, new_lon)
    ################################################################################
    # 获取cimiss数据集,此处仅为读取,实况数据获取及保存由另一程序实现
    cmissdata = np.loadtxt('/home/cqkj/QHTraffic/qhroadic/cmsk.csv', delimiter=',')
    icedays = RoadIceindex(cmissdata, iceroad)
    roadicing = icedays.iceday()
    write(indexpath, roadicing, 'RoadicIndex', type=1)
示例#5
0
def write(path, data, name, lat=None, lon=None, type=0):
    filetime = ecmwf.ecreptime()
    fh = range(3, 169, 3)
    fnames = ['_%03d' % i for i in fh]
    if type == 0:
        Writefile.write_to_nc(path, data, lat, lon, name, fnames, filetime)
    else:
        Writefile.write_to_csv(path, data, name, fnames, filetime)
示例#6
0
文件: snow.py 项目: fourmia/learngit
 def write(self, data, lat=None, lon=None, type=0):
     filetime = ecmwf.ecreptime()
     fh = range(3, 169, 3)
     fnames = ['_%03d' % i for i in fh]
     name = 'Snow'
     if type == 0:
         Writefile.write_to_nc(self.savepath, data, lat, lon, name, fnames,
                               filetime)
     else:
         Writefile.write_to_csv(self.indexpath, data, 'SnowIndex', fnames,
                                filetime)
示例#7
0
        self.prosrs, self.geosrs = self.getSRSPair()

    def getSRSPair(self):
        """获取投影坐标系和地理坐标系"""
        prosrs = osr.SpatialReference()
        prosrs.ImportFromWkt(self._dataset.GetProjection())
        geosrs = prosrs.CloneGeogCS()
        return prosrs, geosrs

    def imagexy2pro(self):
        """将图上坐标转化为投影坐标"""
        row, col = np.mgrid[0:self._shape[0], 0:self._shape[1]]
        trans = self._dataset.GetGeoTransform()
        px = trans[0] + col * trans[1] + row * trans[2]
        py = trans[3] + col * trans[4] + row * trans[5]
        return px, py

    def pro2geo(self,x,y):
        """将投影坐标转化为地理坐标,仅仅适用于单点,非等经纬度"""
        ct = osr.CoordinateTransformation(self.prosrs, self.geosrs)
        coords = ct.TransformPoint(x,y)
        return coords[:2]
'''
if __name__ == '__main__':
    ectime = ecmwf.ecreptime()
    dics = ['ECMWF_HR/RH/1000', 'ECMWF_HR/SKINT']
    fh = list(range(12, 72, 3)) + list(range(72, 205, 6))
    data = micapsdata(ectime, dics, fh)
    with open('ectest.pkl', 'wb') as f:
        f.dump()