Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ValueError: raster.coords should be named as coordinates:(y, x) when using proximity on xarray#601

Answeredbyianthomas23
kulpojke asked this question inQ&A
Discussion options

Hello,
I have created a binary raster from a vector file as an xarray dataset.

>>> g<xarray.Dataset>Dimensions:      (y: 12869, x: 6050)Coordinates:  * y            (y) float64 2.301e+06 2.301e+06 ... 2.173e+06 2.173e+06  * x            (x) float64 6.315e+06 6.315e+06 ... 6.375e+06 6.375e+06    spatial_ref  int64 0Data variables:    value        (y, x) float64 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0

when I try to compute proximity ong,

>>> from xrspatial import proximity>>> prox_agg = proximity(g)

I get the following ,

---------------------------------------------------------------------------ValueError                                Traceback (most recent call last)<ipython-input-24-d0c7776397ce> in <module>----> 1 prox_agg = proximity(g)/opt/conda/lib/python3.8/site-packages/xrspatial/proximity.py in proximity(raster, x, y, target_values, max_distance, distance_metric)    771     """    772 --> 773     proximity_img = _process(    774         raster,    775         x=x,/opt/conda/lib/python3.8/site-packages/xrspatial/proximity.py in _process(raster, x, y, target_values, max_distance, distance_metric, process_mode)    414     raster_dims = raster.dims    415     if raster_dims != (y, x):--> 416         raise ValueError(    417             "raster.coords should be named as coordinates:"    418             "({0}, {1})".format(y, x)ValueError: raster.coords should be named as coordinates:(y, x)

when I examine the dims

>>> g.dimsFrozen({'y': 12869, 'x': 6050})

Any ideas how I can get this to work?

You must be logged in to vote

Hi@kulpojke,

xrspatial.proximity is expecting anxarray.DataArray not anxarray.Dataset. You should replace

prox_agg=proximity(g)

with

prox_agg=proximity(g.value)

This is not an uncommon problem, we should probably explicitly check that arguments areDataArrays and give a more meaningful error message if they are not.

Replies: 1 comment 2 replies

Comment options

Hi@kulpojke,

xrspatial.proximity is expecting anxarray.DataArray not anxarray.Dataset. You should replace

prox_agg=proximity(g)

with

prox_agg=proximity(g.value)

This is not an uncommon problem, we should probably explicitly check that arguments areDataArrays and give a more meaningful error message if they are not.

You must be logged in to vote
2 replies
@kulpojke
Comment options

Ok, that worked. That was so simple. Thank you.

@ianthomas23
Comment options

You're welcome!

Answer selected byianthomas23
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@kulpojke@ianthomas23

[8]ページ先頭

©2009-2025 Movatter.jp