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 | import map_cartesian_grid |
---|
17 | |
---|
18 | |
---|
19 | |
---|
20 | MONTH = np.array(['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']) |
---|
21 | month = np.array(['JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE', 'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER']) |
---|
22 | month_day = np.array([31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]) |
---|
23 | M = len(month) |
---|
24 | |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | ######################## |
---|
29 | # grid characteristics # |
---|
30 | ######################## |
---|
31 | x0 = -3000. # min limit of grid |
---|
32 | x1 = 2500. # max limit of grid |
---|
33 | dx = 40. |
---|
34 | xvec = np.arange(x0, x1+dx, dx) |
---|
35 | nx = len(xvec) |
---|
36 | y0 = -3000. # min limit of grid |
---|
37 | y1 = 3000. # max limit of grid |
---|
38 | dy = 40. |
---|
39 | yvec = np.arange(y0, y1+dy, dy) |
---|
40 | ny = len(yvec) |
---|
41 | |
---|
42 | |
---|
43 | |
---|
44 | ############################################ |
---|
45 | # Read daily gridded OSISAF and AMSUB data # |
---|
46 | ############################################ |
---|
47 | sl_rate = np.zeros([M, 31, ny, nx], float) |
---|
48 | for imo in range (0, M): |
---|
49 | print 'month: ' + month[imo] |
---|
50 | ### AMSUA23 ### |
---|
51 | print 'open data file' |
---|
52 | fichier = Dataset('/net/argos/data/parvati/lahlod/ARCTIC/monthly_GLACE/gridded_data/cartesian_grid/res_40/cartesian_grid_monthly_data_lamb_spec_near_nadir_AMSUA30_' + str(month[imo]) + '2009.nc', 'r', format='NETCDF3_CLASSIC') |
---|
53 | xdist = fichier.variables['longitude'][:] |
---|
54 | ydist = fichier.variables['latitude'][:] |
---|
55 | day = fichier.variables['days'][:] |
---|
56 | emis_spec = fichier.variables['e_spec'][:] |
---|
57 | emis_lamb = fichier.variables['e_lamb'][:] |
---|
58 | fichier.close() |
---|
59 | print 'calculate rate' |
---|
60 | for ijr in range (0, month_day[imo]): |
---|
61 | for ilat in range (0, len(ydist)): |
---|
62 | for ilon in range (0, len(xdist)): |
---|
63 | sl_rate[imo, ijr, ilat, ilon] = ((emis_lamb[ilat, ilon, ijr] - emis_spec[ilat, ilon, ijr]) / emis_spec[ilat, ilon, ijr]) * 100. |
---|
64 | |
---|
65 | |
---|
66 | |
---|
67 | |
---|
68 | ############################################# |
---|
69 | # compute monthly means of emissivity ratio # |
---|
70 | ############################################# |
---|
71 | print 'compute monthly mean of emissivity ratio' |
---|
72 | monthly_ratio = np.zeros([M, ny, nx], float) |
---|
73 | for imo in range (0, M): |
---|
74 | print 'month ' + str(month[imo]) |
---|
75 | for ilon in range (0, len(xdist)): |
---|
76 | for ilat in range (0, len(ydist)): |
---|
77 | monthly_ratio[imo, ilat, ilon] = mean(sl_rate[imo, 0 : month_day[imo], ilat, ilon][nonzero(isnan(sl_rate[imo, 0 : month_day[imo], ilat, ilon]) == False)]) |
---|
78 | |
---|
79 | |
---|
80 | |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | ######################################### |
---|
85 | # map monthly means of emissivity ratio # |
---|
86 | ######################################### |
---|
87 | print 'start mapping' |
---|
88 | ## parameters of coast coordinates for mapping ## |
---|
89 | plt.ion() |
---|
90 | x_ind, y_ind, z_ind, volume = arctic_map.arctic_map_lat50() |
---|
91 | x_coast = x_ind |
---|
92 | y_coast = y_ind |
---|
93 | z_coast = z_ind |
---|
94 | colormap = cm.s3pcpn_l_r |
---|
95 | ## start mapping ratio ## |
---|
96 | for imo in range (0, M): |
---|
97 | print 'map month ' +str(month[imo]) |
---|
98 | map_cartesian_grid.draw_map_cartes_l(x_coast, y_coast, z_coast, volume, xdist, ydist, monthly_ratio[imo, :, :], 0., 6., 0.1, colormap, 'emissivity ratio [(LAMB - SPEC)/SPEC]*100') |
---|
99 | title(month[imo] + ' 2009 - AMSUA 30GHz') |
---|
100 | plt.savefig('/usr/home/lahlod/twice_d/fig_output_ARCTIC/fig_output_sea_ice_study/comparison_lamb_spec/space_evolution/EMIS/cartesian_grid/emis_ratio/emis_ratio_spec-lamb_AMSUA30_' + month[imo] + '2009.png') |
---|
101 | |
---|
102 | |
---|
103 | |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | ########################################################### |
---|
108 | # stack monthly means of emissivity ratio in netcdf files # |
---|
109 | ########################################################### |
---|
110 | print 'start stacking' |
---|
111 | ## AMSUA ratio ## |
---|
112 | for imo in range (0, M): |
---|
113 | print 'stack in file month ' + str(month[imo]) |
---|
114 | rootgrp = Dataset('/net/argos/data/parvati/lahlod/ARCTIC/monthly_GLACE/gridded_data/cartesian_grid/res_40/cartesian_grid_monthly_lamb-spec_ratio_near_nadir_AMSUA30_' + month[imo] + '2009.nc', 'w', format='NETCDF3_CLASSIC') |
---|
115 | rootgrp.createDimension('longitude', len(xdist)) |
---|
116 | rootgrp.createDimension('latitude', len(ydist)) |
---|
117 | nc_lon = rootgrp.createVariable('longitude', 'f', ('longitude',)) |
---|
118 | nc_lat = rootgrp.createVariable('latitude', 'f', ('latitude',)) |
---|
119 | nc_ratio = rootgrp.createVariable('emis_ratio', 'f', ('latitude', 'longitude')) |
---|
120 | nc_lon[:] = xdist |
---|
121 | nc_lat[:] = ydist |
---|
122 | nc_ratio[:] = monthly_ratio[imo, :, :] |
---|
123 | rootgrp.close() |
---|