コード例 #1
0
ファイル: fuel_moisture_da.py プロジェクト: huangynj/wrfxpy
def assimilate_fm10_observations(path_wrf, path_wrf0, mesowest_token):
  
  # load the wrfinput file
  wrfin = WRFModelData(path_wrf, ['T2', 'Q2', 'PSFC', 'HGT', 'FMC_GC', 'FMEP'])
  lat, lon = wrfin.get_lats(), wrfin.get_lons()
  tss = wrfin.get_gmt_times()
  tm_start, tm_end = tss[0], tss[-1]
  dom_shape = lat.shape
  logging.info('FMDA domain size is %d x %d grid points with lats (%g to %g) and lons (%g to %g)' %
              (dom_shape[0], dom_shape[1],np.amin(lat),np.amax(lat),np.amin(lon),np.amax(lon)))

  # compute the diagonal distance between grid points
  grid_dist_km = great_circle_distance(lon[0,0], lat[0,0], lon[1,1], lat[1,1])
 
  # retrieve fuel moisture observations via the Mesowest API
  fm10 = retrieve_mesowest_observations(mesowest_token, tm_start, tm_end, wrfin.get_lats(), wrfin.get_lons())

  logging.info('FMDA retrieved %d observations from Mesowest.' % len(fm10))

  # if a previous cycle is available (i.e. the wrfoutput is a valid file), load the model
  prev_wrf = None
  if path_wrf0 is not None and os.path.exists(path_wrf0) and check_overlap(path_wrf0,tm_start):
      prev_wrf = WRFModelData(path_wrf0)
      outts = prev_wrf['GMT']
      logging.info("FMDA previous forecast [%s - %s] exists" % (str(outts[0]),str(outts[-1])))
  else:
      logging.info("FMDA no previous forecast found, running DA from equilibrium at %s" % str(tm_start))
 
  # run from the start until now (retrieve fuel moisture, extended parameters, covariance matrix)
  run_data_assimilation(wrfin, fm10, prev_wrf)

  return 0
コード例 #2
0
ファイル: fuel_moisture_da.py プロジェクト: huangynj/wrfxpy
def check_overlap(wrf_path,ts_now):
  """
  Check if the WRF file <wrf_path> timstamps contain <ts_now>.
  """
  wrfout = WRFModelData(wrf_path)
  outts = wrfout['GMT']
  if ts_now in outts:
    return True
  else:
    logging.info("FMDA previous forecast [%s - %s] exists, running DA till %s" % (str(outts[0]),str(outts[-1]),str(ts_now)))
    return False