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

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

new_scripts

File size: 3.8 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 scipy.special
11import ffgrid2
12import map_ffgrid
13from matplotlib import colors
14import cartesian_grid_monthly
15
16
17
18##########################
19# time period parameters #
20##########################
21MONTH = np.array(['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'])
22month = np.array(['JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE', 'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER'])
23month_day = np.array([31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31])
24M = len(month)
25
26
27
28###################
29# grid parameters #
30###################
31x0 = -3000. # min limit of grid
32x1 = 2500. # max limit of grid
33dx = 10.
34xvec = np.arange(x0, x1+dx, dx)
35nx = len(xvec) 
36y0 = -3000. # min limit of grid
37y1 = 3000. # max limit of grid
38dy = 10.
39yvec = np.arange(y0, y1+dy, dy)
40ny = len(yvec)
41
42
43
44
45##########################
46# daily OSISAF ice types #
47##########################
48OSI_TYPE = np.zeros([M, 31, ny, nx], float)
49DAY = np.zeros([31], object)
50for imo in range (0, M):
51    osi_type = np.zeros([month_day[imo], ny, nx], float)
52    for ijr in range (0, month_day[imo]):
53        if (ijr < 9):
54            day = '0' + str(ijr + 1)
55        else:
56            day = str(ijr + 1)
57        DAY[ijr] = day
58        print 'date : ' + str(day) + '_' + str(month[imo]) + '_2009'
59        osisaf = Dataset('/net/argos/data/parvati/lahlod/ARCTIC/OSISAF_Ice_Types/OSISAF_ice_types_ini/ice_type_nh_polstere-100_multi_2009' + MONTH[imo] + day + '1200.nc', 'r', format='NETCDF3_CLASSIC')
60        osi_lat = reshape(osisaf.variables['lat'][:], (851200,1))[:,0]
61        osi_lon= reshape(osisaf.variables['lon'][:],(851200,1))[:,0]
62        ice_type = reshape(osisaf.variables['ice_type'][:],(851200,1))[:,0]
63        osisaf.close()
64        bb_osi = nonzero((ice_type > 0))[0]
65        print 'start re-gridding' 
66        z0 = ice_type[bb_osi].min()
67        z1 = ice_type[bb_osi].max()
68        zgrid, ngrid, z2grid, sigmagrid, xvec, yvec, xgrid_cart, ygrid_cart = cartesian_grid_monthly.new_cartesian_grid_month(osi_lon[bb_osi], osi_lat[bb_osi], ice_type[bb_osi], z0, z1, dx, dy)
69        osi_type[ijr, :, :] = zgrid[:, :]
70        osi_lon_grid = xvec
71        osi_lat_grid = yvec
72    OSI_TYPE[imo, 0 : month_day[imo], :, :] = osi_type[:, :, :]
73    print 'stack gridded OSISAF data'
74    ################################################
75    # stack new-gridded OSISAF data in NETCDF file #
76    ################################################
77    print 'open file month' + str(month[imo])
78    rootgrp = Dataset('/net/argos/data/parvati/lahlod/ARCTIC/OSISAF_Ice_Types/OSISAF_ice_types_cartesian_grid/OSISAF_ice_types_cartes_grid_res-10_' + str(month[imo]) + '_2009.nc', 'w', format='NETCDF3_CLASSIC')
79    rootgrp.createDimension('longitude', len(xvec))
80    rootgrp.createDimension('latitude', len(yvec))
81    rootgrp.createDimension('days', month_day[imo])
82    nc_lon = rootgrp.createVariable('longitude', 'f', ('longitude',))
83    nc_lat = rootgrp.createVariable('latitude', 'f', ('latitude',))
84    nc_day = rootgrp.createVariable('days', 'f', ('days',))
85    nc_ice_type = rootgrp.createVariable('osi_ice_type', 'f', ('days', 'latitude', 'longitude'))
86    nc_lon[:] = xvec
87    nc_lat[:] = yvec
88    nc_day[:] = np.arange(0., month_day[imo], 1.)
89    nc_ice_type[:] = OSI_TYPE[imo, 0 : month_day[imo], :, :]
90    rootgrp.close()
91
92
93
94
95########
96# test #
97########
98'''x_ind, y_ind, z_ind, volume = arctic_map.arctic_map_lat50()
99x_coast = x_ind
100y_coast = y_ind
101z_coast = z_ind
102zvar = OSI_TYPE[0, 6, :, :]
103c0 = 0
104c1 = 5
105dc = 1
106colormap = cm.s3pcpn_l_r
107map_cartesian_grid.draw_map_cartes_l(x_coast, y_coast, z_coast, volume, xvec, yvec, zvar, c0, c1, dc, colormap, 'hello')'''
108
109
110
111
112
113
114
115
116
117
Note: See TracBrowser for help on using the repository browser.