Created
October 29, 2024 19:58
-
-
Save sharkinsspatial/332f6c9ce8789ca4eb34f547c02aaa46 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "id": "8332bd3f-a657-42b9-9067-210d4de0e565", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "import xarray as xr" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 5, | |
| "id": "223fd220-fca1-4a70-9c4a-f7484370c888", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "zlib_url = \"zlib.nc\"\n", | |
| "url = \"air.nc\"" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 6, | |
| "id": "24b2ef34-6027-4e42-8e2e-69abea557b89", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stderr", | |
| "output_type": "stream", | |
| "text": [ | |
| "/Users/seanharkins/micromamba/envs/virtualizarr-notebooks/lib/python3.12/site-packages/IPython/core/interactiveshell.py:3577: SerializationWarning: saving variable air with floating point data as an integer dtype without any _FillValue to use for NaNs\n", | |
| " exec(code_obj, self.user_global_ns, self.user_ns)\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "ds = xr.tutorial.open_dataset(\"air_temperature\")\n", | |
| "encoding = {}\n", | |
| "encoding_config = {\"zlib\": True, \"complevel\": 1}\n", | |
| "for var_name in ds.variables:\n", | |
| " encoding[var_name] = encoding_config\n", | |
| "ds.to_netcdf(zlib_url, encoding=encoding)\n", | |
| "ds.to_netcdf(url)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 7, | |
| "id": "23b7bf88-6673-45cf-a81b-f273627b24ee", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "{'dtype': dtype('int64'),\n", | |
| " 'zlib': True,\n", | |
| " 'szip': False,\n", | |
| " 'zstd': False,\n", | |
| " 'bzip2': False,\n", | |
| " 'blosc': False,\n", | |
| " 'shuffle': True,\n", | |
| " 'complevel': 1,\n", | |
| " 'fletcher32': False,\n", | |
| " 'contiguous': False,\n", | |
| " 'chunksizes': (2920,),\n", | |
| " 'preferred_chunks': {'time': 2920},\n", | |
| " 'source': '/Users/seanharkins/Downloads/kerchunk_test/zlib.nc',\n", | |
| " 'original_shape': (2920,),\n", | |
| " 'units': 'nanoseconds since 2013-01-01 00:02:06.757437440',\n", | |
| " 'calendar': 'proleptic_gregorian'}" | |
| ] | |
| }, | |
| "execution_count": 7, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "ds_zlib = xr.open_dataset(\"zlib.nc\")\n", | |
| "ds_zlib[\"time\"].encoding" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 8, | |
| "id": "6a0a7fc5-1e83-4cc4-85b5-72f959462bd5", | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "{'dtype': dtype('float32'),\n", | |
| " 'zlib': False,\n", | |
| " 'szip': False,\n", | |
| " 'zstd': False,\n", | |
| " 'bzip2': False,\n", | |
| " 'blosc': False,\n", | |
| " 'shuffle': False,\n", | |
| " 'complevel': 0,\n", | |
| " 'fletcher32': False,\n", | |
| " 'contiguous': True,\n", | |
| " 'chunksizes': None,\n", | |
| " 'source': '/Users/seanharkins/Downloads/kerchunk_test/air.nc',\n", | |
| " 'original_shape': (2920,),\n", | |
| " '_FillValue': np.float32(nan),\n", | |
| " 'units': 'hours since 1800-01-01',\n", | |
| " 'calendar': 'standard'}" | |
| ] | |
| }, | |
| "execution_count": 8, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "ds_air = xr.open_dataset(url)\n", | |
| "ds_air[\"time\"].encoding" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "id": "1aa29746-4ce4-4fb0-bc36-14f1a9ce7fbc", | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python 3 (ipykernel)", | |
| "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.12.4" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 5 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment