python-xarray

Masking nan values from an xarray dataset for scikit.learn mulltiple linear regression following scipy

Masking nan values from an xarray dataset for scikit.learn mulltiple linear regression following scipy Question: I’m attempting to use scikit-learn.linear_model’s LinearRegression find the multiple linear regression coefficients for different variables at each latitude and longitude point along the time dimension like so: for i in range(len(data.lat)): for j in range(len(data.lon)): storage_dframe[i, j, :] = LinearRegression().fit(np.array((data.ivar1.values[:, …

Total answers: 2

How to compute one mean dataset of 4 datasets [Python, xarray]

How to compute one mean dataset of 4 datasets [Python, xarray] Question: I’m having 4 [GFS] temperature datasets: they are all the same in spatial resolution, the only difference is timestamp – they are for 00 UTC, 06 UTC, 12 UTC, 18 UTC within one day. I need to compute the mean daily temperature dataset. …

Total answers: 1

How can I create a multiindex matrix from a 4D xarray dataset?

How can I create a multiindex matrix from a 4D xarray dataset? Question: I currently have a 4D dataset ds in xarray that looks like this: <xarray.Dataset> Dimensions: (lat: 60, lon: 78, time: 216, pres: 395) Coordinates: * lat (lat) float32 0.5 1.5 2.5 3.5 4.5 5.5 … 55.5 56.5 57.5 58.5 59.5 * lon …

Total answers: 1

use numpy.ndarray in matplotlib title plot with format

use numpy.ndarray in matplotlib title plot with format Question: I am using Sara and matplotlib of some of work and I was wondering how could I use a class numpy.ndarray with specific format in the title of a plot I am doing. The variable type is: type(global_mean.data) <class ‘numpy.ndarray’> and value: global_mean.data array(0.12485412, dtype=float32) And …

Total answers: 2

Reversing subdivision of latitude and longitude coordinates in xarray

Reversing subdivision of latitude and longitude coordinates in xarray Question: I’m using Python to work with geospatial data in xarray, where locations are subdivided into subregions/tiles, similar (not the same) to the example at the bottom of the page of the xarray documentation for reshaping reorganising. I want to reverse this subdivision in xarray as …

Total answers: 1

Why does saving `to_netcdf` without `encoding=` change some values to `nan`?

Why does saving `to_netcdf` without `encoding=` change some values to `nan`? Question: I’m struggling to understand a problem in my code when saving a xarray.DataSet as netCDF. The file does not contain any nan values. However after saving and loading it suddenly does for one value: Before: no nan in the original data before saving: …

Total answers: 1

Merging series of 2D DataFrames to 3D xarray

Merging series of 2D DataFrames to 3D xarray Question: I have a series of 2D DataFrames that should be merged into a 3D xarray. The structure of DataFrames looks like this: 5 6 4 8 -1 3 angle 5 105.87 459.62 0.1 10 211.74 919.24 0.1 5 6 4 8 -1 3 angle 5 125.87 …

Total answers: 1

Code works fine with xarray version 0.17.0 but not in version 2022.11.0

Code works fine with xarray version 0.17.0 but not in version 2022.11.0 Question: This code works in version ‘0.17.0’, but not in version ‘2022.11.0’. The error is: /home/alexandre/miniconda3/envs/grade_2020_3/bin/python /home/alexandre/Dropbox/grade_2020/examples/teste_lixo.py Traceback (most recent call last): File "/home/alexandre/Dropbox/grade_2020/examples/teste_lixo.py", line 14, in <module> prec.coords[‘mask’] = ((‘latitude’, ‘longitude’), mask_array) File "/home/alexandre/miniconda3/envs/grade_2020_3/lib/python3.8/site-packages/xarray/core/coordinates.py", line 32, in __setitem__ self.update({key: value}) File "/home/alexandre/miniconda3/envs/grade_2020_3/lib/python3.8/site-packages/xarray/core/coordinates.py", …

Total answers: 1

Combining xarray datasets with combine_by_coords() for 2 dimensions simultaneously in python

Combining xarray datasets with combine_by_coords() for 2 dimensions simultaneously in python Question: I have multiple xarray datasets with the dimensions: target-latitudes (180) and target-longitudes 360) and one variable: variable1. Each of these datasets represents a source-gridcell and thus corresponds to a particular source-latitude and source-longitude; e.g., the dataset sourcelat25_sourcelon126_mm3_per_yr.nc corresponds to a gridcell with the …

Total answers: 1

Is bilinear resampling to a coarser resolution is similar to weighted spatial averaging?

Is bilinear resampling to a coarser resolution is similar to weighted spatial averaging? Question: I am using the xESMF python package to resample NDVI (greeness) data from 500 * 500 m to 1 * 1 degree.To clarify, I’m increasing the scale of the data. The package offers several techniques, including bilinear and conservative. I’m wondering …

Total answers: 1