Closed CameronLP closed 8 months ago
A workable approach is the following:
`from satpy import Scene import sys from glob import glob
sys.path.insert(0,'/home/cameron/Projects/')
files_3 = glob('/home/cameron/Dokumenter/Data/svalbardeidembukta/svalbardeidembukta_2023-03-14_14*') scene_3 = Scene(filenames=files_3, reader='hypso1_l1a_nc', reader_kwargs={'flip': True}) datasets_3 = scene_3.available_dataset_names() scene_3.load(datasets_3) ds = scene_3.to_xarray() da = ds.to_stacked_array('band', sample_dims=['x','y']) da.to_numpy().shape`
This produces a NumPy array with dimensions (956, 684, 122). The third dimension corresponds to 120 bands + latitude dataset + longitude dataset. This method does not preserve the order of spectral bands, so this needs to be added before it can be used for exporting datacubes as NumPy arrays.
Another possible approach: https://numpy.org/doc/stable/reference/generated/numpy.dstack.html
The code for doing this is saved in the file 'xarray_to_numpy.ipynb'. Closing issue.
Find a memory-efficient way of exporting data held in a Scene directly to a numpy array (not an xarray).