Giter Site home page Giter Site logo

royalosyin / python-practical-application-on-climate-variability-studies Goto Github PK

View Code? Open in Web Editor NEW
216.0 216.0 122.0 13.96 MB

This tutorial is a companion volume of Matlab versionm but add more. Main objective is the transference of know-how in practical applications and management of statistical tools commonly used to explore meteorological time series, focusing on applications to study issues related with the climate variability and climate change. This tutorial starts with some basic statistic for time series analysis as estimation of means, anomalies, standard deviation, correlations, arriving the estimation of particular climate indexes (Niño 3), detrending single time series and decomposition of time series, filtering, interpolation of climate variables on regular or irregular grids, leading modes of climate variability (EOF or HHT), signal processing in the climate system (spectral and wavelet analysis). In addition, this tutorial also deals with different data formats such as CSV, NetCDF, Binary, and matlab'mat, etc. It is assumed that you have basic knowledge and understanding of statistics and Python.

License: MIT License

Jupyter Notebook 99.68% Python 0.32%

python-practical-application-on-climate-variability-studies's Introduction

Python & Practical Application on Climate Variability Studies

Main objective of this tutorial is the transference of know-how in practical applications and management of statistical tools commonly used to explore meteorological time series, focusing on applications to study issues related with the climate variability and climate change. This tutorial starts with some basic statistic for time series analysis as estimation of means, anomalies, standard deviation, correlations, arriving the estimation of particular climate indexes (Niño 3), detrending single time series and decomposition of time series, filtering, interpolation of climate variables on regular or irregular grids, leading modes of climate variability (EOF or HHT), signal processing in the climate system (spectral and wavelet analysis). In addition, this tutorial also deals with different data formats such as CSV, NetCDF, Binary, and matlab'mat, etc. It is assumed that you have basic knowledge and understanding of statistics and Python.

Generic libraries for scientific analysis

The default Python library for dealing with large arrays of numeric data (e.g. four dimensional latitude/longitude/altitude/time data arrays) is numpy, while the netCDF data format is commonly used in Atmospheric science and Oceanography as it is convinient to store various variables of many dimensions. The default for reading and writing netCDF files is netCDF4 (the capability to read and write text files, including .csv, is built into numpy).

What is NetCDF?

NetCDF is a set of software libraries and self-describing, machine-independent data formats that support the creation, access, and sharing of array-oriented scientific data. NetCDF was developed and is maintained at Unidata. Unidata provides data and software tools for use in geoscience education and research. The NetCDF homepage may be found at http://www.unidata.ucar.edu/software/netcdf/. The NetCDF source-code is hosted at GitHub, and may be found directly at http://github.com/Unidata/netcdf-c.

How to deal with NetCDF and other data with Python?

we mainly use netCDF4-python, NumPy and SciPy to process NetCDF and other data formats.

  • netCDF4-python

netcdf4-python is a Python interface to the netCDF C library. netCDF version 4 has many features not found in earlier versions of the library and is implemented on top of HDF5. This module can read and write files in both the new netCDF 4 and the old netCDF 3 format, and can create files that are readable by HDF5 clients. The API modelled after Scientific.IO.NetCDF, and should be familiar to users of that module (see more http://unidata.github.io/netcdf4-python/).

  • NumPy

NumPy is the fundamental package for scientific computing with Python (see more http://www.numpy.org/). It contains among other things: a powerful N-dimensional array object sophisticated (broadcasting) functions tools for integrating C/C++ and Fortran code useful linear algebra, Fourier transform, and random number capabilities Besides its obvious scientific uses, NumPy can also be used as an efficient multi-dimensional container of generic data. Arbitrary data-types can be defined. This allows NumPy to seamlessly and speedily integrate with a wide variety of databases.

  • SciPy

SciPy is a collection of mathematical algorithms and convenience functions built on the Numpy extension of Python (https://www.scipy.org/index.html). It adds significant power to the interactive Python session by providing the user with high-level commands and classes for manipulating and visualizing data. With SciPy an interactive Python session becomes a data-processing and system-prototyping environment rivaling systems such as MATLAB, IDL, Octave, R-Lab, and SciLab. The additional benefit of basing SciPy on Python is that this also makes a powerful programming language available for use in developing sophisticated programs and specialized applications. Scientific applications using SciPy benefit from the development of additional modules in numerous niches of the software landscape by developers across the world. Everything from parallel programming to web and data-base subroutines and classes have been made available to the Python programmer. All of this power is available in addition to the mathematical libraries in SciPy.

Data Sources

We will use the data publicly available as possible. The data are mainly downloaded from https://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanalysis.derived.surfaceflux.html

Visualization

Matplotlib

Matplotlib is a Python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. Matplotlib can be used in Python scripts, the Python and IPython shell, the jupyter notebook, web application servers, and four graphical user interface toolkits. Matplotlib tries to make easy things easy and hard things possible. You can generate plots, histograms, power spectra, bar charts, errorcharts, scatterplots, etc., with just a few lines of code. For a sampling, see the screenshots, thumbnail gallery, and examples directory For simple plotting the pyplot module provides a MATLAB-like interface, particularly when combined with IPython. For the power user, you have full control of line styles, font properties, axes properties, etc, via an object oriented interface or via a set of functions familiar to MATLAB users. See more from https://matplotlib.org/

Basemap

Basemap is a great tool for creating maps using python in a simple way. It’s a matplotlib extension, so it has got all its features to create data visualizations, and adds the geographical projections and some datasets to be able to plot coast lines, countries, and so on directly from the library. Basemap has got some documentation, but some things are a bit more difficult to find. I started this documentation to extend a little the original documentation and examples, but it grew a little, and now covers many of the basemap possibilities. See more from https://basemaptutorial.readthedocs.io/en/latest/

More

We will mainly apply these mostly generic libraries to carry out data analysis step by step. The procedures or steps are common to the atmospheric and ocean sciences. Although other advanced libraries will simpilfy the procedures, the underlying ideas should be the same in essense. We will also introduce more other libraries such as xarray and iris in the following parts.

python-practical-application-on-climate-variability-studies's People

Contributors

royalosyin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-practical-application-on-climate-variability-studies's Issues

Continuous Wavelet Spectrum - Example for NINO3 SST

In'Continuous Wavelet Spectrum - Example for NINO3 SST ',Here lag1 = 0.72,both α1 and α2 >0. TC98 says explicitly that "this red-noise was estimated from( α1+√α2) /2 where α1and α2 are the lag-1 and lag-2 autocorrelations of the Niño3 SST". So this is NOT a constant value, valid for each and every time series, but one which must be estimated.
when α1<0,especially α2<0,how to compute it? Look forward for your reply.

Trend and anomaly analysis question

Thank you for all of your contributions. Your notebooks were really helpful for climate analysis. I was not able to understand how you came up with reshaping dataset at "421". will it be possible for you to provide more context? Thank you

ncset= netcdf(r'data/sst.mnmean.nc')
lons = ncset['lon'][:]
lats = ncset['lat'][:]
sst = ncset['sst'][1:421,:,:] # 1982-2016 to make it divisible by 12
nctime = ncset['time'][1:421]
t_unit = ncset['time'].units

try :
t_cal =ncset['time'].calendar
except AttributeError : # Attribute doesn't exist
t_cal = u"gregorian" # or standard

nt, nlat, nlon = sst.shape
ngrd = nlon*nlat

something wrong about ex01-Read SST NetCDF data, subsample and save.ipynb

Hi,
I am a beginner in learning Python ,and there is something wrong when i testing ex01.
the error is taking place at "np.savez('skt.so.mon.mean.npz',skt_so=skt_so,lat_so=lat_so,lon_so=lon_so)",
the information about error :
Traceback (most recent call last):
File "./readNC.py", line 28, in
np.savez('skt.so.mon.mean.npz',skt_so=skt_so,lat_so=lat_so,lon_so=lon_so)
File "/software/anaconda3/lib/python3.6/site-packages/numpy/lib/npyio.py", line 593, in savez
_savez(file, args, kwds, False)
File "/software/anaconda3/lib/python3.6/site-packages/numpy/lib/npyio.py", line 703, in _savez
pickle_kwargs=pickle_kwargs)
File "/software/anaconda3/lib/python3.6/site-packages/numpy/lib/format.py", line 587, in write_array
array.tofile(fp)
File "/software/anaconda3/lib/python3.6/site-packages/numpy/ma/core.py", line 5934, in tofile
raise NotImplementedError("MaskedArray.tofile() not implemented yet.")
NotImplementedError: MaskedArray.tofile() not implemented yet.

Can you help me to solve this problem? Look forward for your reply.

Power Spectral Density

Hi, I am a beginner in learning Python. In 'Power Spectral Density’.In my opinion,for monthly data, the results are divided by 12 to calculate annual cycles like this 'plt.plot(1.0/f1[1:47]/12, pxx1[1:47], label='welch')',but for annual data,how to deal with it?I tried not to divide by 12,but
the maximum period of abscissa is 250 years,this may be something wrong .Could you help me to solve this problem? Look forward for your reply.

bivariate choropleth map Make

Hello, I'm a college student and saw your bivariate choropleth map,
Very cool chart, can you refer to the source code of the drawing? Because when I am drawing, involving numpy.nan values, the color of the plot is always handled poorly? Hope you can give some advice, thanks again

Uncertainty ex15-Trend and Anomaly Analyses

Hello,

I was checking your notebook (very good btw, thank you). And I was wondering how you would go about obtaining the trend uncertainty for global values.

Thank you,
Carolina

Error in lmoments.quanor

Hi, I am working with the SPI code. The code is running fine until it computes the dim_spi_n. I am getting the following error
lmoments quanor

When it read the probability values in lmoments.quannor and goes to the function quanor(F,para), here it is getting the F values which are not iterable. Any suggestions why is it happening. I am working with the sample netcdf file as used in your code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.