{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Example script for reading MAIA cloud product files.\n",
"\n",
"\n",
"Created with:\n",
"\n",
"Package | Version\n",
"--- | ---\n",
"SatPy | 0.9.0\n",
"PyResample | 1.10.1\n",
"Trollimage | 1.5.3\n",
"PyKdtree | 1.3.1\n",
"\n",
"\n",
"MAIA files can be created with AAPP with scripts MAIA4_RUN and MAIA4_RUN_AVHRR scripts\n",
"\n",
"for BOTH VIIRS an AVHRR imagers\n",
"\n",
"- Install satpy and pyresample\n",
"- pycoast can also be installed if you want to generate plots with coast lines\n",
"- Here is an example of a minimal script that reads MAIA files\n",
"\n",
"MAIA files are named with a specific syntax for example:\n",
"\n",
" - avhCT_M02_GL_20151012_S005503_E005802_DES_D_La-11_Lo0126_00000.h5\n",
" \n",
" - viiCT_npp_DB_20121010_S132824_E132947_ASC_D_La050_Lo-012_00001.h5\n",
" \n",
"References : \n",
"\n",
"https://nwpsaf.eu/site/software/aapp/\n",
"\n",
" [NWPSAF-MF-UD-003] DATA Formats\n",
" \n",
" [NWPSAF-MF-UD-009] MAIA version 4 Scientific User Manual\n",
" \n",
"This example uses the MAIA cloud product which can be found in the MAIA4_test.tgz tar test case file available with the AAPP software."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from satpy import Scene\n",
"from satpy.utils import debug_on\n",
"import numpy as np\n",
"from satpy.composites import PaletteCompositor\n",
"from satpy.writers import to_image"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# define palette (matplotlib style)\n",
"cpool = ['#4e7791', # not processed 0\n",
" '#008c30', # Cloud free land 1\n",
" '#000000', # Cloud free sea 2\n",
" '#ffbbff', # Snow over ice 3\n",
" '#dda0dd', # Sea ice 4\n",
" '#ffa500', # Very low cumuliforme 5 # non utilisé par maia\n",
" '#ff6600', # Very low no cumuliforme 6\n",
" '#ffd800', # Low cumuliforme 7 # non utilisé par maia\n",
" '#ffa500', # Low cumuliforme 8\n",
" '#ffff00', # Mid-level cumuliforme 9 # non utilisé par maia\n",
" '#d8ff00', # Mid-level no cumuliforme 10\n",
" '#cccc00', # High opaque cumuliforme 11 # on utilisé par maia\n",
" '#d8b575', # High opaque no cumuliforme 12\n",
" '#ffffff', # Very High opaque cumuliforme 13 # non utilisé par maia\n",
" '#ffe0aa', # Very High opaque no cumuliforme 14\n",
" '#0000ff', # Semi transp. thin 15\n",
" \"#00b2ff\", # Semi transp. meanly thick 16\n",
" '#00ffe5', # Semi transp. thick 17\n",
" '#00ffb2', # semi transp abobe others 18\n",
" '#d800ff', # fractionnal\n",
" '#660f00', # Not classified 20\n",
" ]\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# function to convert it in satpy style\n",
"def hex_to_rgb(value):\n",
" value = value.lstrip('#')\n",
" lv = len(value)\n",
" return [int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3)]\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"fnmaia = \"/home/a000680/data/maia/viiCT_npp_DB_20121010_S132824_E132947_ASC_D_La050_Lo-012_00001.h5\""
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/a000680/.local/lib/python2.7/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
" from ._conv import register_converters as _register_converters\n"
]
}
],
"source": [
"maia_scene = Scene(sensor='viirs', reader='maia', filenames=[fnmaia])"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['Alt_surface',\n",
" 'CM_qual',\n",
" 'CloudMask',\n",
" 'CloudTopPres',\n",
" 'CloudTopTemp',\n",
" 'CloudType',\n",
" 'Latitude',\n",
" 'Longitude',\n",
" 'Mask_in',\n",
" 'Mask_ind',\n",
" 'Sat_zenith',\n",
" 'Tsurf',\n",
" 'cma',\n",
" 'cma_conf',\n",
" 'ct',\n",
" 'fov_qual',\n",
" 'land_water_background',\n",
" 'opaq_cloud']"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"maia_scene.all_dataset_names()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"maia_scene.load([\"CloudType\", \"ct\", \"cma\", \"cma_conf\",\n",
" 'opaq_cloud', \"CloudTopPres\", \"CloudTopTemp\", \"Alt_surface\"])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
" The CloudType is a bit field containing the actual \"ct\" with values from 0 to 20\n",
" which can be interpreted according to the cpool colormap\n",
"\n",
" \"ct\" can be display in black and white:\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"maia_scene.show(\"ct\")\n",
"maia_scene.save_dataset(\"ct\", filename=\"ct_bw.png\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"but it is better to palettize the image:\n",
"\n",
"step 1: creation of the palette"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"mycolors = []\n",
"for i in range(21):\n",
" mycolors.append(hex_to_rgb(cpool[i]))\n",
"arr = np.array(mycolors)\n",
"np.save(\"/tmp/binary_maia_ct_colormap.npy\", arr)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"step2: creation of the composite"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"compositor = PaletteCompositor(\"test\", standard_name=\"maia_ct\")\n",
"composite = compositor((maia_scene[\"ct\"], arr))\n",
"img = to_image(composite)\n",
"img.show()\n",
"img.pil_save(\"ct.png\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}