├── gr.png ├── graphsfix ├── MeanAOD1-2km_Year.png ├── SlopeAOD1-2km_Year.png ├── MeanAOD1-2km_Autumn.png ├── MeanAOD1-2km_Spring.png ├── MeanAOD1-2km_Summer.png ├── MeanAOD1-2km_Winter.png ├── SlopeAOD1-2km_Autumn.png ├── SlopeAOD1-2km_Spring.png ├── SlopeAOD1-2km_Summer.png ├── SlopeAOD1-2km_Winter.png ├── reglineat_36.5_24.5_Year_1-2km.png ├── reglineat_36.5_24.5_Autumn_1-2km.png ├── reglineat_36.5_24.5_Spring_1-2km.png ├── reglineat_36.5_24.5_Summer_1-2km.png └── reglineat_36.5_24.5_Winter_1-2km.png ├── README.md ├── Aod.py ├── .gitignore ├── main.py ├── plots.py └── Utils.py /gr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomasalex/aerosol/HEAD/gr.png -------------------------------------------------------------------------------- /graphsfix/MeanAOD1-2km_Year.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomasalex/aerosol/HEAD/graphsfix/MeanAOD1-2km_Year.png -------------------------------------------------------------------------------- /graphsfix/SlopeAOD1-2km_Year.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomasalex/aerosol/HEAD/graphsfix/SlopeAOD1-2km_Year.png -------------------------------------------------------------------------------- /graphsfix/MeanAOD1-2km_Autumn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomasalex/aerosol/HEAD/graphsfix/MeanAOD1-2km_Autumn.png -------------------------------------------------------------------------------- /graphsfix/MeanAOD1-2km_Spring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomasalex/aerosol/HEAD/graphsfix/MeanAOD1-2km_Spring.png -------------------------------------------------------------------------------- /graphsfix/MeanAOD1-2km_Summer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomasalex/aerosol/HEAD/graphsfix/MeanAOD1-2km_Summer.png -------------------------------------------------------------------------------- /graphsfix/MeanAOD1-2km_Winter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomasalex/aerosol/HEAD/graphsfix/MeanAOD1-2km_Winter.png -------------------------------------------------------------------------------- /graphsfix/SlopeAOD1-2km_Autumn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomasalex/aerosol/HEAD/graphsfix/SlopeAOD1-2km_Autumn.png -------------------------------------------------------------------------------- /graphsfix/SlopeAOD1-2km_Spring.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomasalex/aerosol/HEAD/graphsfix/SlopeAOD1-2km_Spring.png -------------------------------------------------------------------------------- /graphsfix/SlopeAOD1-2km_Summer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomasalex/aerosol/HEAD/graphsfix/SlopeAOD1-2km_Summer.png -------------------------------------------------------------------------------- /graphsfix/SlopeAOD1-2km_Winter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomasalex/aerosol/HEAD/graphsfix/SlopeAOD1-2km_Winter.png -------------------------------------------------------------------------------- /graphsfix/reglineat_36.5_24.5_Year_1-2km.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomasalex/aerosol/HEAD/graphsfix/reglineat_36.5_24.5_Year_1-2km.png -------------------------------------------------------------------------------- /graphsfix/reglineat_36.5_24.5_Autumn_1-2km.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomasalex/aerosol/HEAD/graphsfix/reglineat_36.5_24.5_Autumn_1-2km.png -------------------------------------------------------------------------------- /graphsfix/reglineat_36.5_24.5_Spring_1-2km.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomasalex/aerosol/HEAD/graphsfix/reglineat_36.5_24.5_Spring_1-2km.png -------------------------------------------------------------------------------- /graphsfix/reglineat_36.5_24.5_Summer_1-2km.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomasalex/aerosol/HEAD/graphsfix/reglineat_36.5_24.5_Summer_1-2km.png -------------------------------------------------------------------------------- /graphsfix/reglineat_36.5_24.5_Winter_1-2km.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomasalex/aerosol/HEAD/graphsfix/reglineat_36.5_24.5_Winter_1-2km.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # aerosol 2 | Aerosol Optical Depth Statistical Analysis 3 | 4 | The purpose of this project is to observe the temporal and spatial variability of the aerosols over the southern Balkan Peninsula. 5 | The region of interest is confined between 19o and 29o E and between 34o and 42o N (fig. 1) and for the years 2007-2014. 6 | The aim will be to utilize the Moderate Resolution Imaging Spectroradiometer (MODIS) instrumentation on board Aqua, and CALIOP on board CALIPSO 7 | satellite in order to investigate the variation of Atmospheric Optical Depth (AOD). 8 | 9 |

Implementation

10 | 11 | Development of a python code in order to perform the data reading, the calculation of means, deseasonalization and the plot. 12 | 13 | 14 | ![Autumn](https://github.com/tomchavakis/aerosol/blob/master/graphsfix/MeanAOD1-2km_Autumn.png) 15 | 16 | 17 | ![Year](https://github.com/tomasalex/aerosol/blob/master/graphsfix/SlopeAOD1-2km_Year.png) -------------------------------------------------------------------------------- /Aod.py: -------------------------------------------------------------------------------- 1 | class AOD: 2 | AODCount = 0 3 | 4 | def __init__(self, latitude, longitude, aod_12, aod_030, nprofiles, uprofiles, month, year): 5 | self.latitude = latitude 6 | self.longitude = longitude 7 | self.aod_12 = aod_12 8 | self.aod_030 = aod_030 9 | self.nprofiles = nprofiles 10 | self.uprofiles = uprofiles 11 | self.month = month 12 | self.year = year 13 | AOD.AODCount += 1 14 | 15 | def displayCount(self): 16 | print "Total AOD %d" % AOD.AODCount 17 | 18 | def displayAOD(self): 19 | print "month :", self.month, "year :", self.year, "Latitude : ", self.latitude, ", Longitude: ", self.longitude, ", aod12 ", self.aod_12, ", nprofiles ", self.nprofiles, ", uprofiles ", self.uprofiles 20 | 21 | def getLat(self): 22 | print self.latitude 23 | 24 | def getYear(self): 25 | print self.year 26 | 27 | def getMonth(self): 28 | print self.month 29 | 30 | def getAod(self): 31 | return self.aod_12 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | 55 | # Sphinx documentation 56 | docs/_build/ 57 | 58 | # PyBuilder 59 | target/ 60 | 61 | #Ipython Notebook 62 | .ipynb_checkpoints 63 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import os 2 | import Aod 3 | import Utils 4 | import plots 5 | import numpy as np 6 | import matplotlib.pyplot as plt 7 | import matplotlib.mlab as mlab 8 | import matplotlib.cbook as cbook 9 | import datetime 10 | 11 | print('Hello :)') 12 | print(os.path.dirname(os.path.abspath(__file__))) 13 | 14 | plt.close('all') 15 | 16 | 17 | AOD12=4 18 | AOD01=3 19 | AOD030=2 20 | AODranges=[AOD030,AOD01,AOD12] 21 | #AODranges=[AOD12] 22 | 23 | for AODcol in AODranges: 24 | AODrange_labels=['0-30km','0-1km','1-2km'] 25 | AODcat=AODranges.index(AODcol) 26 | 27 | aodvalues, monthYears = Utils.load_data(AODranges[AODcat]) 28 | 29 | mn,stdv, mpn, stdvp,nan,zerovals =Utils.getStat(aodvalues) 30 | 31 | print('Sample mean:', mn,'Sample std dev:', stdv) 32 | print('Sample mean of AOD percentage of AOD 0-30:', mpn,'Sample std dev of AOD percentage of AOD 0-30:', stdvp) 33 | print('Number of NaN values:', nan,'Number of zero values:', zerovals) 34 | 35 | #exit() 36 | 37 | allLats, allLongs = Utils.getLats(aodvalues) 38 | allLats_s=allLats[:] 39 | allLats.sort(reverse=True) 40 | winter = [12, 1, 2] 41 | spring = [3, 4, 5] 42 | summer = [6, 7, 8] 43 | autumn = [9, 10, 11] 44 | year = list(range(1, 13)) 45 | 46 | #periods=[winter, spring, summer, autumn, year ] 47 | periods=[winter, spring, summer, autumn, year] 48 | #periods=[winter] 49 | #periods=[year] 50 | 51 | period_names=['Winter', 'Spring', 'Summer', 'Autumn', 'Year' ] 52 | #period_names=['Year' ] 53 | 54 | 55 | for period in periods: 56 | pnum=periods.index(period) 57 | meanAODperDegree = Utils.GetPeriodData_v2(period, aodvalues, allLats, allLongs,False,uprof=15) 58 | slopeAODperDegree, intercAODdegree, alldeseasondata=Utils.GetDeseasonalizedData(period, aodvalues, allLats, allLongs, monthYears, 59 | meanAODperDegree, False, uprof=15) 60 | 61 | # plots.plot_regline(alldeseasondata[5][5], allLats[5], allLongs[5], slopeAODperDegree[5][5], intercAODdegree[5][5], 62 | # monthYears, period,period_names[pnum],AODrange_labels[AODcat],True, aodvalues) 63 | 64 | # plots.plot_data(np.flipud(meanAODperDegree), np.asarray(map(float,allLongs)),np.asarray(map(float, allLats_s)), 65 | # period_names[pnum],AODrange_labels[AODcat],"Mean",'jet',minv=0,maxv=0.10,folder="./graphsfix/") 66 | 67 | # plots.plot_data(np.flipud(slopeAODperDegree), np.asarray(map(float,allLongs)),np.asarray(map(float, allLats_s)), 68 | # period_names[pnum],AODrange_labels[AODcat],"Slope",'gnuplot',minv=-7,maxv=7,folder="./graphsfix/") 69 | 70 | plots.plot_regline(alldeseasondata[5][5], allLats[5], allLongs[5], slopeAODperDegree[5][5], intercAODdegree[5][5], 71 | monthYears, period,period_names[pnum],AODrange_labels[AODcat],True, aodvalues,folder="./graphsprof15/") 72 | 73 | plots.plot_data(np.flipud(meanAODperDegree), np.asarray(map(float,allLongs)),np.asarray(map(float, allLats_s)), 74 | period_names[pnum],AODrange_labels[AODcat],"Mean",'jet',folder="./graphsprof15/") 75 | plots.plot_data(np.flipud(slopeAODperDegree), np.asarray(map(float,allLongs)),np.asarray(map(float, allLats_s)), 76 | period_names[pnum],AODrange_labels[AODcat],"Slope",'gnuplot',folder="./graphsprof15/") 77 | 78 | 79 | 80 | plt.show() 81 | 82 | # plt.figure(2) 83 | # x, y, AodToDouble = Utils.aodPerMonthGraph(aodvalues) 84 | # plots.perMonth(x, y) 85 | # 86 | # plt.figure(3) 87 | # x, y = Utils.aodDeseasonalisation(aodvalues, AodToDouble) 88 | # plots.perMonth(x, y) 89 | # plt.show() 90 | -------------------------------------------------------------------------------- /plots.py: -------------------------------------------------------------------------------- 1 | from mpl_toolkits.basemap import Basemap#, cm 2 | import numpy as np 3 | from matplotlib import cm 4 | import matplotlib.pyplot as plt 5 | import matplotlib.mlab as mlab 6 | import matplotlib.cbook as cbook 7 | # import scipy as sp 8 | from scipy.misc import imread 9 | import pylab 10 | 11 | 12 | def perMonth(a, b): 13 | plt.plot(b, a) 14 | plt.grid() 15 | 16 | 17 | def mapPerPeriod(aodperDegree, lats, longs, title, savefile, cmapname,minv=0,maxv=0): 18 | # Make plot with vertical (default) colorbar 19 | 20 | fig, ax = plt.subplots() 21 | 22 | data = aodperDegree 23 | datafile = cbook.get_sample_data('C:/Users/alex/marspython/aerosol/gr.png') 24 | img = imread(datafile) 25 | 26 | ax.imshow(img, zorder=1, alpha=0.3, 27 | extent=[float(min(longs))-0.5, float(max(longs))+0.5, float(min(lats)) - 0.5, float(max(lats))+0.5]) 28 | 29 | if minv<>0 or maxv<>0 : 30 | cax = ax.imshow(data, zorder=0, interpolation='spline16', cmap=cm.get_cmap(cmapname), 31 | extent=[float(min(longs)), float(max(longs)), float(min(lats)), float(max(lats))], 32 | vmin=minv,vmax=maxv) 33 | else: 34 | cax = ax.imshow(data, zorder=0, interpolation='spline16', cmap=cm.get_cmap(cmapname), 35 | extent=[float(min(longs)), float(max(longs)), float(min(lats)), float(max(lats))]) 36 | ax.set_title(title) 37 | 38 | # Add colorbar, make sure to specify tick locations to match desired ticklabels 39 | #cbar = fig.colorbar(cax, ticks=[-1, 0, 1]) 40 | cbar = fig.colorbar(cax) 41 | #cbar.ax.set_yticklabels(['< -1', '0', '> 1']) # vertically oriented colorbar 42 | pylab.savefig(savefile + ".png") 43 | 44 | 45 | #plt.show() 46 | 47 | def plot_data(data,lon_data, lat_data, periodname, AODcatname,maptype,cmapname,minv=0,maxv=0,folder=""): 48 | fig = plt.figure() 49 | #ax = fig.add_axes([0.1,0.1,0.8,0.8]) 50 | 51 | m = Basemap(llcrnrlon=19,llcrnrlat=34,urcrnrlon=29,urcrnrlat=42, 52 | resolution='h',projection='cass',lon_0=24,lat_0=38) 53 | 54 | nx = int((m.xmax-m.xmin)/1000.)+1 55 | ny = int((m.ymax-m.ymin)/1000.)+1 56 | topodat = m.transform_scalar(data,lon_data,lat_data,nx,ny) 57 | 58 | if minv<>0 or maxv<>0 : 59 | im = m.imshow(topodat,cmap=plt.get_cmap(cmapname),vmin=minv,vmax=maxv) 60 | else: 61 | im = m.imshow(topodat,cmap=plt.get_cmap(cmapname)) 62 | 63 | 64 | m.drawcoastlines() 65 | m.drawmapboundary() 66 | m.drawcountries() 67 | m.drawparallels(np.arange(35,42.,1.), labels=[1,0,0,1]) 68 | m.drawmeridians(np.arange(-20.,29.,1.), labels=[1,0,0,1]) 69 | cb = m.colorbar(im,"right", size="5%", pad='2%') 70 | title=maptype+" AOD "+AODcatname+" "+periodname+" 2007-2014" 71 | plt.title(title) 72 | pylab.savefig(folder+maptype+"AOD"+AODcatname+"_"+periodname + ".png") 73 | #plt.show() 74 | 75 | def plot_regline(data, lat, lon, slope, intercept,months, period, periodlabel, AODrange, plotAOD=False, aodvalues=[],folder=""): 76 | fig = plt.figure(figsize=(8,7)) 77 | 78 | ax1=fig.add_subplot(111) 79 | 80 | mlist=[] 81 | for m in months: 82 | if int(m.split('-')[0]) in period: 83 | mlist.append(m.split('-')[1]+m.split('-')[0]) 84 | mlist.sort() 85 | axlabels=mlist[:] 86 | for ms in axlabels: 87 | i=axlabels.index(ms) 88 | if i%3==0 or len(axlabels)<30: 89 | axlabels[i]=ms[4:]+'-'+ms[:4] 90 | else: 91 | axlabels[i]='' 92 | 93 | x = np.arange(0,len(data)) 94 | 95 | ax1.scatter(x, data[x],color='blue', label='AOD deseasonalized') 96 | plt.xticks(x, axlabels, rotation=45) 97 | 98 | x_plot = np.linspace(0,len(data),100*len(data)) 99 | ax1.plot(x_plot, x_plot*slope + intercept, label='Regression Line') 100 | 101 | if plotAOD: 102 | aodvals=np.zeros(len(mlist)) 103 | for e in aodvalues: 104 | if e.month in period and lat==e.latitude and lon==e.longitude: 105 | k=mlist.index(str(e.year)+str(e.month).zfill(2)) 106 | aodvals[k]=float(e.aod_12) 107 | 108 | ax2 = fig.add_subplot(111, sharex=ax1, frameon=False) 109 | ax2.scatter(x, aodvals[x],color='green',label='AOD values') 110 | #ax2.scatter(x, data[x]/100.0,color='red') 111 | 112 | ax2.yaxis.tick_right() 113 | for t in ax2.get_xticklabels(): 114 | t.set_visible(False) 115 | #ax2.yaxis.set_label_position("right") 116 | #ylabel("Right Y-Axis Data") 117 | 118 | ax1.legend(loc='upper left') 119 | ax2.legend() 120 | plt.title('Regression line at '+lat+' '+lon+'. Slope : '+"{0:.2f}".format(slope)+" "+periodlabel+" "+AODrange) 121 | pylab.savefig(folder+"reglineat_"+lat+"_"+lon+"_"+periodlabel+"_"+AODrange+".png") 122 | 123 | -------------------------------------------------------------------------------- /Utils.py: -------------------------------------------------------------------------------- 1 | import os 2 | import Aod 3 | import datetime 4 | import numpy as np 5 | import math 6 | from statistics import mean,stdev 7 | from scipy.stats import linregress 8 | # from main import aodvalues, monthYears 9 | #from scipy.ndimage.measurements import variance 10 | 11 | def load_data(aodcol): 12 | dir = "./CALIPSO_data/Total_AOD/" 13 | 14 | files = os.listdir(dir) 15 | files.sort() 16 | monthYears = [] 17 | aodvalues = [] 18 | AodToDouble = [] 19 | for file in files: 20 | if file.endswith(".txt"): 21 | with open(dir + file) as f: 22 | data = f.read() 23 | # parse filename and take month and year 24 | p = file.split('-') 25 | monthYears.append(p[0].split('_')[3] + '-' + p[1].split('.')[0]) 26 | data = data.split('\n') 27 | for i in range(1, len(data) - 1): 28 | linesplit = data[i].split('\t') 29 | 30 | rows = linesplit[0] 31 | cols = rows.split(' ') 32 | Latitude = cols[0] 33 | Longitude = cols[1] 34 | AOD_12 = cols[aodcol] 35 | AOD_030 = cols[2] 36 | Number_of_profiles = cols[6] 37 | Utilized_profiles = cols[7] 38 | month = int(p[0].split('_')[3]) 39 | year = int(p[1].split('.')[0]) 40 | aod_element = Aod.AOD(Latitude, Longitude, AOD_12, AOD_030, Number_of_profiles, Utilized_profiles, month, year) 41 | # aod_element.displayAOD() 42 | aodvalues.append(aod_element) 43 | # tom_index = next(index for (index, d) in enumerate(aodvalues) if d["name"] == "Tom") 44 | return aodvalues, monthYears 45 | 46 | def aodPerMonthGraph(aodvalues): 47 | AodToDouble = [] 48 | plotVal = [] 49 | xdates = [] 50 | for j in range(2007, 2014): 51 | k = 0 52 | n = 0 53 | for i in range(1, 12): 54 | for element in aodvalues: 55 | if element.getYear() == j and element.getMonth() == i and float(element.getAod()) >= 0: 56 | k += float(element.getAod()) 57 | n += 1 58 | # print element.displayAOD() 59 | AodToDouble.append(str(i) + "_" + str(j) + "_" + str(float(k / n))) 60 | plotVal.append(float(k / n)) 61 | xdates.append(datetime.datetime(j, i, 5)) 62 | return plotVal, xdates, AodToDouble 63 | 64 | 65 | def aodDeseasonalisation(aodvalues, AodToDouble): 66 | plotVal = [] 67 | xdates = [] 68 | 69 | for j in range(2007, 2014): 70 | k = 0 71 | n = 0 72 | for i in range(1, 12): 73 | content = [x for x in AodToDouble if x.startswith(str(i) + '_' + str(j))] 74 | for element in aodvalues: 75 | if element.getYear() == j and element.getMonth() == i and float(element.getAod()) >= 0: 76 | k += float(element.getAod()) 77 | n += 1 78 | # print element.displayAOD() 79 | monthMean = content[0].split('_')[2] 80 | plotVal.append(float(k / n) - float(monthMean)) 81 | xdates.append(datetime.datetime(j, i, 5)) 82 | return plotVal, xdates 83 | 84 | 85 | # l = filter(lambda x: str(i) + '_' + str(j) in x, AodToDouble) 86 | # ll = [s for s in AodToDouble if str(i) + '_' + str(j) in s] 87 | # lll = any(item.startswith(str(i) + '_' + str(j)) for item in AodToDouble) 88 | # [s for s in AodToDouble if str(i) + '_' + str(j) in s] 89 | 90 | def getStat(aodvalues): 91 | aods=[] 92 | aodpercent=[] 93 | nan=0 94 | zerovals=0 95 | for e in aodvalues: 96 | if isfloat(e.aod_12): 97 | aods.append(float(e.aod_12)) 98 | if float(e.aod_12)==0: 99 | zerovals+=1 100 | if float(e.aod_030)>0 : 101 | aodpercent.append(float(e.aod_12)/float(e.aod_030)) 102 | if e.aod_12=='NaN': 103 | nan+=1 104 | m=mean(aods) 105 | s=stdev(aods) 106 | mp=mean(aodpercent) 107 | sp=stdev(aodpercent) 108 | 109 | return m,s,mp,sp,nan,zerovals 110 | 111 | 112 | 113 | def getLats(aodvalues): 114 | allLats = [] 115 | for el in aodvalues: 116 | if el.latitude not in allLats: 117 | allLats.append(el.latitude) 118 | 119 | allLongs = [] 120 | for el in aodvalues: 121 | if el.longitude not in allLongs: 122 | allLongs.append(el.longitude) 123 | 124 | return allLats, allLongs 125 | 126 | 127 | def GetPeriodData(period, aodvalues, allLats, allLongs): 128 | data = np.ndarray((len(allLats), len(allLongs))) 129 | i = -1 130 | for lati in allLats: 131 | i += 1 132 | j = -1 133 | for longi in allLongs: 134 | j += 1 135 | AODSum = 0 136 | aodcounter = 0 137 | for e in aodvalues: 138 | if e.latitude == lati and e.longitude == longi and e.month in period and float(e.aod_12) > 0: 139 | aodcounter += 1 140 | AODSum += float(e.aod_12) 141 | if aodcounter > 0: 142 | data[i][j] = AODSum / aodcounter 143 | return data 144 | 145 | def isfloat(value): 146 | try: 147 | float(value) 148 | if not math.isnan(float(value)): 149 | return True 150 | except ValueError: 151 | return False 152 | 153 | def GetPeriodData_v2(period, aodvalues, allLats, allLongs, rejectzeros=True, uprof=0): 154 | data = np.zeros((len(allLats), len(allLongs))) 155 | counters = np.zeros((len(allLats), len(allLongs))) 156 | countzeros = np.zeros((len(allLats), len(allLongs))) 157 | 158 | 159 | for e in aodvalues: 160 | i=allLats.index(e.latitude) 161 | j=allLongs.index(e.longitude) 162 | if not rejectzeros : 163 | numcheck=isfloat(e.aod_12) 164 | if float(e.aod_12)<0.000000000000000001 : 165 | countzeros[i][j]+=1 166 | else : 167 | numcheck=False 168 | if isfloat(e.aod_12): 169 | if float(e.aod_12)>0.0 : 170 | numcheck=True 171 | 172 | if e.uprofiles.isdigit(): 173 | uprofcheck=(int(e.uprofiles)>=uprof) 174 | else : 175 | uprofcheck=False 176 | 177 | if e.month in period and numcheck and uprofcheck : 178 | data[i][j]+=float(e.aod_12) 179 | counters[i][j] += 1 180 | 181 | #elif not isfloat(e.aod_12): 182 | # print 'NAN value ',e.aod_12,' for ', e.month,' ',e.year, ' at ', allLats[i], allLongs[j] 183 | 184 | #if float(e.aod_12)>0.1: 185 | # print 'Big value ',e.aod_12,' for ', e.month,' ',e.year, ' at ', allLats[i], allLongs[j] 186 | 187 | for ind, x in np.ndenumerate(data) : 188 | if data[ind[0]][ind[1]]<0.00000000000000001 : 189 | print 'zero aod for period ', period, ' at ', allLats[ind[0]], allLongs[ind[1]] 190 | 191 | 192 | if counters[ind[0]][ind[1]]>0 : 193 | data[ind[0]][ind[1]] /= counters[ind[0]][ind[1]] 194 | else : 195 | print 'Only NAN values for period ', period, ' at ', allLats[ind[0]], allLongs[ind[1]] 196 | 197 | #if countzeros[ind[0]][ind[1]]>0 : 198 | # print 'num of zero values for period ', period, ' at ', allLats[ind[0]], allLongs[ind[1]], ' : ', countzeros[ind[0]][ind[1]] 199 | 200 | return data 201 | 202 | 203 | 204 | def GetDeseasonalizedData(period, aodvalues, allLats, allLongs, months, meanAOD, rejectzeros=True, uprof=0): 205 | 206 | mlist=[] 207 | for m in months: 208 | if int(m.split('-')[0]) in period: 209 | mlist.append(m.split('-')[1]+m.split('-')[0]) 210 | mlist.sort() 211 | 212 | data = np.zeros((len(allLats), len(allLongs), len(mlist))) 213 | 214 | slopedata = np.zeros((len(allLats), len(allLongs))) 215 | interceptdata = np.zeros((len(allLats), len(allLongs))) 216 | 217 | for e in aodvalues: 218 | i=allLats.index(e.latitude) 219 | j=allLongs.index(e.longitude) 220 | if not rejectzeros : 221 | numcheck=isfloat(e.aod_12) 222 | else : 223 | numcheck=False 224 | if isfloat(e.aod_12): 225 | if float(e.aod_12)>0.0 : 226 | numcheck=True 227 | 228 | if e.month in period and numcheck and int(e.uprofiles)>=uprof: 229 | k=mlist.index(str(e.year)+str(e.month).zfill(2)) 230 | if meanAOD[i][j]>0 : 231 | data[i][j][k]=(float(e.aod_12)-meanAOD[i][j])/meanAOD[i][j]*100 232 | 233 | x = np.arange(0,len(mlist)) 234 | for ind, e in np.ndenumerate(data[:,:,-1]) : 235 | slope, intercept, r_value, p_value, std_err = linregress(x,data[ind[0]][ind[1]]) 236 | slopedata[ind[0]][ind[1]]=slope 237 | interceptdata[ind[0]][ind[1]]=intercept 238 | 239 | return slopedata, interceptdata, data 240 | 241 | 242 | --------------------------------------------------------------------------------