Dataset structure

Image coordinates included in data

Examining the object returned by mcam_data.new we notice not only an array of zeros, but also properties such as the x and y indices, as well as the image_x, and image_y indices.

>>> from owl import mcam_data
>>> dataset = mcam_data.new_dataset()
>>> dataset
<xarray.Dataset>
Dimensions:           (image_y: 9, image_x: 6, y: 3120, x: 4096)
Coordinates:
  * image_y           (image_y) int64 0 1 2 3 4 5 6 7 8
  * image_x           (image_x) int64 0 1 2 3 4 5
  * y                 (y) int64 0 1 2 3 4 5 6 ... 3114 3115 3116 3117 3118 3119
  * x                 (x) int64 0 1 2 3 4 5 6 ... 4090 4091 4092 4093 4094 4095
Data variables:
    images            (image_y, image_x, y, x) uint8 0 0 0 0 0 0 ... 0 0 0 0 0 0

This kind of metadata is important when slicing data. For example, slicing the newly created m_data object, we can see that the coordinates are also sliced

>>> dataset.isel({'y': slice(None, None, 2), 'x': slice(1, None, 3)})
<xarray.Dataset>
Dimensions:           (image_y: 9, image_x: 6, y: 1560, x: 1365)
Coordinates:
  * image_y           (image_y) int64 0 1 2 3 4 5 6 7 8
  * image_x           (image_x) int64 0 1 2 3 4 5
  * y                 (y) int64 0 2 4 6 8 10 ... 3108 3110 3112 3114 3116 3118
  * x                 (x) int64 1 4 7 10 13 16 ... 4078 4081 4084 4087 4090 4093
Data variables:
    images            (image_y, image_x, y, x) uint8 0 0 0 0 0 0 ... 0 0 0 0 0 0

We notice that the x and y coordinates now reflect that the original array has been sliced in a particular fashion. It may be important for you to recall this data when doing advanced analysis on your datasets.

The raw data, without any metadata is accessible through the data attribute of the images data variable.

>>> dataset.images.data
array([[[[0, 0, 0, ..., 0, 0, 0],
         [0, 0, 0, ..., 0, 0, 0],
         [0, 0, 0, ..., 0, 0, 0],
         ...,
         [0, 0, 0, ..., 0, 0, 0],
         [0, 0, 0, ..., 0, 0, 0],
         [0, 0, 0, ..., 0, 0, 0]]]], dtype=uint8)

Coordinates are also attributes, and can be accessed in a similar fashion:

>>> dataset.image_x
<xarray.DataArray 'image_x' (image_x: 6)>
array([0, 1, 2, 3, 4, 5])
Coordinates:
  * image_x           (image_x) int64 0 1 2 3 4 5

The owl library leverages the work done by the xarray community to offer labeled datasets. To learn more about all the features of xarrays, please refer to their documentation.