import matplotlib.pylab as plt import numpy as np %matplotlib inline from IPython.display import Image print('I love Python 2000!') x = [1,2,3,4,5,6,7] plt.plot(x) from IPython.html.widgets import * x=np.linspace(0,1,100) def pltsin(f, a): plt.plot(x,a*np.sin(2*np.pi*x*f)) plt.ylim(-10,10) interact(pltsin, f=(1,10,0.1), a=(1,10,1)); !pwd #download some data !wget ftp://ftp.cdc.noaa.gov/Datasets/ncep.reanalysis.dailyavgs/surface/air.sig995.1981.nc !ncdump -h air.sig995.1981.nc !cdo nyear air.sig995.1981.nc !cdo monmean air.sig995.1981.nc air.sig995.1981_mm.nc %%writefile sc.gs 'sdfopen air.sig995.1981_mm.nc' 'd air' 'printim out.png' * 'printim out.png white x400 y300' !grads -blxc "run sc.gs" > log Image('out.png') %%writefile nc2.ncl load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" begin a = addfile("air.sig995.1981_mm.nc","r") air = a->air(1,:,:) ; read July zonal winds wks_type = "png" wks_type@wkWidth = 800 wks_type@wkHeight = 600 wks = gsn_open_wks(wks_type,"ce") ; open a ps file gsn_define_colormap(wks,"BlAqGrYeOrRe") ; choose colormap res = True ; plot mods desired res@cnFillOn = True ; turn on color fill res@cnLevelSpacingF = 5 ; contour spacing res@gsnMaximize = True plot = gsn_csm_contour_map_ce(wks,air,res) ; create a default plot end !ncl nc2.ncl > log !convert -trim +repage ce.png ce1.png Image('ce1.png') from netCDF4 import Dataset, num2date f = Dataset('air.sig995.1981.nc') air = f.variables['air'][:]-273.15 air_point = air[:,30,30] air_point2 = air[:,50,50] x = range(air_point.shape[0]) plt.plot(x, air_point, x, air_point2); %load_ext rpy2.ipython %%R -i air_point,air_point2,x y1 <- air_point y2 <- air_point2 plot(x,y1,type="l",bty="L",xlab="days",ylab="temperature", ylim=c(5, 35)) points(x,y2,type="l",col="red") polygon(c(x,rev(x)),c(y2,rev(y1)),col="skyblue") air.shape def asum(air): z = 0 for j in range(air.shape[0]): for k in range(air.shape[1]): for l in range(air.shape[2]): z = z+air[j,k,l] return z %time asum(air) #%install_ext https://raw.github.com/mgaitan/fortran_magic/master/fortranmagic.py %load_ext fortranmagic %%fortran subroutine sum_fort(a,i,m,n,z) integer :: j,k,l integer :: i, m, n real*8 :: a(i,m,n) real*8, intent(out) :: z z=0 do j = 1,i do k = 1,m do l= 1,n z=z+a(j,k,l) end do end do end do end subroutine sum_fort %time sum_fort(air) print sum_fort.__doc__ %%bash echo "My shell is:" $SHELL echo "My memory status is:" free %%perl $variable = 1; print "The variable has the value of $variable\n";