{"id":27289258,"url":"https://github.com/mgduda/mpas-plotting","last_synced_at":"2025-10-08T15:29:45.738Z","repository":{"id":69539092,"uuid":"181039534","full_name":"mgduda/MPAS-Plotting","owner":"mgduda","description":"References and Examples for Plotting MPAS Output","archived":false,"fork":false,"pushed_at":"2019-04-19T20:37:40.000Z","size":10815,"stargazers_count":30,"open_issues_count":0,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-11T21:13:54.360Z","etag":null,"topics":["atmospheric-science","meterology","mpas","plotting","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mgduda.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-04-12T15:54:32.000Z","updated_at":"2025-01-28T18:06:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"94d10988-6bbf-4145-bc20-0e5be77d7ae9","html_url":"https://github.com/mgduda/MPAS-Plotting","commit_stats":{"total_commits":33,"total_committers":1,"mean_commits":33.0,"dds":0.0,"last_synced_commit":"1f8589b089e9cadfa316b532d0f15d3b92bd7f4d"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgduda%2FMPAS-Plotting","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgduda%2FMPAS-Plotting/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgduda%2FMPAS-Plotting/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mgduda%2FMPAS-Plotting/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mgduda","download_url":"https://codeload.github.com/mgduda/MPAS-Plotting/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248480427,"owners_count":21110937,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["atmospheric-science","meterology","mpas","plotting","python"],"created_at":"2025-04-11T21:13:58.598Z","updated_at":"2025-10-08T15:29:40.714Z","avatar_url":"https://github.com/mgduda.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"MPAS Plotting\n=============\nThis repository contains a number of examples related to plotting MPAS model\noutput with Python. It contains examples using MatPlotLib and will later\ncontain examples using NCAR's PyNGO as well as any other NCAR NCL Python\nmodules that appear.\n\nThe goal of this repository is to function as a set of examples and reference\nfor Python Modules that can be used to create model output plots.\n\nNote: Files that are named with 'clean' are the same as the files with\nthe same name, but have less documentation and code comments.\n\n**Tutorial Contents**\n* mpas_patches - Tutorial for plotting each indivual MPAS Grid Cell\n* ll-plotting - Tutorial for plotting a normal lat, lon grid (using convert_mpas).\n\n\n**Readme Contents**\n* [Introduction to Python Modules](#Introduction)\n    * [Numpy](#Numpy)\n    * [Python NetCDF Modules and other Met Datatypes](#NetCDF)\n    * [Cartopy and Basemap](#Basemap)\n    * [Python on Cheyenne and Casper](#venv)\n    * [Python 2 and Python 3](#version)\n* [Quick Introduction to MatPlotLib](#MPL-Intro)\n* [Helpful References and Guides](#Module-References)\n\u003c!-- [References and Credits](#Refs-and-Credits) --\u003e\n\n\n# Introduction to Python Modules\u003ca name=\"Introduction\"/\u003e\n\nPlotting Meteorological data in Python is a multi-module endeavour and is\nundoubtedly a bit overwhelming. Some modules even contain references to each\nother, which can be even more consufing. I hope to break this process down \ninto more manageable chunks, and also point you in the right direction to \nfind the information you need.\n\n\n**Numpy**\u003ca name=\"Numpy\"/\u003e\n\nOne feature that Fortran has over vanilla Python are its n-dimensional arrays and its\noperations around those arrays. Out of the box Python allows you to have\nmultidimensional 'lists', but these list of lists are large and\ninefficient for vector and scaler operations.\n\nThe Numpy module enables smaller, more efficient n-dimensional arrays in a very similar\napproach to Fortran n-d arrays. With useful intrinsics such as `shape`,\n`size`, `ndim` and others, which allow you to inspect data as you see fit.\n\nIt also enables a load of optimized mathematical functions that you can dream of: \n\u003chttps://docs.scipy.org/doc/numpy/reference/routines.math.html\u003e.\n\n**Python NetCDF Modules and other Met Datatypes**\u003ca name=\"NetCDF\"/\u003e\n\nThere are a few modules out there that can support reading, creating and\nmanipulating NetCDF datafiles. These include: Scipy NetCDF, NetCDF4 Dataset, xArray, as\nwell as NCAR's PyNIO (which is an NCL wrapper).\n\nThere are multitude of modules to choose from, but I recommend starting with\nScipy's NetCDF module to start. It contains the most examples and is the best\ndocumented; however, it cannot open NetCDF4, but you can use UNIDATA's NetCDF4\nDataset instead, its also easy to use, but its documentation could be better. The\nexamples in this tutorial use the UNIDATA's NetCDF4 module.\n\nIf you need to open other Datatypes such as Grib, HDF, etc. PyNIO is currently\nyour best choice: \u003chttps://www.pyngl.ucar.edu/Nio.shtml\u003e. However, with the\nshift to Python and PyNIO going into maintenance mode, it may be worth becoming\nfamiliar with Python alternatives. Here is a list of common met datatypes and\nmodules that can open them:\n\n* GRIB - [cfgrib](https://github.com/ecmwf/cfgrib)\n* HDFS - [PyTables](http://www.pytables.org/index.html)\n* HDF-EOS - [PyHDF](https://www.hdfeos.org/software/pyhdf.php)\n\n(Note: Besides Scipy's NetCDF and Unidata's NetCDF4 I don't know how many of \nthese are on cheyenne or capser)\n\n**MatPlotLib (MPL)**\u003ca name=\"MatPlotLib\"/\u003e\n\nThe free alternative to creating plots in MATLAB, MPL was created by\nneurobiologist to plot EEG of his patients, it has perhaps the largest \nopen source python modules out there.\n\nIt is flexible beyond belief to fit a variety of application and can be used to\ncreate publication-quality figures (though you may disagree coming from NCL) to\nreal time forecasting plots or overlays.\n\nIt has been extended to be used Geogrpahically/Meterographically with Basemap\nand Cartopy.\n\n\n**Basemap and Cartopy**\u003ca name=\"Basemap\"/\u003e\n\nThese two modules are built on top of MatPlotLib and allow the complicated \nhandling of projections and converting between projections.\n\nCartopy is a newer module, but is still in alpha and lacking in features and\ndocumentation which makes it difficult to use, but it appears to be developing\nrapidly.\n\nBasemap, the original of the two modules, is much better documented and contains\nmore features and more examples and is much easier to use at the current\nmoment. I recommend using Basemap while Cartopy gains documentation and\nfeatures.\n\nExamples within this tutorial use Basemap; however, once I see Cartopy\ngaining more traction and better documentation (and I get more familar with it)\nI will create examples using it.\n\n**Python on Cheyenne and Casper**\u003ca name=\"venv\"/\u003e\n\nTo use Python with the modules above on Cheyenne and Casper. We'll need to\ncreate a Python virtual environment that contains these modules. Thankfully,\nCISL has created a command that will do that for us: `ncar_pylib`. Once you\nhave loaded a Python (version \u003e=3.6.4) run `ncar_pylib` in your terminal window\nand you'll have access to all the above modules.\n\n**Python 2, Python 3**\u003ca name=\"version\"/\u003e\n\nPython 2 will soon not be maintained. All of these examples use Python 3. Use\nPython 3.\n\n# Quick Introduction to MatPlotLib\u003ca name=\"MPL-Intro\"/\u003e\n\nMatPlotLib can be a confusing module to use and understand at first, but with\npractice and understanding of how its mechanisms work, plotting becomes much\neasier.\n\n\u003ca href=\"./data/MatPlotLib-Anatomy1.png\"\u003e\u003cimg src=\"./data/MatPlotLib-Anatomy1.png\" alt=\"Anatomy1\" width=\"400\"/\u003e\u003c/a\u003e\n\u003ca href=\"./data/MatPlotLib-Anatomy2.png\"\u003e\u003cimg src=\"./data/MatPlotLib-Anatomy2.png\" alt=\"Anatomy2\" width=\"430\"/\u003e\u003c/a\u003e\n\nAbove, are two images that I wish I had when I started using MPL. They both\ngive an overview of the anatomy of a MPL Figure and its parts.\n\nYou'll see on the image on the left, those two main parts are the Figure, and\nthe Axes/Subplot. The Figure, is highest in the hierarchy of MPL, and it\ncontains 1 or more Axes/Subplots. An Axes/Subplot represent an individual plot\nor graphic.\n\nSo, for instance, the plots above contain a single Axes/Subplot, but are both,\nseparately, their own figure. Often times, it is needed to create multiple\nsubplots in a single figure, which MPL allows, such as: \u003ca href=\"./data/MPL-SubPLot.png\"\u003e\u003cimg src=\"./data/MPL-SubPlot.png\" alt=Subplots width=\"300\"/\u003e\u003c/a\u003e\n\nIf you are wanting to create a plot that is not within this tutorial. I\nrecommend taking a look at the [MPL Example Gallery][MPL Example Gallery] and\nthe [MPL Tutorial Page][MPL Tutorial Page] for a load of examples and tutorials\non everything MPL.\n\n# Module and other Helpful References\u003ca name=\"Module-References\"/\u003e\n\n* Plotting\n    * [MatPlotLib](https://matplotlib.org/)\n* Meteorological and Geographic Plotting\n    * [Basemap](https://matplotlib.org/basemap/)\n    * [Cartopy](https://scitools.org.uk/cartopy/docs/latest/)\n    * [Gold-Standard Basemap Tutorial](https://basemaptutorial.readthedocs.io/en/latest/)\n* Python NetCDF Tools\n    * [Scipy Netcdf](https://docs.scipy.org/doc/scipy-0.16.1/reference/generated/scipy.io.netcdf.netcdf_file.html)\n    * [Unidata's NetCDF4 Dataset](https://unidata.github.io/netcdf4-python/netCDF4/index.html)\n    * [xArray](http://xarray.pydata.org/en/stable/generated/xarray.Dataset.to_netcdf.html)\n* Numpy\n    * [Numpy Basics](https://docs.scipy.org/doc/numpy/user/index.html)\n    * [Numpy Reference](https://docs.scipy.org/doc/numpy/reference/)\n\nHelpful References and Guides\n* [Anatomy Of MatplotLib](https://github.com/matplotlib/AnatomyOfMatplotlib)\n* [MPL Tutorial Page][MPL Tutorial Page]\n* [MPL Example Gallery][MPL Example Gallery]\n* [MPL Color Maps Reference](https://matplotlib.org/users/colormaps.html)\n* [MPL Plot Style Reference](https://matplotlib.org/gallery/style_sheets/style_sheets_reference.html)\n* [Figure Documentation](https://matplotlib.org/api/_as_gen/matplotlib.figure.Figure.html)\n* [Axes Documentation](https://matplotlib.org/api/axes_api.html)\n\n\n# References \u0026 Credits\u003ca name=\"Refs-and-Credits\"/\u003e\n* [For examples and the Antomy of MatPlotLib Image used in and Introduction to MatPlotLib][1]\n* [For help creating mpas_patches][2]\n* [Anatomy of A Figure Image](https://matplotlib.org/gallery/showcase/anatomy.html)\n\n\n[1]: https://github.com/matplotlib/AnatomyOfMatplotlib\n[2]: https://github.com/lmadaus/mpas_python\n[MPL Example Gallery]: https://matplotlib.org/gallery/index.html\n[MPL Tutorial Page]: https://matplotlib.org/tutorials/index.html\n\n# Todo:\n1. Add more examples (espcially 2D examples)\n   * Histogram, Barplots, Scatter Plots etc.\n   * Add a Subplot example (possibly using grid spacing)\n   * Add an example longitude or latitude 'slize' of a variable or two.\n2. Clean up the helpful reference and guide list into one list and not two\n3. Add documentation to `mpas_patches.py`\n4. Find a way to apply patches to Cartopy\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmgduda%2Fmpas-plotting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmgduda%2Fmpas-plotting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmgduda%2Fmpas-plotting/lists"}