当前位置: 首页>>代码示例>>Python>>正文


Python netcdftime.utime函数代码示例

本文整理汇总了Python中netcdftime.utime函数的典型用法代码示例。如果您正苦于以下问题:Python utime函数的具体用法?Python utime怎么用?Python utime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了utime函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: read_ncdf

def read_ncdf(name,path='/work/gg0877/KST/tide_gaughes/ncdf',origin='2012-01-01 00:00:00'):
  ncname = '_'.join(word[0].upper()+word[1:] for word in name.split('_'))
  if path[-6:]=='hawaii':
    nc = netCDF4.MFDataset(path+'/'+ncname+'*.nc')
  else:
    nc = netCDF4.Dataset(path+'/'+ncname+'.nc')
  ncv = nc.variables
  ot = utime('seconds since '+origin)
  ut = utime(ncv['time'].units)
  time = ot.date2num(ut.num2date(ncv['time'][:]))
  print(ncv.keys())
  scale = {'cm':100.,'m':1.0,'millimeters':1000.,'mm':1000.}

  if 'elev' in ncv:
    if 'units' in ncv['elev'].ncattrs():
      scale_factor = scale[ncv['elev'].units]
    else:
      if ncv['elev'][:].std()>100.:
        scale_factor=1000.
      elif ncv['elev'][:].std()>10.:
        scale_factor=100.
      else:
        scale_factor=1.0
    elev = ncv['elev'][:].squeeze()/scale_factor
  elif 'sea_surface_height_above_reference_level' in ncv:
    if 'units' in ncv['sea_surface_height_above_reference_level'].ncattrs():
      scale_factor = scale[ncv['sea_surface_height_above_reference_level'].units]
    else:
      scale_factor = 1000.
    elev = ncv['sea_surface_height_above_reference_level'][:].squeeze()/scale_factor
  nc.close()
  return time,elev
开发者ID:hofmeist,项目名称:schism-setups,代码行数:32,代码来源:plot_tide_stations.py

示例2: check

 def check(self, max_n_ticks, num1, num2):
     locator = NetCDFTimeDateLocator(max_n_ticks=max_n_ticks,
                                     calendar=self.calendar,
                                     date_unit=self.date_unit)
     utime = netcdftime.utime(self.date_unit, self.calendar)
     return locator.compute_resolution(num1, num2, utime.num2date(num1),
                                       utime.num2date(num2))
开发者ID:djkirkham,项目名称:nc-time-axis,代码行数:7,代码来源:test_NetCDFTimeDateLocator.py

示例3: read_ncom

def read_ncom(flow_data):
    print '  > NCOM;'
    filename  = data_dir + '/ncom/ncom_glb_regp01_2012-3-4-5.nc'

    ncf   = netCDF4.Dataset(filename,'r')
    ncvar = ncf.variables
    time       = ncvar['time']
    utime      = netcdftime.utime(time.units)
    dates      = utime.num2date(time[:])
    sta_name   = filename.split('/')[-1][:3]
    
    lona,lata = np.meshgrid(ncvar['lon'][:],ncvar['lat'][:])
    dist = ((lona - lon_orig)**2 + (lata - lat_orig)**2)
    [i,j] = np.where(dist==dist.min())
    
    elev  = ncvar['surf_el'][:,i,j].flatten()
    data  = pd.DataFrame(data = elev, columns = ['elev'], index = dates)    
    data  = data.dropna()
    data  = data.resample('H')  #hourly mean
    
    date_tmp =  ps.datetime64todatetime(data.index.values)
    datenum  = [ps.datetime2datenum(datei) for datei in  date_tmp]
    
    flow_data[sta_name]['name_long'] = 'Elevation from NCOM model '
    flow_data[sta_name]['lat']       = lata[i,j].item()
    flow_data[sta_name]['lon']       = lona[i,j].item()
    flow_data[sta_name]['elev']      = data['elev'].values
    flow_data[sta_name]['date']      = date_tmp
    flow_data[sta_name]['datenum_mat']   = datenum
开发者ID:moghimis,项目名称:pynmd,代码行数:29,代码来源:tide_analysis.py

示例4: units_checker

 def units_checker(units):
     try:
         u = utime(units)
         return u.unit_string
     except ValueError, TypeError:
         msg = 'Invalid time units format - Available format is "{}"'.format(TIME_UNITS_FORMAT)
         raise ArgumentTypeError(msg)
开发者ID:Prodiguer,项目名称:nctime,代码行数:7,代码来源:parser.py

示例5: read_Elgar_pressure_data

def read_Elgar_pressure_data(flow_data):
    print '   > Elgar pressure data;'
    dir1 = data_dir + '/elgar/*_filter_abs.nc'
    flist    = glob.glob(dir1)
    flist.sort()

    for filename in flist[:]:
        ncf   = netCDF4.Dataset(filename,'r')
        ncvar = ncf.variables
        time       = ncvar['time']
        utime      = netcdftime.utime(time.units)
        dates      = utime.num2date(time[:])
        sta_name   = filename.split('/')[-1][:3]
        if 'p' in sta_name or 'q' in sta_name:
            print '    > read  > Station name: ', sta_name
    
            water_depth = ncvar['water_depth'][:]
    
            data  = pd.DataFrame(data = water_depth, columns = ['water_depth'], index = dates)    
            data  = data.dropna()
            data  = data.resample('H')  #hourly mean
            
            date_tmp =  ps.datetime64todatetime(data.index.values)
            datenum  = [ps.datetime2datenum(datei) for datei in  date_tmp]

            
            flow_data[sta_name]['name_long'] = 'Bottom pressure '+sta_name
            flow_data[sta_name]['lat']       = ncvar['lat'][:]
            flow_data[sta_name]['lon']       = ncvar['lon'][:]
            flow_data[sta_name]['elev']      = (data['water_depth'] - data['water_depth'].mean()).values
            flow_data[sta_name]['date']      = date_tmp
            flow_data[sta_name]['datenum_mat']   = datenum
开发者ID:moghimis,项目名称:pynmd,代码行数:32,代码来源:tide_analysis.py

示例6: __init__

  def __init__(self,ncfile='na_aviso_2012.nc'):
    self.sshname='adt_mean'
    self.lonname='lon'
    self.latname='lat'
    self.timename='time'

    nc = netCDF4.Dataset(ncfile)
    sv = nc.variables
    self.ncv = sv
    xslice=slice(None)
    yslice=slice(None)
    self.lon = sv[self.lonname][xslice]
    self.lat = sv[self.latname][yslice]
    self.lon2,self.lat2 = np.meshgrid(self.lon,self.lat)
    self.time = sv[self.timename][:]
    self.timeunits = sv[self.timename].units
    self.ut = netcdftime.utime(self.timeunits)
    self.dates = self.ut.num2date(self.time)
    self.ssh = sv[self.sshname][yslice,xslice]

    print('  build spatial tree')
    self.mask = self.ssh.mask.squeeze()
    self.water = where(self.mask==False)
    vlon2 = self.lon2[self.water]
    vlat2 = self.lat2[self.water]
    self.tree = cKDTree(zip(vlon2,vlat2))
开发者ID:hofmeist,项目名称:schism-setups,代码行数:26,代码来源:avisodata.py

示例7: get_list_dates_from_nc

def get_list_dates_from_nc(nc, type_dates):
    
    '''
    Returns list of dates from NetCDF dataset.
    
    :param nc: NetCDF dataset
    :type nc: netCDF4.Dataset
    :param type_dates: type of dates ('dt' for datetime objects, 'num' for float objects) 
    :type type_dates: str

    :rtype: list of datetime/float 
    
    '''
    
    var_time = nc.variables['time']
    time_units = var_time.units # str (ex.: 'days since 1850-01-01 00:00:00')
    try:
        time_calend = var_time.calendar # str (ex.: 'standard'/'gregorian'/...)
    except:
        time_calend = 'gregorian'
    
    if type_dates == 'num':
        arr_dt = var_time[:]
        list_dt = arr_dt.tolist() # numpy array -> list
        
    if type_dates == 'dt':
        t = netcdftime.utime(time_units, time_calend) 
        arr_dt = t.num2date(var_time[:]) 
        list_dt = arr_dt.tolist() # numpy array -> list
    del arr_dt
    
    return list_dt
开发者ID:andrejsim,项目名称:icclim,代码行数:32,代码来源:util_dt.py

示例8: load_time

 def load_time(self):
   tnum=self.nc.variables['time'][-self.ntimes_max:]
   tunits=self.nc.variables['time'].units
   self.time=utime(tunits,calendar='standard').num2date(tnum)
   ind0=self.nc.variables['time'].size-self.ntimes_max
   ind1=self.nc.variables['time'].size
   self.time_inds=range(ind0,ind1)
开发者ID:martalmeida,项目名称:tabs,代码行数:7,代码来源:radar.py

示例9: num2date

def num2date(tnum,tunits,calendar='standard'):
  from netcdftime import utime

  #return utime(tunits,calendar).num2date(tnum)
  # for numpy 1.15.3 there are problems with masked arrays without mask!
  # for some reason, removing mask or dividing by 1 solves the problem!!!
  return utime(tunits,calendar).num2date(tnum/1)
开发者ID:martalmeida,项目名称:okean,代码行数:7,代码来源:netcdf.py

示例10: get_list_dates

def get_list_dates(ifile, type_dates):
    
    '''
    Returns list of dates from one file.
    
    :param ifile: NetCDF file
    :type ifile: str
    :param type_dates: type of dates ('dt' for datetime objects, 'num' for float objects) 
    :type type_dates: str

    :rtype: list of datetime/float 
    
    '''
    
    nc = Dataset(ifile, 'r')
    var_time = nc.variables['time']
    time_units = var_time.units # str (ex.: 'days since 1850-01-01 00:00:00')
    time_calend = var_time.calendar # str (ex.: 'standard'/'gregorian'/...)
    
    if type_dates == 'num':
        arr_dt = var_time[:]
        list_dt = arr_dt.tolist() # numpy array -> list
        
    if type_dates == 'dt':
        t = utime(time_units, time_calend) # <netcdftime.utime instance at 0xecae18>
        arr_dt = t.num2date(var_time[:]) # arr_dt: numpy array of dates datetime; var_time[:]: time values (ex.: [49323.5, 49353, 49382.5, ...])
        list_dt = arr_dt.tolist() # numpy array -> list
    del arr_dt
    
    nc.close()
    
    return list_dt
开发者ID:NCPP,项目名称:icclim,代码行数:32,代码来源:icclim.py

示例11: _fix_netcdftime_datetime

def _fix_netcdftime_datetime(dt, unit):
    # Fix netcdftime bug: netcdftime.datetime(2000, 03, 31).dayofyr
    # Happens to work with datetime objects too.
    fix_unit = "days since {}".format(str(dt))
    fix_utime = netcdftime.utime(fix_unit, calendar=unit.calendar)
    dt = fix_utime.num2date(0)
    return dt
开发者ID:mcmweb80,项目名称:iris,代码行数:7,代码来源:util.py

示例12: num2date

def num2date(num, calend, units):
    '''
    type num: float date
    '''   
    t = utime(units, calend) 
    dt = t.num2date(num) 
    return dt
开发者ID:NCPP,项目名称:icclim,代码行数:7,代码来源:icclim.py

示例13: date2num

def date2num(dt, calend, units):
    '''
    type dt: datetime object
    '''
    t = utime(units, calend)
    dt_num = t.date2num(dt)
    return dt_num
开发者ID:NCPP,项目名称:icclim,代码行数:7,代码来源:icclim.py

示例14: read_d3d_time

def read_d3d_time(netcdf_vars):
    """
    Read time from netcdf file and return Datetime vector
    """
    utime = netcdftime.utime(netcdf_vars['time'].units)
    dates = utime.num2date(netcdf_vars['time'][:])
    return dates
开发者ID:garciaga,项目名称:pynmd,代码行数:7,代码来源:delft3d_post.py

示例15: extract_netcdf_time

 def extract_netcdf_time(cls, bandName, calendar):
     """Convert netcdf time to datetime using appropriate library"""
     from netcdftime import utime
     epoch, units = cls.extract_epoch_units(bandName)
     cdftime = utime(units, calendar)
     timestamps = cdftime.num2date([epoch])
     return timestamps[0]
开发者ID:jeperez,项目名称:TimeManager,代码行数:7,代码来源:cdflayer.py


注:本文中的netcdftime.utime函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。