5

I have a DataArray that I want to convert to a numpy array. For reference it's a three dimensional gridded dataset containing (time, latitude, longitude). I have tried using xarray.DataArray.values(), but receive the error: TypeError: 'property' object is not callable.

I want to transform it into a numpy array as I'm using a function that utilizes the reshape capabilities and won't work properly with the DataArray. I've tried simply converting it to a numpy array using np.array(), but it converts every value into a NaN.

datatlt=xr.open_dataset("/nfs/home11/staff/lzhou/Public/Satellite_data/RSS_Tb_Anom_Maps_ch_TLT_V4_0.nc", decode_times=False)

tlt=datatlt['brightness_temperature'].sel(months=slice(121,492))
tlt2=np.ma.masked_invalid(tlt)

tlt2=xr.DataArray.values(tlt2)
2
  • Please edit your question to mention what kind of data is present in your data array -- are they integers or floats? What is minimum possible value and maximum possible value? If floats, can they be represented in 32-bit floats? Before creating a numpy array, you need to decide upon a suitable numpy dtype for each element, and that would depend upon details such as what I just mentioned Commented Mar 13, 2019 at 0:24
  • 1
    Did you try xarray.DataArray.values? The error means you can't use () after values because it isn't callable (it isn't a function). What is the type of that values object? Is it an array? If so, what shape and dtype? Commented Mar 13, 2019 at 0:42

1 Answer 1

5

DataArray.values is a property. Properties are not callable. Instead, you just access the numpy array as if it were an attribute of the DataArray.

tlt2 = tlt.values

If you want a masked array, you'll want to call the to_masked_array method:

tlt2 = tlt.to_masked_array()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.