{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Add and use a user-defined colormap" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "1. Look at the Colormaps page in **epygram** doc, and try out some of these to see their characteristics - basically, 3 kinds:\n", " * continuous (default)\n", " * normalized (e.g. _rr1h_), i.e. each value interval occupy a normalized size in colormap\n", " * and normalized-centered (e.g. _ptype_), i.e. normalized, with interval centered on defined values\n", "2. Once you found the one which characteristics you would like to imitate, copy its `.json` file from `EPYGRAM_INSTALL_DIR/epygram/data/colormaps/` to wherever you want (say, `/path/to/my_cmap.json`)\n", "3. Modify the name of the new colormap, its colors (RGB, optional transparency) and colorsteps in the json file.\n", "4. Register your colormap in your `HOME/.epygram/userconfig.py`:\n", " `usercolormaps = {'my_cmap':'/path/to/my_cmap.json'}`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## An example below of a normalized-centered colormap" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:31:09.025564Z", "iopub.status.busy": "2025-01-13T11:31:09.025094Z", "iopub.status.idle": "2025-01-13T11:31:09.557258Z", "shell.execute_reply": "2025-01-13T11:31:09.556642Z" } }, "outputs": [], "source": [ "%matplotlib inline\n", "# for figures in notebook\n", "\n", "# import & initialize epygram\n", "import epygram\n", "epygram.init_env()\n", "\n", "import os\n", "INPUTS_DIR = os.path.join('..', 'inputs')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:31:09.559440Z", "iopub.status.busy": "2025-01-13T11:31:09.559239Z", "iopub.status.idle": "2025-01-13T11:31:09.676897Z", "shell.execute_reply": "2025-01-13T11:31:09.676394Z" } }, "outputs": [], "source": [ "r = epygram.open(os.path.join(INPUTS_DIR, 'grid.arome-forecast.guyane0025+0024:00.grib'), 'r')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:31:09.678939Z", "iopub.status.busy": "2025-01-13T11:31:09.678778Z", "iopub.status.idle": "2025-01-13T11:31:09.883509Z", "shell.execute_reply": "2025-01-13T11:31:09.883015Z" } }, "outputs": [], "source": [ "f = r.readfield('parameterCategory:1,parameterNumber:19,typeOfStatisticalProcessing:0')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "execution": { "iopub.execute_input": "2025-01-13T11:31:09.885660Z", "iopub.status.busy": "2025-01-13T11:31:09.885452Z", "iopub.status.idle": "2025-01-13T11:31:10.628590Z", "shell.execute_reply": "2025-01-13T11:31:10.628185Z" } }, "outputs": [], "source": [ "fig, ax = f.cartoplot(colormap='ptype')" ] }, { "cell_type": "code", "execution_count": null, "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.10.12" } }, "nbformat": 4, "nbformat_minor": 2 }