小编Mat*_*ira的帖子

Fortran正在读取endfile记录之外的内容

我正在尝试从文件中读取一些数据,并且结束文件记录检测对于停止读取非常重要.但是,根据用于读取数据的数组的数组维度,我无法正确检测到endfile记录,并且我的Fortran程序停止.

该计划如下:

!integer, dimension(3) :: x                      ! line 1.1
!integer, dimension(3,10) :: x                   ! line 1.2
integer, dimension(10,3) ::                      ! line 1.3
integer :: status,i=1
character(len=100) :: error

open( 30, file='data.dat', status='old' )
do
  print *,i
  !read( 30, *, iostat=status, iomsg=error ) x          ! line 2.1
  !read( 30, *, iostat=status, iomsg=error ) x(:,i)     ! line 2.2
  read( 30, *, iostat=status, iomsg=error ) x(i,:)      ! line 2.3

  if ( status < 0 ) then        print *,'EOF'
    print *,'total of ',i-1,' lines …
Run Code Online (Sandbox Code Playgroud)

fortran data-files gfortran eof

5
推荐指数
1
解决办法
359
查看次数

How to join data from multiple netCDF files with xarray in Python?

I'm trying to open multiple netCDF files with xarray in Python. The files have data with same shape and I want to join them, creating a new dimension.

I tried to use concat_dim argument for xarray.open_mfdataset(), but it doesn't work as expected. An example is given below, which open two files with temperature data for 124 times, 241 latitudes and 480 longitudes:

DS = xr.open_mfdataset( 'eraINTERIM_t2m_*.nc', concat_dim='cases' )
da_t2m = DS.t2m

print( da_t2m )
Run Code Online (Sandbox Code Playgroud)

有了这段代码,我希望结果数据数组的形状像(情况:2,时间:124,纬度:241,经度:480)。但是,其形状为(案例:2,时间:248,纬度:241,经度:480)。它创建了一个新维度,但也将最左边的维度相加:两个数据集的“时间”维度。我想知道这是来自“ xarray.open_mfdateset”的错误还是预期的行为,因为两个数据集的“时间”维度都是无限的。

有没有一种方法可以直接使用xarray从这些文件中联接数据并获得上述预期收益?

谢谢。

马泰斯

python concatenation netcdf python-xarray

5
推荐指数
1
解决办法
653
查看次数

从 netCDF 文件读取数据时 Missing_value 属性丢失?

我正在从 NCEP/NCAR Reanalysis 1 的 netCDF 文件中读取风分量(u 和 v)数据来进行一些计算。我正在使用 xarray 来读取文件。

在其中一项计算中,我想屏蔽掉低于某个阈值的所有数据,使它们等于 Missing_value 属性。我不想使用 NaN。

但是,当使用 xarray 读取数据时,missing_value 属性(存在于 netCDF 文件中的变量中)不会复制到包含数据的 xarray.DataArray。

我找不到使用 xarray 从 netCDF 文件变量复制此属性的方法。

这是我正在尝试做的事情的一个例子:

import xarray as xr
import numpy as np

DS1 = xr.open_dataset( "u_250_850_2009012600-2900.nc" )
DS2 = xr.open_dataset( "v_250_850_2009012600-2900.nc" )

u850 = DS1.uwnd.sel( time='2009-01-28 00:00', level=850, lat=slice(10,-60), lon=slice(260,340) )
v850 = DS2.vwnd.sel( time='2009-01-28 00:00', level=850, lat=slice(10,-60), lon=slice(260,340) )

vvel850 = np.sqrt( u850*u850 + v850*v850 )

jet850 = vvel850.where( vvel850 >= 12 )
#jet850 = …
Run Code Online (Sandbox Code Playgroud)

python netcdf missing-data python-xarray

2
推荐指数
1
解决办法
1355
查看次数