{ "cells": [ { "cell_type": "markdown", "id": "3f2c9098", "metadata": {}, "source": [ "# Quick start" ] }, { "cell_type": "code", "execution_count": null, "id": "0f7e319d-8e1c-4116-8ea3-59349e26fdad", "metadata": {}, "outputs": [], "source": [ "import xbitinfo as xb\n", "\n", "import xarray as xr\n", "\n", "xr.set_options(display_style=\"text\")" ] }, { "cell_type": "code", "execution_count": null, "id": "b6f1bcc1-fb6b-47d5-9603-5a915a04f768", "metadata": {}, "outputs": [], "source": [ "ds = xr.tutorial.load_dataset(\"eraint_uvz\")\n", "\n", "# xb.plot_distribution(ds)", "\n", "ds" ] }, { "cell_type": "markdown", "id": "822d7b08", "metadata": {}, "source": [ "## Get information content per bit\n", "\n", "using {py:func}`xbitinfo.xbitinfo.get_bitinformation`" ] }, { "cell_type": "code", "execution_count": null, "id": "f4fd451f-4853-498a-a029-364a62a9c2b0", "metadata": {}, "outputs": [], "source": [ "info_per_bit = xb.get_bitinformation(ds, dim=\"longitude\")\n", "\n", "info_per_bit" ] }, { "cell_type": "markdown", "id": "bdfd9186", "metadata": {}, "source": [ "## Visualize information content", "\n", "using {py:func}`xbitinfo.graphics.plot_bitinformation`" ] }, { "cell_type": "code", "execution_count": null, "id": "05d43ae8", "metadata": {}, "outputs": [], "source": [ "fig = xb.plot_bitinformation(info_per_bit)" ] }, { "cell_type": "markdown", "id": "c14645a5", "metadata": {}, "source": [ "## Get keepbits\n", "\n", "using {py:func}`xbitinfo.xbitinfo.get_keepbits`" ] }, { "cell_type": "code", "execution_count": null, "id": "5385105d", "metadata": {}, "outputs": [], "source": [ "keepbits = xb.get_keepbits(info_per_bit, 0.99)\n", "keepbits" ] }, { "cell_type": "markdown", "id": "ec3dd057-b634-48b8-b9f4-47b09b2f4599", "metadata": {}, "source": [ "## Apply bitrounding\n", "\n", "using {py:func}`xbitinfo.bitround.xr_bitround` or {py:func}`xbitinfo.bitround.jl_bitround` (does not work for chunked data)" ] }, { "cell_type": "code", "execution_count": null, "id": "8af292c1-1354-45a9-ba04-e129acfad3bb", "metadata": {}, "outputs": [], "source": [ "ds_bitrounded = xb.xr_bitround(ds, keepbits)" ] }, { "cell_type": "markdown", "id": "c0b507c7-4261-4ff0-8d8e-617d874c6832", "metadata": {}, "source": [ "## Save compressed\n", "\n", "using {py:class}`xbitinfo.save_compressed.ToCompressed_Netcdf` or {py:class}`xbitinfo.save_compressed.ToCompressed_Zarr`" ] }, { "cell_type": "markdown", "id": "b9615eeb", "metadata": {}, "source": [ "### NetCDF" ] }, { "cell_type": "code", "execution_count": null, "id": "41604e42-f6ee-482c-b43f-fcf1252d6b5f", "metadata": {}, "outputs": [], "source": [ "ds_bitrounded.to_compressed_netcdf(\"bitrounded_compressed.nc\")" ] }, { "cell_type": "code", "execution_count": null, "id": "fd9be7d7-3e36-457f-9714-0afd94f85625", "metadata": {}, "outputs": [], "source": [ "ds.to_compressed_netcdf(\"compressed.nc\")" ] }, { "cell_type": "code", "execution_count": null, "id": "0dd7c1e3-bf5a-406d-b6b9-dda26c160188", "metadata": {}, "outputs": [], "source": [ "ds.to_netcdf(\"original.nc\")" ] }, { "cell_type": "code", "execution_count": null, "id": "5c4a0f91-c276-4b75-a854-4490d023ed60", "metadata": {}, "outputs": [], "source": [ "!du -hs *.nc" ] }, { "cell_type": "code", "execution_count": null, "id": "ed962dee-45ac-4745-968f-76848a4ae845", "metadata": {}, "outputs": [], "source": [ "!rm *.nc" ] }, { "cell_type": "markdown", "id": "dcdbe8ed", "metadata": {}, "source": [ "### Zarr" ] }, { "cell_type": "code", "execution_count": null, "id": "5e4b423e", "metadata": {}, "outputs": [], "source": [ "ds_bitrounded.to_compressed_zarr(\"bitrounded_compressed.zarr\", mode=\"w\")\n", "ds.to_compressed_zarr(\"compressed.zarr\", mode=\"w\")\n", "ds.to_zarr(\n", " \"original.zarr\", mode=\"w\", encoding={v: {\"compressor\": None} for v in ds.data_vars}\n", ");" ] }, { "cell_type": "code", "execution_count": null, "id": "ab0da898", "metadata": {}, "outputs": [], "source": [ "!du -hs *.zarr" ] }, { "cell_type": "code", "execution_count": null, "id": "3779baf6", "metadata": {}, "outputs": [], "source": [ "!rm -r *.zarr" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.4" }, "toc-autonumbering": true }, "nbformat": 4, "nbformat_minor": 5 }