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


Python Nco.ncks方法代码示例

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


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

示例1: normalize_time

# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncks [as 别名]
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,代码行数:36,代码来源:utils.py

示例2: normalize_ctd_depths

# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncks [as 别名]
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,代码行数:30,代码来源:ctd.py

示例3: normalize_netcdf4

# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncks [as 别名]
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,代码行数:14,代码来源:utils.py

示例4: test_command_line_options

# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncks [as 别名]
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,代码行数:14,代码来源:test_nco_examples.py

示例5: test_ncks_hdf2nc

# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncks [as 别名]
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,代码行数:14,代码来源:test_nco_examples.py

示例6: test_ncks_hdf2nc

# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncks [as 别名]
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,代码行数:16,代码来源:test_nco_examples.py

示例7: test_temp_output_files

# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncks [as 别名]
def test_temp_output_files(foo_nc):
    """
    2.3 Temporary Output Files
    ncks in.nc out.nc # Default: create out.pid.tmp.nc then move to out.nc
    ncks --wrt_tmp_fl in.nc out.nc # Same as default
    ncks --no_tmp_fl in.nc out.nc # Create out.nc directly on disk
    ncks --no_tmp_fl in.nc in.nc # ERROR-prone! Overwrite in.nc with itself
    ncks --create_ram --no_tmp_fl in.nc in.nc # Create in RAM, write to disk
    ncks --open_ram --no_tmp_fl in.nc in.nc # Read into RAM, write to disk
    """
    nco = Nco(debug=True)
    nco.ncks(input=foo_nc, output='bar.nc')
    nco.ncks(input=foo_nc, output='bar.nc', wrt_tmp_fl=True)
    nco.ncks(input=foo_nc, output='bar.nc', no_tmp_fl=True)
    nco.ncks(input=foo_nc, output=foo_nc, no_tmp_fl=True, create_ram=True)
    nco.ncks(input=foo_nc, output=foo_nc, no_tmp_fl=True, open_ram=True)
开发者ID:kwilcox,项目名称:pynco,代码行数:18,代码来源:test_nco_examples.py

示例8: test_ncks_append_variables

# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncks [as 别名]
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,代码行数:14,代码来源:test_nco_examples.py

示例9: test_determining_file_format

# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncks [as 别名]
def test_determining_file_format(foo3c, foo364, foo4c, hdf_file):
    """
    3.9.2 Determining File Format

    ncks -M foo_3c.nc
    ncks -M foo_364.nc
    ncks -M foo_4c.nc
    ncks -M foo_4.nc
    ncks -D 2 -M hdf.hdf
    # ncks -D 2 -M http://thredds-test.ucar.edu/thredds/dodsC/testdods/in.nc
    ncks -D 2 -M foo_4.nc
    """
    nco = Nco(debug=True)
    nco.ncks(input=foo3c, options='-M')
    nco.ncks(input=foo364, options='-M')
    nco.ncks(input=foo4c, options='-M')
    assert os.path.isfile(hdf_file)
    nco.ncks(input=hdf_file, options='-D 2 -M')
    # nco.ncks(input='http://thredds-test.ucar.edu/thredds/dodsC/testdods/in.nc',
    #          options='-D 2 -M') # does not work from command line either
    nco.ncks(input=foo4c, options='-D 2 -M')
开发者ID:jhamman,项目名称:pynco,代码行数:23,代码来源:test_nco_examples.py

示例10: test_determining_file_format

# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncks [as 别名]
def test_determining_file_format(foo3c, foo364, foo4c, hdf_file):
    """
    3.9.2 Determining File Format

    ncks -M foo_3c.nc
    ncks -M foo_364.nc
    ncks -M foo_4c.nc
    ncks -M foo_4.nc
    ncks -D 2 -M hdf.hdf
    # ncks -D 2 -M http://thredds-test.ucar.edu/thredds/dodsC/testdods/in.nc
    ncks -D 2 -M foo_4.nc
    """
    nco = Nco(debug=True)
    nco.ncks(input=foo3c, options=['-M'])
    nco.ncks(input=foo364, options=['-M'])
    nco.ncks(input=foo4c, options=['-M'])
    nco.ncks(input=foo4c, options=['-D 2 -M'])

    if hdf_file is not None:
        assert os.path.isfile(hdf_file)
        nco.ncks(input=hdf_file, options=['-D 2 -M'])
开发者ID:kwilcox,项目名称:pynco,代码行数:23,代码来源:test_nco_examples.py

示例11: normalize_locations

# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncks [as 别名]
def normalize_locations(netcdf_file):
    with CFDataset(netcdf_file) as nc:
        y = nc.variables.get("lat")
        y_data = y[:]
        y_atts = nc.vatts('lat')

        x = nc.variables.get("lon")
        x_data = x[:]
        x_atts = nc.vatts('lon')

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

    # Add the new X/Y variables
    with nc4.Dataset(netcdf_file, 'a') as nc:
        lat = nc.createVariable('lat', y_data.dtype)
        lat[:] = y_data
        y_atts.update({
            'standard_name': 'latitude',
            'axis': 'Y'
        })
        lat.setncatts(y_atts)

        lon = nc.createVariable('lon', x_data.dtype)
        lon[:] = x_data
        x_atts.update({
            'standard_name': 'longitude',
            'axis': 'X'
        })
        lon.setncatts(x_atts)
开发者ID:USGS-CMG,项目名称:usgs-cmg-portal,代码行数:42,代码来源:utils.py

示例12: test_ncks_hdf2nc3

# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncks [as 别名]
def test_ncks_hdf2nc3(hdf_file):
    """
    1.6 netCDF2/3/4 and HDF4/5 Support
    Obtaining a netCDF3 file from an HDF4 is now easy, even though the HDF4
    file may contain netCDF4 atomic types (e.g., unsigned bytes,
    64-bit integers):

    ncks -3 fl.hdf fl.nc      # HDF4->netCDF3 (NCO 4.4.0+, netCDF 4.3.1+)
    ncks -7 -L 1 fl.hdf fl.nc # HDF4->netCDF4 (NCO 4.4.0+, netCDF 4.3.1+)
    ncks --hdf4 -3 fl.hdf fl.nc # HDF4->netCDF3 (netCDF 4.3.0-)
    ncks --hdf4 -7 fl.hdf fl.nc # HDF4->netCDF4 classic (netCDF 4.3.0-)
    """
    nco = Nco(debug=True)
    nco.ncks(input=hdf_file, output='foo.nc', options='-3')
    nco.ncks(input=hdf_file, output='foo.nc', options='-7 -L 1')
    nco.ncks(input=hdf_file, output='foo.nc', options='-3', hdf4=True)
    nco.ncks(input=hdf_file, output='foo.nc', options='-7', hdf4=True)
开发者ID:jhamman,项目名称:pynco,代码行数:19,代码来源:test_nco_examples.py

示例13: test_ncks_hdf2nc3

# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncks [as 别名]
def test_ncks_hdf2nc3(hdf_file):
    """
    1.6 netCDF2/3/4 and HDF4/5 Support
    Obtaining a netCDF3 file from an HDF4 is now easy, even though the HDF4
    file may contain netCDF4 atomic types (e.g., unsigned bytes,
    64-bit integers):

    ncks -3 fl.hdf fl.nc      # HDF4->netCDF3 (NCO 4.4.0+, netCDF 4.3.1+)
    ncks -7 -L 1 fl.hdf fl.nc # HDF4->netCDF4 (NCO 4.4.0+, netCDF 4.3.1+)
    ncks --hdf4 -3 fl.hdf fl.nc # HDF4->netCDF3 (netCDF 4.3.0-)
    ncks --hdf4 -7 fl.hdf fl.nc # HDF4->netCDF4 classic (netCDF 4.3.0-)
    """
    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", options=["-3"])
    nco.ncks(input=hdf_file, output="foo.nc", options=["-7 -L 1"])
    nco.ncks(input=hdf_file, output="foo.nc", options=["-3"], hdf4=True)
    nco.ncks(input=hdf_file, output="foo.nc", options=["-7"], hdf4=True)
开发者ID:nco,项目名称:pynco,代码行数:21,代码来源:test_nco_examples.py

示例14: test_hyperslabs

# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncks [as 别名]
def test_hyperslabs(testfileglobal):
    """
    3.15 Hyperslabs

    # First and second indices of lon dimension
    ncks -F -d lon,1,2 in.nc out.nc
    # Second and third indices of lon dimension
    ncks -d lon,1,2 in.nc out.nc
    # All longitude values between 1 and 2 degrees
    ncks -d lon,1.0,2.0 in.nc out.nc
    # All longitude values between 1 and 2 degrees
    ncks -F -d lon,1.0,2.0 in.nc out.nc
    # Every other longitude value between 0 and 90 degrees
    ncks -F -d lon,0.0,90.0,2 in.nc out.nc
    # Last two indices of lon dimension
    ncks -F -d lon,1,-2 in.nc out.nc
    # Third-to-last to last index of lon dimension
    ncks -F -d lon,-3,-1 in.nc out.nc
    # Third-to-last to last index of lon dimension
    ncks -F -d lon,-3, in.nc out.nc
    """
    nco = Nco(debug=True)
    nco.ncks(input=testfileglobal, output='out.nc', fortran=True,
             dimension='lon,1,2')
    nco.ncks(input=testfileglobal, output='out.nc',
             dimension='lon,1,2')
    nco.ncks(input=testfileglobal, output='out.nc', fortran=True,
             dimension='lon,1.0,2.0')
    nco.ncks(input=testfileglobal, output='out.nc', fortran=True,
             dimension='lon,0.0,90.0,2')
    nco.ncks(input=testfileglobal, output='out.nc', fortran=True,
             dimension='lon,1,-2')
    nco.ncks(input=testfileglobal, output='out.nc', fortran=True,
             dimension='lon,-3,-1')
    nco.ncks(input=testfileglobal, output='out.nc', fortran=True,
             dimension='lon,-3')
开发者ID:kwilcox,项目名称:pynco,代码行数:38,代码来源:test_nco_examples.py

示例15: test_file_conversion

# 需要导入模块: from nco import Nco [as 别名]
# 或者: from nco.Nco import ncks [as 别名]
def test_file_conversion(foo3c, foo4c):
    """
    3.9.2 Determining File Format

    ncks --fl_fmt=classic in.nc foo_3c.nc # netCDF3 classic
    ncks --fl_fmt=64bit in.nc foo_364.nc # netCDF3 64bit
    ncks --fl_fmt=netcdf4_classic in.nc foo_4c.nc # netCDF4 classic
    ncks --fl_fmt=netcdf4 in.nc foo_4.nc # netCDF4
    ncks -3 in.nc foo_3c.nc # netCDF3 classic
    ncks --3 in.nc foo_3c.nc # netCDF3 classic
    ncks -6 in.nc foo_364.nc # netCDF3 64bit
    ncks --64 in.nc foo_364.nc # netCDF3 64bit
    ncks -4 in.nc foo_4.nc # netCDF4
    ncks --4 in.nc foo_4.nc # netCDF4
    ncks -7 in.nc foo_4c.nc # netCDF4 classic
    ncks --7 in.nc foo_4c.nc # netCDF4 classic
    """
    nco = Nco(debug=True)
    nco.ncks(input=foo4c, output='foo_3c.nc', fl_fmt='classic')
    nco.ncks(input=foo4c, output='foo_364.nc', fl_fmt='64bit')
    nco.ncks(input=foo3c, output='foo_4c.nc', fl_fmt='netcdf4_classic')
    nco.ncks(input=foo3c, output='foo_4.nc', fl_fmt='netcdf4')
    nco.ncks(input=foo4c, output='foo_3c.nc', options=['-3'])
    nco.ncks(input=foo4c, output='foo_3c.nc', options=['--3'])
    nco.ncks(input=foo3c, output='foo_364c.nc', options=['-6'])
    nco.ncks(input=foo3c, output='foo_364c.nc', options=['--64bit_offset'])
    nco.ncks(input=foo3c, output='foo_4.nc', options=['-4'])
    nco.ncks(input=foo3c, output='foo_4.nc', options=['--4'])
    nco.ncks(input=foo3c, output='foo_4c.nc', options=['-7'])
    nco.ncks(input=foo3c, output='foo_4c.nc', options=['--7'])
开发者ID:kwilcox,项目名称:pynco,代码行数:32,代码来源:test_nco_examples.py


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