source: trunk/src/python_script/newgridns_z.py @ 6

Last change on this file since 6 was 6, checked in by gaclod, 12 years ago

add GC python scripts

  • Property svn:executable set to *
File size: 2.5 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3import numpy as np
4from numpy import *
5
6
7def newgridns(xx, yy, zz, vnx, nscan, pos, z0, z1):
8
9    x=xx
10    y=yy
11    z=zz
12    dx=0.1
13    dy=1       
14    dparx=0.05
15    dpary=0.5
16    n0=0
17    y11= -50
18    x0, x1 = -180, 180
19    y0, y1 = -90, 90
20    dx=0.1
21    dy=1.0
22    n=size(x)   
23    xvec = arange(x0,x1,dx)
24    yvec = arange(y0,y11,dy)
25    nx = size(xvec)
26    ny = size(yvec)
27    ix = zeros(n, float)   
28    iy = zeros(n, float)   
29
30    for kk in range(0,n):
31        if x[kk] == -180:
32           ix[kk] = 3600
33        else:
34           ix[kk] = math.ceil((x[kk] - x0)/dx)-1
35
36    for kk in range(0,n):
37        if y[kk] == -90:
38           iy[kk] = 0
39        else:
40           iy[kk] = math.ceil((y[kk] - y0)/dy)-1
41
42   
43    if nscan==1:
44       ipos = ((pos <=5) | (pos >=26))
45    if nscan==2:   
46       ipos = ((pos >=6) & (pos <=10))| ((pos >=21) & (pos<=25))
47    if nscan==3:
48       ipos = ((pos >=11) & (pos<=20))
49   
50    inx = (ix >= 0) & (ix < nx) 
51    iny = (iy >= 0) & (iy < ny)
52    inz = (z >= z0) & (z <= z1) 
53    inn = inx & iny & inz & ipos
54    iix = ix[inn]
55    iiy = iy[inn]
56    zz = z[inn]
57    N = size(iix)# how many datapoints are left now?
58    #calculation of the each arc legth
59
60    dxx=vnx
61    ngrid = zeros([nx, ny], float)# no of obs per grid cell
62    nngrid = zeros([nx, ny], float)
63    zgrid = zeros([nx, ny], float)# z-coordinate
64    zzgrid = zeros([nx, ny], float)# z-coordinate grouped
65    zdgrid = zeros([nx, ny], float)# z-coordinate 2
66    zz2grid = zeros([nx, ny], float)# z-coordinate 2 grouped
67
68    for i in range(0, N):
69        zgrid[iix[i], iiy[i]] = zgrid[iix[i],iiy[i]]+zz[i]
70        zdgrid[iix[i], iiy[i]] = zdgrid[iix[i],iiy[i]]+zz[i]*zz[i]
71        ngrid[iix[i], iiy[i]] = ngrid[iix[i],iiy[i]]+ 1 
72       
73    for i in range(0,ny):
74        jj=round(3600/dxx[i])
75        c=reshape(ngrid[:,i],(jj,dxx[i]))
76        b=c.sum(axis=1)
77        d=reshape(zgrid[:,i],(jj,dxx[i]))
78        e=d.sum(axis=1)
79        f=reshape(zdgrid[:,i],(jj,dxx[i]))
80        g=f.sum(axis=1) 
81        for j in range(0, nx):
82            ii=ceil((j+1)/dxx[i])-1
83            nngrid[j,i]=b[ii]
84            zzgrid[j,i]=e[ii]
85            zz2grid[j,i]=g[ii]
86
87    zzpgrid = zeros([nx, ny], float)   
88    zzpgrid = zzgrid/nngrid
89    sigma_grid=sqrt(zz2grid/nngrid-zzpgrid*zzpgrid)
90    zgrid = np.transpose(zgrid)
91    sigma_grid=np.transpose(sigma_grid)
92    zzpgrid = np.transpose(zzpgrid)
93    ngrid = np.transpose(ngrid)
94    nngrid = np.transpose(nngrid)
95    return zgrid, zzpgrid, ngrid, nngrid, sigma_grid, xvec, yvec, zz
Note: See TracBrowser for help on using the repository browser.