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 scipy.special |
---|
11 | import ffgrid2 |
---|
12 | import map_ffgrid |
---|
13 | from matplotlib import colors |
---|
14 | import cartesian_grid_monthly |
---|
15 | |
---|
16 | |
---|
17 | |
---|
18 | ########################## |
---|
19 | # time period parameters # |
---|
20 | ########################## |
---|
21 | MONTH = np.array(['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12']) |
---|
22 | month = np.array(['JANUARY', 'FEBRUARY', 'MARCH', 'APRIL', 'MAY', 'JUNE', 'JULY', 'AUGUST', 'SEPTEMBER', 'OCTOBER', 'NOVEMBER', 'DECEMBER']) |
---|
23 | month_day = np.array([31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]) |
---|
24 | M = len(month) |
---|
25 | |
---|
26 | |
---|
27 | |
---|
28 | ################### |
---|
29 | # grid parameters # |
---|
30 | ################### |
---|
31 | x0 = -3000. # min limit of grid |
---|
32 | x1 = 2500. # max limit of grid |
---|
33 | dx = 10. |
---|
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 = 10. |
---|
39 | yvec = np.arange(y0, y1+dy, dy) |
---|
40 | ny = len(yvec) |
---|
41 | |
---|
42 | |
---|
43 | |
---|
44 | |
---|
45 | ########################## |
---|
46 | # daily OSISAF ice types # |
---|
47 | ########################## |
---|
48 | OSI_TYPE = np.zeros([M, 31, ny, nx], float) |
---|
49 | DAY = np.zeros([31], object) |
---|
50 | for 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() |
---|
99 | x_coast = x_ind |
---|
100 | y_coast = y_ind |
---|
101 | z_coast = z_ind |
---|
102 | zvar = OSI_TYPE[0, 6, :, :] |
---|
103 | c0 = 0 |
---|
104 | c1 = 5 |
---|
105 | dc = 1 |
---|
106 | colormap = cm.s3pcpn_l_r |
---|
107 | map_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 | |
---|