source: trunk/src/scripts_Laura/ARCTIC/read_bathy.py @ 54

Last change on this file since 54 was 35, checked in by lahlod, 10 years ago

modifs

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