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


Python nco.Nco类代码示例

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


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

示例1: test_use_list_options

def test_use_list_options(foo_nc):
    nco = Nco(debug=True)
    options = []
    options.extend(['-a', 'units,time,o,c,days since 1999-01-01'])
    options.extend(['-a', 'long_name,time,o,c,time'])
    options.extend(['-a', 'calendar,time,o,c,noleap'])
    nco.ncrcat(input=foo_nc, output='out.nc', options=options)
开发者ID:jvegasbsc,项目名称:pynco,代码行数:7,代码来源:test_nco.py

示例2: test_returnArray

def test_returnArray(foo_nc):
    nco = Nco(cdfMod='netcdf4')
    random1 = nco.ncea(input=foo_nc, output="tmp.nc", returnCdf=True, options=['-O']).variables['random'][:]
    assert type(random1) == np.ndarray
    random2 = nco.ncea(input=foo_nc, output="tmp.nc",returnArray='random' ,options=['-O'])
    assert type(random2) == np.ndarray
    np.testing.assert_equal(random1, random2)
开发者ID:jvegasbsc,项目名称:pynco,代码行数:7,代码来源:test_nco.py

示例3: normalize_time

def normalize_time(netcdf_file):
    epoch_units       = 'seconds since 1970-01-01T00:00:00Z'
    millisecond_units = 'milliseconds since 1858-11-17T00:00:00Z'

    with nc4.Dataset(netcdf_file, 'a') as nc:
        # Signell said this works, any problems and we can all blame him!
        time_data = nc4.num2date(
            (
                np.int64(nc.variables['time'][:]) - 2400001
            ) * 3600 * 24 * 1000 + nc.variables['time2'][:].__array__(),
            units=millisecond_units
        )
        nc.renameVariable("time", "old_time")
        nc.sync()

        time = nc.createVariable('time', 'f8', ('time'))
        time.units          = epoch_units
        time.standard_name  = "time"
        time.long_name      = "time of measurement"
        time.calendar       = "gregorian"
        time.axis           = "T"
        time[:] = nc4.date2num(time_data, units=epoch_units).round()

    o = Nco()
    o.ncks(
        input=netcdf_file,
        output=netcdf_file,
        options=[
            '-O',
            '-h',
            '-x',
            '-v', 'time2,old_time'
        ]
    )
开发者ID:USGS-CMG,项目名称:usgs-cmg-portal,代码行数:34,代码来源:utils.py

示例4: test_use_list_options

def test_use_list_options(foo_nc):
    nco = Nco(debug=True)
    options = []
    options.extend(["-a", 'units,time,o,c,"days since 1999-01-01"'])
    options.extend(["-a", "long_name,time,o,c,time"])
    options.extend(["-a", "calendar,time,o,c,noleap"])
    nco.ncatted(input=foo_nc, output="out.nc", options=options)
开发者ID:nco,项目名称:pynco,代码行数:7,代码来源:test_nco.py

示例5: normalize_ctd_depths

def normalize_ctd_depths(netcdf_file):
    with CFDataset(netcdf_file, 'a') as nc:
        depths = nc.variables['depth'][:][0]
        z_atts = nc.vatts('depth')

    # Remove the old depth variable so we can add a new one with no dimensions
    o = Nco()
    o.ncks(
        input=netcdf_file,
        output=netcdf_file,
        options=[
            '-O',
            '-h',
            '-x',
            '-v', 'depth'
        ]
    )

    # Add the new Z variable
    with nc4.Dataset(netcdf_file, 'a') as nc:
        z = nc.createVariable('depth', 'f4')
        z[:] = depths
        z_atts.update({
            'standard_name': 'depth',
            'axis': 'Z',
            'positive': 'down'
        })
        z.setncatts(z_atts)
开发者ID:USGS-CMG,项目名称:usgs-cmg-portal,代码行数:28,代码来源:ctd.py

示例6: test_return_array

def test_return_array(foo_nc):
    nco = Nco(cdf_module="netcdf4")
    random1 = nco.ncea(
        input=foo_nc, output="tmp.nc", returnCdf=True, options=["-O"]
    ).variables["random"][:]
    assert isinstance(random1, np.ndarray)
    random2 = nco.ncea(
        input=foo_nc, output="tmp.nc", returnArray="random", options=["-O"]
    )
    assert isinstance(random2, np.ndarray)
    np.testing.assert_equal(random1, random2)
开发者ID:nco,项目名称:pynco,代码行数:11,代码来源:test_nco.py

示例7: test_command_line_options

def test_command_line_options(foo_nc):
    """
    3.4 Command Line Options

    ncks -D 3 in.nc        # Short option
    ncks --dbg_lvl=3 in.nc # Long option, preferred form
    ncks --dbg_lvl 3 in.nc # Long option, alternate form
    """
    nco = Nco(debug=True)
    nco.ncks(input=foo_nc, options=["-O -D 3"])
    nco.ncks(input=foo_nc, options=["-O --dbg_lvl=3"])
    nco.ncks(input=foo_nc, options=["-O --dbg_lvl 3"])
开发者ID:nco,项目名称:pynco,代码行数:12,代码来源:test_nco_examples.py

示例8: normalize_netcdf4

def normalize_netcdf4(netcdf_file):
    o = Nco()
    o.ncks(
        input=netcdf_file,
        output=netcdf_file,
        options=[
            '-O',
            '-h',
            '-4',
            '-L3'
        ]
    )
开发者ID:USGS-CMG,项目名称:usgs-cmg-portal,代码行数:12,代码来源:utils.py

示例9: test_ncks_hdf2nc

def test_ncks_hdf2nc(hdf_file):
    """
    1.6 netCDF2/3/4 and HDF4/5 Support
    Converting HDF4 files to netCDF: Since NCO reads HDF4 files natively,
    it is now easy to convert HDF4 files to netCDF files directly, e.g.,

    ncks        fl.hdf fl.nc # Convert HDF4->netCDF4 (NCO 4.4.0+, netCDF4.3.1+)
    ncks --hdf4 fl.hdf fl.nc # Convert HDF4->netCDF4 (NCO 4.3.7-4.3.9)
    """
    nco = Nco(debug=True)
    nco.ncks(input=hdf_file, output='foo.nc')
    nco.ncks(input=hdf_file, output='foo.nc', hdf4=True)
开发者ID:jhamman,项目名称:pynco,代码行数:12,代码来源:test_nco_examples.py

示例10: test_returnCdf

def test_returnCdf(foo_nc):
    nco = Nco(cdfMod='scipy')
    testCdf = nco.ncea(input=foo_nc, output="tmp.nc", returnCdf=True,options=['-O'])
    assert type(testCdf) == scipy.io.netcdf.netcdf_file
    expected_vars = ['time', 'random']
    for var in expected_vars:
        assert var in list(testCdf.variables.keys())

    nco = Nco(cdfMod='netcdf4')
    testCdf = nco.ncea(input=foo_nc, output="tmp.nc", returnCdf=True, options=['-O'])
    assert type(testCdf) == netCDF4.Dataset
    for var in expected_vars:
        assert var in list(testCdf.variables.keys())
开发者ID:jvegasbsc,项目名称:pynco,代码行数:13,代码来源:test_nco.py

示例11: test_return_cdf

def test_return_cdf(foo_nc):
    nco = Nco(cdf_module="scipy")
    test_cdf = nco.ncea(input=foo_nc, output="tmp.nc", returnCdf=True, options=["-O"])
    assert type(test_cdf) == scipy.io.netcdf.netcdf_file
    expected_vars = ["time", "random"]
    for var in expected_vars:
        assert var in list(test_cdf.variables.keys())

    nco = Nco(cdf_module="netcdf4")
    test_cdf = nco.ncea(input=foo_nc, output="tmp.nc", returnCdf=True, options=["-O"])
    assert type(test_cdf) == netCDF4.Dataset
    for var in expected_vars:
        assert var in list(test_cdf.variables.keys())
开发者ID:nco,项目名称:pynco,代码行数:13,代码来源:test_nco.py

示例12: test_ncks_hdf2nc

def test_ncks_hdf2nc(hdf_file):
    """
    1.6 netCDF2/3/4 and HDF4/5 Support
    Converting HDF4 files to netCDF: Since NCO reads HDF4 files natively,
    it is now easy to convert HDF4 files to netCDF files directly, e.g.,

    ncks        fl.hdf fl.nc # Convert HDF4->netCDF4 (NCO 4.4.0+, netCDF4.3.1+)
    ncks --hdf4 fl.hdf fl.nc # Convert HDF4->netCDF4 (NCO 4.3.7-4.3.9)
    """
    if hdf_file is None:
        pytest.skip("Skipped because h5py is not installed")
    nco = Nco(debug=True)
    nco.ncks(input=hdf_file, output="foo.nc")
    nco.ncks(input=hdf_file, output="foo.nc", hdf4=True)
开发者ID:nco,项目名称:pynco,代码行数:14,代码来源:test_nco_examples.py

示例13: test_ncks_append_variables

def test_ncks_append_variables(foo_nc, bar_nc):
    """
    2.4 Appending Variables
    The simplest way to create the union of two files is

    ncks -A fl_1.nc fl_2.nc
    """
    nco = Nco(debug=True)
    nco.ncks(input=foo_nc, output=bar_nc, options=['-A'])
    nco.ncks(input=foo_nc, output=bar_nc, append=True)
    nco.ncks(input=foo_nc, output=bar_nc, apn=True)
    nco.ncks(input=foo_nc, output=bar_nc)
开发者ID:kwilcox,项目名称:pynco,代码行数:12,代码来源:test_nco_examples.py

示例14: xgeo_multifile_load

def xgeo_multifile_load(nc_wildcard, nc_dir=None):
    """
    Read data from multiple (e.g. hourly xgeo data) netcdf files
    :param nc_wildcard: common section of the filenams, e.g. mf_files*.nc
    :return:
    """
    if dir:
        nc_path = os.path.join(nc_dir, nc_wildcard)
    else:
        nc_path = nc_wildcard

    nco = Nco()
    nc_temp = nco.ncrcat(input=nc_path)
    nc = netCDF4.Dataset(nc_temp)

    #add function to restrict dates and times
    return nc
开发者ID:kmunve,项目名称:APS,代码行数:17,代码来源:aps_nc.py

示例15: test_specifying_input_files

def test_specifying_input_files(testfiles8589):
    """
    3.5 Specifying Input Files

    ncra 85.nc 86.nc 87.nc 88.nc 89.nc 8589.nc
    ncra 8[56789].nc 8589.nc
    ncra -p input-path 85.nc 86.nc 87.nc 88.nc 89.nc 8589.nc
    ncra -n 5,2,1 85.nc 8589.nc
    """
    inputs = ['85.nc', '86.nc', '87.nc', '88.nc', '89.nc']
    nco = Nco(debug=True)
    nco.ncra(input=inputs, ouptut='8589.nc')
    nco.ncra(input='8[56789].nc', ouptut='8589.nc')
    srcdir = os.path.split(inputs[0])
    nco.ncra(input=inputs, ouptut='8589.nc', path=srcdir)
    nco.ncra(input=inputs, ouptut='8589.nc', nintap='5,2,1')
开发者ID:jhamman,项目名称:pynco,代码行数:16,代码来源:test_nco_examples.py


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