Exemplo n.º 1
0
def gen_clmbry(date,FA='a',nest=0,cf=CONF,quiet=True):
  date=dateu.parse_date(date)
  err=''
  isFatal=False

  fclm=opt.nameof('in','clm',date=date,FA=FA,nest=nest,cf=cf)
  fbry=opt.nameof('in','bry',date=date,FA=FA,nest=nest,cf=cf)
  grd=opt.nameof('in','grd',cf=cf)

  if os.path.isfile(fclm) and os.path.isfile(fbry):
    err='CLMBRY files already exists'
    isFatal=False
  else:
    nforec=opt.n_pred(cf)
    import get_mercator as get_hycom
    # no need to check if data is ready! if not gen_clm_bry will return error!
    # anyway, cannot know if hycom data of today is analtsis or forecast!!

    date1=None
    if FA=='f': date1=dateu.parse_date(dateu.next_date(date,nforec))
    try:
      err=get_hycom.gen_clm_bry(fclm,fbry,grd,date,date1,quiet=quiet)
      if err:
        err='ERROR creating clm bry files : %s' % err
        isFatal=True
    except:
      err='ERROR creating clm bry files'
      isFatal=True


  return err, isFatal, fclm,fbry
Exemplo n.º 2
0
def gen_atmfrc(date,FA='a',nest=0,cf=CONF,quiet=True):
  date=dateu.parse_date(date)
  err=''
  isFatal=False

  fname=opt.nameof('in','blk',date=date,FA=FA,nest=nest,cf=cf)

  if os.path.isfile(fname):
    err='BLK file already exists'
    isFatal=False
  else:
    grd=opt.nameof('in','grd',cf=cf)
    atmPath = opt.pathof(cf,'external','atm')
    atmData=opt.atm_info(cf)['data']
    nforec=opt.n_pred(cf)

    if atmData=='wrf':
      cycle=366-29+dateu.mndays(date.year,date.month)
      err=bfrc.make_blk_wrf(fname,grd,date,FA,atmPath,quiet=quiet,cycle=cycle)
    elif atmData=='gfs':
      from okean.roms.inputs import surface
      if FA=='a': nforec=0
      model=opt.get_conf(cf,'MODEL','name',type=str)[nest].lower()
      surface.make_blk_gfs(atmPath,grd,fname,date,nforec=nforec,model=model,quiet=quiet)

    try:
      if err:
        err='ERROR creating bulk file ('+err+')'
        isFatal=True
    except OSError, e:
      err='ERROR creating bulk file ('+str(e)+')'
      isFatal=True
    except:
Exemplo n.º 3
0
def check_bc(date,FA,wait=3600,cf=CONF):
  print 'checking parent model...'
  import get_mercator as get_hycom
  nforec=opt.n_pred(cf)
  date1=None
  if FA=='f': date1=dateu.parse_date(dateu.next_date(date,nforec))

  ir=get_hycom.is_ready(date,date1,check1=FA=='a')

  if get_hycom.is_ready(date,date1):
    print 'bc ok at check'
    return True
  else:
    now   = dateu.currday()
    tdiff = dateu.date_diff(date,now)
    print "waiting for bc"
    while tdiff.days < 1.5:
      time.sleep(wait)
      sys.stdout.write('.')
      now   = dateu.currday()
      tdiff = dateu.date_diff(date,now)

      cond= get_hycom.is_ready(date,date1,check1=FA=='a')
      print "  bc file ready =  ",cond,' at ',now, tdiff
      if cond: return True

  return get_hycom.is_ready(date,date1,check1=FA=='a')
Exemplo n.º 4
0
def gen_rivfrc(date,FA='a',nest=0,cf=CONF):
  date=dateu.parse_date(date)
  err=''
  isFatal=False

  fname=opt.nameof('in','frc',date=date,FA=FA,nest=nest,cf=cf)
  grd=opt.nameof('in','grd',cf=cf)

  if os.path.isfile(fname):
    err='RIVERS file already exists'
    isFatal=False
  else:
    nforec=opt.n_pred(cf)
    import get_rivers
    date1=None
    if FA=='f': date1=dateu.parse_date(dateu.next_date(date,nforec))
    try:
      err=get_rivers.gen_frc(fname,grd,date,date1)
    except:
      err='ERROR creating rivers file'

    if err: isFatal=True

  return err, isFatal, fname
Exemplo n.º 5
0
def check_atm(date,FA,wait=3600,cf=CONF):
  atmPath = opt.pathof(cf,'external','atm')
  atmData=opt.atm_info(cf)['data']
  npred=opt.n_pred(cf)
  if atmData=='wrf':
    from ompy.roms import atmblk_forcing as bfrc
    ir=bfrc.is_ready_wrf(date,FA,wrfpath=atmPath)
  elif atmData=='gfs':
    from okean.datasets.gfs import is_ready as is_ready_gfs
    ir=is_ready_gfs(atmPath,date,FA,npred)

  if ir is True:
    print 'atm ok at check'
    return True

  now   = dateu.currday()
  tdiff = now-date
  tdiff=tdiff.days+tdiff.seconds/86400.

  print "waiting for atm: %s" % FA
  if FA=='a':
    # wait till 12am today to start creating anaylysis of prev day!->tdif=1.5
    # with all atm data ok
    # if time higher, the available possible data is used.
    while tdiff < 1.5:
      time.sleep(wait)
      sys.stdout.write('.')

      now   = dateu.currday()
      tdiff = now-date
      tdiff=tdiff.days+tdiff.seconds/86400.

      if atmData=='wrf':
        ir=bfrc.is_ready_wrf(date,FA,wrfpath=atmPath)
      elif atmData=='gfs':
        ir=is_ready_gfs(atmPath,date,FA,npred)

      print "  atm data ready = %s  : %s  tdiff %6.2f"%(ir,now.isoformat(' '), tdiff)

      if ir is True: return True

  elif FA=='f':
    # if atm not data present after tdiff, forget current forecast
    while tdiff < 1.5:
      time.sleep(wait)
      sys.stdout.write('.')

      now   = dateu.currday()
      tdiff = now-date
      tdiff=tdiff.days+tdiff.seconds/86400.

      if atmData=='wrf':
        ir=bfrc.is_ready_wrf(date,FA,wrfpath=atmPath)
      elif atmData=='gfs':
        ir=is_ready_gfs(atmPath,date,FA,npred)

      print "  atm data ready = ",ir,' at ',now, tdiff

      if ir is True: return True

  return ir