Clarification about the right use of DataArray and Dataset #6748
-
I've a lot of scenes from Landsat 8 that I manage as DataArray. I put 9 bands from a scene into one DataArray and I set
Below the output from one band:
All bands are stored into a list(
Now I add the sensing date as another dimension:
Below my output at this point:
As I said I've a lot of scenes, so I put all the above data into a list and using again
With this output I'm be able to compute many spectral indexes, for examples NDVI. My question: is this a right approach? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@MaxDragonheart it's a matter of preference to use the DataArray or DataSet representation with bands as variables. Xarray allows you to move back and forth with Just be careful that the CRS (spatial_ref) of your DataArrays match as Xarray will not automatically reproject data in different CRS when constructing a cube. You might check out this example notebook for a DataSet representation https://planetarycomputer.microsoft.com/dataset/landsat-c2-l2#Example-Notebook: There are so many ways to get Landsat data these days, where are you obtaining it from? Libraries that build on Xarray like stackstac or odc-stac make constructing DataSets easy and will even handle reprojection if the Landsat data has accompanying STAC metadata (like the planetary computer example above). If you don't have the STAC metadata, your approach works fine. But if the CRS of scenes is different you need to manually deal with matching the grids of different data arrays, which the rioxarray extension can do |
Beta Was this translation helpful? Give feedback.
@MaxDragonheart it's a matter of preference to use the DataArray or DataSet representation with bands as variables. Xarray allows you to move back and forth with
to_dataset()
andto_array()
methods.Just be careful that the CRS (spatial_ref) of your DataArrays match as Xarray will not automatically reproject data in different CRS when constructing a cube. You might check out this example notebook for a DataSet representation https://planetarycomputer.microsoft.com/dataset/landsat-c2-l2#Example-Notebook:
There are so many ways to get Landsat data these days, where are you obtaining it from? Libraries that build on Xarray like stackstac or odc-stac make constructing DataSets easy and will …