{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "statewide-viking",
   "metadata": {},
   "source": [
    "# Magics 4.11.0 ( Released 03/03/2022)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "scenic-running",
   "metadata": {},
   "outputs": [],
   "source": [
    "from Magics import macro as magics"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "blessed-grade",
   "metadata": {},
   "source": [
    "## User defined coastlines\n",
    "\n",
    "In Magics there is a possibility for the user to use her own set of shapefiles as coastlines. \n",
    "In this version, we added a parameter **map_user_layer_land_colour**(*Default:NONE*). If given a colour , the user coastlines will be filled.  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "rough-polish",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 45516 characters]\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "map = magics.mmap(\n",
    "subpage_map_projection = 'cylindrical',\n",
    "subpage_lower_left_longitude = -61.4,\n",
    "subpage_lower_left_latitude = -63.25,\n",
    "subpage_upper_right_longitude = -59.6,\n",
    "subpage_upper_right_latitude = -62.0,\n",
    ")\n",
    "\n",
    "coast = magics.mcoast(\n",
    "map_coastline = \"off\",\n",
    "map_user_layer = 'on',\n",
    "map_user_layer_name = 'release-4.11.0/user-coastlines/GSHHS_f_L5',\n",
    "map_user_layer_land_colour = 'grey',\n",
    "map_user_layer_colour = 'charcoal',\n",
    "map_user_layer_thickness = 5\n",
    ")\n",
    "\n",
    "magics.plot(map,coast)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bizarre-stake",
   "metadata": {},
   "source": [
    "## Observations Templating \n",
    "\n",
    "Magics allows users to define a XML template to display observations-like information.\n",
    "The template describes how to position the information. \n",
    "Users is able to pass a json object as observation, and Magics will use the template to position the different items of the observation."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "heated-pressing",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<observations>\n",
      "\n",
      "\t<obs_template type='guan_plot' rows='3' columns='3'>\n",
      "\n",
      "     \t<obs_identification colour='navy' row='0' column='0'/>   \n",
      "\n",
      "     \t<obs_string format='${freq00}/${gross00}' colour='blue' row='1' column='-2'/>      \n",
      "\n",
      "     \t<obs_string format='${freq06}/${gross06}' colour='red' row='1' column='2'/>\n",
      "\n",
      "     \t<obs_string format='${freq12}/${gross12}' colour='purple' row='-1' column='-2'/>      \n",
      "\n",
      "     \t<obs_string format='${freq18}/${gross18}' colour='green' row='-1' column='2'/>            \n",
      "\n",
      " \t</obs_template>\n",
      "\n",
      "</observations>\n",
      "\n"
     ]
    }
   ],
   "source": [
    "with open(\"release-4.11.0/obs-template/obs.template\") as f:\n",
    "    template = f.readlines()\n",
    "for l in template:\n",
    "    print(l)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "secondary-portable",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 102216 characters]\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import json\n",
    "\n",
    "projection = magics.mmap(\n",
    "    subpage_x_length=24.0,\n",
    "    subpage_upper_right_longitude=50.00,\n",
    "    subpage_upper_right_latitude=65.00,\n",
    "    subpage_lower_left_latitude=25.00,\n",
    "    subpage_lower_left_longitude=-20.0,\n",
    "    subpage_map_projection=\"cylindrical\",\n",
    ")\n",
    "\n",
    "coastlines = magics.mcoast()\n",
    "\n",
    "observations = {\"type\": \"guan_plot\",\n",
    "        \"identifier\": \"station1\",\n",
    "        \"freq00\": 4.,\n",
    "        \"gross00\": 6.,\n",
    "        \"freq06\": 6.,\n",
    "        \"gross06\":0.,\n",
    "        \"freq12\": 12.,\n",
    "        \"gross12\": 12.,\n",
    "        \"freq18\": 18.,\n",
    "        \"gross18\": 18.,\n",
    "        \"longitude\": 20,\n",
    "        \"latitude\": 50}\n",
    "\n",
    "obs = magics.mobs(\n",
    "    obsjson_info_list=[\n",
    "       json.dumps(observations)\n",
    "    ],\n",
    "    obs_template_file_name=\"release-4.11.0/obs-template/obs.template\",\n",
    "    obs_size=0.6,\n",
    "    obs_ring_size=0.2,\n",
    "    obs_distance_apart=0.0,\n",
    ")\n",
    "title = magics.mtext(\n",
    "    text_lines=[\"Observation plotting using template ...\"],\n",
    "    text_justification=\"left\",\n",
    "    text_font_size=1.5,\n",
    "    text_colour=\"charcoal\",\n",
    ")\n",
    "\n",
    "magics.plot(projection, coastlines, obs, title)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "according-founder",
   "metadata": {},
   "source": [
    "## LineString in GeoJSon \n",
    "\n",
    "Magics is now supporting the feature **Linestring** from the [GeoJSON](https://geojson.org/) format. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "remarkable-painting",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 101224 characters]\n",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "background = magics.mcoast( map_coastline_sea_shade_colour= 'white',\n",
    "                     map_coastline_land_shade_colour= 'grey',\n",
    "                     map_grid= 'off',\n",
    "                     map_coastline_land_shade= 'on',\n",
    "                     map_coastline_sea_shade= 'on',\n",
    "                     map_label= 'off',\n",
    "                     map_coastline_colour= 'charcoal')\n",
    "\n",
    "fronts =  magics.mgeojson( geojson_input_filename = 'release-4.11.0/linestring.geojson',)\n",
    "red = magics.mline(polyline_line_colour = \"red\", polyline_line_thickness = 4)\n",
    "\n",
    "\n",
    "title = magics.mtext(text_lines = [\"<font size='1'>GeoJSon LineString</font>\",],\n",
    "\t      text_justification = 'left',\n",
    "\t      text_font_size = 0.8,\n",
    "\t      text_colour = 'charcoal')\n",
    "\n",
    "magics.plot(background, fronts, red, title)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "spectacular-russell",
   "metadata": {},
   "source": [
    "## Fortran interface \n",
    "A bug was fixed in the Fortran interface when popen/pclose were called in a loop.\n"
   ]
  }
 ],
 "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.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
