1 | #!/usr/bin/env python |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | import string |
---|
4 | import numpy as np |
---|
5 | import matplotlib.pyplot as plt |
---|
6 | import ffgrid2 |
---|
7 | from pylab import * |
---|
8 | from mpl_toolkits.basemap import Basemap |
---|
9 | from mpl_toolkits.basemap import shiftgrid, cm |
---|
10 | from netCDF4 import Dataset |
---|
11 | |
---|
12 | |
---|
13 | ## read bathymetry data from netcdf file 'ETOPO1_Ice_g_gmt4.nc' ## |
---|
14 | bathy = Dataset ('/net/argos/data/parvati/lahlod/ARCTIC/ETOPO1_Ice_g_gmt4.nc','r', format = 'NETCDF4') |
---|
15 | #bathy.variables |
---|
16 | lon_bath = bathy.variables['lon'][:] |
---|
17 | lat_bath = bathy.variables['lat'][:] |
---|
18 | z_bath = bathy.variables['z'][:] |
---|
19 | bathy.close() |
---|
20 | |
---|
21 | |
---|
22 | lat_limit = 50. |
---|
23 | |
---|
24 | |
---|
25 | ## read all points with bathymerty around 0, create z_cote 0 or 1 matrix ## |
---|
26 | z_cote = np.zeros([len(lat_bath[np.where(lat_bath >= lat_limit)]), len(lon_bath)], float) |
---|
27 | nn = min(np.where(lat_bath >= lat_limit)[0]) |
---|
28 | for ilon in range (0, len(lon_bath)): |
---|
29 | for ilat in range (0, len(lat_bath[np.where(lat_bath >= lat_limit)])): |
---|
30 | if ((z_bath[ilat+nn, ilon] == 0.)): |
---|
31 | z_cote[ilat, ilon] = 1. |
---|
32 | else: |
---|
33 | z_cote[ilat, ilon] = NaN |
---|
34 | |
---|
35 | |
---|
36 | ## write z_cote in netcdf file 'z_cote_global_final.nc' ## |
---|
37 | rootgrp = Dataset('/net/argos/data/parvati/lahlod/ARCTIC/z_cote_global_final_z0_lat50.nc', 'w', format = 'NETCDF4') |
---|
38 | rootgrp.createDimension('longitude', len(lon_bath)) |
---|
39 | rootgrp.createDimension('latitude', len(lat_bath[np.where(lat_bath >= lat_limit)])) |
---|
40 | nc_lon = rootgrp.createVariable('longitude', 'f', ('longitude',)) |
---|
41 | nc_lat = rootgrp.createVariable('latitude', 'f', ('latitude',)) |
---|
42 | nc_zcote = rootgrp.createVariable('cote', 'f', ('latitude', 'longitude',)) |
---|
43 | nc_lon[:] = lon_bath |
---|
44 | nc_lat[:] = lat_bath[np.where(lat_bath >= lat_limit)] |
---|
45 | nc_zcote[:] = z_cote |
---|
46 | rootgrp.close() |
---|
47 | |
---|
48 | |
---|
49 | ## read z_cote from netcfd file 'z_cote_global_final.nc' ## |
---|
50 | cote_bin = Dataset ('/net/argos/data/parvati/lahlod/ARCTIC/z_cote_global_final_z0_lat50.nc','r', format = 'NETCDF4') |
---|
51 | #cote_bin.variables |
---|
52 | lon_cote = cote_bin.variables['longitude'][:] |
---|
53 | lat_cote = cote_bin.variables['latitude'][:] |
---|
54 | lim_cote = cote_bin.variables['cote'][:] |
---|
55 | cote_bin.close() |
---|
56 | |
---|
57 | |
---|
58 | ## tests ## |
---|
59 | plt.ion() |
---|
60 | plt.figure() |
---|
61 | m = Basemap(llcrnrlon=-180, urcrnrlon=180, llcrnrlat=-90., urcrnrlat=90, projection='cyl', resolution='c', fix_aspect=True) |
---|
62 | m.drawcoastlines(linewidth = 1) |
---|
63 | m.drawparallels(np.arange(-90., 90., 20.)) |
---|
64 | m.drawmeridians(np.arange(-180., 180., 20.)) |
---|
65 | xii,yii = m(*np.meshgrid(lon_cote, lat_cote)) |
---|
66 | cs = m.scatter(xii, yii, lim_cote) |
---|
67 | |
---|
68 | |
---|
69 | ## conversion to cartesian grid points ( lon, lat ) --> ( x[lon, lat], y[lon, lat] ) ## |
---|
70 | latitude = lat_cote |
---|
71 | longitude = lon_cote |
---|
72 | |
---|
73 | Rt = 6371. |
---|
74 | alpha = (pi*Rt)/180. |
---|
75 | beta = pi/180. |
---|
76 | x = np.zeros([len(latitude), len(longitude)], float) |
---|
77 | y = np.zeros([len(latitude), len(longitude)], float) |
---|
78 | |
---|
79 | for ilon in range (0, len(longitude)): |
---|
80 | for ilat in range (0, len(latitude)): |
---|
81 | if ((longitude[ilon] >= 0.) & (longitude[ilon] <= 90.)): # 4eme quadrant |
---|
82 | theta = (90. - longitude[ilon]) * beta |
---|
83 | x[ilat, ilon] = (90. - latitude[ilat]) * alpha * cos(theta) |
---|
84 | y[ilat, ilon] = (90. - latitude[ilat]) * alpha * sin(-theta) |
---|
85 | else: |
---|
86 | if ((longitude[ilon] > 90.) & (longitude[ilon] <= 180.)): # 1er quadrant |
---|
87 | theta = (longitude[ilon] - 90.) * beta |
---|
88 | x[ilat, ilon] = (90. - latitude[ilat]) * alpha * cos(theta) |
---|
89 | y[ilat, ilon] = (90. - latitude[ilat]) * alpha * sin(theta) |
---|
90 | else: |
---|
91 | if ((longitude[ilon] >= -180.) & (longitude[ilon] < 0.)): # 2eme et 3eme quadrants |
---|
92 | theta = (270. + longitude[ilon]) * beta |
---|
93 | x[ilat, ilon] = (90. - latitude[ilat]) * alpha * cos(theta) |
---|
94 | y[ilat, ilon] = (90. - latitude[ilat]) * alpha * sin(theta) |
---|
95 | |
---|
96 | |
---|
97 | ## write x and y equivalents of lon, lat points in netcdf file 'z_cote_global_final_cartes_z0.nc' ## |
---|
98 | rootgrp = Dataset('/net/argos/data/parvati/lahlod/ARCTIC/z_cote_global_final_cartes_z0_lat50.nc', 'w', format = 'NETCDF4') |
---|
99 | rootgrp.createDimension('longitude', len(lon_cote)) |
---|
100 | rootgrp.createDimension('latitude', len(lat_cote)) |
---|
101 | nc_lon = rootgrp.createVariable('longitude', 'f', ('longitude',)) |
---|
102 | nc_lat = rootgrp.createVariable('latitude', 'f', ('latitude',)) |
---|
103 | nc_x = rootgrp.createVariable('x', 'f', ('latitude', 'longitude',)) |
---|
104 | nc_y = rootgrp.createVariable('y', 'f', ('latitude', 'longitude',)) |
---|
105 | nc_lon[:] = lon_cote |
---|
106 | nc_lat[:] = lat_cote |
---|
107 | nc_x[:] = x |
---|
108 | nc_y[:] = y |
---|
109 | rootgrp.close() |
---|
110 | |
---|
111 | |
---|
112 | ## read x and y equivalents of lon, lat points in netcdf file 'z_cote_global_final_cartes_z0.nc' ## |
---|
113 | coast_bin = Dataset('/net/argos/data/parvati/lahlod/ARCTIC/z_cote_global_final_cartes_z0_lat50.nc', 'r', format = 'NETCDF4') |
---|
114 | #coast_bin.variables |
---|
115 | #lon_cote = coast_bin.variables['longitude'][:] |
---|
116 | #lat_cote = coast_bin.variables['latitude'][:] |
---|
117 | x_cote = coast_bin.variables['x'][:] |
---|
118 | y_cote = coast_bin.variables['y'][:] |
---|
119 | coast_bin.close() |
---|
120 | |
---|
121 | X = reshape(x_cote, size(x_cote)) |
---|
122 | Y = reshape(y_cote, size(y_cote)) |
---|
123 | Z_LIM = reshape(lim_cote, size(lim_cote)) |
---|
124 | |
---|
125 | indices = np.where(Z_LIM == 1.)[0] |
---|
126 | x_ind = X[indices] |
---|
127 | y_ind = Y[indices] |
---|
128 | z_ind = Z_LIM[indices] |
---|
129 | |
---|
130 | volume = z_ind/50. |
---|
131 | plt.figure() |
---|
132 | plt.scatter(x_ind, y_ind, c = z_ind, s = volume) |
---|
133 | |
---|
134 | |
---|
135 | |
---|
136 | |
---|
137 | |
---|
138 | |
---|
139 | |
---|
140 | |
---|
141 | |
---|
142 | |
---|