| 1 |
""" |
| 2 |
Copyright (c) 2021 Blosc Development Team <[email protected]> |
| 3 |
https://blosc.org |
| 4 |
License: BSD 3-Clause (see LICENSE.txt) |
| 5 |
|
| 6 |
Script to extract a small grid of precipitation out of this file: |
| 7 |
|
| 8 |
ftp://ftp-cdc.dwd.de/pub/REA/COSMO_REA6/hourly/2D/TOT_PRECIP/TOT_PRECIP.2D.201512.grb.bz2 |
| 9 |
|
| 10 |
After downloading it and uncompressing it, just run this script for extracting a small grid. |
| 11 |
|
| 12 |
For more info on these datasets, see https://reanalysis.meteo.uni-bonn.de. |
| 13 |
""" |
| 14 |
|
| 15 |
from osgeo import gdal |
| 16 |
import numpy as np |
| 17 |
import blosc |
| 18 |
|
| 19 |
# Read a 150x150 grid from the first band |
| 20 |
dataset = gdal.Open("TOT_PRECIP.2D.201512.grb", gdal.GA_ReadOnly) |
| 21 |
band = dataset.GetRasterBand(1) |
| 22 |
precip_data = band.ReadAsArray(0, 0, 150, 150).astype(np.float32) |
| 23 |
|
| 24 |
# Compress the chunk and write it to a file |
| 25 |
cdata = blosc.compress(precip_data, cname="blosclz", clevel=9, typesize=4) |
| 26 |
open("rainfall-band-150x150.bin", "wb").write(cdata) |