Changeset 30


Ignore:
Timestamp:
06/19/14 18:22:12 (10 years ago)
Author:
lahlod
Message:

scrit nouvelle grille

Location:
trunk/src/scripts_Laura
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/scripts_Laura/cartesian_grid_test.py

    r29 r30  
    1111 
    1212 
    13 ############################## 
    14 # parameters of the new grid # 
    15 ############################## 
    1613 
    17 # apres avoir fait un ffgrid ==> lon et lat regulieres # 
     14############### 
     15# test values # 
     16############### 
     17longi = array([-109.208, -117.39 , -117.928, -123.927, -120.325, -128.82 , -125.947, -122.596, -133.173, -124.778, -137.312, -134.984, -132.538, -129.883, -126.898, -136.826, -134.414, -131.833, -128.978, -141.05 , -138.707, -136.313, -133.787, -131.036, -127.931, -140.634, -138.243, -135.757, -133.087, -130.122, -126.704, -110.352, -142.613, -140.213, -137.751, -135.144, -132.291, -129.058, -125.246, -114.38 , -147.118, -144.65 , -142.229, -139.777, -137.216, -134.453, -131.372, -127.803, -118.005, -146.753]) 
    1818 
    19 Rt = 6371 
    20 alpha = (pi*Rt)/180 
    21 beta = pi/180 
    22 # definition of theta angle and coord x,y # 
    23 x = np.zeros([len(lat_mesh), len(lon_mesh)], float) 
    24 y = np.zeros([len(lat_mesh), len(lon_mesh)], float) 
    25 for ilat in range (0, len(lat_mesh)): 
    26     for ilon in range (0, len(lon_mesh)): 
    27         if ((lon_mesh[ilon] >= 0.) & (lon_mesh[ilon] <= 90.)): # 4eme quadrant 
    28             theta = - (90 - lon_mesh[ilon]) * beta 
    29             x[ilat, ilon] = (90 - lat_mesh[ilat]) * alpha * cos(theta) 
    30             y[ilat, ilon] = (90 - lat_mesh[ilat]) * alpha * sin(theta) 
    31         else: 
    32             if ((lon_mesh[ilon] > 90.) & (lon_mesh[ilon] <= 180.)): # 1er quadrant 
    33                 theta = (lon_mesh[ilon] - 90) * beta 
    34                 x[ilat, ilon] = (90 - lat_mesh[ilat]) * alpha * cos(theta) 
    35                 y[ilat, ilon] = (90 - lat_mesh[ilat]) * alpha * sin(theta) 
    36             else:  
    37                 if ((lon_mesh[ilon] >= -180.) & (lon_mesh[ilon] < 0.)): # 2eme et 3eme quadrants 
    38                     theta = (270 + lon_mesh[ilon]) * beta 
    39                     x[ilat, ilon] = (90 - lat_mesh[ilat]) * alpha * cos(theta) 
    40                     y[ilat, ilon] = (90 - lat_mesh[ilat]) * alpha * sin(theta) 
     19lati = array([ 68.164,  69.205,  70.121,  70.087,  70.422,  69.994,  70.359, 70.709,  69.846,  70.983,  69.619,  70.061,  70.474,  70.867, 71.246,  70.259,  70.693,  71.103,  71.496,  69.936,  70.437, 70.896,  71.325,  71.735,  72.129,  70.593,  71.08 ,  71.532, 71.959,  72.369,  72.764,  73.708,  70.723,  71.244,  71.721, 72.168,  72.595,  73.007,  73.403,  74.075,  70.188,  70.824, 71.384,  71.891,  72.361,  72.807,  73.235,  73.648,  74.394, 70.892]) 
     20 
     21z = array([ 0.938 ,  0.899 ,  0.958 ,  0.944 ,  0.991 ,  0.867 ,  0.948 , 0.963 ,  0.911 ,  0.978 ,  0.935 ,  0.932 ,  0.957 ,  0.972 , 0.983 ,  0.945 ,  0.941 ,  0.965 ,  0.986 ,  0.88  ,  0.942 , 0.945 ,  0.966 ,  0.989 ,  0.9999,  0.914 ,  0.908 ,  0.93  , 0.96  ,  0.996 ,  0.9999,  0.952 ,  0.898 ,  0.88  ,  0.852 , 0.86  ,  0.906 ,  0.984 ,  0.976 ,  0.888 ,  0.794 ,  0.89  , 0.846 ,  0.849 ,  0.869 ,  0.812 ,  0.764 ,  0.904 ,  0.853 , 0.934 ]) 
     22z0 = min(z) 
     23z1 = max(z) 
    4124 
    4225 
    43 # definition of nex grid cells #  
     26#################################################### 
     27# from polar (lon, lat) to cartesian coords (x, y) # 
     28#################################################### 
     29# associates a (x, y) couple to each point of (longitude, latitude) coordinates  
     30# origin of the (x, y) grid : (x=0, y=0) <=> (lon=0, lat=0)  
     31Rt = 6371. 
     32alpha = (pi*Rt)/180. 
     33beta = pi/180. 
     34# definition of theta angle and coord x,y # 
     35x = np.zeros([len(lati), len(longi)], float) 
     36y = np.zeros([len(lati), len(longi)], float) 
     37for ilat in range (0, len(lati)): 
     38    for ilon in range (0, len(longi)): 
     39        if ((longi[ilon] >= 0.) & (longi[ilon] <= 90.)): # 4eme quadrant 
     40            theta = (90. - longi[ilon]) * beta 
     41            x[ilat, ilon] = (90. - lati[ilat]) * alpha * cos(theta) 
     42            y[ilat, ilon] = (90. - lati[ilat]) * alpha * sin(-theta) 
     43        else: 
     44            if ((longi[ilon] > 90.) & (longi[ilon] <= 180.)): # 1er quadrant 
     45                theta = (longi[ilon] - 90.) * beta 
     46                x[ilat, ilon] = (90. - lati[ilat]) * alpha * cos(theta) 
     47                y[ilat, ilon] = (90. - lati[ilat]) * alpha * sin(theta) 
     48            else:  
     49                if ((longi[ilon] >= -180.) & (longi[ilon] < 0.)): # 2eme et 3eme quadrants 
     50                    theta = (270. + longi[ilon]) * beta 
     51                    x[ilat, ilon] = (90. - lati[ilat]) * alpha * cos(theta) 
     52                    y[ilat, ilon] = (90. - lati[ilat]) * alpha * sin(theta) 
     53 
     54 
     55# definition of the new cartesian grid (x, y) # 
     56Sx = size(x) 
     57Sy = size(y) 
    4458xx = reshape(x, size(x)) 
    45 yy = np.append(y[:,180], y[:,360]) 
     59yy = reshape(y, size(y)) 
     60mx = min(xx) 
     61Mx = max(xx) 
     62my = min(yy) 
     63My = max(yy) 
    4664 
    47 x0 = -2780. 
    48 x1 = 2780. 
    49 y0 = -2780. 
    50 y1 = 2780. 
    51 dx = 2 
    52 dy = 2 
    53 xvec = arange(x0, x1 + dx, dx) 
    54 yvec = arange(y0, y1 + dy, dy) 
     65x0 = round(mx) - 50. # xmin 
     66x1 = round(Mx) + 50. # xmax 
     67dx = 25. # delta(x) 
     68xvec = np.arange(x0, x1+dx, dx) 
    5569nx = size(xvec) 
     70y0 = round(my) - 50. # ymin 
     71y1 = round(My) + 50. # ymax 
     72dy = 25. # delta(y) 
     73yvec = np.arange(y0, y1+dy, dy) 
    5674ny = size(yvec) 
    57 n = size(xx) 
     75xgrid_cart, ygrid_cart = np.meshgrid(xvec, yvec) # new cartesian grid (centered on North pole) 
    5876 
    59 ix = np.zeros([n], int) 
    60 for kk in range(0, n): 
    61     if xx[kk] == x0: 
    62         ix[kk] = 0 
     77 
     78# counting each grid cell # 
     79ix = np.zeros([Sx], int) 
     80for i in range (0, Sx): # boucle sur les points M (abscisses) 
     81    if xx[i] == x0: 
     82        ix[i] = 0 
    6383    else: 
    64         ix[kk] = math.ceil((xx[kk] - x0)/dx) 
     84        ix[i] = math.ceil((xx[i] - x0) / dx) - 1 
    6585 
    66 iy = np.zeros([n], int) 
    67 for kk in range(0, n): 
    68     if yy[kk] == min(y): 
    69         iy[kk] = 0 
     86iy = np.zeros([Sy], int)  
     87for j in range (0, Sy): # boucle sur les points M (ordonnees) 
     88    if yy[j] == y0: 
     89        iy[j] = 0 
    7090    else: 
    71         iy[kk] = math.ceil((yy[kk] - y0)/dy) 
     91        iy[j] = math.ceil((yy[j] - y0) / dy) - 1  
    7292 
    73 zz = reshape(emis_mesh, size(emis_mesh)) 
    74 zgrid = np.zeros([len(ixx), len(iyy)], float) 
    75 for i in range (0, size(x)): 
    76     zgrid[ixx[i], iyy[i]] = zgrid[ixx[i], iyy[i]] + zz[i] 
     93 
     94#inx = (ix >= 0) & (ix < nx) 
     95#iny = (iy >= 0) & (iy < ny) 
     96#inz = (z > z0) & (z < z1) 
     97#inn = inx & iny & inz 
     98#iix = ix[inn] 
     99#iiy = iy[inn] 
     100#zz = z[inn] 
    77101 
    78102 
    79103 
    80 xii,yii = np.meshgrid(xx ,yy) 
     104 
     105# calculation of distances between point M(x,y) and 4 grid points of its belonging cell # 
     106dist1 = np.zeros([Sx], float) 
     107dist2 = np.zeros([Sx], float) 
     108dist3 = np.zeros([Sx], float) 
     109dist4 = np.zeros([Sx], float) 
     110min_dist = np.zeros([Sx], float) 
     111for k in range (0, Sx): # boucle sur les points M (x et y) 
     112    dist1[k] = sqrt(((xx[k] - xvec[ix[k]]) ** 2) + ((yy[k] - yvec[iy[k]]) ** 2)) 
     113    dist2[k] = sqrt(((xx[k] - xvec[ix[k] + 1]) ** 2) + ((yy[k] - yvec[iy[k]]) ** 2)) 
     114    dist3[k] = sqrt(((xx[k] - xvec[ix[k]])**2) + ((yy[k] - yvec[iy[k] + 1]) ** 2)) 
     115    dist4[k] = sqrt(((xx[k] - xvec[ix[k] + 1]) ** 2) + ((yy[k] - yvec[iy[k] + 1]) ** 2)) 
     116    dist_vec = np.array([dist1[k], dist2[k], dist3[k], dist4[k]]) 
     117    ind = np.where(dist_vec == min(dist_vec)) 
     118    print 'grid cell no : ' + str(ind[0][0]+1) 
     119     
     120 
     121##### probleme: z pas la même dimension (plus petite)!!####### 
     122 
     123 
     124 
     125 
     126 
     127 
     128 
     129 
     130 
     131 
     132 
     133 
     134 
     135 
     136 
     137 
     138 
     139 
     140 
     141 
     142 
     143 
     144for i in range (0, 5): 
     145    np.where((xx - xvec[i]) <= dx) 
     146         
     147    for j in range (0, len(yy)): 
     148        np.where ((xx[i] - xvec) <= dx): 
     149        print 'ok' 
     150        else: 
     151            print 'not ok' 
     152        np.where((yy[i] - yvec) <= dy) 
     153 
     154 
     155 
     156M = np.array([xx, yy]) 
     157for k in range (0, len(xx)): 
     158    xcoord[k] = M[:,k][0] 
     159    ycoord[k] = M[:,k][1] 
     160 
     161 
     162 
     163 
     164ix = np.zeros([len(xx)], int) 
     165for i in range (0, len(xx)): 
     166    if xx[i] == x0: 
     167        ix[i] = 0 
     168    else: 
     169        ix[i] = math.ceil((xx[i] - x0) / dx) - 1 
     170 
     171iy = np.zeros([len(yy)], int) 
     172for j in range (0, len(yy)): 
     173    if yy[j] == y0: 
     174        iy[j] = 0 
     175    else: 
     176        iy[j] = math.ceil((yy[j] - y0) / dy) - 1  
     177 
     178 
     179 
     180 
     181 
     182 
    81183 
    82184figure() 
  • trunk/src/scripts_Laura/read_emis_glace.py

    r29 r30  
    3535tup=np.zeros([4,nbtotal],float) 
    3636tdn=np.zeros([4,nbtotal],float) 
     37#trans=np.zeros([4,nbtotal],float) 
    3738 
    3839 
     
    9495lat_mesh = outy 
    9596 
     97plt.ion() 
    9698figure() 
    9799#m = Basemap(llcrnrlon=-180,urcrnrlon=180,llcrnrlat=65,urcrnrlat=90,projection='cyl',resolution='c',fix_aspect=True) 
    98100m = Basemap(projection = 'npaeqd',boundinglat = 60, lon_0 = 0, resolution = 'l') 
    99101xii, yii = m(*np.meshgrid(lon_mesh,lat_mesh)) 
    100 clevs=arange(zz0,zz1,0.01) 
     102#clevs=arange(-2400, -800, 10) 
    101103m.drawcoastlines(linewidth=1) 
    102104m.drawparallels(np.arange(60, 90, 20)) 
    103105m.drawmeridians(np.arange(-180, 180, 20)) 
    104 cs=m.contourf(xii,yii,emis_mesh, clevs, cmap=cm.s3pcpn_l_r) # emissivity 
     106cs=m.contourf(xii,yii,y, cmap=cm.s3pcpn_l_r) # emissivity 
    105107cbar =colorbar(cs) 
    106108#cbar.set_label(txt) 
Note: See TracChangeset for help on using the changeset viewer.