python-xarray

Create and write xarray DataArray to NetCDF in chunks

我的梦境 提交于 2021-02-07 03:25:15
问题 Is it also possible to create an out-of-core DataArray, and write it chunk-by-chunk to a NetCDF4 file using xarray? For example, I want to be able to do this in an out-of-core fashion when the dimensions are much bigger and I thus cannot store the whole array in memory: num_steps = 20 num_times = 100 #Create DataArray d = xr.DataArray(np.zeros([num_steps, num_times], np.float32), {'Step': np.arange(num_steps), 'Time': np.arange(num_times)}, ('Step', 'Time')) #Computatation for i in range(num

Xarray Roll and Cartopy add_cyclic_point functions conflicting

二次信任 提交于 2021-02-05 11:12:58
问题 Recently I tried to make a simple plot of the Pacific and Atlantic Oceans together, from 180W-20E. To cross the 0 degree line I used the roll method as follows: import matplotlib.pyplot as plt import cartopy.crs as ccrs import cartopy.feature as cf import cartopy as cartopy import numpy as np import xarray as xr from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter from cartopy.util import add_cyclic_point dset = xr.open_dataset('sst.mnmean.nc') var = dset['sst'][:,:,:] lat =

How to fix attribute error for Metpy data from a netcdf file involving xarray

筅森魡賤 提交于 2021-01-29 17:53:23
问题 I am getting this error: AttributeError: 'Dataset' object has no attribute 'metpy' when I am running my code. The particular lines in particular are: import Scientific.IO.NetCDF as S import cartopy.crs as ccrs import cartopy.feature as cfeature import matplotlib.pyplot as plt import xarray as xr import metpy # Any import of metpy will activate the accessors import metpy.calc as mpcalc #from metpy.testing import get_test_data from metpy.units import units # Open the netCDF file as a xarray

How to plot a vertical section of the atmosphere along with the topography using the Iris module?

爱⌒轻易说出口 提交于 2021-01-29 12:55:29
问题 I have a netcdf with wind speed at model levels. On the same netcdf I have the altitude of each model level. I converted netcdf to a cube, so the altitude of each level became an auxiliary coordinate. I would like to plot a cross section (longitude x longitude) and would like the model levels to follow the topography. I tried using the Iris module documentation example (https://scitools.org.uk/iris/docs/latest/examples/General/cross_section.html), but it's not working. As I already have the

xarray: coords conversion to datetime64

自闭症网瘾萝莉.ら 提交于 2021-01-29 05:18:58
问题 I have a NetCDF4 file that i'm handling using xarray. The dataset has a "time" coordinate as dtype=object and i would like to convert it ot datetime64 in order to simplify plotting of the variables contained in the file. My plan was to create a new time coordinate called "time1" using ds.assign_coords(time1=pd.to_datetime(ds.time.values,infer_datetime_format=True)) and then delete the old one. But i get a new coordinate still as dtype=object. here's how the new dataset looks like What am i

Xarray: Make two DataArrays in the same Dataset use the same coordinate system

你。 提交于 2021-01-28 13:34:55
问题 I have an ArviZ InferenceData posterior trace which is an XArray Dataset. In there, posterior traces for two of my random variables, a_mu_org and b_mu_org are DataArrays. Their coordinates are: a_mu_org : ( chain , draws , a_mu_org ), with lengths (1, 2000, 15) respectively. b_mu_org : ( chain , draws , b_mu_org ), with lengths (1, 2000, 15) respectively. Semantically, a_mu_org and b_mu_org should really be indexed by a single categorical coordinate system of 15 organisms, rather than be

Is there a way to release the file lock for a xarray.Dataset?

ぃ、小莉子 提交于 2021-01-27 07:29:27
问题 I have a process that grows a NetCDF file fn every 5 minutes using netcdf4.Dataset(fn, mode=a) . I also have a bokeh server visualization of that NetCDF file using a xarray.Dataset (which I want to keep, because it is so convenient). The problem is that the NetCDF-update-process fails when trying to add new data to fn if it is open in my bokeh server process via ds = xarray.open_dataset(fn) If I use the option autoclose ds = xarray.open_dataset(fn, autoclose=True) updating fn with the other

get mean of netcdf file using xarray

浪子不回头ぞ 提交于 2021-01-02 08:17:27
问题 I have opened a netcdf file in python using xarray, and the dataset summary looks like this. Dimensions: (latitude: 721, longitude: 1440, time: 41) Coordinates: * longitude (longitude) float32 0.0 0.25 0.5 0.75 ... 359.25 359.5 359.75 * latitude (latitude) float32 90.0 89.75 89.5 89.25 ... -89.5 -89.75 -90.0 expver int32 1 * time (time) datetime64[ns] 1979-01-01 1980-01-01 ... 2019-01-01 Data variables: z (time, latitude, longitude) float32 50517.914 ... 49769.473 Attributes: Conventions: CF

get mean of netcdf file using xarray

ⅰ亾dé卋堺 提交于 2021-01-02 08:17:13
问题 I have opened a netcdf file in python using xarray, and the dataset summary looks like this. Dimensions: (latitude: 721, longitude: 1440, time: 41) Coordinates: * longitude (longitude) float32 0.0 0.25 0.5 0.75 ... 359.25 359.5 359.75 * latitude (latitude) float32 90.0 89.75 89.5 89.25 ... -89.5 -89.75 -90.0 expver int32 1 * time (time) datetime64[ns] 1979-01-01 1980-01-01 ... 2019-01-01 Data variables: z (time, latitude, longitude) float32 50517.914 ... 49769.473 Attributes: Conventions: CF

Load selection GFS-ensemble openDAP data into memory (Python)

生来就可爱ヽ(ⅴ<●) 提交于 2020-12-06 12:25:26
问题 I want to download a subselection from GFS-ensemble data from an OpenDAP server via netCDF and xarray. However, when trying to load the subselection into memory, the program crashes after a while returning a RuntimeError (netCDF: I/O failure). The amount of data points I wish to obtain is 13650, therefore the data size should be easily handleable in Python. Oddly enough, I do not experience this problem when downloading GFS-data or NCEP-Reanalysis data. This makes me believe that the issue