source: trunk/src/scripts_Laura/ARCTIC/Travail_CEN/discrim_rate_espec-elamb_espec.py @ 56

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

new scripts

File size: 4.5 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 import colors
16import map_cartesian_grid
17
18   
19
20MONTH = np.array(['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'])
21month = np.array(['JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE', 'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER'])
22month_day = np.array([31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31])
23M = len(month)
24
25
26
27
28########################
29# grid characteristics #
30########################
31x0 = -3000. # min limit of grid
32x1 = 2500. # max limit of grid
33dx = 40.
34xvec = np.arange(x0, x1+dx, dx)
35nx = len(xvec) 
36y0 = -3000. # min limit of grid
37y1 = 3000. # max limit of grid
38dy = 40.
39yvec = np.arange(y0, y1+dy, dy)
40ny = len(yvec)
41
42
43
44############################################
45# Read daily gridded OSISAF and AMSUB data #
46############################################
47sl_rate = np.zeros([M, 31, ny, nx], float)
48for 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#############################################
71print 'compute monthly mean of emissivity ratio'
72monthly_ratio = np.zeros([M, ny, nx], float)
73for 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#########################################
87print 'start mapping'
88## parameters of coast coordinates for mapping ##
89plt.ion()
90x_ind, y_ind, z_ind, volume = arctic_map.arctic_map_lat50()
91x_coast = x_ind
92y_coast = y_ind
93z_coast = z_ind
94colormap = cm.s3pcpn_l_r
95## start mapping ratio ##
96for 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###########################################################
110print 'start stacking'
111## AMSUA ratio ##
112for 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()
Note: See TracBrowser for help on using the repository browser.