source: trunk/src/scripts_Laura/ARCTIC/Travail_CEN/read_ffgrid_osisaf_ice_types.py @ 55

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

scripts ajoutes apres CEN

File size: 5.4 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
16
17
18
19MONTH = np.array(['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'])
20month = np.array(['JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE', 'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER'])
21month_day = np.array([31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31])
22M = len(month)
23
24
25
26###################
27# grid parameters #
28###################
29dx=1
30dy=0.5
31x0, x1 = -180., 180.
32y0, y1 = 30., 90.
33xvec = np.arange(x0, x1 + dx, dx)
34yvec = np.arange(y0, y1 + dy, dy)
35nx = len(xvec)
36ny = len(yvec)
37
38
39
40osi_type = np.zeros([M, 31, ny, nx], float)
41spec = np.zeros([M, 31, ny, nx], float)
42lamb = np.zeros([M, 31, ny, nx], float)
43for imo in range (3, 4):
44    print 'month ' + month[imo]
45    # osisaf
46    print 'read OSISAF'
47    fichier_osi = Dataset('/mma/hermozol/Documents/Data/OSISAF_Ice_Types/OSISAF_ice_types_ffgrid/OSISAF_ice_types_ffgrid_' + month[imo] + '_2009.nc', 'r', format='NETCDF3_CLASSIC')
48    lon_osi = fichier_osi.variables['longitude'][:]
49    lat_osi = fichier_osi.variables['latitude'][:]
50    days_osi = fichier_osi.variables['days'][:]
51    osi_ice_type = fichier_osi.variables['osi_ice_type'][:]
52    osi_type[imo, 0 : month_day[imo], :, :] = osi_ice_type[:, :, :]
53    fichier_osi.close()
54    # AMSUB data
55    print 'read AMSUB'
56    fichier_amsub = open('/mma/hermozol/Documents/Data/monthly_GLACE/lamb_spec_param_near_nadir_' + month[imo] + '2009.dat','r')
57    numlines = 0
58    for line in fichier_amsub: numlines += 1
59    fichier_amsub.close
60    fichier_amsub = open('/mma/hermozol/Documents/Data/monthly_GLACE/lamb_spec_param_near_nadir_' + month[imo] + '2009.dat','r') 
61    nbtotal = numlines-1
62    iligne = 0
63    jjr = np.zeros([nbtotal],float)
64    lat = np.zeros([nbtotal],float)
65    lon = np.zeros([nbtotal],float)
66    e_spec = np.zeros([nbtotal],float)
67    e_lamb = np.zeros([nbtotal],float)
68    while (iligne < nbtotal) :
69         line=fichier_amsub.readline()
70         liste = line.split()
71         jjr[iligne] = float(liste[0])
72         lat[iligne] = float(liste[2])
73         lon[iligne] = float(liste[1])
74         e_spec[iligne] = float(liste[16])
75         e_lamb[iligne] = float(liste[17])
76         iligne=iligne+1
77    fichier_amsub.close()
78    for ijr in range (0, month_day[imo]):
79        if ((ijr + 1) > month_day[imo]): continue
80        else:
81           bbjr = nonzero(jjr == float(ijr) + 1.)[0]
82           if (len(jjr[bbjr]) == 0):
83               print 'PAS DE JOUR : ', str(ijr + 1) 
84               continue
85           else:
86               print 'date ', jjr[bbjr][0] 
87               lat_jr = lat[bbjr]
88               lon_jr = lon[bbjr]
89               e_spec_jr = e_spec[bbjr]
90               e_lamb_jr = e_lamb[bbjr]
91               # spec
92               print 'grid spec'
93               z0 = e_spec_jr[nonzero(isnan(e_spec_jr) == False)].min()
94               z1 = e_spec_jr[nonzero(isnan(e_spec_jr) == False)].max()
95               zgrid, xvec, yvec = ffgrid2.ffgrid(lon_jr, lat_jr, e_spec_jr, dx, dy, x0, x1, y0, y1, z0, z1)
96               spec [imo, ijr, :, :] = zgrid
97               # lamb
98               print 'grid lamb'
99               z0 = e_lamb_jr.min()
100               z1 = e_lamb_jr.max()
101               zgrid, xvec, yvec = ffgrid2.ffgrid(lon_jr, lat_jr, e_lamb_jr, dx, dy, x0, x1, y0, y1, z0, z1)
102               lamb[imo, ijr, :, :] = zgrid
103
104
105
106###################################################################
107# stacking of daily gridded data AMSUB and OSISAF in NETCDF files #
108###################################################################
109for imo in range (11, M):
110    rootgrp = Dataset('/mma/hermozol/Documents/Data/daily_OSISAF_SPEC_LAMB/daily_OSISAF_emis_spec_lamb_AMSUB_ffgrid_' + str(month[imo]) + '_2009.nc', 'w', format='NETCDF3_CLASSIC')
111    rootgrp.createDimension('longitude', len(xvec))
112    rootgrp.createDimension('latitude', len(yvec))
113    rootgrp.createDimension('days', month_day[imo])
114    nc_lon = rootgrp.createVariable('longitude', 'f', ('longitude',))
115    nc_lat = rootgrp.createVariable('latitude', 'f', ('latitude',))
116    nc_day = rootgrp.createVariable('days', 'f', ('days',))
117    nc_ice_type = rootgrp.createVariable('osi_ice_type', 'f', ('days', 'latitude', 'longitude'))
118    nc_spec = rootgrp.createVariable('spec_emis', 'f', ('days', 'latitude', 'longitude'))
119    nc_lamb = rootgrp.createVariable('lamb_emis', 'f', ('days', 'latitude', 'longitude'))
120    nc_lon[:] = xvec
121    nc_lat[:] = yvec
122    nc_day[:] = np.arange(0., month_day[imo], 1.)
123    nc_ice_type[:] = osi_type[imo, 0 : month_day[imo], :, :]
124    nc_spec[:] = spec[imo, 0 : month_day[imo], :, :]
125    nc_lamb[:] = lamb[imo, 0 : month_day[imo], :, :]
126    rootgrp.close()
127
128
129
130
131
132#########
133# tests #
134#########
135# spec
136# lamb
137# osi_type
138map_ffgrid.draw_map_l (xvec, yvec, 0.4, 1.02, 0.01, spec[11, 12, :, :] , cm.s3pcpn_l_r, 'emis SPEC')
139map_ffgrid.draw_map_l (xvec, yvec, 0.4, 1.02, 0.01, lamb[11, 0, :, :] , cm.s3pcpn_l_r, 'emis LAMB')
140cmap2 = colors.ListedColormap(['1.', '0.25', '0.50', '0.75'])
141map_ffgrid.draw_map_l (xvec, yvec, 0, 5, 1, osi_type[11, 19, :, :] , cmap2, 'OSISAF ice type')
142
143
144
145
146
147
148
149
150
Note: See TracBrowser for help on using the repository browser.