0

I want to do a 3Dscatterplot out of an xarray dataset. For this I have a variable called vari form the dataset. With plova I want to extract the variable specific for that time I need. And then I want to make a grid that fits to those values. But no matter what I do its not working.

plova=vari.isel(time=1)
x_=plova.x.values
y_=plova.y.values
z_=plova.zu.3d.values

x, y, z = np.meshgrid(x_, y_, z_)

ax1.scatter(x,y,z,c=plova)

But I get this Errors:

Traceback (most recent call last):
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\matplotlib\colors.py", line 174, in to_rgba
    rgba = _colors_full_map.cache[c, alpha]
TypeError: unhashable type: 'DataArray'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\matplotlib\axes\_axes.py", line 4232, in scatter
    colors = mcolors.to_rgba_array(c)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\matplotlib\colors.py", line 275, in to_rgba_array
    result[i] = to_rgba(cc, alpha)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\matplotlib\colors.py", line 176, in to_rgba
    rgba = _to_rgba_no_colorcycle(c, alpha)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\matplotlib\colors.py", line 227, in _to_rgba_no_colorcycle
    raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))
ValueError: Invalid RGBA argument: <xarray.DataArray 'theta' (y: 180, x: 180)>
array([[nan, nan, nan, ..., nan, nan, nan],
       [nan, nan, nan, ..., nan, nan, nan],
       [nan, nan, nan, ..., nan, nan, nan],
       ...,
       [nan, nan, nan, ..., nan, nan, nan],
       [nan, nan, nan, ..., nan, nan, nan],
       [nan, nan, nan, ..., nan, nan, nan]], dtype=float32)
Coordinates:
    time     timedelta64[ns] 00:15:00.392000
    zu_3d    float64 0.0
  * x        (x) float64 1.0 3.0 5.0 7.0 9.0 ... 351.0 353.0 355.0 357.0 359.0
  * y        (y) float64 1.0 3.0 5.0 7.0 9.0 ... 351.0 353.0 355.0 357.0 359.0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "auswerten1.py", line 58, in <module>
    cmap=cmap)
  File "I:\Praktikum_Sibylle Krause\funkt1.py", line 109, in temp_xy_save_scatter
    ax1.scatter(x,y,z,c=plova/300)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 2305, in scatter
    patches = super().scatter(xs, ys, s=s, c=c, *args, **kwargs)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\matplotlib\__init__.py", line 1810, in inner
    return func(ax, *args, **kwargs)
  File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\matplotlib\axes\_axes.py", line 4245, in scatter
    .format(nc=n_elem, xs=x.size, ys=y.size)
ValueError: 'c' argument has 62 elements, which is not acceptable for use with 'x' with size 2008800, 'y' with size 2008800.

This is what Plova looks like:

array([[[      nan,       nan, ...,       nan,       nan],
        [      nan,       nan, ...,       nan,       nan],
        ...,
        [      nan,       nan, ...,       nan,       nan],
        [      nan,       nan, ...,       nan,       nan]],

       [[290.69363, 290.8678 , ..., 290.24393, 290.4742 ],
        [290.61032, 290.75577, ..., 290.3259 , 290.4544 ],
        ...,
        [290.6593 , 290.87863, ..., 290.08743, 290.31827],
        [290.69678, 290.91376, ..., 290.14935, 290.41815]],

       ...,

       [[289.38855, 289.39468, ..., 289.38168, 289.38623],
        [289.38788, 289.39893, ..., 289.37695, 289.3846 ],
        ...,
        [289.39008, 289.39423, ..., 289.39124, 289.3914 ],
        [289.39157, 289.39432, ..., 289.38803, 289.39127]],

       [[289.40854, 289.4147 , ..., 289.40167, 289.40625],
        [289.4079 , 289.4189 , ..., 289.39694, 289.4046 ],
        ...,
        [289.41006, 289.4142 , ..., 289.41125, 289.4114 ],
        [289.41156, 289.4143 , ..., 289.40805, 289.41125]]], dtype=float32)

This is what the complete Dataset looks like:

Dimensions:  (time: 5, x: 180, xu: 180, y: 180, yv: 180, zs_3d: 8, zu_3d: 62, zw_3d: 62)
Coordinates:
  * time     (time) timedelta64[ns] 00:00:00 00:15:00.392000 ... 01:00:00.512000
  * zu_3d    (zu_3d) float64 0.0 1.0 3.0 5.0 7.0 ... 115.0 117.0 119.0 121.0
  * zw_3d    (zw_3d) float64 0.0 2.0 4.0 6.0 8.0 ... 116.0 118.0 120.0 122.0
  * x        (x) float64 1.0 3.0 5.0 7.0 9.0 ... 351.0 353.0 355.0 357.0 359.0
  * xu       (xu) float64 0.0 2.0 4.0 6.0 8.0 ... 350.0 352.0 354.0 356.0 358.0
  * y        (y) float64 1.0 3.0 5.0 7.0 9.0 ... 351.0 353.0 355.0 357.0 359.0
  * yv       (yv) float64 0.0 2.0 4.0 6.0 8.0 ... 350.0 352.0 354.0 356.0 358.0
  * zs_3d    (zs_3d) float64 -0.005 -0.02 -0.05 -0.1 -0.2 -0.4 -0.8 -2.0
Data variables:
    E_UTM    (x) float64 ...
    N_UTM    (y) float64 ...
    Eu_UTM   (xu) float64 ...
    Nu_UTM   (y) float64 ...
    Ev_UTM   (x) float64 ...
    Nv_UTM   (yv) float64 ...
    lon      (y, x) float64 ...
    lat      (y, x) float64 ...
    lonu     (y, xu) float64 ...
    latu     (y, xu) float64 ...
    lonv     (yv, x) float64 ...
    latv     (yv, x) float64 ...
    crs      int32 ...
    u        (time, zu_3d, y, xu) float32 ...
    v        (time, zu_3d, yv, x) float32 ...
    w        (time, zw_3d, y, x) float32 ...
    theta    (time, zu_3d, y, x) float32 ...
    wdir     (time, zu_3d, y, x) float32 ...
    wspeed   (time, zu_3d, y, x) float32 ...
    q        (time, zu_3d, y, x) float32 ...
    e        (time, zu_3d, y, x) float32 ...
    p        (time, zu_3d, y, x) float32 ...
    m_soil   (time, zs_3d, y, x) float32 ...
    t_soil   (time, zs_3d, y, x) float32 ...
    ta       (time, zu_3d, y, x) float32 ...
Attributes:
    title:           PALM 22.04  run: uenv_soest10.00  host: emlws  2022-08-0...
    Conventions:     CF-1.7
    creation_time:   2022-08-09 11:38:07 +02
    data_content:    3d
    version:         1
    origin_time:     2021-07-01 17:00:00 +00
    origin_lat:      50.0
    origin_lon:      12.0
    origin_x:        308124.0
    origin_y:        6098908.0
    origin_z:        0.0
    rotation_angle:  0.0
    dependencies:
    history:
    author:          ein sehr netter Mensch
    contact_person:
    institution:
    acronym:
    campaign:
    location:
    site:
    source:          PALM 22.04
    references:
    keywords:
    licence:
    comment:
    VAR_LIST:        ;u;v;w;theta;wdir;wspeed;q;e;p;m_soil;t_soil;ta;

Mabey someone knows what I am doing wrong?

Casheww
  • 47
  • 4

0 Answers0