manipulating image data with a negative y coordinate axis

44 views
Skip to first unread message

Jessica Scheick

unread,
Jan 7, 2021, 2:07:19 PM1/7/21
to xarray
Hello all,

I've got a set of raster images that have a negative y coordinate axis. I'm trying to apply some image analysis techniques like segmentation using scipy.ndimage. Since the ndimage library doesn't handle coordinate systems, I'm passing the raster in as an array and re-attaching it to the coordinates later (I'm producing arrays of an identical size and shape). However, I'm getting funny results when I then try to do any further geospatially aware operations (such as polygonizing the raster using rasterio). The issue seems to stem from how I'm handling the arrays, and I've landed on a few "basic" questions I can't seem to puzzle out, even with basic examples.

da = dataarray
var = variable in da
1. What's the difference between da.var.values and da.var.data? In a MWE I get np.allcose(da.var.values, da.var.data) returning True, as I'd expect, but when I do the same thing on a particular dataarray (of type float64) from my dataset , I get False. I can't fathom why - any ideas?
2. Does anyone know of any example workflows doing image analysis on an xarray dataset with a non-geospatially aware package where the y coordinates are negative? I know that there are lots of good examples out there created by the awesome folks on this list that don't show up in google searches.

Thanks,
~Jessica

Jessica Scheick

unread,
Jan 7, 2021, 6:12:46 PM1/7/21
to xar...@googlegroups.com
Question number one warrants a facepalm once I revisited the np.allclose docs again - I'd forgotten to set the equal_nan flag, and there are nans in my dataset. I am still curious why there seem to be two ways to get the same data though.

Pointers to examples are still welcome to see how others handle this, though I think my method is pretty robust. I've traced my "funny" results to the image analysis itself, which is returning different results depending on the orientation of the input image (still need to track down why on that).

Thanks!
~Jessica

--
You received this message because you are subscribed to a topic in the Google Groups "xarray" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/xarray/4DTbZG-htkw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to xarray+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xarray/522e411b-f4c4-46f5-afbe-1062aef75545n%40googlegroups.com.


--
Jessica Scheick, PhD
she/her/hers

Justus Magin

unread,
Jan 8, 2021, 9:30:20 AM1/8/21
to xar...@googlegroups.com
Hi

> I am still curious why there seem to be two ways to get the same data
> though.

The difference between .data and .values is that .data returns the
wrapped object directly while .values casts it to a numpy array using
numpy.asarray first.

This only matters if your DataArray objects wrap something other than
numpy arrays (mostly dask, sparse, or pint), or if you used open_* to
open a file but didn't load it into memory, yet (in that case the repr
of the DataArray contains something like "[2029500 values with
dtype=float64]" or a dask repr).

Justus
>> <https://groups.google.com/d/msgid/xarray/522e411b-f4c4-46f5-afbe-1062aef75545n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
Reply all
Reply to author
Forward
0 new messages