Selecting Specific Time Steps for Rainfall Data Visualization #6261
-
What happened?i just want plot particular time steps variable data What did you expect to happen?i want data only some time steps Minimal Complete Verifiable Exampleimport xarray as xr
import cartopy.crs as ccrs
from cartopy import feature as cf
import matplotlib.pyplot as plt
import numpy as np
#Opening and reading data
data=xr.open_dataset("heavyrain3.nc")
print(data)
lon=data.lon[:]
lat=data.lat[:]
#lev_2=data.lev_2[:]
rainnc=data.rainnc[17-9]
#time=data.time[0]
ax = plt.axes(projection=ccrs.PlateCarree())
rainnc.isel(time=16, lev_2=0).plot.pcolormesh(cmap='Purples',add_colorbar=False);
#ax.set_extent([west, east, south, north])
ax.coastlines()
ax.add_feature(cf.BORDERS)
plt.savefig("rain31.jpg")
plt.show() Relevant log outputraise ValueError(
ValueError: Dimensions {'time'} do not exist. Expected one or more of ('lev_2', 'lat', 'lon') Anything else we need to know?No response EnvironmentTraceback (most recent call last): |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 5 replies
-
Please review the links on producing quality examples. I'll close for now but feel free to reopen if you're up for producing one. |
Beta Was this translation helpful? Give feedback.
-
import xarray as xr
import cartopy.crs as ccrs
from cartopy import feature as cf
import matplotlib.pyplot as plt
import numpy as np
data=xr.open_dataset("rainncreq.nc")
print(data)
lon=data.lon[:]
lat=data.lat[:]
lev_2=data.lev_2[0]
rainnc=data.rainnc[:]
ax = plt.axes(projection=ccrs.PlateCarree())
rainnc.isel(time=0+8,lev_2=0).plot.pcolormesh(cmap='jet',vmax=100,vmin=0,add_colorbar=True);
ax.coastlines()
ax.add_feature(cf.BORDERS)
plt.savefig("rain31.jpg")
plt.show() then it is not giving error just the data File "/home/user/Documents/IGCAR/rain/rain.py", line 36, in <module>
rainnc.isel(time=0+1+2+3+4+5+6+7+8,lev_2=0).plot.pcolormesh(cmap='jet',vmax=100,vmin=0,add_colorbar=True);
File "/home/user/anaconda3/lib/python3.9/site-packages/xarray/core/dataarray.py", line 1208, in isel
variable = self._variable.isel(indexers, missing_dims=missing_dims)
File "/home/user/anaconda3/lib/python3.9/site-packages/xarray/core/variable.py", line 1193, in isel
return self[key]
File "/home/user/anaconda3/lib/python3.9/site-packages/xarray/core/variable.py", line 786, in __getitem__
data = as_indexable(self._data)[indexer]
File "/home/user/anaconda3/lib/python3.9/site-packages/xarray/core/indexing.py", line 555, in __getitem__
return type(self)(_wrap_numpy_scalars(self.array[key]))
File "/home/user/anaconda3/lib/python3.9/site-packages/xarray/core/indexing.py", line 524, in __getitem__
return type(self)(_wrap_numpy_scalars(self.array[key]))
File "/home/user/anaconda3/lib/python3.9/site-packages/xarray/core/indexing.py", line 431, in __getitem__
return type(self)(self.array, self._updated_key(indexer))
File "/home/user/anaconda3/lib/python3.9/site-packages/xarray/core/indexing.py", line 403, in _updated_key
full_key.append(_index_indexer_1d(k, next(iter_new_key), size))
File "/home/user/anaconda3/lib/python3.9/site-packages/xarray/core/indexing.py", line 176, in _index_indexer_1d
indexer = _expand_slice(old_indexer, size)[applied_indexer]
IndexError: index 36 is out of bounds for axis 0 with size 9 hope you understand my problem |
Beta Was this translation helpful? Give feedback.
-
good morning sir
slice working on latitude and longitude
but it is not working on time
when i give slice to time it giving error
```pytb
Traceback (most recent call last):
File "/home/user/Documents/IGCAR/rain/rain.py", line 36, in <module>
rainnc.isel(time=slice(0,8),lev_2=0).plot.pcolormesh(cmap='jet',vmax=100,vmin=0,add_colorbar=True);
File "/home/user/anaconda3/lib/python3.9/site-packages/xarray/plot/plot.py", line 1302, in plotmethod
return newplotfunc(**allargs)
File "/home/user/anaconda3/lib/python3.9/site-packages/xarray/plot/plot.py", line 1132, in newplotfunc
xlab, ylab = _infer_xy_labels(
File "/home/user/anaconda3/lib/python3.9/site-packages/xarray/plot/utils.py", line 390, in _infer_xy_labels
raise ValueError("DataArray must be 2d")
ValueError: DataArray must be 2d
```
|
Beta Was this translation helpful? Give feedback.
-
yeah sure
|
Beta Was this translation helpful? Give feedback.
-
actually i want add the rainnc value from time step 0 to 8
…On Thu, Feb 10, 2022 at 2:33 PM keewis ***@***.***> wrote:
The error is raised because pcolormesh needs a 2D array but the slice
returns a 3D array ((time, lat, lon)). To fix that, you can try plotting
each time separately by passing col="time". If that's not what you
wanted, can you describe what you wanted to do?
—
Reply to this email directly, view it on GitHub
<#6261 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AXIX2YDP4C6KI5M2DYEVPOTU2N5O5ANCNFSM5N6E647A>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
i want to plot total rainnc data in a single plot
i want add the rainnc timesteps
On Thu, Feb 10, 2022 at 2:35 PM haritha meka ***@***.***>
wrote:
… actually i want add the rainnc value from time step 0 to 8
On Thu, Feb 10, 2022 at 2:33 PM keewis ***@***.***> wrote:
> The error is raised because pcolormesh needs a 2D array but the slice
> returns a 3D array ((time, lat, lon)). To fix that, you can try plotting
> each time separately by passing col="time". If that's not what you
> wanted, can you describe what you wanted to do?
>
> —
> Reply to this email directly, view it on GitHub
> <#6261 (reply in thread)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AXIX2YDP4C6KI5M2DYEVPOTU2N5O5ANCNFSM5N6E647A>
> .
> Triage notifications on the go with GitHub Mobile for iOS
> <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
> or Android
> <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
>
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
|
Beta Was this translation helpful? Give feedback.
-
then you're looking for rainnc.isel(time=slice(0, 8), lev_2=0).sum(dim="time") which sums up the 8 time steps between the 0th and 7th ( |
Beta Was this translation helpful? Give feedback.
-
actually there are 9 time steps |
Beta Was this translation helpful? Give feedback.
-
I will try sir |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot.
it works sir
…On Thu, Feb 10, 2022 at 2:50 PM keewis ***@***.***> wrote:
then you have to use slice(0, 9)
—
Reply to this email directly, view it on GitHub
<#6261 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AXIX2YE44W7O4WKKDVXT73DU2N7O3ANCNFSM5N6E647A>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
then you're looking for
which sums up the 8 time steps between the 0th and 7th (
slice
s are right-exclusive)