精华内容
下载资源
问答
  • m trying to write a netcdf file directly from xarray to S3 object storage. I'm wondering: <ol><li>Why writing NetCDF files requires a "seek"</li><li>Why the <code>scipy</code> engine is ...
  • /home/mowglie/Documents/git/xarray/xarray/backends/api.py in to_netcdf(dataset, path, mode, format, group, engine, writer, encoding) 516 try: --> 517 dataset.dump_to_store(store, sync=sync, ...
  • <div><p>At the Pangeo developers meetings, I am hearing lots of reports from folks like and -usgs about netCDF datasets that xarray can't open. <p>My expectation is that xarray doesn't have ...
  • /users/pwolfram/envs/LIGHT_analysis/lib/python2.7/site-packages/xarray/backends/netCDF4_.py", line 283, in sync super(NetCDF4DataStore, self).sync() File "/users/pwolfram/envs/LIGHT_analysis...
  • 将来,您可以通过使用cftime对象创建日期轴来实现此目的,但是当前有一个outstanding issue in xarray,它不允许您编写包含此类对象的netCDF文件.但是,即使您可以保存此类对象,最简单,最干净的方法仍然是将该轴手动定义...

    将来,您可以通过使用cftime对象创建日期轴来实现此目的,但是当前有一个

    outstanding issue in xarray,它不允许您编写包含此类对象的netCDF文件.

    但是,即使您可以保存此类对象,最简单,最干净的方法仍然是将该轴手动定义为具有某些单位的整数数组.

    import numpy as np

    import xarray as xr

    days = np.asarray(range(100*365))

    ds = xr.Dataset(

    {'time': (['time'], days, {'units': 'days since 2200-01-01 0:0:0'})}

    )

    print(ds['time'][-1]

    ds.to_netcdf('test.nc')

    ds = xr.open_dataset('test.nc')

    print(ds['time'][-1])

    给出输出

    array(36499)

    Coordinates:

    time int64 36499

    Attributes:

    units: days since 2200-01-01 0:0:0

    其次是

    array(datetime.datetime(2299, 12, 7, 0, 0), dtype=object)

    Coordinates:

    time object 2299-12-07

    请注意,当您重新打开数据集时,xarray会自动对其进行解码.

    您使用的“单位”属性应遵循CF conventions的时间坐标.您可以根据需要将“天”替换为“小时”,“分钟”或“秒”.

    这确实需要您手动计算所需的整数,如果您的时间轴以年为单位,这主要是困难的(因为“年”不是定义的时间度量单位,长度根据闰年而变化).如果是这种情况,您可以使用以下内容:

    import cftime

    # replace this to use a different calendar

    Datetime = cftime.DatetimeProlepticGregorian

    # make your list of Datetime objects

    time_list = []

    month = day = 1

    hour = minute = second = 0

    for year in range(2200, 2300, 1):

    time_list.append(Datetime(year, month, day, hour, minute, second))

    # this will convert them into a time axis, here in units of

    # 'days since 2200-01-01 0:0:0'

    seconds_in_day = 60*60*24

    day_list = []

    for dt in time_list:

    time_since_2200 = dt - Datetime(2200, month, day, hour, minute, second)

    day_list.append(int(time_since_2200.total_seconds() / seconds_in_day))

    您可以使用不同的cftime类(例如cftime.DatetimeJulian或cftime.DatetimeNoLeap)来使用其他日历.应修改此代码以提供正确的time_list供您使用.您还可以在其他某个时间单位中将seconds_in_day切换为秒(并且还将该单位提供给xr.Dataset调用).

    展开全文
  • However, when computing on the .data attribute backed by a NetCDF object wrapped by a few XArray containers we run into the following error. It appears to be coming from computing the shape, which is...
  • <h2>Different behaviour of xarray comparing to netCDF4 Dataset <p>When reading the dataset with xarray we found that the decoded type was numpy.float32 instead of numpy.float64 This netcdf variable ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,601
精华内容 640
关键字:

netcdfxarray