if(__name__ == "__main__"): print 'It is a main programm module-file' else: print 'It is just a module' import math print 'PI number is %.10f' % math.pi # formatted output import math # without using short name print math.pi import math as m # using short name print m.pi import math # without using short name print math.pi from math import pi, cos # using from print pi print 'cos: %f' % cos(0.0) # formatted output from math import pi as pin # using from & as print pin from math import * print sin(1.0) print pi from scipy import stats def trend(x,y,out='spv'): ''' From given vectors 'x' and 'y' linear trend components are calculated \n **INPUT:** \n `x [np.ma.arr]` - numpy 1D array of values \n `y [np.ma.arr]` - numpy masked 1D array of values \n `char [str]` - defines the calculated parameter (sum, mean \ and so on)(default='mean') \n `anom [bool]` - switch array values into anomalies divided on std \ (default=False) \n **OUTPUT:** \n `slope [float]` - slope koef. \n `p_value [float]` - p_value \n `sig [float]` - shows alpha-level, where trend is \ statistically significant \n Author: Pavel Shabanov \n Email: meteomail@yandex.ru \n Blog: http://geofortran.blogspot.ru \n ''' slope, intercept, r_value, p_value, std_err = stats.mstats.linregress(x,y) ss = np.arange(1.0,0.00,-0.01) for i in ss: # print p_value, i if (p_value < i): sig = i if (out == 'all'): return slope, intercept, r_value, p_value, std_err elif (out == 'ab'): return slope, intercept elif (out == 'spv'): return slope, p_value elif (out == 'pv'): return p_value elif (out == 's'): return slope elif (out == 'spvr'): return slope, p_value, r_value**2 else: return slope, p_value, sig import scipy.stats.mstats.linregress as linetr import numpy as np import scimod as sm x1 = np.arange(10) y1 = np.random.random(10) print x1,y1 a,b = sm.trend(x1,y1,out='ab') print 'A: %f | B: %f' % (a,b) import matplotlib.pyplot as plt import numpy as np def graph2d(x, y, color='black',legend=False): ''' Это функция рисует двумерный график по двум входящим массивам. **INPUT:** `x [np.array] - argument, time` `y [np.array] - function` `color [str] - graph color (Default: 'black')` `legend [bool] - print or not graph legend (Default: False)` **OUTPUT:** `picture` - 2D graph ''' xy = plt.plot(x,y,color,label='Random') # xy2 = plt.plot(x,y-0.5,color) plt.grid(True) plt.ylabel('Y') plt.xlabel('Time') plt.xlim(x[0],x[-1]) if(legend): plt.legend(frameon=False, loc='best') plt.show() # ----- PROGRAM BODY ----- # Testing our module N = 10 x1 = np.arange(N) y1 = np.random.random(N) pic = graph2d(x1,y1, color='red',legend=True) print 'Описание функции graph2d:', graph2d.__doc__