source: trunk/src/scripts_Laura/ARCTIC/Travail_CEN/ice_class_delimit_AMSU_data.py @ 46

Last change on this file since 46 was 46, checked in by lahlod, 10 years ago

new scripts

File size: 8.2 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3import string
4import numpy as np
5import matplotlib.pyplot as plt
6from pylab import *
7from mpl_toolkits.basemap import Basemap
8from mpl_toolkits.basemap import shiftgrid, cm
9from netCDF4 import Dataset
10import arctic_map # function to regrid coast limits
11import cartesian_grid_test # function to convert grid from polar to cartesian
12import scipy.special
13import ffgrid2
14import map_ffgrid
15from matplotlib.font_manager import FontProperties
16import map_cartesian_grid
17
18
19
20
21
22
23def filtering(frequ):
24
25
26
27    MONTH = np.array(['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'])
28    month = np.array(['JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE', 'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER'])
29    month_day = np.array([31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31])
30    M = len(month)
31
32
33    ########################
34    # grid characteristics #
35    ########################
36    x0 = -3000. # min limit of grid
37    x1 = 2500. # max limit of grid
38    dx = 40.
39    xvec = np.arange(x0, x1+dx, dx)
40    nx = len(xvec) 
41    y0 = -3000. # min limit of grid
42    y1 = 3000. # max limit of grid
43    dy = 40.
44    yvec = np.arange(y0, y1+dy, dy)
45    ny = len(yvec)
46
47
48    #########################
49    # emissivity thresholds #
50    #########################
51    fichier = open('/net/argos/data/parvati/lahlod/ARCTIC/AMSUA_ice_class/AMSUA'+ str(frequ) + '_data_classification_parameters_ice_no-ice_2009.dat', 'r')
52    numlines = 0
53    for line in fichier: numlines += 1
54
55    fichier.close()
56
57    fichier=open('/net/argos/data/parvati/lahlod/ARCTIC/AMSUA_ice_class/AMSUA' + str(frequ) + '_data_classification_parameters_ice_no-ice_2009.dat','r')
58    nbtotal = numlines-1
59    iligne = 0
60    mois = np.zeros([nbtotal],object)
61    emis_lim_spec = np.zeros([nbtotal],float)
62    emis_lim_lamb = np.zeros([nbtotal],float) 
63    while (iligne < nbtotal) :
64         line=fichier.readline()
65         liste = line.split()
66         mois[iligne] = str(liste[0])
67         emis_lim_spec[iligne] = float(liste[7])
68         emis_lim_lamb[iligne] = float(liste[8])
69         iligne=iligne+1
70
71    fichier.close()
72    vec = np.arange(0, nbtotal + 1, 50)
73    lim_spec = np.zeros([M], float)
74    lim_lamb = np.zeros([M], float)
75    for imo in range (0, M):
76        lim_spec[imo] = emis_lim_spec[vec[imo]]
77        lim_lamb[imo] = emis_lim_lamb[vec[imo]]
78
79
80
81
82    emis_spec_moy = np.zeros([ny, nx, M], float)
83    emis_lamb_moy = np.zeros([ny, nx, M], float)
84    emis_diff = np.zeros([ny, nx, M], float)
85    emis_ratio = np.zeros([ny, nx, M], float)
86    for imo in range (0, M):
87        #print 'month ' + month[imo]
88        ##############
89        # emissivity #
90        ##############
91        #print 'read file for emiss'
92        fichier_emis = Dataset('/net/argos/data/parvati/lahlod/ARCTIC/monthly_GLACE/gridded_data/cartesian_grid/res_40/cartesian_grid_monthly_data_lamb_spec_near_nadir_AMSUA' + str(frequ) + '_' + month[imo] + '2009.nc', 'r', format='NETCDF3_CLASSIC')
93        xdist = fichier_emis.variables['longitude'][:]
94        ydist = fichier_emis.variables['latitude'][:]
95        day = fichier_emis.variables['days'][:]
96        emis_spec = fichier_emis.variables['e_spec'][:]
97        emis_lamb = fichier_emis.variables['e_lamb'][:]
98        fichier_emis.close()
99        #print 'calculation of monthly mean'
100        for ilon in range (0, nx):
101            for ilat in range (0, ny):
102                emis_spec_moy[ilat, ilon, imo] = mean(emis_spec[ilat, ilon, :][nonzero(isnan(emis_spec[ilat, ilon, :]) == False)])
103                emis_lamb_moy[ilat, ilon, imo] = mean(emis_lamb[ilat, ilon, :][nonzero(isnan(emis_lamb[ilat, ilon, :]) == False)])
104        #print 'calculation of monthly mean difference lamb-spec'
105        emis_diff[:, :, imo] = emis_lamb_moy[:, :, imo] - emis_spec_moy[:, :, imo]
106        #########
107        # ratio #
108        #########
109        #print 'read file for ratio'
110        fichier_ratio = Dataset('/net/argos/data/parvati/lahlod/ARCTIC/monthly_GLACE/gridded_data/cartesian_grid/res_40/cartesian_grid_monthly_lamb-spec_ratio_near_nadir_AMSUA' + str(frequ) + '_' + month[imo] + '2009.nc', 'r', format='NETCDF3_CLASSIC')
111        xdist = fichier_ratio.variables['longitude'][:]
112        ydist = fichier_ratio.variables['latitude'][:]
113        emis_ratio[:, :, imo] = fichier_ratio.variables['emis_ratio'][:]
114        fichier_ratio.close()
115
116
117
118    ###########################################
119    # emissivity distribution after filtering #
120    ###########################################
121    '''
122    hist_val_spec = np.zeros([50, M], float)
123    hist_val_lamb = np.zeros([50, M], float)
124    hist_val_ratio = np.zeros([50, M], float)
125    hist_val_diff = np.zeros([50, M], float)
126    corresp_val_spec = np.zeros([50, M], float)
127    corresp_val_lamb = np.zeros([50, M], float)
128    corresp_val_ratio = np.zeros([50, M], float)
129    corresp_val_diff = np.zeros([50, M], float)
130    '''
131    emis_spec_f = np.zeros([7000, M], float)
132    emis_lamb_f = np.zeros([7000, M], float)
133    emis_ratio_f = np.zeros([7000, M], float)
134    emis_diff_f = np.zeros([7000, M], float)
135    L_spec = np.zeros([M], int)
136    for imo in range (0, M):
137        #print 'month ' + month[imo]
138        # choice of spec emissivity as the threshold for the study // definition of x and y index corresponding to the points which emissivity value is over threshold
139        y_index_spec = np.where(emis_spec_moy[:, :, imo] >= lim_spec[imo])[0] 
140        x_index_spec = np.where(emis_spec_moy[:, :, imo] >= lim_spec[imo])[1]
141        L_spec[imo] = len(x_index_spec) # = len(y_index)
142        #print 'length of x and y index ', L_spec[imo]
143        # definition of filtered values (vectors) with the previous threshold // values of filtered emissivity SPEC, LAMB, rate and difference LAMB-SPEC
144        for ii in range (0, L_spec[imo]):
145            emis_spec_f[ii, imo] = emis_spec_moy[y_index_spec[ii], x_index_spec[ii], imo]
146            emis_lamb_f[ii, imo] = emis_lamb_moy[y_index_spec[ii], x_index_spec[ii], imo]
147            emis_ratio_f[ii, imo] = emis_ratio[y_index_spec[ii], x_index_spec[ii], imo]
148            emis_diff_f[ii, imo] = emis_diff[y_index_spec[ii], x_index_spec[ii], imo]
149        '''
150        # definition of their distribution within the new filtered values
151        hist_val_spec[:, imo] = hist(emis_spec_f, bins = 50, normed = True, histtype='step')[0]
152        hist_val_lamb[:, imo] = hist(emis_lamb_f, bins = 50, normed = True, histtype='step')[0]
153        hist_val_ratio[:, imo] = hist(emis_ratio_f, bins = 50, normed = True, histtype='step')[0]
154        hist_val_diff[:, imo] = hist(emis_diff_f, bins = 50, normed = True, histtype='step')[0]
155        for ibin in range (0, 50):
156            corresp_val_spec[ibin, imo] = mean(hist(emis_spec_f, bins = 50, normed = True, histtype='step')[1][ibin : ibin + 2])
157            corresp_val_lamb[ibin, imo] = mean(hist(emis_lamb_f, bins = 50, normed = True, histtype='step')[1][ibin : ibin + 2])
158            corresp_val_ratio[ibin, imo] = mean(hist(emis_ratio_f, bins = 50, normed = True, histtype='step')[1][ibin : ibin + 2])
159            corresp_val_diff[ibin, imo] = mean(hist(emis_diff_f, bins = 50, normed = True, histtype='step')[1][ibin : ibin + 2])
160        '''
161
162    return(emis_spec_f, emis_lamb_f, emis_ratio_f, emis_diff_f, L_spec)     
163
164
165
166'''
167########
168# plot #
169########
170c = np.array(['r', 'b', 'c', 'm', 'y', 'g'])
171figure()
172for imo in range (0, 6):
173    plot(corresp_val[:, imo], hist_val[:, imo], c = str(c[imo]), label = str(month[imo]))
174
175grid()
176xlim(corresp_val.min() - 0.02, corresp_val.max() + 0.02)
177xlabel('emissivity parameter')
178ylabel('frequency of occurence')
179fontP = FontProperties()
180fontP.set_size('small')
181legend(prop = fontP)
182#plt.savefig('/usr/home/lahlod/twice_d/fig_output_ARCTIC/fig_output_sea_ice_study/ice_class_AMSUA/emiss_rate_AMSUA30_JANUARY-JUNE_2009.png')
183## plot six following months of spec emissivity histograms ##
184figure()
185for imo in range (6, M):
186    plot(corresp_val[:, imo], hist_val[:, imo], c = str(c[imo - 6]), label = str(month[imo]))
187
188grid()
189xlim(corresp_val.min() - 0.02, corresp_val.max() + 0.02)
190xlabel('emissivity parameter')
191ylabel('frequency of occurence')
192legend(loc = 1, prop = fontP)
193#plt.savefig('/usr/home/lahlod/twice_d/fig_output_ARCTIC/fig_output_sea_ice_study/ice_class_AMSUA/emiss_rate_AMSUA30_JULY-DECEMBER_2009.png')
194'''
Note: See TracBrowser for help on using the repository browser.