{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Generate a mosaic of the GOES-16 ABI channels with Satpy and ImageMagick" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This example shows the basic functionality of reading GOES-16 ABI data and creating a PNG grayscale image for each of the 16 channels. The `montage` command line utility from `ImageMagick` is then used to join the individual images in to one image. In this first cell we do all of this using data from Amazon Web Services (AWS) from the S3 bucket created by NOAA.\n", "\n", "We use the feature of the `fsspec` library called `simplecache` to store files locally. This makes sure that any repeated access to the same files will be fast and use the local cache. In the below code, accessing the remote data the first time and processing it with Satpy will take about 4 minutes depending on your network connection and your local system's resources. Running the same cell again will use the cache and take around 1 minute and 45 seconds." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "%%time\n", "\n", "import glob\n", "from satpy import Scene\n", "from satpy.readers import FSFile\n", "import fsspec\n", "\n", "# Access data from AWS S3 to be read by Satpy\n", "filename = 'noaa-goes16/ABI-L1b-RadF/2019/001/17/*_G16_s201900117003*'\n", "the_files = fsspec.open_files(\"simplecache::s3://\" + filename, s3={'anon': True})\n", "fs_files = [FSFile(open_file) for open_file in the_files]\n", "\n", "# Pass S3 file objects to Satpy and read them with the 'abi_l1b' reader\n", "scn = Scene(filenames=fs_files, reader='abi_l1b')\n", "\n", "# Load all 16 ABI channels\n", "scn.load(['C01', 'C02', 'C03', 'C04', 'C05', 'C06', 'C07', 'C08',\n", " 'C09', 'C10', 'C11', 'C12', 'C13', 'C14', 'C15', 'C16'])\n", "\n", "# Save each channel to a PNG image\n", "scn.save_datasets(filename='{name}.png')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Then we can use the ImageMagick command `montage` to join all the images together.\n", "\n", "Note: Some ImageMagick installations may be limited and unable to process every image in the montage." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!montage C??.png -tile 4x4 -geometry 128x128+4+4 -background black montage_abi.png" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from IPython.display import Image\n", "Image(filename='montage_abi.png') " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Local Files\n", "\n", "Alternatively, if you have ABI L1b files on your local machine already, you can point Satpy to those directly:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "import glob\n", "from satpy.scene import Scene\n", "\n", "# Access local ABI L1b NetCDF files\n", "scn = Scene(\n", " filenames=glob.glob(\"/path/to/the/GOES-16/data/*RadF*.nc\"),\n", " reader='abi_l1b'\n", ")\n", "\n", "# Load all 16 ABI channels\n", "scn.load(['C01', 'C02', 'C03', 'C04', 'C05', 'C06', 'C07', 'C08',\n", " 'C09', 'C10', 'C11', 'C12', 'C13', 'C14', 'C15', 'C16'])\n", "\n", "# Save each channel to a PNG image\n", "scn.save_datasets(filename='{name}.png')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Additional Information\n", "\n", "1. To avoid S3 files being cached on your local system, modify the `fsspec.open_files` line to say:\n", "\n", " ```\n", " the_files = fsspec.open_files(\"s3://\" + filename, anon=True)\n", " ```\n", " \n", " Note however that this means that any repeated access to file content will take longer and will increase the overall processing time.\n", " \n", "2. To save images in the GeoTIFF format, you can call `scn.save_datasets()` without any arguments as geotiffs are the default." ] } ], "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.7.8" } }, "nbformat": 4, "nbformat_minor": 4 }