This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
other:python:jyp_steps [2021/07/21 15:18] jypeter [Extra numpy information] Reorganized some of the indexing section |
other:python:jyp_steps [2023/01/13 12:31] jypeter [NetCDF files: using cdms2, xarray and netCDF4] Added link to CliMAF and C-ESM-EP |
||
---|---|---|---|
Line 123: | Line 123: | ||
==== Extra numpy information ==== | ==== Extra numpy information ==== | ||
+ | |||
+ | <WRAP center round tip 60%> | ||
+ | You can also check the [[other:python:misc_by_jyp#numpy_related_stuff|numpy section]] of the //Useful python stuff// page | ||
+ | </WRAP> | ||
+ | |||
* More information about **array indexing**:\\ <wrap em>Always check what you are doing on a simple test case, when you use advanced/fancy indexing!</wrap> | * More information about **array indexing**:\\ <wrap em>Always check what you are doing on a simple test case, when you use advanced/fancy indexing!</wrap> | ||
Line 134: | Line 139: | ||
* [[https://numpy.org/doc/stable/reference/routines.array-creation.html|Array creation routines]] | * [[https://numpy.org/doc/stable/reference/routines.array-creation.html|Array creation routines]] | ||
* [[https://numpy.org/doc/stable/reference/routines.array-manipulation.html|Array manipulation routines]] | * [[https://numpy.org/doc/stable/reference/routines.array-manipulation.html|Array manipulation routines]] | ||
+ | * [[https://numpy.org/doc/stable/reference/routines.sort.html|Sorting, searching, and counting routines]] | ||
* [[https://numpy.org/doc/stable/reference/maskedarray.html|Masked arrays]] | * [[https://numpy.org/doc/stable/reference/maskedarray.html|Masked arrays]] | ||
* [[https://numpy.org/doc/stable/reference/routines.ma.html|Masked array operations]] | * [[https://numpy.org/doc/stable/reference/routines.ma.html|Masked array operations]] | ||
* [[https://numpy.org/doc/stable/user/misc.html#ieee-754-floating-point-special-values|Dealing with special numerical values]] (//Nan//, //inf//) | * [[https://numpy.org/doc/stable/user/misc.html#ieee-754-floating-point-special-values|Dealing with special numerical values]] (//Nan//, //inf//) | ||
* If you know that your data has missing values, it is cleaner and safer to handle them with [[https://numpy.org/doc/stable/reference/maskedarray.html|masked arrays]]! | * If you know that your data has missing values, it is cleaner and safer to handle them with [[https://numpy.org/doc/stable/reference/maskedarray.html|masked arrays]]! | ||
+ | * If you know that some of your data //may// have masked values, play safe by explicitly using ''np.ma.some_function()'' rather than just ''np.some_function()'' | ||
+ | * More details in the [[https://github.com/numpy/numpy/issues/18675|Why/when does np.something remove the mask of a np.ma array ?]] discussion | ||
* [[https://numpy.org/doc/stable/user/misc.html#how-numpy-handles-numerical-exceptions|Handling numerical exceptions]] | * [[https://numpy.org/doc/stable/user/misc.html#how-numpy-handles-numerical-exceptions|Handling numerical exceptions]] | ||
* [[https://numpy.org/doc/stable/reference/routines.err.html|Floating point error handling]] | * [[https://numpy.org/doc/stable/reference/routines.err.html|Floating point error handling]] | ||
- | ===== cdms2 and netCDF4 ===== | + | ===== Using NetCDF files with Python ===== |
+ | |||
+ | <note tip>People using CMIPn and model data on the IPSL servers can easily search and process NetCDF files using: | ||
+ | * the [[https://climaf.readthedocs.io/|Climate Model Assessment Framework (CliMAF)]] environment | ||
+ | * and the [[https://github.com/jservonnat/C-ESM-EP/wiki|CliMAF Earth System Evaluation Platform (C-ESM-EP)]] | ||
+ | </note> | ||
There is a good chance that your input array data will come from a file in the [[other:newppl:starting#netcdf_and_file_formats|NetCDF format]]. | There is a good chance that your input array data will come from a file in the [[other:newppl:starting#netcdf_and_file_formats|NetCDF format]]. | ||
- | Depending on which [[other:python:starting#some_python_distributions|python distribution]] you are using, you can use the //cdms2// or or //netCDF4// modules to read the data. | + | Depending on which [[other:python:starting#some_python_distributions|python distribution]] you are using, you can use the //cdms2//, //xarray// or //netCDF4// modules to read the data. |
==== cdms2 ==== | ==== cdms2 ==== | ||
- | Summary: cdms2 can read/write netCDF files (and read //grads// dat+ctl files) and provides a higher level interface than netCDF4. cdms2 is available in the [[other:python:starting#uv-cdat|UV-CDAT distribution]], and can theoretically be installed independently of UV-CDAT (e.g. it will be installed when you install [[https://cmor.llnl.gov/mydoc_cmor3_conda/|CMOR in conda)]]. When you can use cdms2, you also have access to //cdtime//, that is very useful for handling time axis data. | + | Summary: cdms2 can read/write netCDF files (and read //grads// dat+ctl files) and provides a higher level interface than netCDF4. cdms2 is available in the [[other:python:starting#cdat|CDAT distribution]], and can theoretically be installed independently of CDAT (e.g. it will be installed when you install [[https://cmor.llnl.gov/mydoc_cmor3_conda/|CMOR in conda)]]. When you can use cdms2, you also have access to //cdtime//, that is very useful for handling time axis data. |
How to get started: | How to get started: | ||
Line 156: | Line 169: | ||
- you have to replace //cdms// with **cdms2**, and //MV// with **MV2** (sooorry about that, the tutorial was written when CDAT was based on //Numeric// instead of //numpy// to handle array data) | - you have to replace //cdms// with **cdms2**, and //MV// with **MV2** (sooorry about that, the tutorial was written when CDAT was based on //Numeric// instead of //numpy// to handle array data) | ||
- read the [[http://cdms.readthedocs.io/en/docstanya/index.html|official cdms documentation]] (link may change) | - read the [[http://cdms.readthedocs.io/en/docstanya/index.html|official cdms documentation]] (link may change) | ||
+ | |||
+ | ==== xarray ==== | ||
+ | |||
+ | Summary: [[http://xarray.pydata.org/en/stable/|xarray]] is an open source project and Python package that makes working with labelled multi-dimensional arrays simple, efficient, and fun! [...] It is particularly tailored to working with netCDF files | ||
Line 166: | Line 183: | ||
===== CDAT-related resources ===== | ===== CDAT-related resources ===== | ||
- | Some links, in case they can't be found easily on the [[https://uv-cdat.llnl.gov|UV-CDAT]] web site... | + | Some links, in case they can't be found easily on the [[https://cdat.llnl.gov|CDAT]] web site... |
- | * [[https://uv-cdat.llnl.gov/tutorials.html|Tutorials in ipython notebooks]] | + | * [[https://cdat.llnl.gov/tutorials.html|Tutorials in ipython notebooks]] |
* [[http://cdat-vcs.readthedocs.io/en/latest/|VCS: Visualization Control System]] | * [[http://cdat-vcs.readthedocs.io/en/latest/|VCS: Visualization Control System]] | ||
* [[https://github.com/CDAT/vcs/issues/238|Colormaps in vcs examples]] | * [[https://github.com/CDAT/vcs/issues/238|Colormaps in vcs examples]] | ||
Line 296: | Line 313: | ||
//json// files look basically like a **list of (nested) python dictionaries** that would have been dumped to a text file | //json// files look basically like a **list of (nested) python dictionaries** that would have been dumped to a text file | ||
- | * [[https://docs.python.org/2/library/json.html|json module]] documentation | + | * [[https://docs.python.org/3/library/json.html|json module]] documentation |
* [[https://realpython.com/python-json/|Working With JSON Data in Python]] tutorial | * [[https://realpython.com/python-json/|Working With JSON Data in Python]] tutorial | ||
* example script: ''/home/users/jypeter/CDAT/Progs/Devel/beaugendre/nc2json.py'' | * example script: ''/home/users/jypeter/CDAT/Progs/Devel/beaugendre/nc2json.py'' | ||
Line 342: | Line 359: | ||
This document will teach you even more things about python, numpy and matplotlib, debugging and optimizing scripts, and about using python for statistics, image processing, machine learning, washing dishes (this is just to check if you have read this page), etc... | This document will teach you even more things about python, numpy and matplotlib, debugging and optimizing scripts, and about using python for statistics, image processing, machine learning, washing dishes (this is just to check if you have read this page), etc... | ||
* Example: the [[http://www.scipy-lectures.org/packages/statistics/index.html|Statistics in Python]] tutorial that combines [[other:python:jyp_steps#pandas|Pandas]], [[http://statsmodels.sourceforge.net/|Statsmodels]] and [[http://seaborn.pydata.org/|Seaborn]] | * Example: the [[http://www.scipy-lectures.org/packages/statistics/index.html|Statistics in Python]] tutorial that combines [[other:python:jyp_steps#pandas|Pandas]], [[http://statsmodels.sourceforge.net/|Statsmodels]] and [[http://seaborn.pydata.org/|Seaborn]] | ||
+ | |||
+ | ===== statsmodels ===== | ||
+ | |||
+ | [[https://www.statsmodels.org/|statsmodels ]] is a Python module that provides classes and functions for the estimation of many different statistical models, as well as for conducting statistical tests, and statistical data exploration. | ||
+ | |||
+ | ===== scikit-learn ===== | ||
+ | |||
+ | [[http://scikit-learn.org/|scikit-learn]] is an open source machine learning library that supports supervised and unsupervised learning. It also provides various tools for model fitting, data preprocessing, model selection and evaluation, and many other utilities. | ||
+ | |||
+ | ===== scikit-image ===== | ||
+ | |||
+ | [[https://scikit-image.org/|scikit-image]] is a collection of algorithms for image processing in Python | ||
===== Quick Reference and cheat sheets ===== | ===== Quick Reference and cheat sheets ===== |