Exemple #1
0
def lookup(x, y, z, table, mod='column'):
    if mod == 'column':
        table = table.T
    _x, _y, _z, _fs = table[0], table[1], table[2], table[3:]
    result = array([x, y, z])
    for _f in _fs:
        _table = array([_x, _y, _z, _f]).T
	result.append(trunc(interp3d(x, y, z, _table), 14))
    return result
def ltmPressure(jdays, time, lon, lat, ncfile):
    """
    Extract pressure value from a daily long-term mean SLP dataset at the
    given day of year and lon,lat position
    To use this function (and hence some form of daily LTM SLP data) requires
    knowledge of the day of year.

    :param jdays: Julian day (day of year) values.
    :param time: Time of day for each observation (fraction of a day).
    :param lon: Longitude of TC position.
    :param lat: Latitude of TC position.
    :param str ncfile: Path to netCDF file containing daily long-term mean
                       sea level pressure data.

    :type  jdays: :class:`numpy.ndarray`
    :type  time: :class:`numpy.ndarray`
    :type  lon: :class:`numpy.ndarray`
    :type  lat: :class:`numpy.ndarray`

    :returns: :class:`numpy.ndarray` of long-term mean sea level pressure
              values at the day of year and positions given.
    """
    jtime = jdays + np.modf(time)[0]
    coords = np.array([jtime, lat, lon])

    LOG.debug("Sampling data from MSLP data in {0}".format(ncfile))
    ncobj = nctools.ncLoadFile(ncfile)
    slpunits = getattr(ncobj.variables['slp'], 'units')

    data = nctools.ncGetData(ncobj, 'slp')
    # Get the MSLP by interpolating to the location of the TC:
    penv = interp3d.interp3d(data,
                             coords,
                             scale=[365., 180., 360.],
                             offset=[0., -90., 0.])
    penv = metutils.convert(penv, slpunits, 'hPa')
    del data
    ncobj.close()
    del ncobj

    return penv
Exemple #3
0
def ltmPressure(jdays, time, lon, lat, ncfile):
    """
    Extract pressure value from a daily long-term mean SLP dataset at the
    given day of year and lon,lat position
    To use this function (and hence some form of daily LTM SLP data) requires
    knowledge of the day of year.

    :param jdays: Julian day (day of year) values.
    :param time: Time of day for each observation (fraction of a day).
    :param lon: Longitude of TC position.
    :param lat: Latitude of TC position.
    :param str ncfile: Path to netCDF file containing daily long-term mean
                       sea level pressure data.

    :type  jdays: :class:`numpy.ndarray`
    :type  time: :class:`numpy.ndarray` 
    :type  lon: :class:`numpy.ndarray`
    :type  lat: :class:`numpy.ndarray`

    :returns: :class:`numpy.ndarray` of long-term mean sea level pressure
              values at the day of year and positions given. 
    """
    jtime = jdays + np.modf(time)[0]
    coords = np.array([jtime, lat, lon])

    logger.debug("Sampling data from MSLP data in {0}".format(ncfile))
    ncobj = nctools.ncLoadFile(ncfile)
    slpunits = getattr(ncobj.variables['slp'], 'units')

    data = nctools.ncGetData(ncobj, 'slp')
    # Get the MSLP by interpolating to the location of the TC:
    penv = interp3d.interp3d(data, coords, scale=[365., 180., 360.],
                             offset=[0., -90., 0.])
    penv = metutils.convert(penv, slpunits, 'hPa')
    del data
    ncobj.close()
    del ncobj

    return penv
Exemple #4
0
def ltmPressure(jdays, time, lon, lat, ncfile):
    """
    Extract pressure value from a daily long-term mean SLP dataset at the
    given day of year and lon,lat position
    To use this function (and hence some form of daily LTM SLP data) requires
    knowledge of the day of year.
    """
    jtime = jdays + np.modf(time)[0]
    coords = np.array([jtime, lat, lon])

    logger.debug("Sampling data from MSLP data in {0}".format(ncfile))
    ncobj = nctools.ncLoadFile(ncfile)
    slpunits = getattr(ncobj.variables['slp'], 'units')

    data = nctools.ncGetData(ncobj, 'slp')
    # Get the MSLP by interpolating to the location of the TC:
    penv = interp3d.interp3d(data, coords)
    penv = metutils.convert(penv, slpunits, 'hPa')
    del data
    ncobj.close()
    del ncobj

    return penv
Exemple #5
0
    coords = ncv[var].coordinates.split()
    v = nc.createVariable(var+'_z',vardtype,newdims)
    v.units = ncv[var].units
    v.long_name = ncv[var].long_name
    v.standard_name = ncv[var].standard_name
    v.missing_value = fillvalue
    #v.coordinates = zaxname+' '+coords[1]+' '+coords[2]
    v.coordinates = coords[2]+' '+coords[1]


# so far assume sigma coordinates
for t in range(tnum):
  print('  timestep %d'%t)
  h = numpy.tile(depth[t]/znum,(znum,1,1))
  z = cumsum(h,axis=0)-0.5*h - numpy.tile(depth[t],(znum,1,1))
  for varname in variables:
    # Cython:
    ncv[varname+'_z'][t] = interp3d(z.filled(1.0),ncv[varname][t].filled(fillvalue),-zlevels,fillvalue=fillvalue)

    # Scipy interp:    
    #
    #for j in range(ynum):
    #  for i in range(xnum):
    #    varz[:,j,i] = interp(-zlevels,squeeze(z[:,j,i]),squeeze(ncv[varname][t,:,j,i]))
    #ncv[varname+'_z'][t]=varz

  nc.sync()

nc.close()