Change the units of edge_size
¶
In this tutorial we will learn how to change the units of edge_size
.
[1]:
import cubo
By default, the units of edge_size
are pixels:
[2]:
da = cubo.create(
lat=51.079225,
lon=10.452173,
collection="sentinel-2-l2a",
bands=["B02","B03","B04"],
start_date="2021-06-01",
end_date="2021-07-01",
edge_size=64, # Edge size of the cube (px)
resolution=20, # Pixel size of the cube (m)
query={"eo:cloud_cover": {"lt": 10}}
)
da
/home/dmontero/anaconda3/envs/cubo/lib/python3.9/site-packages/stackstac/prepare.py:364: UserWarning: The argument 'infer_datetime_format' is deprecated and will be removed in a future version. A strict version of it is now the default, see https://pandas.pydata.org/pdeps/0004-consistent-to-datetime-parsing.html. You can safely remove this argument.
times = pd.to_datetime(
[2]:
<xarray.DataArray 'sentinel-2-l2a' (time: 2, band: 3, y: 64, x: 64)> dask.array<fetch_raster_window, shape=(2, 3, 64, 64), dtype=float64, chunksize=(1, 1, 64, 64), chunktype=numpy.ndarray> Coordinates: (12/47) * time (time) datetime64[ns] 2021-06-13... id (time) <U54 'S2B_MSIL2A_20210613... * band (band) <U3 'B02' 'B03' 'B04' * x (x) float64 6.011e+05 ... 6.023e+05 * y (y) float64 5.66e+06 ... 5.659e+06 s2:water_percentage (time) float64 0.1445 0.1281 ... ... title (band) <U20 'Band 2 - Blue - 10m... common_name (band) <U5 'blue' 'green' 'red' center_wavelength (band) float64 0.49 0.56 0.665 full_width_half_max (band) float64 0.098 0.045 0.038 epsg int64 32632 cubo:distance_from_center (y, x) float64 908.2 ... 873.7 Attributes: collection: sentinel-2-l2a stac: https://planetarycomputer.microsoft.com/api/stac/v1 epsg: 32632 resolution: 20 edge_size: 64 edge_size_m: 1280 central_lat: 51.079225 central_lon: 10.452173 central_y: 5659638.0946523 central_x: 601722.4825156148 time_coverage_start: 2021-06-01 time_coverage_end: 2021-07-01
But you can use the units
argument to change this to meters ("m"
).
[4]:
da = cubo.create(
lat=51.079225,
lon=10.452173,
collection="sentinel-2-l2a",
bands=["B02","B03","B04"],
start_date="2021-06-01",
end_date="2021-07-01",
edge_size=1280, # Edge size of the cube (m)
units="m",
resolution=20, # Pixel size of the cube (m)
query={"eo:cloud_cover": {"lt": 10}}
)
da
/home/dmontero/anaconda3/envs/cubo/lib/python3.9/site-packages/stackstac/prepare.py:364: UserWarning: The argument 'infer_datetime_format' is deprecated and will be removed in a future version. A strict version of it is now the default, see https://pandas.pydata.org/pdeps/0004-consistent-to-datetime-parsing.html. You can safely remove this argument.
times = pd.to_datetime(
[4]:
<xarray.DataArray 'sentinel-2-l2a' (time: 2, band: 3, y: 64, x: 64)> dask.array<fetch_raster_window, shape=(2, 3, 64, 64), dtype=float64, chunksize=(1, 1, 64, 64), chunktype=numpy.ndarray> Coordinates: (12/47) * time (time) datetime64[ns] 2021-06-13... id (time) <U54 'S2B_MSIL2A_20210613... * band (band) <U3 'B02' 'B03' 'B04' * x (x) float64 6.011e+05 ... 6.023e+05 * y (y) float64 5.66e+06 ... 5.659e+06 s2:water_percentage (time) float64 0.1445 0.1281 ... ... title (band) <U20 'Band 2 - Blue - 10m... common_name (band) <U5 'blue' 'green' 'red' center_wavelength (band) float64 0.49 0.56 0.665 full_width_half_max (band) float64 0.098 0.045 0.038 epsg int64 32632 cubo:distance_from_center (y, x) float64 908.2 ... 873.7 Attributes: collection: sentinel-2-l2a stac: https://planetarycomputer.microsoft.com/api/stac/v1 epsg: 32632 resolution: 20 edge_size: 64 edge_size_m: 1280 central_lat: 51.079225 central_lon: 10.452173 central_y: 5659638.0946523 central_x: 601722.4825156148 time_coverage_start: 2021-06-01 time_coverage_end: 2021-07-01
You can also use any unit from `scipy.constants
<https://docs.scipy.org/doc/scipy/reference/constants.html#units>`__:
[7]:
da = cubo.create(
lat=51.079225,
lon=10.452173,
collection="sentinel-2-l2a",
bands=["B02","B03","B04"],
start_date="2021-06-01",
end_date="2021-07-01",
edge_size=1.5, # Edge size of the cube (km)
units="kilo",
resolution=20, # Pixel size of the cube (m)
query={"eo:cloud_cover": {"lt": 10}}
)
da
/home/dmontero/anaconda3/envs/cubo/lib/python3.9/site-packages/stackstac/prepare.py:364: UserWarning: The argument 'infer_datetime_format' is deprecated and will be removed in a future version. A strict version of it is now the default, see https://pandas.pydata.org/pdeps/0004-consistent-to-datetime-parsing.html. You can safely remove this argument.
times = pd.to_datetime(
[7]:
<xarray.DataArray 'sentinel-2-l2a' (time: 2, band: 3, y: 76, x: 76)> dask.array<fetch_raster_window, shape=(2, 3, 76, 76), dtype=float64, chunksize=(1, 1, 76, 76), chunktype=numpy.ndarray> Coordinates: (12/47) * time (time) datetime64[ns] 2021-06-13... id (time) <U54 'S2B_MSIL2A_20210613... * band (band) <U3 'B02' 'B03' 'B04' * x (x) float64 6.01e+05 ... 6.025e+05 * y (y) float64 5.66e+06 ... 5.659e+06 s2:water_percentage (time) float64 0.1445 0.1281 ... ... title (band) <U20 'Band 2 - Blue - 10m... common_name (band) <U5 'blue' 'green' 'red' center_wavelength (band) float64 0.49 0.56 0.665 full_width_half_max (band) float64 0.098 0.045 0.038 epsg int64 32632 cubo:distance_from_center (y, x) float64 1.078e+03 ... 1.0... Attributes: collection: sentinel-2-l2a stac: https://planetarycomputer.microsoft.com/api/stac/v1 epsg: 32632 resolution: 20 edge_size: 76 edge_size_m: 1520 central_lat: 51.079225 central_lon: 10.452173 central_y: 5659638.0946523 central_x: 601722.4825156148 time_coverage_start: 2021-06-01 time_coverage_end: 2021-07-01
You can also get creative and define your cube in LIGHT YEARS!
[8]:
da = cubo.create(
lat=51.079225,
lon=10.452173,
collection="sentinel-2-l2a",
bands=["B02","B03","B04"],
start_date="2021-06-01",
end_date="2021-07-01",
edge_size=0.0000000000003, # Edge size of the cube (light years)
units="light_year",
resolution=20, # Pixel size of the cube (m)
query={"eo:cloud_cover": {"lt": 10}}
)
da
/home/dmontero/anaconda3/envs/cubo/lib/python3.9/site-packages/stackstac/prepare.py:364: UserWarning: The argument 'infer_datetime_format' is deprecated and will be removed in a future version. A strict version of it is now the default, see https://pandas.pydata.org/pdeps/0004-consistent-to-datetime-parsing.html. You can safely remove this argument.
times = pd.to_datetime(
[8]:
<xarray.DataArray 'sentinel-2-l2a' (time: 2, band: 3, y: 142, x: 142)> dask.array<fetch_raster_window, shape=(2, 3, 142, 142), dtype=float64, chunksize=(1, 1, 142, 142), chunktype=numpy.ndarray> Coordinates: (12/47) * time (time) datetime64[ns] 2021-06-13... id (time) <U54 'S2B_MSIL2A_20210613... * band (band) <U3 'B02' 'B03' 'B04' * x (x) float64 6.003e+05 ... 6.031e+05 * y (y) float64 5.661e+06 ... 5.658e+06 s2:water_percentage (time) float64 0.1445 0.1281 ... ... title (band) <U20 'Band 2 - Blue - 10m... common_name (band) <U5 'blue' 'green' 'red' center_wavelength (band) float64 0.49 0.56 0.665 full_width_half_max (band) float64 0.098 0.045 0.038 epsg int64 32632 cubo:distance_from_center (y, x) float64 2.011e+03 ... 1.9... Attributes: collection: sentinel-2-l2a stac: https://planetarycomputer.microsoft.com/api/stac/v1 epsg: 32632 resolution: 20 edge_size: 142 edge_size_m: 2840 central_lat: 51.079225 central_lon: 10.452173 central_y: 5659638.0946523 central_x: 601722.4825156148 time_coverage_start: 2021-06-01 time_coverage_end: 2021-07-01