Repository navigation
Replies: 1 comment
|
A convenient way is to turn the two spatial dimensions into a single point dimension, remove the points where the data value is NaN, then convert the surviving coordinates to a table: points = (
da.stack(point=("latitude", "longitude"))
.dropna("point")
)
out = points.to_dataframe(name="deptho").reset_index()
out[["longitude", "latitude"]].to_csv("lonlat.csv", index=False)For your 2-D If you also want the depth value in the output, just write: out[["longitude", "latitude", "deptho"]].to_csv(
"lonlat_depth.csv", index=False
)An alternative is I also checked this on a small 2-D DataArray with the same dimension layout before posting; the resulting rows contain only the lon/lat pairs corresponding to non-NaN values. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I have the following Data array and I want to export a list of lons and lats to a .csv or .txt, but only for lonlat pairs have have a value ~NaN.
Here is my array:
Any suggestions?
All reactions