[英]Reading Time Series from netCDF with python for a specific location and time is in seconds
I'm trying to extract a time series csv from a netcdf file.我正在尝试从 netcdf 文件中提取时间序列 csv 。 I have a tried a few options and it seems that using xarray is the simplest one.我尝试了一些选项,似乎使用 xarray 是最简单的选项。
My variables I want are 'time' 'stage' and I want to specify the coords of 'x' and 'y' Time happens to be in seconds, which messed me up when I tried the netCDF4 answers on this site.我想要的变量是“时间”“阶段”,我想指定“x”和“y”的坐标时间恰好以秒为单位,当我在这个网站上尝试 netCDF4 答案时,这让我很困惑。
I tried the following我尝试了以下
import xarray as xr
ds = xr.open_dataset('boundary_conditions.sts')
xi = 125285.25; yi = 42519.85
dsloc = ds.sel(x=xi, y=yi, method='nearest')
dsloc['stage'].plot()
But I don't get past the 'dsloc' section as it says x is not defined.但是我没有通过“dsloc”部分,因为它说 x 没有定义。
Ideally I would also like to export it as a csv.理想情况下,我还想将其导出为 csv。
I'm sure it's an easy fix but I don't know what it is...我确定这很容易解决,但我不知道它是什么...
please help请帮忙
This is the file if it helps如果有帮助,这是文件
https://www.dropbox.com/s/dr3k7zynt54joti/boundary_conditions.sts?dl=0 https://www.dropbox.com/s/dr3k7zynt54joti/boundary_conditions.sts?dl=0
Ideally, you would provide a reproducible example, but the following code should probably replace your final line:理想情况下,您将提供一个可重现的示例,但以下代码可能应该替换您的最后一行:
dsloc.stage.plot()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.