1 | #!/usr/bin/env python |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | import string |
---|
4 | import numpy as np |
---|
5 | import matplotlib.pyplot as plt |
---|
6 | from pylab import * |
---|
7 | from mpl_toolkits.basemap import Basemap |
---|
8 | from mpl_toolkits.basemap import shiftgrid, cm |
---|
9 | from netCDF4 import Dataset |
---|
10 | import arctic_map # function to regrid coast limits |
---|
11 | import cartesian_grid_test # function to convert grid from polar to cartesian |
---|
12 | import scipy.special |
---|
13 | import ffgrid2 |
---|
14 | import map_ffgrid |
---|
15 | from matplotlib import colors |
---|
16 | from matplotlib.font_manager import FontProperties |
---|
17 | import map_cartesian_grid |
---|
18 | |
---|
19 | |
---|
20 | ############################### |
---|
21 | # time period characteristics # |
---|
22 | ############################### |
---|
23 | MONTH = np.array(['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']) |
---|
24 | month = np.array(['JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE', 'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER']) |
---|
25 | month_day = np.array([31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]) |
---|
26 | M = len(month) |
---|
27 | |
---|
28 | |
---|
29 | ######################## |
---|
30 | # grid characteristics # |
---|
31 | ######################## |
---|
32 | x0 = -3000. # min limit of grid |
---|
33 | x1 = 2500. # max limit of grid |
---|
34 | dx = 40. |
---|
35 | xvec = np.arange(x0, x1+dx, dx) |
---|
36 | nx = len(xvec) |
---|
37 | y0 = -3000. # min limit of grid |
---|
38 | y1 = 3000. # max limit of grid |
---|
39 | dy = 40. |
---|
40 | yvec = np.arange(y0, y1+dy, dy) |
---|
41 | ny = len(yvec) |
---|
42 | |
---|
43 | |
---|
44 | ################################################################################################################## |
---|
45 | # We devide the loop in two steps : |
---|
46 | # - first loop concerns JANUARY, FEBRUARY, MARCH, APRIL, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER - use of AMSUA23GHz SPEC emissivity to seperate ice from no-ice zones |
---|
47 | # - second loop concerns MAY, JUNE, JULY, AUGUST - use of AMSUA89GHz SPEC emissivity to seperate ice from no_ice zones |
---|
48 | ################################################################################################################## |
---|
49 | |
---|
50 | |
---|
51 | frequ = 89 # apply threshold on this frequency |
---|
52 | |
---|
53 | |
---|
54 | # daily parameter (2D-array) on ARCTIC area |
---|
55 | emis_spec = np.zeros([M, ny, nx, 31], float) |
---|
56 | emis_lamb = np.zeros([M, ny, nx, 31], float) |
---|
57 | emis_diff = np.zeros([M, ny, nx, 31], float) |
---|
58 | emis_ratio = np.zeros([M, ny, nx, 31], float) |
---|
59 | |
---|
60 | # daily parameter (2D-array) on ARCTIC SEA ICE area |
---|
61 | daily_spec_ice = np.zeros([M, ny, nx, 31], float) |
---|
62 | daily_lamb_ice = np.zeros([M, ny, nx, 31], float) |
---|
63 | daily_diff_ice = np.zeros([M, ny, nx, 31], float) |
---|
64 | daily_ratio_ice = np.zeros([M, ny, nx, 31], float) |
---|
65 | |
---|
66 | |
---|
67 | months1 = np.array([0, 1, 2, 3, 8, 9, 10, 11]) # use AMSUA 23GHz to delimit ice/no_ice for JANUARY, FEBRUARY, MARCH, APRIL, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER |
---|
68 | for imo in months1: |
---|
69 | print 'month ' + month[imo] |
---|
70 | ################################################################################## |
---|
71 | # choice of AMSUA 23GHz delimitation ice/no_ice for the sub_classification study # |
---|
72 | ################################################################################## |
---|
73 | print 'open threshold file' |
---|
74 | fichier_emis = Dataset('/net/argos/data/parvati/lahlod/ARCTIC/AMSUA_ice_class/cartesian_grid_map_ice_no-ice_' + str(month[imo]) + '2009_AMSUA23_spec_lamb_thresholds.nc', 'r', format='NETCDF3_CLASSIC') |
---|
75 | spec_lim = fichier_emis.variables['spec_ice_area'][:] # sea ice pixels defined with spec emis at 23GHz |
---|
76 | #lamb_lim = fichier_emis.variables['lamb_ice_area'][:] |
---|
77 | fichier_emis.close() |
---|
78 | ######################################################### |
---|
79 | # application of AMSUA 23GHz delimitation to other data # |
---|
80 | ######################################################### |
---|
81 | print 'open emissivity to sub_classify file' |
---|
82 | ## data of emis SPEC, LAMB, DIFF(SPEC-LAMB) |
---|
83 | fichier_e = Dataset('/net/argos/data/parvati/lahlod/ARCTIC/monthly_GLACE/gridded_data/cartesian_grid/res_40/cartesian_grid_monthly_data_lamb_spec_near_nadir_AMSUB' + str(frequ) + '_' + str(month[imo]) + '2009.nc', 'r', format='NETCDF3_CLASSIC') |
---|
84 | day = fichier_e.variables['days'][:] |
---|
85 | emis_spec[imo, :, :, 0 : month_day[imo]] = fichier_e.variables['e_spec'][:] |
---|
86 | emis_lamb[imo, :, :, 0 : month_day[imo]] = fichier_e.variables['e_lamb'][:] |
---|
87 | emis_diff[imo, :, :, 0 : month_day[imo]] = fichier_e.variables['e_spec_lamb'][:] |
---|
88 | fichier_e.close() |
---|
89 | # calculate emis ratio daily |
---|
90 | for ijr in range (0, month_day[imo]): |
---|
91 | for ilon in range (0, nx): |
---|
92 | for ilat in range (0, ny): |
---|
93 | emis_ratio[imo, ilat, ilon, ijr] = ((emis_lamb[imo, ilat, ilon, ijr] - emis_spec[imo, ilat, ilon, ijr]) / emis_spec[imo, ilat, ilon, ijr]) * 100. |
---|
94 | # create 2D-array of emissivity spec, lamb, diff and ratio on sea ice extent only, defined by AMSUA 23GHz spec emiss threshold |
---|
95 | if (isnan(spec_lim[ilat, ilon]) == True): # if pixel of sea ice extent defined with spec_emiss_23_threshold corresponds to 'no_ice', then compute NaN in pixel |
---|
96 | daily_spec_ice[imo, ilat, ilon, ijr] = NaN |
---|
97 | daily_lamb_ice[imo, ilat, ilon, ijr] = NaN |
---|
98 | daily_diff_ice[imo, ilat, ilon, ijr] = NaN |
---|
99 | daily_ratio_ice[imo, ilat, ilon, ijr] = NaN |
---|
100 | else: # if pixel of sea ice extent defined with spec_emiss_23_threshold corresponds to 'ice', then compute value of emis spec, emis lamb or emis diff in pixel |
---|
101 | daily_spec_ice[imo, ilat, ilon, ijr] = emis_spec[imo, ilat, ilon, ijr] |
---|
102 | daily_lamb_ice[imo, ilat, ilon, ijr] = emis_lamb[imo, ilat, ilon, ijr] |
---|
103 | daily_diff_ice[imo, ilat, ilon, ijr] = emis_diff[imo, ilat, ilon, ijr] |
---|
104 | daily_ratio_ice[imo, ilat, ilon, ijr] = emis_ratio[imo, ilat, ilon, ijr] |
---|
105 | ######################## |
---|
106 | # stack in netcdf file # |
---|
107 | ######################## |
---|
108 | print 'stack in file month ' + str(month[imo]) |
---|
109 | rootgrp = Dataset('/net/argos/data/parvati/lahlod/ARCTIC/AMSUB_ice_class/sub_classification/cartesian_grid_map_sea_ice_extent_with-AMSUA23-and-89_' + month[imo] + '2009_AMSUB' + str(frequ) + '_spec_thresholds.nc', 'w', format='NETCDF3_CLASSIC') |
---|
110 | rootgrp.createDimension('longitude', nx) |
---|
111 | rootgrp.createDimension('latitude', ny) |
---|
112 | rootgrp.createDimension('days', month_day[imo]) |
---|
113 | nc_lon = rootgrp.createVariable('longitude', 'f', ('longitude',)) |
---|
114 | nc_lat = rootgrp.createVariable('latitude', 'f', ('latitude',)) |
---|
115 | nc_days = rootgrp.createVariable('days', 'f', ('days',)) |
---|
116 | nc_ice_spec = rootgrp.createVariable('spec_ice_area', 'f', ('latitude', 'longitude', 'days')) |
---|
117 | nc_ice_lamb = rootgrp.createVariable('lamb_ice_area', 'f', ('latitude', 'longitude', 'days')) |
---|
118 | nc_ice_diff = rootgrp.createVariable('diff_ice_area', 'f', ('latitude', 'longitude', 'days')) |
---|
119 | nc_ice_ratio = rootgrp.createVariable('ratio_ice_area', 'f', ('latitude', 'longitude', 'days')) |
---|
120 | nc_lon[:] = xvec |
---|
121 | nc_lat[:] = yvec |
---|
122 | nc_days[:] = np.arange(0, month_day[imo]) |
---|
123 | nc_ice_spec[:] = daily_spec_ice[imo, :, :, 0 : month_day[imo]] |
---|
124 | nc_ice_lamb[:] = daily_lamb_ice[imo, :, :, 0 : month_day[imo]] |
---|
125 | nc_ice_diff[:] = daily_diff_ice[imo, :, :, 0 : month_day[imo]] |
---|
126 | nc_ice_ratio[:] = daily_ratio_ice[imo, :, :, 0 : month_day[imo]] |
---|
127 | rootgrp.close() |
---|
128 | |
---|
129 | |
---|
130 | |
---|
131 | |
---|
132 | months2 = np.array([4, 5, 6, 7])# use AMSUA 89GHz to delimit ice/no_ice for MAY, JUNE, JULY, AUGUST |
---|
133 | for imo in months2: |
---|
134 | print 'month ' + month[imo] |
---|
135 | ################################################################################## |
---|
136 | # choice of AMSUA 23GHz delimitation ice/no_ice for the sub_classification study # |
---|
137 | ################################################################################## |
---|
138 | print 'open threshold file' |
---|
139 | fichier_emis = Dataset('/net/argos/data/parvati/lahlod/ARCTIC/AMSUA_ice_class/cartesian_grid_map_ice_no-ice_' + str(month[imo]) + '2009_AMSUA89_spec_lamb_thresholds.nc', 'r', format='NETCDF3_CLASSIC') |
---|
140 | spec_lim = fichier_emis.variables['spec_ice_area'][:] |
---|
141 | #lamb_lim = fichier_emis.variables['lamb_ice_area'][:] |
---|
142 | fichier_emis.close() |
---|
143 | ######################################################### |
---|
144 | # application of AMSUA 23GHz delimitation to other data # |
---|
145 | ######################################################### |
---|
146 | print 'open emissivity to sub_classify file' |
---|
147 | ## data of emis SPEC, LAMB, DIFF(SPEC-LAMB) |
---|
148 | fichier_e = Dataset('/net/argos/data/parvati/lahlod/ARCTIC/monthly_GLACE/gridded_data/cartesian_grid/res_40/cartesian_grid_monthly_data_lamb_spec_near_nadir_AMSUB' + str(frequ) + '_' + str(month[imo]) + '2009.nc', 'r', format='NETCDF3_CLASSIC') |
---|
149 | day = fichier_e.variables['days'][:] |
---|
150 | emis_spec[imo, :, :, 0 : month_day[imo]] = fichier_e.variables['e_spec'][:] |
---|
151 | emis_lamb[imo, :, :, 0 : month_day[imo]] = fichier_e.variables['e_lamb'][:] |
---|
152 | emis_diff[imo, :, :, 0 : month_day[imo]] = fichier_e.variables['e_spec_lamb'][:] |
---|
153 | fichier_e.close() |
---|
154 | # calculate emis ratio daily |
---|
155 | for ijr in range (0, month_day[imo]): |
---|
156 | for ilon in range (0, nx): |
---|
157 | for ilat in range (0, ny): |
---|
158 | emis_ratio[imo, ilat, ilon, ijr] = ((emis_lamb[imo, ilat, ilon, ijr] - emis_spec[imo, ilat, ilon, ijr]) / emis_spec[imo, ilat, ilon, ijr]) * 100. |
---|
159 | if (isnan(spec_lim[ilat, ilon]) == True): |
---|
160 | daily_spec_ice[imo, ilat, ilon, ijr] = NaN |
---|
161 | daily_lamb_ice[imo, ilat, ilon, ijr] = NaN |
---|
162 | daily_diff_ice[imo, ilat, ilon, ijr] = NaN |
---|
163 | daily_ratio_ice[imo, ilat, ilon, ijr] = NaN |
---|
164 | else: |
---|
165 | daily_spec_ice[imo, ilat, ilon, ijr] = emis_spec[imo, ilat, ilon, ijr] |
---|
166 | daily_lamb_ice[imo, ilat, ilon, ijr] = emis_lamb[imo, ilat, ilon, ijr] |
---|
167 | daily_diff_ice[imo, ilat, ilon, ijr] = emis_diff[imo, ilat, ilon, ijr] |
---|
168 | daily_ratio_ice[imo, ilat, ilon, ijr] = emis_ratio[imo, ilat, ilon, ijr] |
---|
169 | ######################## |
---|
170 | # stack in netcdf file # |
---|
171 | ######################## |
---|
172 | print 'stack in file month ' + str(month[imo]) |
---|
173 | rootgrp = Dataset('/net/argos/data/parvati/lahlod/ARCTIC/AMSUB_ice_class/sub_classification/cartesian_grid_map_sea_ice_extent_with-AMSUA23-and-89_' + month[imo] + '2009_AMSUB' + str(frequ) + '_spec_thresholds.nc', 'w', format='NETCDF3_CLASSIC') |
---|
174 | rootgrp.createDimension('longitude', nx) |
---|
175 | rootgrp.createDimension('latitude', ny) |
---|
176 | rootgrp.createDimension('days', month_day[imo]) |
---|
177 | nc_lon = rootgrp.createVariable('longitude', 'f', ('longitude',)) |
---|
178 | nc_lat = rootgrp.createVariable('latitude', 'f', ('latitude',)) |
---|
179 | nc_days = rootgrp.createVariable('days', 'f', ('days',)) |
---|
180 | nc_ice_spec = rootgrp.createVariable('spec_ice_area', 'f', ('latitude', 'longitude', 'days')) |
---|
181 | nc_ice_lamb = rootgrp.createVariable('lamb_ice_area', 'f', ('latitude', 'longitude', 'days')) |
---|
182 | nc_ice_diff = rootgrp.createVariable('diff_ice_area', 'f', ('latitude', 'longitude', 'days')) |
---|
183 | nc_ice_ratio = rootgrp.createVariable('ratio_ice_area', 'f', ('latitude', 'longitude', 'days')) |
---|
184 | nc_lon[:] = xvec |
---|
185 | nc_lat[:] = yvec |
---|
186 | nc_days[:] = np.arange(0, month_day[imo]) |
---|
187 | nc_ice_spec[:] = daily_spec_ice[imo, :, :, 0 : month_day[imo]] |
---|
188 | nc_ice_lamb[:] = daily_lamb_ice[imo, :, :, 0 : month_day[imo]] |
---|
189 | nc_ice_diff[:] = daily_diff_ice[imo, :, :, 0 : month_day[imo]] |
---|
190 | nc_ice_ratio[:] = daily_ratio_ice[imo, :, :, 0 : month_day[imo]] |
---|
191 | rootgrp.close() |
---|
192 | |
---|
193 | |
---|
194 | |
---|
195 | |
---|
196 | |
---|
197 | ''' |
---|
198 | # test: |
---|
199 | ion() |
---|
200 | x_ind, y_ind, z_ind, volume = arctic_map.arctic_map_lat50() |
---|
201 | x_coast = x_ind |
---|
202 | y_coast = y_ind |
---|
203 | z_coast = z_ind |
---|
204 | for imo in range (0, M): |
---|
205 | map_cartesian_grid.draw_map_cartes_l(x_coast, y_coast, z_coast, volume, xvec, yvec, ratio_ice[imo, :, :], 0., 4., 0.01, cm.s3pcpn_l_r, 'Sea ice extent - emissivity RATIO') |
---|
206 | title('AMSUA ' + str(frequ) + ' - ' + str(month[imo]) + ' 2009') |
---|
207 | plt.savefig('/usr/home/lahlod/twice_d/fig_output_ARCTIC/fig_output_sea_ice_study/ice_class_AMSUA/sub_classification/maps_sea_ice_extent/emiss_ratio_map_AMSUA'+str(frequ)+'_with_AMSUA23-and-30-spec_'+str(month[imo])+'_2009.png') |
---|
208 | ''' |
---|
209 | |
---|
210 | |
---|