def icele(): # 获取ec数据 dics = ['ECMWF_HR\SKINT', 'ECMWF_HR\APCP', 'ECMWF_HR\SNOD'] ectime = ecmwf.ecreptime() fh = [i for i in range(12, 181, 3) ] # 20点的预报获取今天8:00的ec预报(此处可能存在问题,搞清12为5-8,还是8-11) lonlatset, dataset = [], [] for dic in dics: lon, lat, data = Datainterface.micapsdata(ectime, dic, fh) lonlatset.append(lon, lat) for i in range(data.shape[0] - 1): # 此处参考233上的改动 newdata = [] 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)) dataset.append(np.array(newdata)) # 保存插值后的数据集,data形状应为(57,X, X) return dataset
def main(): snowpath, gpath, fpath, rainpath, savepath = Writefile.readxml( glovar.forestpath, 0) # 积雪nc数据存放位置 snow = snowdepth(snowpath) # 积雪数据[10, 801, 1381] data, *_ = Weatherdata(glovar.forestpath) # 森林火险数据 ldtype = landtype(gpath, fpath) gindex, findex, mindex = firelevel(data, rainpath, snow, ldtype) # 最终生成指数 filetime = ecmwf.ecreptime() fh = range(10) fnames = ['_%03d' % i for i in fh] Writefile.write_to_nc(savepath, gindex, filetime=filetime, fnames=fnames, lat=glovar.lat, lon=glovar.lon, name='green') Writefile.write_to_nc(savepath, findex, filetime=filetime, fnames=fnames, lat=glovar.lat, lon=glovar.lon, name='forest') Writefile.write_to_nc(savepath, mindex, filetime=filetime, fnames=fnames, lat=glovar.lat, lon=glovar.lon, name='meteo')
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)
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)
def snowData(): # 获取ec数据信息(气温、降水、地温、湿度、积雪深度) ectime = ecmwf.ecreptime() fh = [i for i in range(12, 181, 3)] # 20点的预报获取今天8:00的ec预报 # *_, dics = Writefile.readxml(glovar.trafficpath, 0) *_, dics = Writefile.readxml( r'/home/cqkj/LZD/Product/Product/config/Traffic.xml', 0) dicslist = dics.split(',')[:-1] 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)
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)
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)
def main(): # 计算出来灾害落区 # dataset 为获取的各气象要素等级预报 ######读取nc要素文件##### varname = ['Rain', 'Snow_depth', 'Wind', 'Roadic'] datasets = [ xr.open_mfdataset(path, concat_dim='time').values for path, name in zip(filelist(), varname) ] rain, snow, wind, roadic = datasets roadic *= 8 snow *= 4 wind *= 2 rain *= 1 ######################## disaster = roadic + snow + wind + rain ######################## configpath = r'../config/disaster.xml' savepath = Writefile.readxml(configpath, 1)[-1] filetime = ecmwf.ecreptime() fh = range(3, 169, 3) fnames = ['_%03d' % i for i in fh] Writefile.write_to_nc(savepath, disaster, glovar.lat, glovar.lon, 'Disaster', fnames, filetime)
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(r'/home/cqkj/QHTraffic/Product/Traffic/ROADIC/config.xml', 0)).split(',')] new_lon = np.arange(region[0], region[2], region[-1]) new_lat = np.arange(region[1], region[3], region[-1]) ''' dataset = icele() icgrid = ice.icegrid(dataset, glovar.lat, glovar.lon) # savepath, indexpath = Writefile.readxml(r'/home/cqkj/QHTraffic/Product/Traffic/ROADIC/config.xml', 1)[2:] savepath, indexpath, cmpath, _ = Writefile.readxml(glovar.trafficpath, 4)[2:] # write(savepath, icgrid, 'Roadic', new_lat, new_lon) # 先保存厚度网格数据 write(savepath, icgrid, 'Roadic', glovar.lat, glovar.lon) # iceroad = ice.depth2onezero(icgrid, new_lat, new_lon) iceroad = ice.depth2onezero(icgrid, glovar.lat, glovar.lon) ################################################################################ # 获取cimiss数据集,此处仅为读取,实况数据获取及保存由另一程序实现 cmissdata = np.loadtxt(cmpath, delimiter=',') icedays = RoadIceindex(cmissdata, iceroad) roadicing = icedays.iceday() write(indexpath, roadicing, 'RoadicIndex', type=1)