Reputation: 311
I am new to xarray data structure. I have xarrary data variable (intensity_table) which looks like following in the image. This xarrary structure comes from the postprocess of tif images. The tif image has 6 Round and 3 Channels. Intensity_table compute normalize intensity in these images and save it in features. I want to see this feature variable for each image separately. Is there any way to read this data in easy format or save in text file so that I can read from anywhere. Thanks a lot.
Upvotes: 0
Views: 1147
Reputation: 15442
Both Datasets and DataArrays have xr.DataArray.to_pandas
and xr.Dataset.to_pandas
methods. once you're in pandas, you can write to a variety of tabular data formats including, e.g. with pd.DataFrame.to_csv
If you'd like to preserve all non-indexing coordinates in the result, you might prefer to convert the data to a long-form table with each coordinate a column and all dimensions as levels in a MultiIndex. In that case, first convert the DataArray to a Dataset, then write this to a dataframe with xr.Dataset.to_dataframe()
:
df = intensity_table.to_dataset(name='IntensityTable').to_dataframe()
df.to_csv(filepath, index=True)
Note, however, that because pandas/CSV do not have any way of representing multiple datasets with different sets of dimensions, preserving all non-index coordinates will first broadcast all non-index coordinates and variables against each other. So all of your variables indexed only by features
will be repeated for each element in r
and c
.
Upvotes: 1