From d23c4f9bc8874b755652d2c2779877c9701af22d Mon Sep 17 00:00:00 2001 From: csyhuang Date: Sun, 16 Jan 2022 23:18:55 -0600 Subject: [PATCH 01/19] save progress --- .../demo_script_for_nh2018.ipynb | 2 +- hn2016_falwa/compute_flux_dirinv.f90 | 240 +++++++++ hn2016_falwa/compute_qref_and_fawa_first.f90 | 460 ++++++++++++++++++ hn2016_falwa/interpolate_fields.f90 | 6 +- hn2016_falwa/interpolate_fields_dirinv.f90 | 232 +++++++++ hn2016_falwa/inversion_refactored.f90 | 428 ++++++++++++++++ hn2016_falwa/matrix_after_inversion.f90 | 50 ++ hn2016_falwa/matrix_b4_inversion.f90 | 97 ++++ hn2016_falwa/oopinterface.py | 385 ++++++++++++++- hn2016_falwa/upward_sweep.f90 | 116 +++++ scripts/nhn_grl2022/Fig1a.py | 81 +++ scripts/nhn_grl2022/Fig1b.py | 66 +++ scripts/nhn_grl2022/Fig1c.py | 64 +++ scripts/nhn_grl2022/Fig1d-Fig2.py | 132 +++++ scripts/nhn_grl2022/Fig3a-d.py | 266 ++++++++++ scripts/nhn_grl2022/Fig3e.py | 67 +++ scripts/nhn_grl2022/Fig3f.py | 75 +++ scripts/nhn_grl2022/Fig4.py | 225 +++++++++ scripts/nhn_grl2022/Fig5.py | 316 ++++++++++++ .../nhn_grl2022/download_data_nhn_grl2022.py | 59 +++ scripts/nhn_grl2022/era1000.f90 | 435 +++++++++++++++++ scripts/nhn_grl2022/era4000n.f90 | 239 +++++++++ scripts/nhn_grl2022/era4000n_nc.f90 | 312 ++++++++++++ scripts/nhn_grl2022/era4004n.f90 | 460 ++++++++++++++++++ scripts/nhn_grl2022/lwa_flux_computation.py | 174 +++++++ setup.py | 25 +- 26 files changed, 5006 insertions(+), 6 deletions(-) create mode 100644 hn2016_falwa/compute_flux_dirinv.f90 create mode 100644 hn2016_falwa/compute_qref_and_fawa_first.f90 create mode 100644 hn2016_falwa/interpolate_fields_dirinv.f90 create mode 100644 hn2016_falwa/inversion_refactored.f90 create mode 100644 hn2016_falwa/matrix_after_inversion.f90 create mode 100644 hn2016_falwa/matrix_b4_inversion.f90 create mode 100644 hn2016_falwa/upward_sweep.f90 create mode 100644 scripts/nhn_grl2022/Fig1a.py create mode 100644 scripts/nhn_grl2022/Fig1b.py create mode 100644 scripts/nhn_grl2022/Fig1c.py create mode 100644 scripts/nhn_grl2022/Fig1d-Fig2.py create mode 100644 scripts/nhn_grl2022/Fig3a-d.py create mode 100644 scripts/nhn_grl2022/Fig3e.py create mode 100644 scripts/nhn_grl2022/Fig3f.py create mode 100644 scripts/nhn_grl2022/Fig4.py create mode 100644 scripts/nhn_grl2022/Fig5.py create mode 100644 scripts/nhn_grl2022/download_data_nhn_grl2022.py create mode 100644 scripts/nhn_grl2022/era1000.f90 create mode 100644 scripts/nhn_grl2022/era4000n.f90 create mode 100644 scripts/nhn_grl2022/era4000n_nc.f90 create mode 100644 scripts/nhn_grl2022/era4004n.f90 create mode 100644 scripts/nhn_grl2022/lwa_flux_computation.py diff --git a/examples/nh2018_science/demo_script_for_nh2018.ipynb b/examples/nh2018_science/demo_script_for_nh2018.ipynb index 0566516..6e82a6f 100644 --- a/examples/nh2018_science/demo_script_for_nh2018.ipynb +++ b/examples/nh2018_science/demo_script_for_nh2018.ipynb @@ -601,7 +601,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.7.10" } }, "nbformat": 4, diff --git a/hn2016_falwa/compute_flux_dirinv.f90 b/hn2016_falwa/compute_flux_dirinv.f90 new file mode 100644 index 0000000..aeb09e6 --- /dev/null +++ b/hn2016_falwa/compute_flux_dirinv.f90 @@ -0,0 +1,240 @@ +SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fawa,ubar,tbar,& + imax, JMAX, kmax, nd, nnd, jb, jd,& + astarbaro,ubaro,urefbaro,ua1baro,ua2baro,ep1baro,ep2baro,ep3baro,ep4,astar1,astar2) + + INTEGER, INTENT(IN) :: imax, JMAX, kmax, nd, nnd, jb, jd + REAL, INTENT(IN) :: pv(imax,jmax,kmax),uu(imax,jmax,kmax),vv(imax,jmax,kmax),pt(imax,jmax,kmax),& + tn0(kmax),ts0(kmax),statn(kmax),stats(kmax),qref(nd,kmax),uref(jd,kmax),tref(jd,kmax),& + fawa(nd,kmax),ubar(nd,kmax),tbar(nd,kmax) + REAL, INTENT(OUT) :: astarbaro(imax,nd),ubaro(imax,nd),urefbaro(nd),ua1baro(imax,nd),ua2baro(imax,nd),& + ep1baro(imax,nd),ep2baro(imax,nd),ep3baro(imax,nd),ep4(imax,nd),astar1(imax,nd,kmax),astar2(imax,nd,kmax) + +! read(35) pv +! read(36) uu +! read(39) vv +! read(37) pt,tn0,ts0,statn,stats +! read(40) qref,uref,tref,fawa,ubar,tbar +! **** take QGPV and compute LWA and fluxes for +! NH *** +! Only barotropic fluxes are saved + + !integer,parameter :: imax = 360, JMAX = 181, KMAX = 97 + !integer,parameter :: nd = 91,nnd=181,jd = 86 + REAL :: tb(kmax),tg(kmax) + REAL :: ua1(imax,nd),ua2(imax,nd),ep1(imax,nd) + REAL :: ep2(imax,nd),ep3(imax,nd) + REAL :: qe(imax,nd),ue(imax,nd) + REAL :: z(kmax) + REAL :: u(nd,kmax) + !integer :: md(12) + +! character*35 fn,fn0,fn1 +! character*34 fu +! character*34 ft,fv +! character*38 fx +! character*4 fn2(12),fy,fy1,fy2 +! character*18 f1,f2 +! character*19 f3 +! character*36 fr +! character*37 fm + + a = 6378000. + pi = acos(-1.) + om = 7.29e-5 + dp = pi/180. + dz = 500. + h = 7000. + r = 287. + rkappa = r/1004. + + do k = 1,kmax + z(k) = dz*float(k-1) + enddo + +! do m = 2021,2021 + +! md(1) = 31 +! md(2) = 28 +! if(mod(m,4).eq.0) md(2) = 29 +! md(3) = 31 +! md(4) = 30 +! md(5) = 31 +! md(6) = 30 +! md(7) = 31 +! md(8) = 31 +! md(9) = 30 +! md(10) = 31 +! md(11) = 30 +! md(12) = 31 +! +! fn2(1) = '_01_' +! fn2(2) = '_02_' +! fn2(3) = '_03_' +! fn2(4) = '_04_' +! fn2(5) = '_05_' +! fn2(6) = '_06_' +! fn2(7) = '_07_' +! fn2(8) = '_08_' +! fn2(9) = '_09_' +! fn2(10) = '_10_' +! fn2(11) = '_11_' +! fn2(12) = '_12_' +! +! write(fy,266) m +! 266 format(i4) + +! do n = 10,10 +! fn = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGPV' +! fu = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGU' +! ft = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGT' +! fv = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGV' +! fx = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGREF_N' +! fr = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'LWA_N' +! fm = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'BARO_N' +! write(6,*) fn,md(n) +! open(35,file =fn, & +! form='unformatted',status = 'old') +! open(36,file =fu, & +! form='unformatted',status = 'old') +! open(37,file =ft, & +! form='unformatted',status = 'old') +! open(38,file =fr, & +! form='unformatted',status = 'new') +! open(39,file =fv, & +! form='unformatted',status = 'old') +! open(40,file =fx, & +! form='unformatted',status = 'old') +! open(41,file =fm, & +! form='unformatted',status = 'new') + +! do mm = 1,md(n)*4 + +! read(35) pv +! read(36) uu +! read(39) vv +! read(37) pt,tn0,ts0,statn,stats +! read(40) qref,uref,tref,fawa,ubar,tbar + + +! **** hemispheric-mean potential temperature **** + tg(:) = tn0(:) + +! **** wave activity and nonlinear zonal flux F2 **** + + astarbaro(:,:) = 0. + ubaro(:,:) = 0. + urefbaro(:) = 0. + ua1baro(:,:) = 0. + ua2baro(:,:) = 0. + ep1baro(:,:) = 0. + ep2baro(:,:) = 0. + ep3baro(:,:) = 0. + ep4(:,:) = 0. + dc = dz/6745.348 + + do k = 2,96 + zk = dz*float(k-1) + do i = 1,imax + do j = 6,nd-1 ! 5N and higher latitude + astar1(i,j,k) = 0. ! LWA*cos(phi) + astar2(i,j,k) = 0. ! LWA*cos(phi) + ua2(i,j) = 0. !F2 + phi0 = dp*float(j-1) !latitude + cor = 2.*om*sin(phi0) !Coriolis parameter + do jj = 1,nd + phi1 = dp*float(jj-1) + qe(i,jj) = pv(i,jj+90,k)-qref(j,k) !qe; Q = qref + ue(i,jj) = uu(i,jj+90,k)-uref(j-5,k) !ue; shift uref 5N + aa = a*dp*cos(phi1) !length element + if((qe(i,jj).le.0.).and.(jj.ge.j)) then !LWA*cos and F2 + astar2(i,j,k)=astar2(i,j,k)-qe(i,jj)*aa !anticyclonic + ua2(i,j) = ua2(i,j)-qe(i,jj)*ue(i,jj)*aa + endif + if((qe(i,jj).gt.0.).and.(jj.lt.j)) then + astar1(i,j,k)=astar1(i,j,k)+qe(i,jj)*aa !cyclonic + ua2(i,j) = ua2(i,j)+qe(i,jj)*ue(i,jj)*aa + endif + enddo + + ! ******** Other fluxes ****** + + ua1(i,j) = uref(j-5,k)*(astar1(i,j,k) + & + astar2(i,j,k)) !F1 + ep1(i,j) = -0.5*(uu(i,j+90,k)-uref(j-5,k))**2 !F3a + ep1(i,j) = ep1(i,j)+0.5*vv(i,j+90,k)**2 !F3a+b + ep11 = 0.5*(pt(i,j+90,k)-tref(j-5,k))**2 !F3c + zz = dz*float(k-1) + ep11 = ep11*(r/h)*exp(-rkappa*zz/h) + ep11 = ep11*2.*dz/(tg(k+1)-tg(k-1)) + ep1(i,j) = ep1(i,j)-ep11 !F3 + phip = dp*float(j) + cosp = cos(phip) ! cosine for one grid north + phi0 = dp*float(j-1) + cos0 = cos(phi0) ! cosine for latitude grid + sin0 = sin(phi0) ! sine for latitude grid + phim = dp*float(j-2) + cosm = cos(phim) ! cosine for one grid south + ep1(i,j) = ep1(i,j)*cos0 ! correct for cosine factor + + + ! meridional eddy momentum flux one grid north and south + ep2(i,j)=(uu(i,j+91,k)-uref(j-5,k))*vv(i,j+91,k)*cosp*cosp + ep3(i,j)=(uu(i,j+89,k)-uref(j-5,k))*vv(i,j+89,k)*cosm*cosm + + ! low-level meridional eddy heat flux + if(k.eq.2) then ! (26) of SI-HN17 + ep41 = 2.*om*sin0*cos0*dz/6745.348 ! prefactor + ep42 = exp(-dz/h)*vv(i,j+90,2)*(pt(i,j+90,2)-tref(j-5,2)) + ep42 = ep42/(tg(3)-tg(1)) + ep43 = vv(i,j+90,1)*(pt(i,j+90,1)-tref(j-5,1)) + ep43 = 0.5*ep43/(tg(2)-tg(1)) + ep4(i,j) = ep41*(ep42+ep43) ! low-level heat flux + endif + enddo + enddo + + ! ******** Column average: (25) of SI-HN17 ******** + + astarbaro(:,:) = astarbaro(:,:)+(astar1(:,:,k) & + + astar2(:,:,k))*exp(-zk/h)*dc + ua1baro(:,:) = ua1baro(:,:)+ua1(:,:)*exp(-zk/h)*dc + ua2baro(:,:) = ua2baro(:,:)+ua2(:,:)*exp(-zk/h)*dc + ep1baro(:,:) = ep1baro(:,:)+ep1(:,:)*exp(-zk/h)*dc + ep2baro(:,:) = ep2baro(:,:)+ep2(:,:)*exp(-zk/h)*dc + ep3baro(:,:) = ep3baro(:,:)+ep3(:,:)*exp(-zk/h)*dc + do j = 6,nd ! ### yet to be multiplied by cosine + ubaro(:,j) = ubaro(:,j)+uu(:,j+90,k)*exp(-zk/h)*dc + urefbaro(j) = urefbaro(j)+uref(j-5,k)*exp(-zk/h)*dc + enddo + enddo + + +! write(6,*) dh + +! write(41) astarbaro,ubaro,urefbaro,ua1baro,ua2baro,ep1baro,& +! ep2baro,& +! ep3baro,ep4 +! +! write(38) astar1,astar2 + +! ******************************** + + +! write(6,*) fy,n,mm + +! ******************************** +! enddo + +! close(35) +! close(36) +! close(37) +! close(38) +! close(39) +! close(40) +! close(41) + +! enddo +! enddo + + +END SUBROUTINE diff --git a/hn2016_falwa/compute_qref_and_fawa_first.f90 b/hn2016_falwa/compute_qref_and_fawa_first.f90 new file mode 100644 index 0000000..0cb109e --- /dev/null +++ b/hn2016_falwa/compute_qref_and_fawa_first.f90 @@ -0,0 +1,460 @@ +SUBROUTINE compute_qref_and_fawa_first(pv, uu, vort, pt, tn0, ts0, statn, stats, imax, JMAX, kmax, nd, nnd, jb, jd, & + qref,u,tref,ubar,tbar,fawa,ckref,tjk,sjk) + + + !USE mkl95_LAPACK, ONLY: GETRF,GETRI + + INTEGER, INTENT(IN) :: imax, JMAX, kmax, nd, nnd, jb, jd + REAL, INTENT(IN) :: pv(imax,jmax,kmax),uu(imax,jmax,kmax),vort(imax,jmax,kmax),pt(imax,jmax,kmax),& + stats(kmax),statn(kmax),ts0(kmax),tn0(kmax) + REAL, INTENT(OUT) :: qref(nd,kmax),u(jd,kmax),tref(jd,kmax),ubar(nd,kmax),tbar(nd,kmax),fawa(nd,kmax),ckref(nd,kmax),& + tjk(jd-2,kmax-1),sjk(jd-2,jd-2,kmax-1) + + ! **** take QG analysis and compute Q_ref and invert for U_ref & Theta_ref for NH (Direct solver) *** + + !integer,parameter :: imax = 360, JMAX = 181, KMAX = 97 + !integer,parameter :: nd = 91,nnd=181 + !integer,parameter :: jb = 5 ! lower bounding latitude + !integer,parameter :: jd = 86 ! nd - lower bounding latitude + + REAL :: pv2(imax,jmax) + REAL :: vort2(imax,jmax) + REAL :: qn(nnd),an(nnd),aan(nnd),tb(kmax),tg(kmax) + REAL :: cn(nnd),ccn(nnd),cref(nd,kmax) + REAL :: alat(nd),phi(nd),z(kmax),cbar(nd,kmax) + REAL :: tj(jd-2),rj(jd-2) + REAL :: qjj(jd-2,jd-2),cjj(jd-2,jd-2) + REAL :: xjj(jd-2,jd-2),yj(jd-2) + REAL :: djj(jd-2,jd-2),sjj(jd-2,jd-2) + REAL :: pjk(jd-2,kmax),pj(jd-2) + REAL :: qbar(nd,kmax) + !integer :: md(12),ipiv(jd-2) + + character*35 fn,fn0,fn1 + character*34 fu + character*34 ft + character*4 fn2(12),fy,fy1,fy2 + character*18 f1,f2 + character*19 f3 + character*36 fv + character*38 fr + + a = 6378000. + pi = acos(-1.) + om = 7.29e-5 + dp = pi/180. + dz = 500. + h = 7000. + r = 287. + rkappa = r/1004. + + do nn = 1,nd + phi(nn) = dp*float(nn-1) + alat(nn) = 2.*pi*a*a*(1.-sin(phi(nn))) + enddo + + do k = 1,kmax + z(k) = dz*float(k-1) + enddo + +! do m = 2021,2021 +! +! md(1) = 31 +! md(2) = 28 +! if(mod(m,4).eq.0) md(2) = 29 +! md(3) = 31 +! md(4) = 30 +! md(5) = 31 +! md(6) = 30 +! md(7) = 31 +! md(8) = 31 +! md(9) = 30 +! md(10) = 31 +! md(11) = 30 +! md(12) = 31 +! +! fn2(1) = '_01_' +! fn2(2) = '_02_' +! fn2(3) = '_03_' +! fn2(4) = '_04_' +! fn2(5) = '_05_' +! fn2(6) = '_06_' +! fn2(7) = '_07_' +! fn2(8) = '_08_' +! fn2(9) = '_09_' +! fn2(10) = '_10_' +! fn2(11) = '_11_' +! fn2(12) = '_12_' +! +! write(fy,266) m +! 266 format(i4) +! +! do n = 10,10 +! fn = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGPV' +! fu = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGU' +! ft = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGT' +! fr = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGREF_N' +! fv = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QVORT' +! write(6,*) fn,md(n) +! open(35,file =fn, & +! form='unformatted',status = 'old') +! open(36,file =fu, & +! form='unformatted',status = 'old') +! open(37,file =ft, & +! form='unformatted',status = 'old') +! open(38,file =fr, & +! form='unformatted',status = 'new') +! open(39,file =fv, & +! form='unformatted',status = 'old') + ! ********************** Analysis starts here ********************** +! do mm = 1,md(n)*4 + +! read(35) pv +! read(36) uu +! read(39) vort +! read(37) pt,tn0,ts0,statn,stats + + ! **** Zonal-mean field **** + do j = 91,jmax + qbar(j-90,:) = 0. + tbar(j-90,:) = 0. + ubar(j-90,:) = 0. + do i = 1,imax + qbar(j-90,:) = qbar(j-90,:)+pv(i,j,:)/float(imax) + tbar(j-90,:) = tbar(j-90,:)+pt(i,j,:)/float(imax) + ubar(j-90,:) = ubar(j-90,:)+uu(i,j,:)/float(imax) + enddo + enddo + + ! **** hemispheric-mean potential temperature **** + tb(:) = tn0(:) + + do k = 2,kmax-1 + pv2(:,:) = pv(:,:,k) + vort2(:,:) = vort(:,:,k) + + ! **** compute qref via area analysis **** + qmax = maxval(pv2) + qmin = minval(pv2) + dq = (qmax-qmin)/float(nnd-1) + qn(:) = 0. + an(:) = 0. + cn(:) = 0. + do nn = 1,nnd + qn(nn) = qmax - dq*float(nn-1) + enddo + do j = 1,jmax + phi0 = -0.5*pi+dp*float(j-1) + do i = 1,imax + ind = 1+int((qmax-pv2(i,j))/dq) + da = a*a*dp*dp*cos(phi0) + an(ind) = an(ind) + da + cn(ind) = cn(ind) + da*pv2(i,j) + enddo + enddo + aan(1) = 0. + ccn(1) = 0. + do nn = 2,nnd + aan(nn) = aan(nn-1)+an(nn) + ccn(nn) = ccn(nn-1)+cn(nn) + enddo + do j = 1,nd-1 + do nn = 1,nnd-1 + if(aan(nn).le.alat(j).and.aan(nn+1).gt.alat(j)) then + dd = (alat(j)-aan(nn))/(aan(nn+1)-aan(nn)) + qref(j,k) = qn(nn)*(1.-dd)+qn(nn+1)*dd + cref(j,k) = ccn(nn)*(1.-dd)+ccn(nn+1)*dd + endif + enddo + enddo + + qref(nd,k) = qmax + + cbar(nd,k) = 0. + do j=nd-1,1,-1 + phi0 = dp*(float(j)-0.5) + cbar(j,k) = cbar(j+1,k)+0.5*(qbar(j+1,k)+qbar(j,k)) & + *a*dp*2.*pi*a*cos(phi0) + enddo + + ! **** compute Kelvin's circulation based on absolute vorticity (for b.c.) **** + + + qmax = maxval(vort2) + qmin = minval(vort2) + dq = (qmax-qmin)/float(nnd-1) + qn(:) = 0. + an(:) = 0. + cn(:) = 0. + do nn = 1,nnd + qn(nn) = qmax - dq*float(nn-1) + enddo + do j = 1,jmax + phi0 = -0.5*pi+dp*float(j-1) + do i = 1,imax + ind = 1+int((qmax-vort2(i,j))/dq) + da = a*a*dp*dp*cos(phi0) + an(ind) = an(ind) + da + cn(ind) = cn(ind) + da*vort2(i,j) + enddo + enddo + aan(1) = 0. + ccn(1) = 0. + do nn = 2,nnd + aan(nn) = aan(nn-1)+an(nn) + ccn(nn) = ccn(nn-1)+cn(nn) + enddo + do j = 1,nd-1 + do nn = 1,nnd-1 + if(aan(nn).le.alat(j).and.aan(nn+1).gt.alat(j)) then + dd = (alat(j)-aan(nn))/(aan(nn+1)-aan(nn)) + ckref(j,k) = ccn(nn)*(1.-dd)+ccn(nn+1)*dd + endif + enddo + enddo + + enddo + + ! ***** normalize QGPV by sine (latitude) **** + + do j = 2,nd + phi0 = dp*float(j-1) + cor = sin(phi0) + qref(j,:) = qref(j,:)/cor + enddo + + do k = 2,kmax-1 + qref(1,k) = 2.*qref(2,k)-qref(3,k) + enddo + + ! ***** FAWA ***** + fawa(:,:) = (cref(:,:)-cbar(:,:))/(2.*pi*a) + + ! ***** Direct solver to invert Q_ref ***** + + ! *** downward sweep *** + + ! **** top boundary condition (Eqs. 24-25) ***** + tjk(:,:) = 0. + sjk(:,:,:) = 0. + do jj = jb+2,90 + j = jj-jb + phi0 = float(jj-1)*dp + cos0 = cos(phi0) + sin0 = sin(phi0) + tjk(j-1,kmax-1) = -dz*r*cos0*exp(-z(kmax-1)*rkappa/h) + tjk(j-1,kmax-1) = tjk(j-1,kmax-1)*(tbar(j+1,kmax)-tbar(j-1,kmax)) + tjk(j-1,kmax-1) = tjk(j-1,kmax-1)/(4.*om*sin0*dp*h*a) + sjk(j-1,j-1,kmax-1) = 1. + enddo +! *** REFACTOR: COMMENT OUT ALL BELOW *** +! ! **** Evaluate Eqs. 22-23 downward *** +! +! do k = kmax-1,2,-1 +! zp = 0.5*(z(k+1)+z(k)) +! zm = 0.5*(z(k-1)+z(k)) +! statp = 0.5*(statn(k+1)+statn(k)) +! statm = 0.5*(statn(k-1)+statn(k)) +! cjj(:,:) = 0. +! djj(:,:) = 0. +! qjj(:,:) = 0. +! sjj(:,:) = sjk(:,:,k) +! tj(:) = tjk(:,k) +! do jj = jb+2,90 +! j = jj - jb +! phi0 = float(jj-1)*dp +! phip = (float(jj)-0.5)*dp +! phim = (float(jj)-1.5)*dp +! cos0 = cos(phi0) +! cosp = cos(phip) +! cosm = cos(phim) +! sin0 = sin(phi0) +! sinp = sin(phip) +! sinm = sin(phim) +! +! fact = 4.*om*om*h*a*a*sin0*dp*dp/(dz*dz*r*cos0) +! amp = exp(-zp/h)*exp(rkappa*zp/h)/statp +! amp = amp*fact*exp(z(k)/h) +! amm = exp(-zm/h)*exp(rkappa*zm/h)/statm +! amm = amm*fact*exp(z(k)/h) +! +! ! ***** Specify A, B, C, D, E, F (Eqs. 4-9) ***** +! ajk = 1./(sinp*cosp) +! bjk = 1./(sinm*cosm) +! cjk = amp +! djk = amm +! ejk = ajk+bjk+cjk+djk +! fjk = -0.5*a*dp*(qref(jj+1,k)-qref(jj-1,k)) +! +! ! ***** Specify rk (Eq. 15) **** +! +! ! **** North-south boundary conditions **** +! u(jd,k) = 0. +! phi0 = dp*float(jb) +! ! u(1,k) = ubar(jb+1,k)*cos(phi0) +! u(1,k) = ckref(jb+1,k)/(2.*pi*a)-om*a*cos(phi0) +! +! rj(j-1) = fjk +! if(j.eq.2) rj(j-1) = fjk - bjk*u(1,k) +! if(j.eq.jd-1) rj(j-1) = fjk - ajk*u(jd,k) +! +! ! ***** Specify Ck & Dk (Eqs. 18-19) ***** +! cjj(j-1,j-1) = cjk +! djj(j-1,j-1) = djk +! +! ! **** Specify Qk (Eq. 17) ***** +! qjj(j-1,j-1) = -ejk +! if(j-1.ge.1.and.j-1.lt.jd-2) then +! qjj(j-1,j) = ajk +! endif +! if(j-1.gt.1.and.j-1.le.jd-2) then +! qjj(j-1,j-2) = bjk +! endif +! enddo +! +! ! **** Compute Qk + Ck Sk ******* +! do i = 1,jd-2 +! do j = 1,jd-2 +! xjj(i,j) = 0. +! do kk = 1,jd-2 +! xjj(i,j) = xjj(i,j)+cjj(i,kk)*sjj(kk,j) +! enddo +! qjj(i,j) = qjj(i,j)+xjj(i,j) +! enddo +! enddo +! ! call gemm(cjj,sjj,xjj) +! ! qjj(:,:) = qjj(:,:)+xjj(:,:) +! +! ! **** Invert (Qk + Ck Sk) ******** +! call getrf(qjj,ipiv) +! call getri(qjj,ipiv) +! +! ! **** Evaluate Eq. 22 **** +! do i = 1,jd-2 +! do j = 1,jd-2 +! xjj(i,j) = 0. +! do kk = 1,jd-2 +! xjj(i,j) = xjj(i,j)+qjj(i,kk)*djj(kk,j) +! enddo +! sjk(i,j,k-1) = -xjj(i,j) +! enddo +! enddo +! +! ! call gemm(qjj,djj,xjj) +! ! sjk(:,:,k-1) = -xjj(:,:) +! +! ! **** Evaluate rk - Ck Tk **** +! do i = 1,jd-2 +! yj(i) = 0. +! do kk = 1,jd-2 +! yj(i) = yj(i)+cjj(i,kk)*tj(kk) +! enddo +! yj(i) = rj(i)-yj(i) +! enddo +! +! ! call gemv(cjj,tj,yj) +! ! yj(:) = rj(:)-yj(:) +! ! call gemv(qjj,yj,tj) +! ! tjk(:,k-1) = tj(:) +! +! +! ! ***** Evaluate Eq. 23 ******* +! do i = 1,jd-2 +! tj(i) = 0. +! do kk = 1,jd-2 +! tj(i) = tj(i)+qjj(i,kk)*yj(kk) +! enddo +! tjk(i,k-1) = tj(i) +! enddo +! +! enddo +! +! ! ***** upward sweep (Eq. 20) **** +! +! pjk(:,1) = 0. +! do k = 1,kmax-1 +! pj(:) = pjk(:,k) +! sjj(:,:) = sjk(:,:,k) +! tj(:) = tjk(:,k) +! +! do i = 1,jd-2 +! yj(i) = 0. +! do kk = 1,jd-2 +! yj(i) = yj(i)+sjj(i,kk)*pj(kk) +! enddo +! pjk(i,k+1) = yj(i)+tj(i) +! enddo +! ! call gemv(sjj,pj,yj) +! ! pjk(:,k+1) = yj(:) + tj(:) +! enddo +! +! ! **** Recover u ***** +! do k = 1,kmax +! do j = 2,jd-1 +! u(j,k) = pjk(j-1,k) +! enddo +! enddo +! +! ! *** Corner boundary conditions *** +! u(1,1) = 0. +! u(jd,1) = 0. +! ! u(1,kmax) = ubar(1+jb,kmax)*cos(dp*float(jb)) +! u(1,kmax) = ckref(1+jb,kmax)/(2.*pi*a)-om*a*cos(dp*float(jb)) +! u(jd,kmax) = 0. +! +! ! *** Divide by cos phi to revover Uref **** +! do jj = jb+1,nd-1 +! j = jj-jb +! phi0 = dp*float(jj-1) +! u(j,:) = u(j,:)/cos(phi0) +! enddo +! u(jd,:) = 2.*u(jd-1,:)-u(jd-2,:) +! +! ! ******** compute tref ******* +! +! do k = 2,96 +! t00 = 0. +! zz = dz*float(k-1) +! tref(1,k) = t00 +! tref(2,k) = t00 +! do j = 2,jd-1 +! phi0 = dp*float(j-1) +! cor = 2.*om*sin(phi0) +! uz = (u(j,k+1)-u(j,k-1))/(2.*dz) +! ty = -cor*uz*a*h*exp(rkappa*zz/h) +! ty = ty/r +! tref(j+1,k) = tref(j-1,k)+2.*ty*dp +! qref(j-1,k) = qref(j-1,k)*sin(phi0) +! enddo +! tg(k) = 0. +! wt = 0. +! do jj = 6,91 +! j = jj-5 +! phi0 = dp*float(jj-1) +! tg(k) = tg(k)+cos(phi0)*tref(j,k) +! wt = wt + cos(phi0) +! enddo +! tg(k) = tg(k)/wt +! tres = tb(k)-tg(k) +! tref(:,k) = tref(:,k)+tres +! enddo +! tref(:,1) = tref(:,2)-tb(2)+tb(1) +! tref(:,97) = tref(:,96)-tb(96)+tb(97) +! +! write(38) qref,u,tref,fawa,ubar,tbar +! +! write(6,*) m,n,mm +! +! ! ******************************** +! enddo +! +! close(35) +! close(36) +! close(37) +! close(38) +! ! ********************** Analysis ends here ********************** +! enddo +! enddo +! +! stop +END diff --git a/hn2016_falwa/interpolate_fields.f90 b/hn2016_falwa/interpolate_fields.f90 index 9e6a625..b42f3c2 100644 --- a/hn2016_falwa/interpolate_fields.f90 +++ b/hn2016_falwa/interpolate_fields.f90 @@ -1,12 +1,12 @@ SUBROUTINE interpolate_fields(nlon, nlat, nlev, kmax, uu, vv, temp, plev, height, & - aa, omega, dz, hh, rr, cp, pv, ut, vt, theta, stat) + aa, omega, dz, hh, rr, cp, pv, ut, vt, avort, theta, stat) INTEGER, INTENT(IN) :: nlon, nlat, nlev, kmax REAL, INTENT(IN) :: uu(nlon,nlat,nlev), vv(nlon,nlat,nlev), temp(nlon,nlat,nlev), & plev(nlev), height(kmax) REAL, INTENT(in) :: aa, omega, dz,hh, rr, cp - REAL, INTENT(out) :: pv(nlon,nlat,kmax), ut(nlon,nlat,kmax), vt(nlon,nlat,kmax) + REAL, INTENT(out) :: pv(nlon,nlat,kmax), ut(nlon,nlat,kmax), vt(nlon,nlat,kmax), avort(nlon,nlat,kmax) REAL, INTENT(out) :: theta(nlon,nlat,kmax), stat(kmax) @@ -18,7 +18,7 @@ SUBROUTINE interpolate_fields(nlon, nlat, nlev, kmax, uu, vv, temp, plev, height REAL :: xlon(nlon),ylat(nlat) REAL :: t0(kmax),zlev(nlev) REAL :: st(nlon,nlat),zmst(nlat) - REAL :: avort(nlon,nlat,kmax),zmav(nlat,kmax) + REAL :: zmav(nlat,kmax) REAL :: zmpv(nlat,kmax) REAL :: rkappa, pi, dphi diff --git a/hn2016_falwa/interpolate_fields_dirinv.f90 b/hn2016_falwa/interpolate_fields_dirinv.f90 new file mode 100644 index 0000000..4da1a16 --- /dev/null +++ b/hn2016_falwa/interpolate_fields_dirinv.f90 @@ -0,0 +1,232 @@ +SUBROUTINE interpolate_fields_direct_inv(nlon, nlat, nlev, kmax, jd, uu, vv, tt, plev, & + aa, omega, dz, hh, rr, cp, & + pv, uq, vq, avort, tq, statn, stats, tn0, ts0) + + + INTEGER, INTENT(IN) :: nlon, nlat, nlev, kmax + REAL, INTENT(IN) :: uu(nlon,nlat,nlev), vv(nlon,nlat,nlev), tt(nlon,nlat,nlev), & + plev(nlev) + REAL, INTENT(in) :: aa, omega, dz,hh, rr, cp + REAL, INTENT(out) :: pv(nlon,nlat,kmax), uq(nlon,nlat,kmax), vq(nlon,nlat,kmax), avort(nlon,nlat,kmax) + REAL, INTENT(out) :: tq(nlon,nlat,kmax), statn(kmax), stats(kmax), tn0(kmax), ts0(kmax) + + real :: tzd(nlat,kmax) + real :: xlon(nlon),ylat(nlat) + real :: height(kmax) + real :: zlev(nlev) + real :: st(nlon,nlat),zmst(nlat) + real :: tt0(nlon,nlat,kmax) + real :: zmav(nlat,kmax) + real :: zmpv(nlat,kmax) + integer :: dsadata,mm(12),inverse(12,nlev) + integer :: k0(kmax),kp(kmax) + real :: dd2(kmax),dd1(kmax),pks(kmax) + character*5 :: yy + character*4 :: y0(44),y00 + character*3 :: mn(12) + character*8 :: yr + +! dz = 500. +! cp = 1004. +! rr = 287. + rkappa = rr/cp + pi = acos(-1.) +! omega = 7.29e-5 +! aa = 6378000. + dphi = pi/float(nlat-1) +! hh = 7000. + +! ====== Assign pseudoheight ===== + + do k = 1,kmax + height(k) = float(k-1)*dz + pks(k) = exp(rkappa*height(k)/hh) + enddo + + do k = 1,nlev + zlev(k) = -hh*alog(plev(k)/1000.) + enddo + + do kk = 2,kmax ! vertical interpolation + ttt = height(kk) + do k = 1,nlev-1 + tt2 = zlev(k+1) + tt1 = zlev(k) + if((ttt.ge.tt1).and.(ttt.lt.tt2)) then + k0(kk) = k + kp(kk) = k+1 + dd1(kk) = (ttt-tt1)/(tt2-tt1) + dd2(kk) = 1.-dd1(kk) + endif + enddo + enddo + +! ==== vertical interpolation ==== + + do i = 1,nlon + do j = 1,nlat + + st(i,j) = tt(i,j,1) ! surface pot. temp + + do kk = 2,kmax ! vertical interpolation + uq(i,j,kk) = uu(i,j,k0(kk))*dd2(kk) + uu(i,j,kp(kk))*dd1(kk) + vq(i,j,kk) = vv(i,j,k0(kk))*dd2(kk) + vv(i,j,kp(kk))*dd1(kk) + ! wq(i,j,kk) = ww(i,j,k0(kk))*dd2(kk) + ww(i,j,kp(kk))*dd1(kk) + tq(i,j,kk) = tt(i,j,k0(kk))*dd2(kk) + tt(i,j,kp(kk))*dd1(kk) + tq(i,j,kk) = tq(i,j,kk)*pks(kk) ! potential temperature + ! zq(i,j,kk) = zz(i,j,k0(kk))*dd2(kk) + zz(i,j,kp(kk))*dd1(kk) + enddo + + tq(i,j,1) = tt(i,j,1) + uq(i,j,1) = uu(i,j,1) + vq(i,j,1) = vv(i,j,1) + ! wq(i,j,1) = ww(i,j,1) + ! zq(i,j,1) = zz(i,j,1) + enddo + enddo + +! **** compute zonal mean **** + + tzd = 0. + + do j = 1,nlat + do k = 1,kmax + do i = 1,nlon + tzd(j,k) = tzd(j,k) + tq(i,j,k)/float(nlon) + enddo + enddo + enddo + + + ! reference theta + do kk = 1,kmax + ts0(kk) = 0. + tn0(kk) = 0. + csm = 0. + cnm = 0. + do j = 1,jd + phi0 = -90.+float(j-1) + phi0 = phi0*pi/float(nlat-1) + ts0(kk) = ts0(kk) + tzd(j,kk)*cos(phi0) + csm = csm + cos(phi0) + enddo + ts0(kk) = ts0(kk)/csm + do j = jd,nlat + phi0 = -90.+float(j-1) + phi0 = phi0*pi/float(nlat-1) + tn0(kk) = tn0(kk) + tzd(j,kk)*cos(phi0) + cnm = cnm + cos(phi0) + enddo + tn0(kk) = tn0(kk)/cnm + enddo + + ! static stability + do kk = 2,kmax-1 + stats(kk) = (ts0(kk+1)-ts0(kk-1))/(height(kk+1)-height(kk-1)) + statn(kk) = (tn0(kk+1)-tn0(kk-1))/(height(kk+1)-height(kk-1)) + enddo + stats(kmax) = 2.*stats(kmax-1)-stats(kmax-2) + statn(kmax) = 2.*statn(kmax-1)-statn(kmax-2) + stats(1) = 2.*stats(2)-stats(3) + statn(1) = 2.*statn(2)-statn(3) + + ! surface temp + + do j = 1,nlat + zmst(j) = 0. + do i = 1,nlon + zmst(j) = zmst(j) + st(i,j)/float(nlon) + enddo + enddo + +! interior abs. vort + + do kk = 1,kmax + do j = 2,nlat-1 + phi0 = -90.+float(j-1) + phi0 = phi0*pi/float(nlat-1) + phim = -90.+float(j-2) + phim = phim*pi/float(nlat-1) + phip = -90.+float(j) + phip = phip*pi/float(nlat-1) + + do i = 2,359 + av1 = 2.*omega*sin(phi0) + av2 = (vq(i+1,j,kk)-vq(i-1,j,kk))/(2.*aa*cos(phi0)*dphi) + av3 = -(uq(i,j+1,kk)*cos(phip)-uq(i,j-1,kk)*cos(phim))/(2.*aa*cos(phi0)*dphi) + avort(i,j,kk) = av1+av2+av3 + enddo + + av1 = 2.*omega*sin(phi0) + av2 = (vq(2,j,kk)-vq(nlon,j,kk))/(2.*aa*cos(phi0)*dphi) + av3 = -(uq(1,j+1,kk)*cos(phip)-uq(1,j-1,kk)*cos(phim))/(2.*aa*cos(phi0)*dphi) + avort(1,j,kk) = av1+av2+av3 + av4 = 2.*omega*sin(phi0) + av5 = (vq(1,j,kk)-vq(359,j,kk))/(2.*aa*cos(phi0)*dphi) + av6 = & + -(uq(nlon,j+1,kk)*cos(phip)-uq(nlon,j-1,kk)*cos(phim))/(2.*aa*cos(phi0)*dphi) + avort(nlon,j,kk) = av4+av5+av6 + enddo + + avs = 0. + avn = 0. + do i = 1,nlon + avs = avs + avort(i,2,kk)/float(nlon) + avn = avn + avort(i,nlat-1,kk)/float(nlon) + enddo + avort(:,1,kk) = avs + avort(:,nlat,kk) = avn + enddo + + ! zonal mean vort + + do kk = 1,kmax + do j = 1,nlat + zmav(j,kk) = 0. + do i = 1,nlon + zmav(j,kk) = zmav(j,kk)+avort(i,j,kk)/float(nlon) + enddo + enddo + enddo + + ! interior pv + + do kk = 2,kmax-1 + do j = 1,nlat + phi0 = -90.+float(j-1) + phi0 = phi0*pi/float(nlat-1) + f = 2.*omega*sin(phi0) + if (j .le. jd) then + statp = stats(kk+1) + statm = stats(kk-1) + t00p = ts0(kk+1) + t00m = ts0(kk-1) + else + statp = statn(kk+1) + statm = statn(kk-1) + t00p = tn0(kk+1) + t00m = tn0(kk-1) + endif + + do i = 1,nlon + thetap = tq(i,j,kk+1) + thetam = tq(i,j,kk-1) + altp = exp(-height(kk+1)/hh)*(thetap-t00p)/statp + altm = exp(-height(kk-1)/hh)*(thetam-t00m)/statm + strc = (altp-altm)*f/(height(kk+1)-height(kk-1)) + pv(i,j,kk) = avort(i,j,kk) + exp(height(kk)/hh)*strc + enddo + enddo + enddo + +! zonal mean pv + + do kk = 1,kmax + do j = 1,nlat + zmpv(j,kk) = 0. + do i = 1,nlon + zmpv(j,kk) = zmpv(j,kk)+pv(i,j,kk)/float(nlon) + enddo + enddo + enddo +END SUBROUTINE diff --git a/hn2016_falwa/inversion_refactored.f90 b/hn2016_falwa/inversion_refactored.f90 new file mode 100644 index 0000000..aa46c0c --- /dev/null +++ b/hn2016_falwa/inversion_refactored.f90 @@ -0,0 +1,428 @@ +SUBROUTINE direct_solver_b4_lu_fact(tjk,sjk,qref,ubar,tbar,fawa,ckref,statn,tn0,imax,JMAX,KMAX,nd,jb,jd,& + a, om, dz, h, rr, cp, & + tref) + +! USE mkl95_BLAS, ONLY: GEMM,GEMV + !USE mkl95_LAPACK, ONLY: GETRF,GETRI + integer, INTENT(in) :: imax, JMAX, KMAX, nd, jb, jd + REAL, INTENT(in) :: tjk(jd-2,kmax-1),sjk(jd-2,jd-2,kmax-1),qref(jd,kmax), ubar(nd,kmax), & + tbar(nd,kmax),fawa(nd,kmax),ckref(nd,kmax),statn(kmax),tn0(kmax) + REAL, INTENT(in) :: a, om, dz,h, rr, cp + REAL, INTENT(out) :: tref(jd,kmax) + +! **** take QG analysis and compute Q_ref and invert for +! U_ref & Theta_ref for NH *** + + !integer,parameter :: imax = 360, JMAX = 181, KMAX = 97 + !integer,parameter :: nd = 91, nnd=181 + !integer,parameter :: jb = 5 ! lower bounding latitude + !integer,parameter :: jd = 86 ! nd - lower bounding latitude + !common /array/ pv(imax,jmax,kmax),pv2(imax,jmax) + !common /brray/ uu(imax,jmax,kmax) + !common /bcray/ pt(imax,jmax,kmax) + !common /bdray/ stats(kmax),ts0(kmax) + !common /crray/ qn(nnd),an(nnd),aan(nnd) + real :: tb(kmax),tg(kmax) + !common /drray/ cn(nnd),ccn(nnd),cbar(nd,kmax) + real :: alat(nd),phi(nd),z(kmax) + real :: tj(jd-2),rj(jd-2) + real :: qjj(jd-2,jd-2),cjj(jd-2,jd-2),qjj_k(jd-2,jd-2,kmax),djj_k(jd-2,jd-2,kmax) + real :: xjj(jd-2,jd-2),yj(jd-2) + real :: djj(jd-2,jd-2),sjj(jd-2,jd-2) + real :: pjk(jd-2,kmax),pj(jd-2) + real :: u(jd,kmax),cref(nd,kmax) + !real :: fawa(nd,kmax) + !real :: qbar(nd,kmax) + integer :: md(12),ipiv(jd-2),nnd + +! character*34 fn,fn0,fn1 +! character*33 fu +! character*33 ft +! character*4 fn2(12),fy,fy1,fy2 +! character*18 f1,f2 +! character*19 f3 +! character*35 fr + + nnd = JMAX + !a = 6378000. + pi = acos(-1.) + !om = 7.29e-5 + dp = pi/180. + !dz = 500. + !h = 7000. + !r = 287. + rkappa = r/cp + + do nn = 1,nd + phi(nn) = dp*float(nn-1) + alat(nn) = 2.*pi*a*a*(1.-sin(phi(nn))) + enddo + + do k = 1,kmax + z(k) = dz*float(k-1) + enddo + +! do m = 2021,2021 +! +! md(1) = 31 +! md(2) = 28 +! if(mod(m,4).eq.0) md(2) = 29 +! md(3) = 31 +! md(4) = 30 +! md(5) = 31 +! md(6) = 30 +! md(7) = 31 +! md(8) = 31 +! md(9) = 30 +! md(10) = 31 +! md(11) = 30 +! md(12) = 31 +! +! fn2(1) = '_01_' +! fn2(2) = '_02_' +! fn2(3) = '_03_' +! fn2(4) = '_04_' +! fn2(5) = '_05_' +! fn2(6) = '_06_' +! fn2(7) = '_07_' +! fn2(8) = '_08_' +! fn2(9) = '_09_' +! fn2(10) = '_10_' +! fn2(11) = '_11_' +! fn2(12) = '_12_' +! +! write(fy,266) m +! 266 format(i4) + +! do n = 1,1 +! fn = '/data/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGPV' +! fu = '/data/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGU' +! ft = '/data/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGT' +! fr = '/data/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGREF' +! write(6,*) fn,md(n) +! open(35,file =fn, & +! form='unformatted',status = 'old') +! open(36,file =fu, & +! form='unformatted',status = 'old') +! open(37,file =ft, & +! form='unformatted',status = 'old') +! open(38,file =fr, & +! form='unformatted',status = 'new') + +! do mm = 1,md(n)*4 +! +! read(35) pv +! read(36) uu +! read(37) pt,tn0,ts0,statn,stats + +! **** Zonal-mean field **** +! do j = 91,jmax +! qbar(j-90,:) = 0. +! tbar(j-90,:) = 0. +! ubar(j-90,:) = 0. +! do i = 1,imax +! qbar(j-90,:) = qbar(j-90,:)+pv(i,j,:)/float(imax) +! tbar(j-90,:) = tbar(j-90,:)+pt(i,j,:)/float(imax) +! ubar(j-90,:) = ubar(j-90,:)+uu(i,j,:)/float(imax) +! enddo +! enddo + +! **** hemispheric-mean potential temperature **** + tb(:) = tn0(:) + +! do k = 2,96 +! pv2(:,:) = pv(:,:,k) +! +!! **** compute qref via area analysis **** +! qmax = maxval(pv2) +! qmin = minval(pv2) +! dq = (qmax-qmin)/float(nnd-1) +! qn(:) = 0. +! an(:) = 0. +! cn(:) = 0. +! do nn = 1,nnd +! qn(nn) = qmax - dq*float(nn-1) +! enddo +! do j = 1,jmax +! phi0 = -0.5*pi+dp*float(j-1) +! do i = 1,imax +! ind = 1+int((qmax-pv2(i,j))/dq) +! da = a*a*dp*dp*cos(phi0) +! an(ind) = an(ind) + da +! cn(ind) = cn(ind) + da*pv2(i,j) +! enddo +! enddo +! aan(1) = 0. +! ccn(1) = 0. +! do nn = 2,nnd +! aan(nn) = aan(nn-1)+an(nn) +! ccn(nn) = ccn(nn-1)+cn(nn) +! enddo +! do j = 1,nd-1 +! do nn = 1,nnd-1 +! if(aan(nn).le.alat(j).and.aan(nn+1).gt.alat(j)) then +! dd = (alat(j)-aan(nn))/(aan(nn+1)-aan(nn)) +! qref(j,k) = qn(nn)*(1.-dd)+qn(nn+1)*dd +! cref(j,k) = ccn(nn)*(1.-dd)+ccn(nn+1)*dd +! endif +! enddo +! enddo +! +! qref(nd,k) = qmax +! +! cbar(nd,k) = 0. +! do j=nd-1,1,-1 +! phi0 = dp*(float(j)-0.5) +! cbar(j,k) = cbar(j+1,k)+0.5*(qbar(j+1,k)+qbar(j,k)) & +! *a*dp*2.*pi*a*cos(phi0) +! enddo +! +! enddo + +! ***** normalize QGPV by sine (latitude) **** + +! do j = 2,nd +! phi0 = dp*float(j-1) +! cor = sin(phi0) +! qref(j,:) = qref(j,:)/cor +! enddo +! +! do k = 2,kmax-1 +! qref(1,k) = 2.*qref(2,k)-qref(3,k) +! enddo + +! ***** FAWA ***** +! fawa(:,:) = (cref(:,:)-cbar(:,:))/(2.*pi*a) + +! ***** Direct solver to invert Q_ref ***** + +! *** downward sweep *** + +! **** top boundary condition (Eqs. 24-25) ***** +! tjk(:,:) = 0. +! sjk(:,:,:) = 0. +! do jj = jb+2,90 +! j = jj-jb +! phi0 = float(jj-1)*dp +! cos0 = cos(phi0) +! sin0 = sin(phi0) +! tjk(j-1,kmax-1) = -dz*r*cos0*exp(-z(kmax-1)*rkappa/h) +! tjk(j-1,kmax-1) = tjk(j-1,kmax-1)*(tbar(j+1,kmax)-tbar(j-1,kmax)) +! tjk(j-1,kmax-1) = tjk(j-1,kmax-1)/(4.*om*sin0*dp*h*a) +! sjk(j-1,j-1,kmax-1) = 1. +! enddo + +! **** Evaluate Eqs. 22-23 downward *** + + do k = kmax-1,2,-1 + zp = 0.5*(z(k+1)+z(k)) + zm = 0.5*(z(k-1)+z(k)) + statp = 0.5*(statn(k+1)+statn(k)) + statm = 0.5*(statn(k-1)+statn(k)) + cjj(:,:) = 0. + djj(:,:) = 0. + qjj(:,:) = 0. + sjj(:,:) = sjk(:,:,k) + tj(:) = tjk(:,k) + do jj = jb+2,90 + j = jj - jb + phi0 = float(jj-1)*dp + phip = (float(jj)-0.5)*dp + phim = (float(jj)-1.5)*dp + cos0 = cos(phi0) + cosp = cos(phip) + cosm = cos(phim) + sin0 = sin(phi0) + sinp = sin(phip) + sinm = sin(phim) + + fact = 4.*om*om*h*a*a*sin0*dp*dp/(dz*dz*rr*cos0) + amp = exp(-zp/h)*exp(rkappa*zp/h)/statp + amp = amp*fact*exp(z(k)/h) + amm = exp(-zm/h)*exp(rkappa*zm/h)/statm + amm = amm*fact*exp(z(k)/h) + + ! ***** Specify A, B, C, D, E, F (Eqs. 4-9) ***** + ajk = 1./(sinp*cosp) + bjk = 1./(sinm*cosm) + cjk = amp + djk = amm + ejk = ajk+bjk+cjk+djk + fjk = -0.5*a*dp*(qref(jj+1,k)-qref(jj-1,k)) + + ! ***** Specify rk (Eq. 15) **** + + ! **** North-south boundary conditions **** + u(jd,k) = 0. + phi0 = dp*float(jb) + u(1,k) = ubar(jb+1,k)*cos(phi0) + + rj(j-1) = fjk + if(j.eq.2) rj(j-1) = fjk - bjk*u(1,k) + if(j.eq.jd-1) rj(j-1) = fjk - ajk*u(jd,k) + + ! ***** Specify Ck & Dk (Eqs. 18-19) ***** + cjj(j-1,j-1) = cjk + djj(j-1,j-1) = djk + + ! **** Specify Qk (Eq. 17) ***** + qjj(j-1,j-1) = -ejk + if(j-1.ge.1.and.j-1.lt.jd-2) then + qjj(j-1,j) = ajk + endif + if(j-1.gt.1.and.j-1.le.jd-2) then + qjj(j-1,j-2) = bjk + endif + enddo + + ! **** Compute Qk + Ck Sk ******* + do i = 1,jd-2 + do j = 1,jd-2 + xjj(i,j) = 0. + do kk = 1,jd-2 + xjj(i,j) = xjj(i,j)+cjj(i,kk)*sjj(kk,j) + enddo + qjj(i,j) = qjj(i,j)+xjj(i,j) + enddo + enddo + qjj_k(:,:,k) = qjj(:,:) + djj_k(:,:,k) = djj(:,:) + enddo + ! call gemm(cjj,sjj,xjj) + ! qjj(:,:) = qjj(:,:)+xjj(:,:) + + do k = kmax-1,2,-1 + qjj = qjj_k(:,:,k) + djj = djj_k(:,:,k) + ! **** Invert (Qk + Ck Sk) ******** + call getrf(qjj,ipiv) + call getri(qjj,ipiv) + + ! **** Evaluate Eq. 22 **** + do i = 1,jd-2 + do j = 1,jd-2 + xjj(i,j) = 0. + do kk = 1,jd-2 + xjj(i,j) = xjj(i,j)+qjj(i,kk)*djj(kk,j) + enddo + sjk(i,j,k-1) = -xjj(i,j) + enddo + enddo + + ! call gemm(qjj,djj,xjj) + ! sjk(:,:,k-1) = -xjj(:,:) + + ! **** Evaluate rk - Ck Tk **** + do i = 1,jd-2 + yj(i) = 0. + do kk = 1,jd-2 + yj(i) = yj(i)+cjj(i,kk)*tj(kk) + enddo + yj(i) = rj(i)-yj(i) + enddo + + ! call gemv(cjj,tj,yj) + ! yj(:) = rj(:)-yj(:) + ! call gemv(qjj,yj,tj) + ! tjk(:,k-1) = tj(:) + + + ! ***** Evaluate Eq. 23 ******* + do i = 1,jd-2 + tj(i) = 0. + do kk = 1,jd-2 + tj(i) = tj(i)+qjj(i,kk)*yj(kk) + enddo + tjk(i,k-1) = tj(i) + enddo + + enddo + +! ***** upward sweep (Eq. 20) **** + + pjk(:,1) = 0. + do k = 1,kmax-1 + pj(:) = pjk(:,k) + sjj(:,:) = sjk(:,:,k) + tj(:) = tjk(:,k) + + do i = 1,jd-2 + yj(i) = 0. + do kk = 1,jd-2 + yj(i) = yj(i)+sjj(i,kk)*pj(kk) + enddo + pjk(i,k+1) = yj(i)+tj(i) + enddo +! call gemv(sjj,pj,yj) +! pjk(:,k+1) = yj(:) + tj(:) + enddo + +! **** Recover u ***** + do k = 1,kmax + do j = 2,jd-1 + u(j,k) = pjk(j-1,k) + enddo + enddo + +! *** Corner boundary conditions *** + u(1,1) = 0. + u(jd,1) = 0. + u(1,kmax) = ubar(1+jb,kmax)*cos(dp*float(jb)) + u(jd,kmax) = 0. + +! *** Divide by cos phi to revover Uref **** + do jj = jb+1,nd-1 + j = jj-jb + phi0 = dp*float(jj-1) + u(j,:) = u(j,:)/cos(phi0) + enddo + u(jd,:) = 2.*u(jd-1,:)-u(jd-2,:) + +! ******** compute tref ******* + + do k = 2,96 + t00 = 0. + zz = dz*float(k-1) + tref(1,k) = t00 + tref(2,k) = t00 + do j = 2,jd-1 + phi0 = dp*float(j-1) + cor = 2.*om*sin(phi0) + uz = (u(j,k+1)-u(j,k-1))/(2.*dz) + ty = -cor*uz*a*h*exp(rkappa*zz/h) + ty = ty/r + tref(j+1,k) = tref(j-1,k)+2.*ty*dp + qref(j-1,k) = qref(j-1,k)*sin(phi0) + enddo + tg(k) = 0. + wt = 0. + do jj = 6,91 + j = jj-5 + phi0 = dp*float(jj-1) + tg(k) = tg(k)+cos(phi0)*tref(j,k) + wt = wt + cos(phi0) + enddo + tg(k) = tg(k)/wt + tres = tb(k)-tg(k) + tref(:,k) = tref(:,k)+tres + enddo + tref(:,1) = tref(:,2)-tb(2)+tb(1) + tref(:,97) = tref(:,96)-tb(96)+tb(97) + + write(38) qref,u,tref,fawa,ubar,tbar + + write(6,*) m,n,mm + +! ******************************** + !enddo + + !close(35) + !close(36) + !close(37) + !close(38) + + !enddo + !enddo + + stop +END SUBROUTINE diff --git a/hn2016_falwa/matrix_after_inversion.f90 b/hn2016_falwa/matrix_after_inversion.f90 new file mode 100644 index 0000000..5798b42 --- /dev/null +++ b/hn2016_falwa/matrix_after_inversion.f90 @@ -0,0 +1,50 @@ +! *** Copying from lines 333-368 from era4004n.f90 *** + +SUBROUTINE matrix_after_inversion(k,kmax,jb,jd,qjj,djj,cjj,tj,rj,sjk,tjk) + + INTEGER, INTENT(in) :: k, kmax, jb, jd + REAL, INTENT(in) :: qjj(jd-2,jd-2),djj(jd-2,jd-2),cjj(jd-2,jd-2),rj(jd-2) + REAL, INTENT(INOUT) :: sjk(jd-2,jd-2,kmax-1),tjk(jd-2,kmax-1),tj(jd-2) ! Note that tj is not used in subsequent modules + + integer :: i, j + real :: xjj(jd-2,jd-2),yj(jd-2) + + + do i = 1,jd-2 + do j = 1,jd-2 + xjj(i,j) = 0. + do kk = 1,jd-2 + xjj(i,j) = xjj(i,j)+qjj(i,kk)*djj(kk,j) + enddo + sjk(i,j,k-1) = -xjj(i,j) + enddo + enddo + + ! call gemm(qjj,djj,xjj) + ! sjk(:,:,k-1) = -xjj(:,:) + + ! **** Evaluate rk - Ck Tk **** + do i = 1,jd-2 + yj(i) = 0. + do kk = 1,jd-2 + yj(i) = yj(i)+cjj(i,kk)*tj(kk) + enddo + yj(i) = rj(i)-yj(i) + enddo + + ! call gemv(cjj,tj,yj) + ! yj(:) = rj(:)-yj(:) + ! call gemv(qjj,yj,tj) + ! tjk(:,k-1) = tj(:) + + + ! ***** Evaluate Eq. 23 ******* + do i = 1,jd-2 + tj(i) = 0. + do kk = 1,jd-2 + tj(i) = tj(i)+qjj(i,kk)*yj(kk) + enddo + tjk(i,k-1) = tj(i) + enddo + +END SUBROUTINE matrix_after_inversion diff --git a/hn2016_falwa/matrix_b4_inversion.f90 b/hn2016_falwa/matrix_b4_inversion.f90 new file mode 100644 index 0000000..5b0586a --- /dev/null +++ b/hn2016_falwa/matrix_b4_inversion.f90 @@ -0,0 +1,97 @@ +! *** Copying from lines 254-324 from era4004n.f90 *** + +SUBROUTINE matrix_b4_inversion(k,jmax,kmax,nd,jb,jd,z,statn,qref,ckref,& + a, om, dz, h, rr, cp, & + qjj,djj,cjj,rj,tj,u,sjk,tjk) + + integer, INTENT(in) :: k, jmax, kmax, nd, jb, jd + REAL, INTENT(in) :: z(kmax),statn(kmax),qref(nd,kmax),ckref(nd,kmax) + REAL, INTENT(in) :: a, om, dz, h, rr, cp + REAL, INTENT(OUT) :: qjj(jd-2,jd-2),djj(jd-2,jd-2),cjj(jd-2,jd-2),rj(jd-2),tj(jd-2) + REAL, INTENT(INOUT) :: u(jd,kmax),sjk(jd-2,jd-2,kmax-1),tjk(jd-2,kmax-1) + + REAL :: stats(kmax),ts0(kmax),tn0(kmax) + REAL :: qn(jmax),an(jmax),aan(jmax),tb(kmax),tg(kmax) + REAL :: cn(jmax),ccn(jmax),tref(jd,kmax) + REAL :: alat(nd),phi(nd),cbar(nd,kmax) +! REAL :: tj(jd-2) + REAL :: xjj(jd-2,jd-2) + REAL :: sjj(jd-2,jd-2) + + rkappa = rr/cp + pi = acos(-1.) + dp = pi/180. + + zp = 0.5*(z(k+1)+z(k)) + zm = 0.5*(z(k-1)+z(k)) + statp = 0.5*(statn(k+1)+statn(k)) + statm = 0.5*(statn(k-1)+statn(k)) + cjj(:,:) = 0. + djj(:,:) = 0. + qjj(:,:) = 0. + sjj(:,:) = sjk(:,:,k) + tj(:) = tjk(:,k) + do jj = jb+2,90 + j = jj - jb + phi0 = float(jj-1)*dp + phip = (float(jj)-0.5)*dp + phim = (float(jj)-1.5)*dp + cos0 = cos(phi0) + cosp = cos(phip) + cosm = cos(phim) + sin0 = sin(phi0) + sinp = sin(phip) + sinm = sin(phim) + + fact = 4.*om*om*h*a*a*sin0*dp*dp/(dz*dz*rr*cos0) + amp = exp(-zp/h)*exp(rkappa*zp/h)/statp + amp = amp*fact*exp(z(k)/h) + amm = exp(-zm/h)*exp(rkappa*zm/h)/statm + amm = amm*fact*exp(z(k)/h) + + ! ***** Specify A, B, C, D, E, F (Eqs. 4-9) ***** + ajk = 1./(sinp*cosp) + bjk = 1./(sinm*cosm) + cjk = amp + djk = amm + ejk = ajk+bjk+cjk+djk + fjk = -0.5*a*dp*(qref(jj+1,k)-qref(jj-1,k)) + + ! ***** Specify rk (Eq. 15) **** + + ! **** North-south boundary conditions **** + u(jd,k) = 0. + phi0 = dp*float(jb) + ! u(1,k) = ubar(jb+1,k)*cos(phi0) + u(1,k) = ckref(jb+1,k)/(2.*pi*a)-om*a*cos(phi0) + + rj(j-1) = fjk + if(j.eq.2) rj(j-1) = fjk - bjk*u(1,k) + if(j.eq.jd-1) rj(j-1) = fjk - ajk*u(jd,k) + + ! ***** Specify Ck & Dk (Eqs. 18-19) ***** + cjj(j-1,j-1) = cjk + djj(j-1,j-1) = djk + + ! **** Specify Qk (Eq. 17) ***** + qjj(j-1,j-1) = -ejk + if(j-1.ge.1.and.j-1.lt.jd-2) then + qjj(j-1,j) = ajk + endif + if(j-1.gt.1.and.j-1.le.jd-2) then + qjj(j-1,j-2) = bjk + endif + enddo + + ! **** Compute Qk + Ck Sk ******* + do i = 1,jd-2 + do j = 1,jd-2 + xjj(i,j) = 0. + do kk = 1,jd-2 + xjj(i,j) = xjj(i,j)+cjj(i,kk)*sjj(kk,j) + enddo + qjj(i,j) = qjj(i,j)+xjj(i,j) + enddo + enddo + +END SUBROUTINE matrix_b4_inversion diff --git a/hn2016_falwa/oopinterface.py b/hn2016_falwa/oopinterface.py index 0686740..457f6e7 100644 --- a/hn2016_falwa/oopinterface.py +++ b/hn2016_falwa/oopinterface.py @@ -2,10 +2,18 @@ import warnings import numpy as np from scipy.interpolate import interp1d +from scipy.linalg.lapack import dgetrf, dgetri from hn2016_falwa import utilities from hn2016_falwa.constant import * from interpolate_fields import interpolate_fields +from interpolate_fields_direct_inv import interpolate_fields_direct_inv +from compute_qref_and_fawa_first import compute_qref_and_fawa_first +from matrix_b4_inversion import matrix_b4_inversion +from matrix_after_inversion import matrix_after_inversion +from upward_sweep import upward_sweep +from compute_flux_dirinv import compute_flux_dirinv + from compute_reference_states import compute_reference_states from compute_lwa_and_barotropic_fluxes import compute_lwa_and_barotropic_fluxes from collections import namedtuple @@ -174,8 +182,17 @@ def __init__(self, xlon, ylat, plev, u_field, v_field, t_field, kmax=49, maxit=1 self._qgpv_temp = None self._interpolated_u_temp = None self._interpolated_v_temp = None + self._interpolated_avort_temp = None self._interpolated_theta_temp = None self._static_stability = None + self._static_stability_n = None + self._static_stability_s = None + self._tn0 = None + self._ts0 = None + + # === Temporary solution for direct inv routine + self._f_qref, self._f_u, self._f_tref, self._f_ubar, self._f_tbar, self._f_fawa, self._f_ckref = \ + None, None, None, None, None, None, None # Computation from computer_reference_states self._qref_stemp = None @@ -204,6 +221,14 @@ def __init__(self, xlon, ylat, plev, u_field, v_field, t_field, kmax=49, maxit=1 self._lwa = None self._divergence_eddy_momentum_flux = None + # Temporary solution for GRL computation + self._ua1baro_nhem = None + self._ua2baro_nhem = None + self._ep1baro_nhem = None + self._ep2baro_nhem = None + self._ep3baro_nhem = None + self._ep4_nhem = None + def _compute_prefactor(self): """ Private function. Compute prefactor for normalization by evaluating @@ -417,6 +442,7 @@ def interpolate_fields(self): self._qgpv_temp, \ self._interpolated_u_temp, \ self._interpolated_v_temp, \ + self._interpolated_avort_temp, \ self._interpolated_theta_temp, \ self._static_stability = \ interpolate_fields( @@ -440,7 +466,7 @@ def interpolate_fields(self): self._interpolated_theta_temp, 0, 2 ) - # Construct a named tuple + # Construct a named tuple # TODO: add absolute vorticity here? But only after testing Interpolated_fields = namedtuple('Interpolated_fields', ['QGPV', 'U', 'V', 'Theta', 'Static_stability']) interpolated_fields = Interpolated_fields( self.qgpv, @@ -450,6 +476,355 @@ def interpolate_fields(self): self.static_stability) return interpolated_fields + def _interpolate_field_dirinv(self): + """ + Added for NHN 2022 GRL + :return: + """ + self._qgpv_temp, \ + self._interpolated_u_temp, \ + self._interpolated_v_temp, \ + self._interpolated_avort_temp, \ + self._interpolated_theta_temp, \ + self._static_stability_n, \ + self._static_stability_s,\ + self._tn0, self._ts0 = \ + interpolate_fields_direct_inv( + self.kmax, + self.nlat // 2 + self.nlat % 2, + np.swapaxes(self.u_field, 0, 2), + np.swapaxes(self.v_field, 0, 2), + np.swapaxes(self.t_field, 0, 2), + self.plev, + self.planet_radius, + self.omega, + self.dz, + self.scale_height, + self.dry_gas_constant, + self.cp) + + self._check_nan("self._qgpv_temp", self._qgpv_temp) + self._check_nan("self._interpolated_u_temp", self._interpolated_u_temp) + self._check_nan("self._interpolated_v_temp", self._interpolated_v_temp) + self._check_nan("self._interpolated_avort_temp", self._interpolated_avort_temp) + self._check_nan("self._interpolated_theta_temp", self._interpolated_theta_temp) + self._check_nan("self._static_stability_n", self._static_stability_n) + self._check_nan("self._static_stability_s", self._static_stability_s) + self._check_nan("self._tn0", self._tn0) + self._check_nan("self._ts0", self._ts0) + + return self._qgpv_temp, self._interpolated_u_temp, self._interpolated_v_temp, self._interpolated_avort_temp, \ + self._interpolated_theta_temp, self._static_stability_n, self._static_stability_s, self._tn0, self._ts0 + + @staticmethod + def _check_nan(name, var): + nan_num = np.count_nonzero(np.isnan(var)) + if nan_num > 0: + print(f"num of nan in {name}: {np.count_nonzero(np.isnan(var))}.") + + def _compute_qref_fawa_and_bc(self): + """ + Added for NHN 2022 GRL + :return: + """ + ans = compute_qref_and_fawa_first( + pv=self._qgpv_temp, + uu=self._interpolated_u_temp, + vort=self._interpolated_avort_temp, + pt=self._interpolated_theta_temp, + tn0=self._tn0, + ts0=self._ts0, + statn=self._static_stability_n, + stats=self._static_stability_s, + nd=91, + nnd=181, + jb=5, + jd=86) + qref_over_cor, u, tref, ubar, tbar, fawa, ckref, tjk, sjk = ans # unpack tuple + + print("Line 535") + self._check_nan("qref_over_cor", qref_over_cor) + self._check_nan("u", u) + self._check_nan("tref", tref) + self._check_nan("ubar", ubar) + self._check_nan("tbar", tbar) + self._check_nan("fawa", fawa) + self._check_nan("ckref", ckref) + self._check_nan("tjk", tjk) + self._check_nan("sjk", sjk) + + for k in range(self.kmax-1, 1, -1): # Fortran indices + ans = matrix_b4_inversion( + k=k, + jmax=self.nlat, + jb=5, + jd=86, + z=np.arange(0, self.kmax*self.dz, self.dz), + statn=self._static_stability_n, + qref=qref_over_cor, + ckref=ckref, + a=self.planet_radius, + om=self.omega, + dz=self.dz, + h=self.scale_height, + rr=self.dry_gas_constant, + cp=self.cp, + u=u, + sjk=sjk, + tjk=tjk) + qjj, djj, cjj, rj, tj = ans + + #print("Line 567") + #self._check_nan("qjj", qjj) + #self._check_nan("djj", djj) + #self._check_nan("cjj", cjj) + #self._check_nan("rj", rj) + #self._check_nan("tj", tj) + + # *** Check dimension *** + # print(f"qjj.shape = {qjj.shape}") + # print(f"djj.shape = {djj.shape}") + # print(f"cjj.shape = {cjj.shape}") + # print(f"rj.shape = {rj.shape}") + # print(f"rj.shape = {tj.shape}") + # print(f"u.shape = {u.shape}") + # print(f"sjk.shape = {sjk.shape}") + # print(f"tjk.shape = {tjk.shape}") + lu, piv, info = dgetrf(qjj) + qjj, info = dgetri(lu, piv) + + #print("Line 586. After inversion:") + #self._check_nan("qjj", qjj) + + _ = matrix_after_inversion( + k=k, + jb=5, + qjj=qjj, + djj=djj, + cjj=cjj, + tj=tj, + rj=rj, + sjk=sjk, + tjk=tjk) + # print(f"k = {k}. Run till here so far") + + qref = upward_sweep( + jmax=self.nlat, + nnd=self.nlat, + jb=5, + sjk=sjk, + tjk=tjk, + ckref=ckref, + tb=self._tn0, + qref_over_cor=qref_over_cor, + u=u, + tref=tref, + a=self.planet_radius, + om=self.omega, + dz=self.dz, + h=self.scale_height, + rr=self.dry_gas_constant, + cp=self.cp) + + return qref, u, tref, fawa, ubar, tbar # uref = u + + # ans2 = direct_solver_b4_lu_fact( + # tjk=tjk, + # sjk=sjk, + # qref=qref_over_cor, + # ubar=ubar, + # tbar=tbar, + # fawa=fawa, + # ckref=ckref, + # statn=self._static_stability_n, + # tn0=self._tn0, + # jmax=self.nlat, + # jb=5, + # a=self.planet_radius, + # om=self.omega, + # dz=self.dz, + # h=self.scale_height, + # rr=self.dry_gas_constant, + # cp=self.cp) + # print(f"len(ans2) = {len(ans2)}.") + # # *** Do inversion here using SciPy package *** + # qjj_k, cjj_k, djj_k, tj, rj = ans2 + # qjj_output = np.zeros_like(qjj_k) + # + # for k in range(self.kmax-1, 2, -1): + # #print(f"In line 542 of oopinterface.py. k = {k}.") + # lu, piv, info = dgetrf(qjj_k[:, :, k]) + # inv_a, info = dgetri(lu, piv) + # #if np.count_nonzero(np.isnan(inv_a)) > 0: + # #print(f"================= k = {k} =================") + # #print(f"Number of nan in inv_a: {np.count_nonzero(np.isnan(inv_a))}") + # qjj_output[:, :, k] = inv_a + # + # ans3 = direct_solver_after_lu_fact( + # qjj_k=qjj_output, + # cjj_k=cjj_k, + # djj_k=djj_k, + # sjk=sjk, + # tjk=tjk, + # tj=tj, + # rj=rj, + # qref_over_cor=qref_over_cor, + # ubar=ubar, + # tbar=tbar, + # tn0=self._tn0, + # jmax=self.nlat, + # jb=5, + # a=self.planet_radius, + # om=self.omega, + # dz=self.dz, + # h=self.scale_height, + # rr=self.dry_gas_constant, + # cp=self.cp) + # uref, qref, tref = ans3 + # print(f"len(ans3) = {len(ans3)}") + # print(f"uref[:, 40] = {uref[:, 40]}") + # print(f"qref[:, 40] = {qref[:, 40]}") + # print(f"tref[:, 40] = {tref[:, 40]}") + + def _compute_lwa_flux_dirinv(self, qref, uref, tref, fawa, ubar, tbar): + """ + Added for NHN 2022 GRL + :return: + """ + ans = compute_flux_dirinv(pv=self._qgpv_temp, uu=self._interpolated_u_temp, vv=self._interpolated_v_temp, + pt=self._interpolated_theta_temp, tn0=self._tn0, ts0=self._ts0, + statn=self._static_stability_n, stats=self._static_stability_s, + qref=qref, uref=uref, tref=tref, fawa=fawa, ubar=ubar, tbar=tbar, + nnd=self.nlat, jb=5) + # astarbaro, ubaro, urefbaro, ua1baro, ua2baro, ep1baro, ep2baro, ep3baro, ep4, astar1, astar2 = ans + return ans + + def interpolate_fields_direct_inversion_old(self): + + """ + Interpolate zonal wind, maridional wind, and potential temperature field onto the uniform pseudoheight grids, + and compute QGPV on the same grids. This returns named tuple called "Interpolated_fields" that consists of + 5 elements as listed below. + + Returns + ------- + QGPV : numpy.ndarray + Three-dimensional array of quasi-geostrophic potential vorticity (QGPV) with dimension = [kmax, nlat, nlon] + + U : numpy.ndarray + Three-dimensional array of interpolated zonal wind with dimension = [kmax, nlat, nlon] + + V : numpy.ndarray + Three-dimensional array of interpolated meridional wind with dimension = [kmax, nlat, nlon] + + Theta : numpy.ndarray + Three-dimensional array of interpolated potential temperature with dimension = [kmax, nlat, nlon] + + Static_stability : numpy.array + One-dimension array of interpolated static stability with dimension = kmax + + + Examples + -------- + + >>> interpolated_fields = test_object.interpolate_fields() + >>> interpolated_fields.QGPV # This is to access the QGPV field + + """ + + if self._qref_ntemp is None: + + # === Interpolate fields and obtain qgpv === + self._qgpv_temp, \ + self._interpolated_u_temp, \ + self._interpolated_v_temp, \ + self._interpolated_avort_temp, \ + self._interpolated_theta_temp, \ + self._static_stability_n, \ + self._static_stability_s,\ + self._tn0, \ + self._ts0 = \ + interpolate_fields_direct_inv( + np.swapaxes(self.u_field, 0, 2), + np.swapaxes(self.v_field, 0, 2), + np.swapaxes(self.t_field, 0, 2), + self.plev, + self.height, + self.planet_radius, + self.omega, + self.dz, + self.scale_height, + self.dry_gas_constant, + self.cp + ) + + self._qgpv = np.swapaxes(self._qgpv_temp, 0, 2) + self._interpolated_u = np.swapaxes(self._interpolated_u_temp, 0, 2) + self._interpolated_v = np.swapaxes(self._interpolated_v_temp, 0, 2) + self._interpolated_theta = np.swapaxes( + self._interpolated_theta_temp, 0, 2 + ) + + print(f"num of nan in statN = {np.count_nonzero(np.isnan(self._static_stability_n))}") + print(f"num of nan in avort zonal mean = {np.count_nonzero(np.isnan(self._interpolated_avort_temp))}") + # Construct a named tuple # TODO: add absolute vorticity here? But only after testing + Interpolated_fields = namedtuple( + 'Interpolated_fields', ['QGPV', 'U', 'V', 'Theta', 'Static_stability_N', 'Static_stability_S']) + interpolated_fields = Interpolated_fields( + self.qgpv, + self.interpolated_u, + self.interpolated_v, + self.interpolated_theta, + self._static_stability_n, + self._static_stability_s) + # TODO: static stability in southern hemisphere has nan values?! + return interpolated_fields + + def compute_reference_states_direct_inversion(self, northern_hemisphere_results_only=True): + """ + Direct inversion algorithm for NHN GRL 2022 + """ + + ans = compute_qref_fawa_and_bc( + 5, + 91, + 91 - 5, + self._qgpv_temp, + self._interpolated_u_temp, + self._interpolated_avort_temp, + self._interpolated_theta_temp, + self._static_stability_n, + self._tn0, + self.planet_radius, + self.omega, + self.dz, + self.tol, # can remove + self.scale_height, + self.dry_gas_constant) + + self._f_qref, self._f_u, self._f_tref, self._f_ubar, self._f_tbar, self._f_fawa, self._f_ckref = ans + + return ans + + # def _compute_reference_states_direct_inversion_wrapper(self, qgpv, u, theta): + # return compute_reference_states( + # qgpv, + # u, + # theta, + # self._static_stability, + # self.equator_idx, + # self.npart, + # self.maxit, + # self.planet_radius, + # self.omega, + # self.dz, + # self.tol, + # self.scale_height, + # self.dry_gas_constant, + # self.cp, + # self.rjac, + # ) + def compute_reference_states(self, northern_hemisphere_results_only=False): """ @@ -626,6 +1001,14 @@ def compute_lwa_and_barotropic_fluxes(self, northern_hemisphere_results_only=Fal self._uref_ntemp, self._ptref_ntemp) + # === Access barotropic components of ua1, ua2, ep1, ep2, ep3, ep4: for the use of nhn GLR paper only === + self._ua1baro_nhem = ua1baro_nhem + self._ua2baro_nhem = ua2baro_nhem + self._ep1baro_nhem = ep1baro_nhem + self._ep2baro_nhem = ep2baro_nhem + self._ep3baro_nhem = ep3baro_nhem + self._ep4_nhem = ep4_nhem + # === Compute barotropic flux terms (SHem) === if not northern_hemisphere_results_only: lwa_shem, astarbaro_shem, ua1baro_shem, ubaro_shem, ua2baro_shem,\ diff --git a/hn2016_falwa/upward_sweep.f90 b/hn2016_falwa/upward_sweep.f90 new file mode 100644 index 0000000..36edc47 --- /dev/null +++ b/hn2016_falwa/upward_sweep.f90 @@ -0,0 +1,116 @@ +! *** Copying from lines 374-442 from era4004n.f90 *** + +SUBROUTINE upward_sweep(jmax, kmax, nd, nnd, jb, jd, sjk, tjk, ckref, tb, qref_over_cor, u, tref, qref, a, om, dz, h, rr, cp) + + INTEGER, INTENT(IN) :: jmax, kmax, nd, nnd, jb, jd + REAL, INTENT(IN) :: sjk(jd-2,jd-2,kmax-1),tjk(jd-2,kmax-1),ckref(nd,kmax),tb(kmax),qref_over_cor(nd,kmax) + REAL, INTENT(IN) :: rr, cp + REAL, INTENT(INOUT) :: u(jd,kmax), tref(jd,kmax) + REAL, INTENT(OUT) :: qref(nd,kmax) + +! integer,parameter :: imax = 360, JMAX = 181, KMAX = 97 +! integer,parameter :: nd = 91,nnd=181 +! integer,parameter :: jb = 5 ! lower bounding latitude +! integer,parameter :: jd = 86 ! nd - lower bounding latitude + +! common /array/ pv(imax,jmax,kmax),pv2(imax,jmax) +! common /brray/ uu(imax,jmax,kmax) +! common /bbray/ vort(imax,jmax,kmax),vort2(imax,jmax) +! common /bcray/ pt(imax,jmax,kmax) +! common /bdray/ stats(kmax),statn(kmax),ts0(kmax),tn0(kmax) +! common /crray/ qn(nnd),an(nnd),aan(nnd) + real :: tg(kmax) + real :: pjk(jd-2,kmax) +! common /frray/ alat(nd),phi(nd),z(kmax),cbar(nd,kmax) + real :: tj(jd-2),rj(jd-2) + real :: qjj(jd-2,jd-2),cjj(jd-2,jd-2) + real :: xjj(jd-2,jd-2),yj(jd-2) +! real :: djj(jd-2,jd-2) + real :: sjj(jd-2,jd-2) + real :: pj(jd-2) + +! common /krray/ fawa(nd,kmax) +! common /jrray/ qbar(nd,kmax),ubar(nd,kmax),tbar(nd,kmax) +! integer :: md(12),ipiv(jd-2) + + rkappa = rr/cp + pi = acos(-1.) + dp = pi/180. + + + pjk(:,1) = 0. + do k = 1,kmax-1 + pj(:) = pjk(:,k) + sjj(:,:) = sjk(:,:,k) + tj(:) = tjk(:,k) + + do i = 1,jd-2 + yj(i) = 0. + do kk = 1,jd-2 + yj(i) = yj(i)+sjj(i,kk)*pj(kk) + enddo + pjk(i,k+1) = yj(i)+tj(i) + enddo + ! call gemv(sjj,pj,yj) + ! pjk(:,k+1) = yj(:) + tj(:) + enddo + + ! **** Recover u ***** + do k = 1,kmax + do j = 2,jd-1 + u(j,k) = pjk(j-1,k) + enddo + enddo + + ! *** Corner boundary conditions *** + u(1,1) = 0. + u(jd,1) = 0. + ! u(1,kmax) = ubar(1+jb,kmax)*cos(dp*float(jb)) + u(1,kmax) = ckref(1+jb,kmax)/(2.*pi*a)-om*a*cos(dp*float(jb)) + u(jd,kmax) = 0. + + ! *** Divide by cos phi to revover Uref **** + do jj = jb+1,nd-1 + j = jj-jb + phi0 = dp*float(jj-1) + u(j,:) = u(j,:)/cos(phi0) + enddo + u(jd,:) = 2.*u(jd-1,:)-u(jd-2,:) + + ! ******** compute tref ******* + qref(:, :) = qref_over_cor(:, :) ! modify for f2py wrapping purpose + do k = 2,96 + t00 = 0. + zz = dz*float(k-1) + tref(1,k) = t00 + tref(2,k) = t00 + do j = 2,jd-1 + phi0 = dp*float(j-1+jb) + cor = 2.*om*sin(phi0) + uz = (u(j,k+1)-u(j,k-1))/(2.*dz) + ty = -cor*uz*a*h*exp(rkappa*zz/h) + ty = ty/rr + tref(j+1,k) = tref(j-1,k)+2.*ty*dp + qref(j-1+jb,k) = qref_over_cor(j-1+jb,k)*sin(phi0) + enddo +! do j = jd, nd ! Add after checking code +! qref(j-1,k) = qref_over_cor(j-1,k)*sin(dp*float(j-1)) +! end do +! qref(nd,k) = 2 * qref(nd-1,k) - qref(nd-2,k) ! Linear interpolation + + tg(k) = 0. + wt = 0. + do jj = 6,91 + j = jj-5 + phi0 = dp*float(jj-1) + tg(k) = tg(k)+cos(phi0)*tref(j,k) + wt = wt + cos(phi0) + enddo + tg(k) = tg(k)/wt + tres = tb(k)-tg(k) + tref(:,k) = tref(:,k)+tres + enddo + tref(:,1) = tref(:,2)-tb(2)+tb(1) + tref(:,97) = tref(:,96)-tb(96)+tb(97) + +END SUBROUTINE upward_sweep \ No newline at end of file diff --git a/scripts/nhn_grl2022/Fig1a.py b/scripts/nhn_grl2022/Fig1a.py new file mode 100644 index 0000000..8b6aa4d --- /dev/null +++ b/scripts/nhn_grl2022/Fig1a.py @@ -0,0 +1,81 @@ +#This script reads in netCDF data for ERA5 +from netCDF4 import Dataset +import numpy as np +import matplotlib.pyplot as plot +import cartopy.crs as ccrs +from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter + +#----------------- +# read netCDF files +#----------------- + +data_dir = "grl2022_data/" +filename1 = data_dir + "2021_06_z.nc" +filename2 = data_dir + "2021_06_u.nc" +filename3 = data_dir + "2021_06_v.nc" + +ncin1 = Dataset(filename1, 'r', format='NETCDF4') +ncin2 = Dataset(filename2, 'r', format='NETCDF4') +ncin3 = Dataset(filename3, 'r', format='NETCDF4') + +zmean = ncin1.variables['z'] +zmean = (np.array(zmean)) +umean = ncin2.variables['u'] +umean = (np.array(umean)) +vmean = ncin3.variables['v'] +vmean = (np.array(vmean)) + +print(zmean.shape) + +zz = np.zeros((44,181,360)) +z = np.zeros((181,360)) +uu = np.zeros((44,181,360)) +u = np.zeros((181,360)) +vv = np.zeros((44,181,360)) +v = np.zeros((181,360)) +m = 76 +while(m < 120): + zz[m-76,:,:] = zmean[m,16,:,:] + uu[m-76,:,:] = umean[m,16,:,:] + vv[m-76,:,:] = vmean[m,16,:,:] + m = m+1 +day = ['00 UTC 20 June 2021','00 UTC 21 June 2021','00 UTC 22 June 2021','00 UTC 23 June 2021','00 UTC 24 June 2021','00 UTC 25 June 2021','00 UTC 26 June 2021','00 UTC 27 June 2021','00 UTC 28 June 2021','00 UTC 29 June 2021','00 UTC 30 June 2021'] +b = ['0620.png','0621.png','0622.png','0623.png','0624.png','0625.png','0626.png','0627.png','0628.png','0629.png','0630.png'] +n = 0 +while(n < 11): + nn = n*4 + j = 0 + while(j < 181): + z[j,:]=zz[nn,180-j,:]/9.81 + u[j,:]=uu[nn,180-j,:] + v[j,:]=vv[nn,180-j,:] + j = j+1 + cl1 = np.arange(9600,11300,100) + cl2 = np.arange(0,95,5) + x = np.arange(0,360) + y = np.arange(0,181)-90. + plot.rcParams.update({'font.size':14,'text.usetex': False}) + fig = plot.figure(figsize=(8,4)) + ax5 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) + plot.xlim(140,280) + plot.ylim(10,80) + plot.title(''+day[n]) + plot.xlabel('Longitude') + plot.ylabel('Latitude') + ax5.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) + ax5.coastlines(color='white',alpha = 0.7) + ax5.set_aspect('auto', adjustable=None) + ax5.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) + ax5.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) + lon_formatter = LongitudeFormatter(zero_direction_label=True) + lat_formatter = LatitudeFormatter() + ax5.xaxis.set_major_formatter(lon_formatter) + ax5.yaxis.set_major_formatter(lat_formatter) + ott = ax5.contourf(x,y,np.sqrt(u*u+v*v),levels=cl2,transform=ccrs.PlateCarree(),cmap='rainbow') + fig.colorbar(ott,ax=ax5,label='wind speed (m/s)') + ott = ax5.contour(x,y,z,levels=cl1,colors='black',transform=ccrs.PlateCarree(),linewidths=1) + ax5.clabel(ott, ott.levels,fmt='%5i') + plot.savefig(b[n],bbox_inches='tight',dpi =600) + # plot.show() + + n = n+1 \ No newline at end of file diff --git a/scripts/nhn_grl2022/Fig1b.py b/scripts/nhn_grl2022/Fig1b.py new file mode 100644 index 0000000..a93d17f --- /dev/null +++ b/scripts/nhn_grl2022/Fig1b.py @@ -0,0 +1,66 @@ +#This script reads in netCDF data for ERA5 +from netCDF4 import Dataset +import numpy as np +import matplotlib.pyplot as plot +import cartopy.crs as ccrs +from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter + +#----------------- +# read netCDF files +#----------------- + +data_dir = "grl2022_data/" +filename1 = data_dir + "2021_06_t.nc" + +ncin1 = Dataset(filename1, 'r', format='NETCDF4') + +tmean = ncin1.variables['t'] +tmean = (np.array(tmean)) + +print(tmean.shape) + +tt = np.zeros((44,181,360)) +t = np.zeros((181,360)) + +r = 287. +cp = 1004. +kappa = r/cp +m = 76 +while(m < 120): +# tt[m-76,:,:] = tmean[m,36,:,:] + tt[m-76,:,:] = tmean[m,20,:,:]*np.power((1000./450.),kappa) + m = m+1 +day = ['00 UTC 20 June 2021','00 UTC 21 June 2021','00 UTC 22 June 2021','00 UTC 23 June 2021','00 UTC 24 June 2021','00 UTC 25 June 2021','00 UTC 26 June 2021','00 UTC 27 June 2021','00 UTC 28 June 2021','00 UTC 29 June 2021','00 UTC 30 June 2021'] +b = ['T_0620.png','T_0621.png','T_0622.png','T_0623.png','T_0624.png','T_0625.png','T_0626.png','T_0627.png','T_0628.png','T_0629.png','T_0630.png'] +n = 0 +while(n < 11): + nn = n*4 + j = 0 + while(j < 181): + t[j,:]=tt[nn,180-j,:] + j = j+1 + cl1 = np.arange(290,342,2) # 450 hPa + cl2 = np.arange(0,95,5) + x = np.arange(0,360) + y = np.arange(0,181)-90. + fig = plot.figure(figsize=(8,4)) + ax5 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) + plot.xlim(140,280) + plot.ylim(10,80) + plot.title(''+day[n]) + plot.xlabel('Longitude') + plot.ylabel('Latitude') + ax5.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) + ax5.coastlines(color='black',alpha = 0.7) + ax5.set_aspect('auto', adjustable=None) + ax5.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) + ax5.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) + lon_formatter = LongitudeFormatter(zero_direction_label=True) + lat_formatter = LatitudeFormatter() + ax5.xaxis.set_major_formatter(lon_formatter) + ax5.yaxis.set_major_formatter(lat_formatter) + ott = ax5.contourf(x,y,t,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') + fig.colorbar(ott,ax=ax5,label='Kelvin') + plot.savefig(b[n],bbox_inches='tight',dpi =600) + + n = n+1 \ No newline at end of file diff --git a/scripts/nhn_grl2022/Fig1c.py b/scripts/nhn_grl2022/Fig1c.py new file mode 100644 index 0000000..42dff97 --- /dev/null +++ b/scripts/nhn_grl2022/Fig1c.py @@ -0,0 +1,64 @@ +#This script reads in netCDF data for ERA5 +from netCDF4 import Dataset +import numpy as np +import matplotlib.pyplot as plot +import cartopy.crs as ccrs +from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter + +#----------------- +# read netCDF files +#----------------- + +data_dir = "grl2022_data/" +filename1 = data_dir + "2021_06_2t.nc" + +ncin1 = Dataset(filename1, 'r', format='NETCDF4') +tm = ncin1.variables['t2m'] +tm = (np.array(tm)) + +print(tm.shape) + +tt = np.zeros((44,181,360)) +t = np.zeros((181,360)) + +r = 287. +cp = 1004. +kappa = r/cp +m = 76 +while(m < 120): + tt[m-76,:,:] = tm[m,:,:] + m = m+1 +day = ['00 UTC 20 June 2021','00 UTC 21 June 2021','00 UTC 22 June 2021','00 UTC 23 June 2021','00 UTC 24 June 2021','00 UTC 25 June 2021','00 UTC 26 June 2021','00 UTC 27 June 2021','00 UTC 28 June 2021','00 UTC 29 June 2021','00 UTC 30 June 2021'] +b = ['2T_0620.png','2T_0621.png','2T_0622.png','2T_0623.png','2T_0624.png','2T_0625.png','2T_0626.png','2T_0627.png','2T_0628.png','2T_0629.png','2T_0630.png'] +n = 0 +while(n < 11): + nn = n*4 + j = 0 + while(j < 181): + t[j,:]=tt[nn,180-j,:] + j = j+1 + cl1 = np.arange(250,325,5) + cl2 = np.arange(0,95,5) + x = np.arange(0,360) + y = np.arange(0,181)-90. + fig = plot.figure(figsize=(8,4)) + ax5 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) + plot.xlim(140,280) + plot.ylim(10,80) + plot.title(''+day[n]) + plot.xlabel('Longitude') + plot.ylabel('Latitude') + ax5.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) + ax5.coastlines(color='black',alpha = 0.7) + ax5.set_aspect('auto', adjustable=None) + ax5.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) + ax5.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) + lon_formatter = LongitudeFormatter(zero_direction_label=True) + lat_formatter = LatitudeFormatter() + ax5.xaxis.set_major_formatter(lon_formatter) + ax5.yaxis.set_major_formatter(lat_formatter) + ott = ax5.contourf(x,y,t,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') + fig.colorbar(ott,ax=ax5,label='Kelvin') + plot.savefig(b[n],bbox_inches='tight',dpi =600) + + n = n+1 \ No newline at end of file diff --git a/scripts/nhn_grl2022/Fig1d-Fig2.py b/scripts/nhn_grl2022/Fig1d-Fig2.py new file mode 100644 index 0000000..3120161 --- /dev/null +++ b/scripts/nhn_grl2022/Fig1d-Fig2.py @@ -0,0 +1,132 @@ +#This script reads in netCDF data for ERA5 +from netCDF4 import Dataset +import numpy as np +import matplotlib.pyplot as plot +import cartopy.crs as ccrs +from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter + +#----------------- +# read netCDF files +#----------------- + +data_dir = "grl2022_data/" +filename1 = data_dir + "2021_06_t.nc" + +ncin1 = Dataset(filename1, 'r', format='NETCDF4') + +tmean = ncin1.variables['t'] +tmean = (np.array(tmean)) + + +print(tmean.shape) + +ttheta = np.zeros((44,37,360)) +theta = np.zeros((37,360)) +p = np.zeros(37) +z = np.zeros(37) +p[36] = 1000. +p[35] = 975. +p[34] = 950. +p[33] = 925. +p[32] = 900. +p[31] = 875. +p[30] = 850. +p[29] = 825. +p[28] = 800. +p[27] = 775. +p[26] = 750. +p[25] = 700. +p[24] = 650. +p[23] = 600. +p[22] = 550. +p[21] = 500. +p[20] = 450. +p[19] = 400. +p[18] = 350. +p[17] = 200. +p[16] = 250. +p[15] = 225. +p[14] = 200. +p[13] = 175. +p[12] = 150. +p[11] = 125. +p[10] = 100. +p[9] = 70. +p[8] = 50. +p[7] = 30. +p[6] = 20. +p[5] = 10. +p[4] = 7. +p[3] = 5. +p[2] = 3. +p[1] = 2. +p[0] = 1. + +r = 287. +cp = 1004. +kappa = r/cp +m = 76 +while(m < 120): + k = 0 + while(k < 37): + z[36-k] = -8000.*np.log(p[k]/1000.) #pseudoheight + ttheta[m-76,36-k,:] = tmean[m,k,41,:] + ttheta[m-76,36-k,:] = ttheta[m-76,36-k,:]*np.power((1000./p[k]),kappa) # potential temp + k = k+1 + m = m+1 +day = ['00 UTC 20 June 2021','00 UTC 21 June 2021','00 UTC 22 June 2021','00 UTC 23 June 2021','00 UTC 24 June 2021','00 UTC 25 June 2021','00 UTC 26 June 2021','00 UTC 27 June 2021','00 UTC 28 June 2021','00 UTC 29 June 2021','00 UTC 30 June 2021'] +b = ['THETA_0620.png','THETA_0621.png','THETA_0622.png','THETA_0623.png','THETA_0624.png','THETA_0625.png','THETA_0626.png','THETA_0627.png','THETA_0628.png','THETA_0629.png','THETA_0630.png'] +n = 0 +while(n < 11): + nn = n*4 + theta[:,:]=ttheta[nn,:,:] + cl1 = np.arange(250,365,5) + x = np.arange(0,360) + plot.rcParams.update({'font.size':14,'text.usetex': False}) + fig = plot.figure(figsize=(8,4)) + ax5 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) + plot.xlim(140,280) + plot.ylim(0,10) + plot.title('49$^\circ$N '+day[n]) + plot.xlabel('Longitude') + plot.ylabel('pseudoheight (km)') + ax5.set_extent([-220, -80, 0, 10], ccrs.PlateCarree()) + ax5.set_aspect('auto', adjustable=None) + ax5.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) + ax5.set_yticks([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], crs=ccrs.PlateCarree()) + lon_formatter = LongitudeFormatter(zero_direction_label=True) + lat_formatter = LatitudeFormatter() + ax5.xaxis.set_major_formatter(lon_formatter) + ott = ax5.contourf(x,z/1000.,theta,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') + fig.colorbar(ott,ax=ax5,label='Kelvin') + ott = ax5.contour(x,z/1000.,theta,levels=cl1,transform=ccrs.PlateCarree(),colors='black',linewidths=0.5) + ott = ax5.contour(x,z/1000.,theta,levels=np.arange(320,325,5),transform=ccrs.PlateCarree(),colors='black',linewidths=1) + ax5.clabel(ott, ott.levels,fmt='%5i') + plot.savefig(b[n],bbox_inches='tight',dpi =600) + n = n+1 + +plot.rcParams.update({'font.size': 16}) +fig = plot.figure(figsize=(6,4)) +ax5.set_yticks([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) +plot.title('49$^\circ$N 119$^\circ$W 00 UTC') +plot.xlabel('Kelvin') +plot.ylabel('pseudoheight (km)') +plot.xlim(290,360) +plot.ylim(0,10) + +lcolor = np.array(['blue', 'red','green', 'black']) +lstyle = np.array(['dotted', 'dashed','dashdot', 'solid']) +lalpha = np.array([1,1,1,1]) +n = 2 +while(n < 6): + thetaz = np.zeros(37) + nn = n*8 + thetaz[:] = ttheta[nn,:,241] + i = 0 + while(i < 37): + if(z[i] < 1000.): + thetaz[i] = np.nan + i = i+1 + fig = plot.plot(thetaz,z/1000.,color=lcolor[n-2],linestyle = lstyle[n-2],alpha=lalpha[n-2]) + n = n+1 +plot.savefig('t_profile.png',bbox_inches='tight',dpi =600) \ No newline at end of file diff --git a/scripts/nhn_grl2022/Fig3a-d.py b/scripts/nhn_grl2022/Fig3a-d.py new file mode 100644 index 0000000..616a536 --- /dev/null +++ b/scripts/nhn_grl2022/Fig3a-d.py @@ -0,0 +1,266 @@ +## This script reads in netCDF LWAb data for ERA5 +from netCDF4 import Dataset +import numpy as np +import matplotlib.pyplot as plot +import cartopy.crs as ccrs +from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter + +#----------------- +# read netCDF files +#----------------- + +data_dir = "grl2022_data/" +# filename0 = data_dir + "2021_06_LWAb_N.nc" +filename0 = "2021-06-01_to_2021-06-30_output3.nc" + +ncin1 = Dataset(filename0, 'r', format='NETCDF4') + +lwa = ncin1.variables['lwa'] +lwa = (np.array(lwa)) + +#print(lwa.shape) + +z = np.zeros((91,360)) +z[:,:] = lwa[100,:,:]-lwa[76,:,:] # m = 100 is 00 UTC 26 June 2021, m = 76 is 00 UTC 20 June 2021 + +zs = np.zeros((91,360)) # smoothed z # + +#### smoothing in longitude #### +n = 5 # smoothing width # +j = 0 +while(j < 91): + zx = np.zeros(360) + zx[:] = z[j,:] + nn = -n + while(nn < n+1): + zy = np.roll(zx,nn) + zs[j,:] = zs[j,:] + zy[:]/(2*n+1) + nn = nn+1 + j = j+1 + + +cl2 = np.arange(-80,90,10) +x = np.arange(0,360) +y = np.arange(0,91) +plot.rcParams.update({'font.size':14}) +fig = plot.figure(figsize=(8,4)) +ax5 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) +plot.xlim(140,280) +plot.ylim(10,80) +plot.title('Column LWA Change June 20 - 26') +plot.xlabel('Longitude') +plot.ylabel('Latitude') +ax5.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) +ax5.coastlines(alpha = 0.3) +ax5.set_aspect('auto', adjustable=None) +ax5.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) +ax5.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) +lon_formatter = LongitudeFormatter(zero_direction_label=True) +lat_formatter = LatitudeFormatter() +ax5.xaxis.set_major_formatter(lon_formatter) +ax5.yaxis.set_major_formatter(lat_formatter) +ott = ax5.contourf(x,y,zs,levels=cl2,transform=ccrs.PlateCarree(),cmap='rainbow') +fig.colorbar(ott,ax=ax5,label='LWA (m/s)') +plot.savefig('dLWA.png',bbox_inches='tight',dpi =600) +#plot.show() + +filename1 = "2021-06-01_to_2021-06-30_output3.nc" +filename2 = "2021-06-01_to_2021-06-30_output3.nc" +filename3 = "2021-06-01_to_2021-06-30_output3.nc" +filename4 = "2021-06-01_to_2021-06-30_output3.nc" +filename5 = "2021-06-01_to_2021-06-30_output3.nc" +filename6 = "2021-06-01_to_2021-06-30_output3.nc" + +# filename1 = data_dir + "2021_06_ua1_N.nc" +# filename2 = data_dir + "2021_06_ua2_N.nc" +# filename3 = data_dir + "2021_06_ep1_N.nc" +# filename4 = data_dir + "2021_06_ep2_N.nc" +# filename5 = data_dir + "2021_06_ep3_N.nc" +# filename6 = data_dir + "2021_06_ep4_N.nc" + +ncin1 = Dataset(filename1, 'r', format='NETCDF4') +ua1 = ncin1.variables['ua1'] +ua1 = (np.array(ua1)) +ncin2 = Dataset(filename2, 'r', format='NETCDF4') +ua2 = ncin2.variables['ua2'] +ua2 = (np.array(ua2)) +ncin3 = Dataset(filename3, 'r', format='NETCDF4') +ep1 = ncin3.variables['ep1'] +ep1 = (np.array(ep1)) +ncin4 = Dataset(filename4, 'r', format='NETCDF4') +ep2 = ncin4.variables['ep2'] +ep2 = (np.array(ep2)) +ncin5 = Dataset(filename5, 'r', format='NETCDF4') +ep3 = ncin5.variables['ep3'] +ep3 = (np.array(ep3)) +ncin6 = Dataset(filename6, 'r', format='NETCDF4') +ep4 = ncin6.variables['ep4'] +ep4 = (np.array(ep4)) + +f1 = np.zeros((91,360)) +f2 = np.zeros((91,360)) +f11 = np.zeros((91,360)) +f22 = np.zeros((91,360)) + +z1 = np.zeros((91,360)) +z2 = np.zeros((91,360)) +z3 = np.zeros((91,360)) +dt = 3600.*6. +a = 6378000. +dl = 2.*np.pi/360. +dp = 2.*np.pi/360. +m = 76 # m = 76 is 20 June 2021 00 UTC +while(m < 100): # m = 100 is 26 June 2021 00 UTC + z3[:,:] = z3[:,:]+0.5*dt*ep4[m,:,:] + z3[:,:] = z3[:,:]+0.5*dt*ep4[m+1,:,:] + f1[:,:] = f1[:,:]+(0.5/24.)*(ua1[m,:,:]+ua2[m,:,:]+ep1[m,:,:]) + f1[:,:] = f1[:,:]+(0.5/24.)*(ua1[m+1,:,:]+ua2[m+1,:,:]+ep1[m+1,:,:]) + f11[:,:] = f11[:,:]+(0.5/24.)*(ua1[m-24,:,:]+ua2[m-24,:,:]+ep1[m-24,:,:]) + f11[:,:] = f11[:,:]+(0.5/24.)*(ua1[m-23,:,:]+ua2[m-23,:,:]+ep1[m-23,:,:]) + j = 0 + while(j < 90): + phi = dp*j + const = 0.5*dt/(2.*a*np.cos(phi)*dl) + z2[j,:]=z2[j,:]+const*(ep2[m,j,:]-ep3[m,j,:]) + z2[j,:]=z2[j,:]+const*(ep2[m+1,j,:]-ep3[m+1,j,:]) + f2[j,:] = f2[j,:]+(0.25/24.)*(ep2[m,j,:]+ep3[m,j,:])/np.cos(phi) + f2[j,:] = f2[j,:]+(0.25/24.)*(ep2[m+1,j,:]+ep3[m+1,j,:])/np.cos(phi) + f22[j,:] = f22[j,:]+(0.25/24.)*(ep2[m-24,j,:]+ep3[m-24,j,:])/np.cos(phi) + f22[j,:] = f22[j,:]+(0.25/24.)*(ep2[m-23,j,:]+ep3[m-23,j,:])/np.cos(phi) + i = 1 + while(i < 359): + z1[j,i] = z1[j,i]-const*(ua1[m,j,i+1]+ua2[m,j,i+1]+ep1[m,j,i+1]-ua1[m,j,i-1]-ua2[m,j,i-1]-ep1[m,j,i-1]) + z1[j,i] = z1[j,i]-const*(ua1[m+1,j,i+1]+ua2[m+1,j,i+1]+ep1[m+1,j,i+1]-ua1[m+1,j,i-1]-ua2[m+1,j,i-1]-ep1[m+1,j,i-1]) + i = i+1 + z1[j,0] = z1[j,0]-const*(ua1[m,j,1]+ua2[m,j,1]+ep1[m,j,1]-ua1[m,j,359]-ua2[m,j,359]-ep1[m,j,359]) + z1[j,0] = z1[j,0]-const*(ua1[m+1,j,1]+ua2[m+1,j,1]+ep1[m+1,j,1]-ua1[m+1,j,359]-ua2[m+1,j,359]-ep1[m+1,j,359]) + z1[j,359] = z1[j,359]-const*(ua1[m,j,0]+ua2[m,j,0]+ep1[m,j,0]-ua1[m,j,358]-ua2[m,j,358]-ep1[m,j,358]) + z1[j,359] = z1[j,359]-const*(ua1[m+1,j,0]+ua2[m+1,j,0]+ep1[m+1,j,0]-ua1[m+1,j,358]-ua2[m+1,j,358]-ep1[m+1,j,358]) + j = j+1 + m = m+1 + +z1s = np.zeros((91,360)) # smoothed z1 # +z2s = np.zeros((91,360)) # smoothed z2 # +z3s = np.zeros((91,360)) # smoothed z3 # + +#### smoothing in longitude #### +j = 0 +while(j < 91): + z1x = np.zeros(360) + z1x[:] = z1[j,:] + z2x = np.zeros(360) + z2x[:] = z2[j,:] + z3x = np.zeros(360) + z3x[:] = z3[j,:] + nn = -n + while(nn < n+1): + z1y = np.roll(z1x,nn) + z1s[j,:] = z1s[j,:] + z1y[:]/(2*n+1) + z2y = np.roll(z2x,nn) + z2s[j,:] = z2s[j,:] + z2y[:]/(2*n+1) + z3y = np.roll(z3x,nn) + z3s[j,:] = z3s[j,:] + z3y[:]/(2*n+1) + nn = nn+1 + j = j+1 + +##### Wind vectors ###### + +x1 = np.arange(0,24)*15.+5. +y1 = np.arange(0,30)*3. +xx,yy = np.meshgrid(x1,y1) +uu = np.zeros((30,24)) +vv = np.zeros((30,24)) + +j = 0 +while(j < 30): + i = 0 + while(i < 24): + uu[j,i] = f1[j*3,i*15+5]-f11[j*3,i*15+5] + vv[j,i] = f2[j*3,i*15+5]-f22[j*3,i*15+5] + i = i+1 + j = j+1 + +print(zs[49,242],z1s[49,242],z2s[49,242],z3s[49,242],zs[49,242]-z1s[49,242]-z2s[49,242]-z3s[49,242]) +print(z1s[60,248]+z2s[60,248]) + +cl1 = np.arange(-200,220,20) +x = np.arange(0,360) +y = np.arange(0,91) +plot.rcParams.update({'font.size':14}) +fig = plot.figure(figsize=(8,4)) +ax6 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) +#ax6 = fig.add_subplot(1,1,1) +plot.xlim(0,360) +plot.ylim(10,80) +plot.title('Integrated Terms (I)+(II) June 20 - 26') +plot.xlabel('Longitude') +plot.ylabel('Latitude') +ax6.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) +ax6.coastlines(alpha = 0.3) +ax6.set_aspect('auto', adjustable=None) +ax6.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) +ax6.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) +lon_formatter = LongitudeFormatter(zero_direction_label=True) +lat_formatter = LatitudeFormatter() +ax6.xaxis.set_major_formatter(lon_formatter) +ax6.yaxis.set_major_formatter(lat_formatter) +ott = ax6.contourf(x,y,z1s+z2s-0.1,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') +fig.colorbar(ott,ax=ax6,label='(m/s)') +ax6.quiver(xx,yy,uu,vv,transform=ccrs.PlateCarree()) +plot.savefig('divFx+Fy.png',bbox_inches='tight',dpi =600) +#plot.show() + +cl1 = np.arange(-200,220,20) +x = np.arange(0,360) +y = np.arange(0,91) +plot.rcParams.update({'font.size':14}) +fig = plot.figure(figsize=(8,4)) +ax6 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) +plot.xlim(0,360) +plot.ylim(10,80) +plot.title('Integrated Term (III) June 20 - 26') +plot.xlabel('Longitude') +plot.ylabel('Latitude') +ax6.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) +ax6.coastlines(alpha = 0.3) +ax6.set_aspect('auto', adjustable=None) +ax6.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) +ax6.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) +lon_formatter = LongitudeFormatter(zero_direction_label=True) +lat_formatter = LatitudeFormatter() +ax6.xaxis.set_major_formatter(lon_formatter) +ax6.yaxis.set_major_formatter(lat_formatter) +ott = ax6.contourf(x,y,z3s,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') +fig.colorbar(ott,ax=ax6,label='(m/s)') +#ax6.quiver(xx,yy,uu,vv,transform=ccrs.PlateCarree()) +plot.savefig('EP4.png',bbox_inches='tight',dpi =600) +#plot.show() + +cl1 = np.arange(-200,220,20) +x = np.arange(0,360) +y = np.arange(0,91) +plot.rcParams.update({'font.size':14}) +fig = plot.figure(figsize=(8,4)) +ax6 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) +plot.xlim(0,360) +plot.ylim(10,80) +plot.title('Integrated Term (IV) June 20 - 26') +plot.xlabel('Longitude') +plot.ylabel('Latitude') +ax6.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) +ax6.coastlines(alpha = 0.3) +ax6.set_aspect('auto', adjustable=None) +ax6.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) +ax6.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) +lon_formatter = LongitudeFormatter(zero_direction_label=True) +lat_formatter = LatitudeFormatter() +ax6.xaxis.set_major_formatter(lon_formatter) +ax6.yaxis.set_major_formatter(lat_formatter) +ott = ax6.contourf(x,y,zs-z1s-z2s-z3s,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') +fig.colorbar(ott,ax=ax6,label='(m/s)') +ax6.quiver(xx,yy,uu,vv,transform=ccrs.PlateCarree()) +plot.savefig('Residual.png',bbox_inches='tight',dpi =600) +#plot.show() + + + diff --git a/scripts/nhn_grl2022/Fig3e.py b/scripts/nhn_grl2022/Fig3e.py new file mode 100644 index 0000000..7ae6899 --- /dev/null +++ b/scripts/nhn_grl2022/Fig3e.py @@ -0,0 +1,67 @@ +#This script reads in netCDF data for ERA5 +from netCDF4 import Dataset +import numpy as np +import matplotlib.pyplot as plot +import cartopy.crs as ccrs +from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter + +#----------------- +# read netCDF files +#----------------- + +data_dir = "grl2022_data/" +filename1 = data_dir + "2021_06_mtnlwrf.nc" # net OLR +filename2 = data_dir + "2021_06_mtnlwrfcs.nc" # OLR clear sky + +ncin1 = Dataset(filename1, 'r', format='NETCDF4') +ncin2 = Dataset(filename2, 'r', format='NETCDF4') +olr = ncin1.variables['mtnlwrf'] +olr = (np.array(olr)) +olrcs = ncin2.variables['mtnlwrfcs'] +olrcs = (np.array(olrcs)) + + +print(olr.shape) + +tt = np.zeros((44,181,360)) +t = np.zeros((181,360)) +m = 77 +while(m < 120): + tt[m-77,:,:] = olr[m,:,:] + m = m+1 +day = ['06 UTC 20 June 2021','06 UTC 21 June 2021','06 UTC 22 June 2021','06 UTC 23 June 2021','06 UTC 24 June 2021','06 UTC 25 June 2021','06 UTC 26 June 2021','06 UTC 27 June 2021','06 UTC 28 June 2021','06 UTC 29 June 2021','06 UTC 30 June 2021'] +b = ['OLR_0620.png','OLR_0621.png','OLR_0622.png','OLR_0623.png','OLR_0624.png','OLR_0625.png','OLR_0626.png','OLR_0627.png','OLR_0628.png','OLR_0629.png','OLR_0630.png'] +n = 0 +while(n < 11): + nn = n*4 + j = 0 + while(j < 181): + t[j,:]=tt[nn,180-j,:] + j = j+1 + cl1 = np.arange(80,390,10) + x = np.arange(0,360) + y = np.arange(0,181)-90. + plot.rcParams.update({'font.size':14,'text.usetex': False}) + fig = plot.figure(figsize=(8,4)) + ax5 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) + plot.xlim(140,280) + plot.ylim(10,80) + plot.title('OLR '+day[n]) + plot.xlabel('Longitude') + plot.ylabel('Latitude') + ax5.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) + ax5.coastlines(color='black',alpha = 0.7) + ax5.set_aspect('auto', adjustable=None) + ax5.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) + ax5.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) + lon_formatter = LongitudeFormatter(zero_direction_label=True) + lat_formatter = LatitudeFormatter() + ax5.xaxis.set_major_formatter(lon_formatter) + ax5.yaxis.set_major_formatter(lat_formatter) + ott = ax5.contourf(x,y,-t,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') + fig.colorbar(ott,ax=ax5,label='W/m$^2$') +# ott = ax5.contour(x,y,z,levels=cl1,colors='black',transform=ccrs.PlateCarree(),linewidths=1) +# ax5.clabel(ott, ott.levels,fmt='%5i') + plot.savefig(b[n],bbox_inches='tight',dpi =600) + + n = n+1 \ No newline at end of file diff --git a/scripts/nhn_grl2022/Fig3f.py b/scripts/nhn_grl2022/Fig3f.py new file mode 100644 index 0000000..695c0df --- /dev/null +++ b/scripts/nhn_grl2022/Fig3f.py @@ -0,0 +1,75 @@ +#This script reads in netCDF data for ERA5 +from netCDF4 import Dataset +import numpy as np +import matplotlib.pyplot as plot +import cartopy.crs as ccrs +from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter + +#----------------- +# read netCDF files +#----------------- + +data_dir = "grl2022_data/" +filename1 = data_dir + "2021_06_tcw.nc" # total column water (kg/m^2) +filename2 = data_dir + "2021_06_tcwv.nc" # total column water vapor (kg/m^2) +filename3 = data_dir + "2021_06_sp.nc" # sea level pressure (hPa) + +ncin1 = Dataset(filename1, 'r', format='NETCDF4') +ncin2 = Dataset(filename2, 'r', format='NETCDF4') +ncin3 = Dataset(filename3, 'r', format='NETCDF4') +cw = ncin1.variables['tcw'] +cw = (np.array(cw)) +cwv = ncin2.variables['tcwv'] +cwv = (np.array(cwv)) +sp = ncin3.variables['sp'] +sp = (np.array(sp)) + +tt = np.zeros((44,181,360)) +pp = np.zeros((44,181,360)) +t = np.zeros((181,360)) +p = np.zeros((181,360)) +m = 77 +while(m < 120): + tt[m-77,:,:] = cw[m,:,:]-cwv[m,:,:] + pp[m-77,:,:] = sp[m,:,:]/100. + m = m+1 +day = ['06 UTC 20 June 2021','06 UTC 21 June 2021','06 UTC 22 June 2021','06 UTC 23 June 2021','06 UTC 24 June 2021','06 UTC 25 June 2021','06 UTC 26 June 2021','06 UTC 27 June 2021','06 UTC 28 June 2021','06 UTC 29 June 2021','06 UTC 30 June 2021'] +b = ['CW_0620.png','CW_0621.png','CW_0622.png','CW_0623.png','CW_0624.png','CW_0625.png','CW_0626.png','CW_0627.png','CW_0628.png','CW_0629.png','CW_0630.png'] +n = 0 +while(n < 11): + nn = n*4 + j = 0 + while(j < 181): + t[j,:]=tt[nn,180-j,:] + p[j,:]=pp[nn,180-j,:] + j = j+1 + cl1 = np.arange(-0.1,3.6,0.1) + c12 = np.arange(980,1032,4) + x = np.arange(0,360) + y = np.arange(0,181)-90. + fig = plot.figure(figsize=(8,4)) + ax5 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) + plot.xlim(140,280) + plot.ylim(10,80) + plot.title('Column water '+day[n]) + plot.xlabel('Longitude') + plot.ylabel('Latitude') + ax5.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) + ax5.coastlines(color='white',alpha = 0.7) + ax5.set_aspect('auto', adjustable=None) + ax5.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) + ax5.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) + lon_formatter = LongitudeFormatter(zero_direction_label=True) + lat_formatter = LatitudeFormatter() + ax5.xaxis.set_major_formatter(lon_formatter) + ax5.yaxis.set_major_formatter(lat_formatter) + ott = ax5.contourf(x,y,t,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') + fig.colorbar(ott,ax=ax5,label='kg/m$^2$') + ott = ax5.contour(x,y,p,levels=c12,colors='white',alpha=0.5,transform=ccrs.PlateCarree(),linewidths=1) + ax5.clabel(ott, ott.levels,fmt='%5i') +# ott = ax5.contour(x,y,z,levels=cl1,colors='black',transform=ccrs.PlateCarree(),linewidths=1) +# ax5.clabel(ott, ott.levels,fmt='%5i') + plot.savefig(b[n],bbox_inches='tight',dpi =600) + # plot.show() + + n = n+1 \ No newline at end of file diff --git a/scripts/nhn_grl2022/Fig4.py b/scripts/nhn_grl2022/Fig4.py new file mode 100644 index 0000000..2f1e0ee --- /dev/null +++ b/scripts/nhn_grl2022/Fig4.py @@ -0,0 +1,225 @@ +## This script reads in netCDF LWAb data for ERA5 +from netCDF4 import Dataset +import numpy as np +import matplotlib.pyplot as plot + + +dt = 3600.*6. +a = 6378000. +dl = 2.*np.pi/360. +dp = 2.*np.pi/360. + +jm = 49 +jp = 49 + +#----------------- +# read netCDF files +#----------------- + +data_dir = "grl2022_data/" +# filename1 = data_dir + "2021_06_LWAb_N.nc" +filename1 = "2021-06-01_to_2021-06-30_output3.nc" + +ncin1 = Dataset(filename1, 'r', format='NETCDF4') + +lwa = ncin1.variables['lwa'] +lwa = (np.array(lwa)) + +print(lwa.shape) + +z = np.zeros((124,360)) # wave activity tendency +w = np.zeros((124,360)) # wave activity +m = 1 +while(m < 119): + j = jm + cos0 = 0 + while(j < jp+1): + phi = dp*j + z[m,:] = z[m,:]+np.cos(phi)*(lwa[m+1,j,:]-lwa[m-1,j,:])/(2.*dt) # wave activity tendency at 49 N + w[m,:] = w[m,:]+np.cos(phi)*lwa[m,j,:] + cos0 = cos0 + np.cos(phi) + j = j+1 + z[m,:] = z[m,:]/cos0 + w[m,:] = w[m,:]/cos0 + m = m+1 + +filename1 = data_dir + "2021_06_ua1_N.nc" +filename2 = data_dir + "2021_06_ua2_N.nc" +filename3 = data_dir + "2021_06_ep1_N.nc" +filename4 = data_dir + "2021_06_ep2_N.nc" +filename5 = data_dir + "2021_06_ep3_N.nc" +filename6 = data_dir + "2021_06_ep4_N.nc" +# filename1 = "2021-06-01_to_2021-06-30_output2.nc" +# filename2 = "2021-06-01_to_2021-06-30_output2.nc" +# filename3 = "2021-06-01_to_2021-06-30_output2.nc" +# filename4 = "2021-06-01_to_2021-06-30_output2.nc" +# filename5 = "2021-06-01_to_2021-06-30_output2.nc" +# filename6 = "2021-06-01_to_2021-06-30_output2.nc" + +ncin1 = Dataset(filename1, 'r', format='NETCDF4') +ua1 = ncin1.variables['ua1'] +ua1 = (np.array(ua1)) +ncin2 = Dataset(filename2, 'r', format='NETCDF4') +ua2 = ncin2.variables['ua2'] +ua2 = (np.array(ua2)) +ncin3 = Dataset(filename3, 'r', format='NETCDF4') +ep1 = ncin3.variables['ep1'] +ep1 = (np.array(ep1)) +ncin4 = Dataset(filename4, 'r', format='NETCDF4') +ep2 = ncin4.variables['ep2'] +ep2 = (np.array(ep2)) +ncin5 = Dataset(filename5, 'r', format='NETCDF4') +ep3 = ncin5.variables['ep3'] +ep3 = (np.array(ep3)) +ncin6 = Dataset(filename6, 'r', format='NETCDF4') +ep4 = ncin6.variables['ep4'] +ep4 = (np.array(ep4)) + +f1 = np.zeros((124,360)) + +z1 = np.zeros((124,360)) +z2 = np.zeros((124,360)) +z3 = np.zeros((124,360)) +z4 = np.zeros((124,360)) + +#phi = dp*49. +#const = 1./(2.*a*np.cos(phi)*dl) +i = 1 +while(i < 359): + j = jm + while(j < jp+1): + phi = dp*j + const = 1./(2.*a*dl) + z1[:,i] = z1[:,i]-const*(ua1[:,j,i+1]+ua2[:,j,i+1]+ep1[:,j,i+1]-ua1[:,j,i-1]-ua2[:,j,i-1]-ep1[:,j,i-1]) + j = j+1 + z1[:,i] = z1[:,i]/cos0 + i = i+1 +i = 0 +while(i < 360): + j = jm + while(j < jp+1): + phi = dp*j + const = 1./(2.*a*dl) + f1[:,i]=f1[:,i]+(ua1[:,j,i]+ua2[:,j,i]+ep1[:,j,i])*np.cos(phi) # zonal wave activity flux + z2[:,i]=z2[:,i]+const*(ep2[:,j,i]-ep3[:,j,i]) # metisional convergence of wave activity flux + z3[:,i]=z3[:,i]+np.cos(phi)*ep4[:,j,i] # bottom source + j = j+1 + f1[:,i] = f1[:,i]/cos0 + z2[:,i] = z2[:,i]/cos0 + z3[:,i] = z3[:,i]/cos0 + i = i+1 + +zs = np.zeros((124,360)) # smoothed z # +ws = np.zeros((124,360)) # smoothed w # +f1s = np.zeros((124,360)) # smoothed f1 # +z1s = np.zeros((124,360)) # smoothed z1 # +z2s = np.zeros((124,360)) # smoothed z2 # +z3s = np.zeros((124,360)) # smoothed z3 # + +#### smoothing in longitude #### +n = 4 # smoothing width = 2n+1 +j = 0 +while(j < 124): + zx = np.zeros(360) + zx[:] = z[j,:] + wx = np.zeros(360) + wx[:] = w[j,:] + f1x = np.zeros(360) + f1x[:] = f1[j,:] + z1x = np.zeros(360) + z1x[:] = z1[j,:] + z2x = np.zeros(360) + z2x[:] = z2[j,:] + z3x = np.zeros(360) + z3x[:] = z3[j,:] + nn = -n + while(nn < n+1): + wy = np.roll(wx,nn) + ws[j,:] = ws[j,:] + wy[:]/(2*n+1) + f1y = np.roll(f1x,nn) + f1s[j,:] = f1s[j,:] + f1y[:]/(2*n+1) + zy = np.roll(zx,nn) + zs[j,:] = zs[j,:] + zy[:]/(2*n+1) + z1y = np.roll(z1x,nn) + z1s[j,:] = z1s[j,:] + z1y[:]/(2*n+1) + z2y = np.roll(z2x,nn) + z2s[j,:] = z2s[j,:] + z2y[:]/(2*n+1) + z3y = np.roll(z3x,nn) + z3s[j,:] = z3s[j,:] + z3y[:]/(2*n+1) + nn = nn+1 + j = j+1 +z4[:,:]=zs[:,:]-z1s[:,:]-z2s[:,:]-z3s[:,:] # residual + + + +############################################## + +cl2 = np.arange(0,135,5) +x = np.arange(0,360) +y = np.arange(0,124)*0.25 +plot.rcParams.update({'font.size': 20}) +fig,ax5 = plot.subplots(1,figsize=(8,8)) +plot.xlim(140,280) +plot.ylim(20,29.75) +plot.title('Column LWA 49$^\circ$N') +plot.xlabel('Longitude') +plot.ylabel('Day') +ott = ax5.contourf(x,y,w,levels=cl2,cmap='rainbow') +fig.colorbar(ott,ax=ax5,label='(ms$^{-1}$)') +plot.savefig('HovmollerLWA.png',bbox_inches='tight',dpi =600) +#plot.show() + + +############################################## + +cl2 = np.arange(-100,1500,100) +x = np.arange(0,360) +y = np.arange(0,124)*0.25 +plot.rcParams.update({'font.size': 20}) +fig,ax5 = plot.subplots(1,figsize=(8,8)) +plot.xlim(140,280) +plot.ylim(20,29.75) +plot.title(' 49$^\circ$N') +plot.xlabel('Longitude') +plot.ylabel('Day') +ott = ax5.contourf(x,y,f1,levels=cl2,cmap='rainbow') +fig.colorbar(ott,ax=ax5,label='(m$^2$s$^{-2}$)') +#ott = ax5.contourf(x,y,z4,levels=[0.0005,0.001]) +plot.savefig('HovmollerFx.png',bbox_inches='tight',dpi =600) +#plot.show() + + +############################################## + +cl2 = np.arange(-10.,9,1) +x = np.arange(0,360) +y = np.arange(0,124)*0.25 +plot.rcParams.update({'font.size': 20}) +fig,ax5 = plot.subplots(1,figsize=(8,8)) +plot.xlim(140,280) +plot.ylim(20,29.5) +plot.title('Term (IV) 49$^\circ$N') +plot.xlabel('Longitude') +plot.ylabel('Day') +ott = ax5.contourf(x,y,z4*10000,levels=cl2,cmap='rainbow') +fig.colorbar(ott,ax=ax5,label='(10$^{-4}$ ms$^{-2}$)') +plot.savefig('HovmollerRes.png',bbox_inches='tight',dpi =600) +#plot.show() + + +############################################## + +cl2 = np.arange(-10.,9,1) +x = np.arange(0,360) +y = np.arange(0,124)*0.25 +plot.rcParams.update({'font.size': 20}) +fig,ax5 = plot.subplots(1,figsize=(8,8)) +plot.xlim(140,280) +plot.ylim(20,29.75) +plot.title('Terms (I)+(II) 49$^\circ$N') +plot.xlabel('Longitude') +plot.ylabel('Day') +ott = ax5.contourf(x,y,(z1s+z2s+z3s)*10000,levels=cl2,cmap='rainbow') +fig.colorbar(ott,ax=ax5,label='(10$^{-4}$ ms$^{-2}$)') +plot.savefig('HovmollerFxy.png',bbox_inches='tight',dpi =600) +#plot.show() \ No newline at end of file diff --git a/scripts/nhn_grl2022/Fig5.py b/scripts/nhn_grl2022/Fig5.py new file mode 100644 index 0000000..324c00d --- /dev/null +++ b/scripts/nhn_grl2022/Fig5.py @@ -0,0 +1,316 @@ +## This script reads in netCDF LWAb data for ERA5 +from netCDF4 import Dataset +import numpy as np +import matplotlib.pyplot as plot + +#----------------- +# read netCDF files +#----------------- + +data_dir = "grl2022_data/" +filename1 = data_dir + "2021_06_LWAb_N.nc" + +ncin1 = Dataset(filename1, 'r', format='NETCDF4') + +lwa = ncin1.variables['lwa'] +lwa = (np.array(lwa)) + +print(lwa.shape) + +z = np.zeros((120,360)) +m = 0 +while(m < 120): + z[m,:] = lwa[m,49,:] # 49N LWA for June 1-30 + m = m+1 + +zs = np.zeros((120,360)) # smoothed z # + +#### smoothing in longitude #### +n = 5 # smoothing width # +m = 0 +while(m < 120): + zx = np.zeros(360) + zx[:] = z[m,:] + nn = -n + while(nn < n+1): + zy = np.roll(zx,nn) + zs[m,:] = zs[m,:] + zy[:]/(2*n+1) + nn = nn+1 + m = m+1 + +zx[:] = zs[100,:]-zs[76,:] +zy[:] = 0 + + +filename1 = data_dir + "2021_06_ua1_N.nc" +filename2 = data_dir + "2021_06_ua2_N.nc" +filename3 = data_dir + "2021_06_ep1_N.nc" +filename4 = data_dir + "2021_06_ep2_N.nc" +filename5 = data_dir + "2021_06_ep3_N.nc" +filename6 = data_dir + "2021_06_ep4_N.nc" + +ncin1 = Dataset(filename1, 'r', format='NETCDF4') +ua1 = ncin1.variables['ua1'] +ua1 = (np.array(ua1)) +ncin2 = Dataset(filename2, 'r', format='NETCDF4') +ua2 = ncin2.variables['ua2'] +ua2 = (np.array(ua2)) +ncin3 = Dataset(filename3, 'r', format='NETCDF4') +ep1 = ncin3.variables['ep1'] +ep1 = (np.array(ep1)) +ncin4 = Dataset(filename4, 'r', format='NETCDF4') +ep2 = ncin4.variables['ep2'] +ep2 = (np.array(ep2)) +ncin5 = Dataset(filename5, 'r', format='NETCDF4') +ep3 = ncin5.variables['ep3'] +ep3 = (np.array(ep3)) +ncin6 = Dataset(filename6, 'r', format='NETCDF4') +ep4 = ncin6.variables['ep4'] +ep4 = (np.array(ep4)) + +f1 = np.zeros((120,360)) +f2 = np.zeros((120,360)) +f11 = np.zeros((120,360)) +f22 = np.zeros((120,360)) + +z1 = np.zeros((120,360)) +z2 = np.zeros((120,360)) +z3 = np.zeros((120,360)) +dt = 3600.*6. +a = 6378000. +dl = 2.*np.pi/360. +dp = 2.*np.pi/360. +m = 0 # m = 76 is 20 June 2021 00 UTC +while(m < 120): # m = 100 is 26 June 2021 00 UTC + z3[m,:] = ep4[m,49,:] + f1[m,:] = ua1[m,49,:]+ua2[m,49,:]+ep1[m,49,:] + j = 49 + phi = dp*j + const = 1./(2.*a*np.cos(phi)*dl) + z2[m,:]=const*(ep2[m,49,:]-ep3[m,49,:]) + f2[m,:] = 0.5*(ep2[m,49,:]+ep3[m,49,:])/np.cos(phi) + i = 1 + while(i < 359): + z1[m,i] = -const*(f1[m,i+1]-f1[m,i-1]) + i = i+1 + z1[m,0] = -const*(f1[m,1]-f1[m,359]) + z1[m,359] = -const*(f1[m,0]-f1[m,358]) + m = m+1 + +z1s = np.zeros((120,360)) # smoothed z1 # +z2s = np.zeros((120,360)) # smoothed z2 # +z3s = np.zeros((120,360)) # smoothed z3 # +f1s = np.zeros((120,360)) # smoothed f1 # + +#### smoothing in longitude #### +m = 0 +while(m < 120): + z1x = np.zeros(360) + z1x[:] = z1[m,:] + z2x = np.zeros(360) + z2x[:] = z2[m,:] + z3x = np.zeros(360) + z3x[:] = z3[m,:] + f1x = np.zeros(360) + f1x[:] = f1[m,:] + + nn = -n + while(nn < n+1): + z1y = np.roll(z1x,nn) + z1s[m,:] = z1s[m,:] + z1y[:]/(2*n+1) + z2y = np.roll(z2x,nn) + z2s[m,:] = z2s[m,:] + z2y[:]/(2*n+1) + z3y = np.roll(z3x,nn) + z3s[m,:] = z3s[m,:] + z3y[:]/(2*n+1) + f1y = np.roll(f1x,nn) + f1s[m,:] = f1s[m,:] + f1y[:]/(2*n+1) + nn = nn+1 + m = m+1 + +##### Time integration test ###### + +lwa = np.zeros(360) +res = np.zeros((120,360)) +dlwa = np.zeros((120,360)) +gama = np.zeros((120,360)) +gama1 = np.zeros((120,360)) +gama2 = np.zeros((120,360)) +cgx = np.zeros((120,360)) + +m = 0 +while(m < 119): + dlwa[m,:] = zs[m+1,:]-zs[m,:] + cgx[m,:] = (f1s[m,:]+f1s[m+1,:])/(zs[m,:]+zs[m+1,:]) + res[m,:] = (dlwa[m,:] - 0.5*dt*(z1s[m,:]+z1s[m+1,:]+z2s[m,:]+z2s[m+1,:]+z3s[m,:]+z3s[m+1,:]))/dt + gama[m,:] = 2.*res[m,:]/(zs[m,:]+zs[m+1,:]) + m = m+1 + +m = 76 +while(m < 100): + lwa[:] = lwa[:] + 0.5*dt*(z1s[m,:]+z1s[m+1,:]+z2s[m,:]+z2s[m+1,:]+z3s[m,:]+z3s[m+1,:]) + dt*res[m,:] + m = m+1 + + +m = 76 +j = 49 +phi = dp*j +const = 1./(2.*a*np.cos(phi)*dl) +lwa0 = np.zeros((120,360)) +lwa1 = np.zeros((120,360)) + +lwa0[:,:] = zs[:,:] +lwa1[:,:] = zs[:,:] + + +while(m < 100): + i = 1 + while(i < 359): + d0 = -const*0.5*((lwa0[m,i+1]+lwa0[m+1,i+1])*cgx[m,i+1]-(lwa0[m,i-1]+lwa0[m+1,i-1])*cgx[m,i-1]) + d2 = 0.5*(z2s[m+1,i]+z2s[m,i]) + d3 = 0.5*(z3s[m+1,i]+z3s[m,i]) + d4 = gama[m,i]*0.5*(zs[m,i]+zs[m+1,i]) + lwa1[m+1,i] = lwa1[m,i]+dt*(d0+d2+d3+d4) + i = i+1 + d0 = -const*0.5*((lwa0[m,0]+lwa0[m+1,0])*cgx[m,0]-(lwa0[m,358]+lwa0[m+1,358])*cgx[m,358]) + d2 = 0.5*(z2s[m+1,359]+z2s[m,359]) + d3 = 0.5*(z3s[m+1,359]+z3s[m,359]) + d4 = gama[m,359]*0.5*(zs[m,359]+zs[m+1,359]) + lwa1[m+1,359] = lwa1[m,359]+dt*(d0+d2+d3+d4) + + d0 = -const*0.5*((lwa0[m,1]+lwa0[m+1,1])*cgx[m,1]-(lwa0[m,359]+lwa0[m+1,359])*cgx[m,359]) + d2 = 0.5*(z2s[m+1,0]+z2s[m,0]) + d3 = 0.5*(z3s[m+1,0]+z3s[m,0]) + d4 = gama[m,0]*0.5*(zs[m,0]+zs[m+1,0]) + lwa1[m+1,0] = lwa1[m,0]+dt*(d0+d2+d3+d4) + m = m+1 + +#### Modify gamma #### + +gama1[:,:] = gama[:,:] +gama2[:,:] = gama[:,:] +m = 76 +while(m < 100): + if((m >= 84) and (m <= 92)): + i = 200 + while(i < 221): + if(gama[m,i] > 0): + gama1[m,i] = gama[m,i]*0.7 + gama2[m,i] = gama[m,i]*0. + i = i+1 + m = m+1 + +gama1[:,:] = gama1[:,:]-gama[:,:] +gama2[:,:] = gama2[:,:]-gama[:,:] + +##### Interpolate gama, gama1, cgx onto finer tiem mesh dt = 30 min ##### + +gamap = np.zeros((8640,360)) +gama1p = np.zeros((8640,360)) +gama2p = np.zeros((8640,360)) +cgxp = np.zeros((8640,360)) +forcep = np.zeros((8640,360)) +lwap = np.zeros((8640,360)) + +m = 76 +while(m < 101): + i = 0 + while(i < 360): + mm = (m-76)*360+i-180 + if(mm >= 0): + if(mm < 8640): + gamap[mm,:] = gama[m,:]*(i/360.)+gama[m-1,:]*(1.-i/360.) + gama1p[mm,:] = gama1[m,:]*(i/360.)+gama1[m-1,:]*(1.-i/360.) + gama2p[mm,:] = gama2[m,:]*(i/360.)+gama2[m-1,:]*(1.-i/360.) + cgxp[mm,:] = cgx[m,:]*(i/360.)+cgx[m-1,:]*(1.-i/360.) + i = i+1 + m = m+1 + +m = 76 +while(m < 100): + i = 0 + while(i < 360): + mm = (m-76)*360+i + forcep[mm,:] = (z2s[m+1,:]+z3s[m+1,:])*(i/360.)+(z2s[m,:]+z3s[m,:])*(1.-i/360.) + lwap[mm,:] = zs[m+1,:]*(i/360.)+zs[m,:]*(1.-i/360.) + i = i+1 + m = m+1 + +##### Time integration #### + +dt = 60. +j = 49 +phi = dp*j +const = 1./(2.*a*np.cos(phi)*dl) +al = 0. +diff = 200000. +dlwap = np.zeros((8641,360)) +dlwap2 = np.zeros((8641,360)) + +m = 1 +while(m < 8640): + i = 1 + while(i < 359): + d1 = -const*(dlwap[m,i+1]*(cgxp[m,i+1]-al*(dlwap[m,i+1]+lwap[m,i+1]))-dlwap[m,i-1]*(cgxp[m,i-1]-al*(dlwap[m,i-1]+lwap[m,i-1]))) + d2 = gama1p[m,i]*dlwap[m,i] + d3 = gamap[m,i]*dlwap[m,i] + d4 = gama1p[m,i]*lwap[m,i] + d5 = diff*(dlwap[m-1,i+1]+dlwap[m-1,i-1]-2.*dlwap[m-1,i])/(a*a*dl*dl*np.cos(phi)*np.cos(phi)) + dlwap[m+1,i] = dlwap[m-1,i]+2.*dt*(d1+d2+d3+d4+d5) + + d12 = -const*(dlwap2[m,i+1]*(cgxp[m,i+1]-al*(dlwap2[m,i+1]+lwap[m,i+1]))-dlwap2[m,i-1]*(cgxp[m,i-1]-al*(dlwap2[m,i-1]+lwap[m,i-1]))) + d22 = gama2p[m,i]*dlwap2[m,i] + d32 = gamap[m,i]*dlwap2[m,i] + d42 = gama2p[m,i]*lwap[m,i] + d52 = diff*(dlwap2[m-1,i+1]+dlwap2[m-1,i-1]-2.*dlwap2[m-1,i])/(a*a*dl*dl*np.cos(phi)*np.cos(phi)) + dlwap2[m+1,i] = dlwap2[m-1,i]+2.*dt*(d12+d22+d32+d42+d52) + i = i+1 + + d1 = -const*(dlwap[m,0]*(cgxp[m,0]-al*(dlwap[m,0]+lwap[m,0]))-dlwap[m,358]*(cgxp[m,358]-al*(dlwap[m,358]+lwap[m,358]))) + d2 = gama1p[m,359]*dlwap[m,359] + d3 = gamap[m,359]*dlwap[m,359] + d4 = gama1p[m,359]*lwap[m,359] + d5 = diff*(dlwap[m-1,0]+dlwap[m-1,358]-2.*dlwap[m-1,359])/(a*a*dl*dl*np.cos(phi)*np.cos(phi)) + dlwap[m+1,359] = dlwap[m-1,359]+2.*dt*(d1+d2+d3+d4+d5) + + d12 = -const*(dlwap2[m,0]*(cgxp[m,0]-al*(dlwap2[m,0]+lwap[m,0]))-dlwap2[m,358]*(cgxp[m,358]-al*(dlwap2[m,358]+lwap[m,358]))) + d22 = gama2p[m,359]*dlwap2[m,359] + d32 = gamap[m,359]*dlwap2[m,359] + d42 = gama2p[m,359]*lwap[m,359] + d52 = diff*(dlwap2[m-1,0]+dlwap2[m-1,358]-2.*dlwap2[m-1,359])/(a*a*dl*dl*np.cos(phi)*np.cos(phi)) + dlwap2[m+1,359] = dlwap[m-1,359]+2.*dt*(d12+d22+d32+d42+d52) + + d1 = -const*(dlwap[m,1]*(cgxp[m,1]-al*(dlwap[m,1]+lwap[m,1]))-dlwap[m,359]*(cgxp[m,359]-al*(dlwap[m,359]+lwap[m,359]))) + d2 = gama1p[m,0]*dlwap[m,0] + d3 = gamap[m,0]*dlwap[m,0] + d4 = gama1p[m,0]*lwap[m,0] + d5 = diff*(dlwap[m-1,1]+dlwap[m-1,359]-2.*dlwap[m-1,0])/(a*a*dl*dl*np.cos(phi)*np.cos(phi)) + dlwap[m+1,0] = dlwap[m-1,0]+2.*dt*(d1+d2+d3+d4+d5) + + d12 = -const*(dlwap2[m,1]*(cgxp[m,1]-al*(dlwap2[m,1]+lwap[m,1]))-dlwap2[m,359]*(cgxp[m,359]-al*(dlwap2[m,359]+lwap[m,359]))) + d22 = gama2p[m,0]*dlwap2[m,0] + d32 = gamap[m,0]*dlwap2[m,0] + d42 = gama2p[m,0]*lwap[m,0] + d52 = diff*(dlwap2[m-1,1]+dlwap2[m-1,359]-2.*dlwap2[m-1,0])/(a*a*dl*dl*np.cos(phi)*np.cos(phi)) + dlwap2[m+1,0] = dlwap2[m-1,0]+2.*dt*(d12+d22+d32+d42+d52) + m = m+1 + +gm = np.zeros(360) +gm2 = np.zeros(360) +gm[:] = lwa[:]+dlwap[8640,:] +gm2[:] = lwa[:]+dlwap2[8640,:] +x = np.arange(0,360) +plot.rcParams.update({'font.size':14}) +fig = plot.figure(figsize=(8,4)) +plot.xlim(140,280) +plot.ylim(-80,80) +plot.title('Column LWA Change 49$^\circ$N June 20 - 26 00 UTC') +plot.xlabel('Longitude') +plot.ylabel('$\Delta$LWA (m/s)') +ott = plot.plot(x,zx) +ott = plot.plot(x,zy,color='black',alpha = 0.3) +ott = plot.plot(x,gm,color='red',alpha = 0.5) +ott = plot.plot(x,gm2,'r--',alpha = 0.5) +plot.savefig('dLWAp.png',bbox_inches='tight',dpi =600) +#plot.show() + +print(lwa[242],lwa[252]+dlwap[8640,252]) \ No newline at end of file diff --git a/scripts/nhn_grl2022/download_data_nhn_grl2022.py b/scripts/nhn_grl2022/download_data_nhn_grl2022.py new file mode 100644 index 0000000..446fd6c --- /dev/null +++ b/scripts/nhn_grl2022/download_data_nhn_grl2022.py @@ -0,0 +1,59 @@ +""" +Download data to reproduce plots in Neal et al. (submitted to GRL) +""" + +import json +from datetime import date, datetime +from calendar import monthrange +import cdsapi + + +def download_era5_pressure_level_data(filename): + cdsapi_client = cdsapi.Client() + all_pressure_level = [ + '1', '2', '3', '5', '7', '10', '20', '30', '50', '70', '100', '125', '150', '175', '200', + '225', '250', '300', '350', '400', '450', '500', '550', '600', '650', '700', '750', '775', + '800', '825', '850', '875', '900', '925', '950', '975', '1000'] + variable_names = [ + "geopotential", + "temperature", + "u_component_of_wind", + "v_component_of_wind", + "vertical_velocity"] + + cdsapi_client.retrieve( + 'reanalysis-era5-pressure-levels', + { + 'pressure_level': all_pressure_level, + 'variable': variable_names, + 'time': ["00:00", "06:00", "12:00", "18:00"], + 'grid': "1.0/1.0", + 'product_type': 'reanalysis', + 'year': '2021', + 'day': [f'{i}' for i in range(20, 31)], + 'month': '6', + 'format': 'netcdf' + }, + filename + ) + + +def download_single_level_data(self, filename): + self._cdsapi_client.retrieve( + 'reanalysis-era5-single-levels', + { + 'variable': ["2m_temperature"], + 'time': ["00:00", "06:00", "12:00", "18:00"], + 'grid': "1.0/1.0", + 'product_type': 'reanalysis', + 'year': '2021', + 'day': [f'{i}' for i in range(20, 31)], + 'month': '6', + 'format': 'netcdf' + }, + filename + ) + + +if __name__ == "__main__": + download_era5_pressure_level_data("pressure_level_data_20210620to30.nc") diff --git a/scripts/nhn_grl2022/era1000.f90 b/scripts/nhn_grl2022/era1000.f90 new file mode 100644 index 0000000..2384c41 --- /dev/null +++ b/scripts/nhn_grl2022/era1000.f90 @@ -0,0 +1,435 @@ + Program era + +! Read ERA5 binary files and computes QG fields. +! *** 6 hourly data *** + + integer,parameter :: kmax = 97 + character*30 :: file1,file2,file3,file4,file5 + character*34 :: file6 + character*33 :: file7 + character*32 :: file8,file9,file10,file11,file12 + character*30 :: fn + + common /arry/ tt(360,181,37),tzd(181,kmax) + common /crry/ uu(360,181,37) + common /drry/ vv(360,181,37) + common /brry/ ww(360,181,37) + common /erry/ zz(360,181,37) + common /brry/ xlon(360),ylat(181),plev(37) + common /frry/ height(kmax),statn(kmax),stats(kmax) + common /ffry/ ts0(kmax),tn0(kmax),zlev(37) + common /grry/ st(360,181),zmst(181),uq(360,181,kmax) + common /irry/ vq(360,181,kmax) + common /jrry/ wq(360,181,kmax) + common /krry/ tq(360,181,kmax) + common /lrry/ zq(360,181,kmax) + common /hhry/ tt0(360,181,kmax) + common /irry/ avort(360,181,kmax),zmav(181,kmax) + common /jrry/ pv(360,181,kmax),zmpv(181,kmax) + integer :: dsadata,mm(12),inverse(12,37) + integer :: k0(kmax),kp(kmax) + real :: dd2(kmax),dd1(kmax),pks(kmax) + character*5 :: yy + character*4 :: y0(44),y00 + character*3 :: mn(12) + character*8 :: yr + + y0(1) = '1978' + y0(2) = '1979' + y0(3) = '1980' + y0(4) = '1981' + y0(5) = '1982' + y0(6) = '1983' + y0(7) = '1984' + y0(8) = '1985' + y0(9) = '1986' + y0(10) = '1987' + y0(11) = '1988' + y0(12) = '1989' + y0(13) = '1990' + y0(14) = '1991' + y0(15) = '1992' + y0(16) = '1993' + y0(17) = '1994' + y0(18) = '1995' + y0(19) = '1996' + y0(20) = '1997' + y0(21) = '1998' + y0(22) = '1999' + y0(23) = '2000' + y0(24) = '2001' + y0(25) = '2002' + y0(26) = '2003' + y0(27) = '2004' + y0(28) = '2005' + y0(29) = '2006' + y0(30) = '2007' + y0(31) = '2008' + y0(32) = '2009' + y0(33) = '2010' + y0(34) = '2011' + y0(35) = '2012' + y0(36) = '2013' + y0(37) = '2014' + y0(38) = '2015' + y0(39) = '2016' + y0(40) = '2017' + y0(41) = '2018' + y0(42) = '2019' + y0(43) = '2020' + y0(44) = '2021' + + dz = 500. + cp = 1004. + rr = 287. + rkappa = rr/cp + grav = 9.81 + pi = acos(-1.) + omega = 7.29e-5 + aa = 6378000. + dphi = pi/180. + hh = 7000. + +! ====== Assign pseudoheight ===== + + do k = 1,kmax + height(k) = float(k-1)*dz + pks(k) = exp(rkappa*height(k)/hh) + enddo + + do mmm = 44,44 + mf = 28 ! 29 for leap year + if(mod(mmm,4).eq.3) mf = 29 + y00 = y0(mmm) + yy = y00//'_' ! Year to extract + mm(1) = 31 + mm(2) = mf ! Adjust for leap years + mm(3) = 31 + mm(4) = 30 + mm(5) = 31 + mm(6) = 30 + mm(7) = 31 + mm(8) = 31 + mm(9) = 30 + mm(10) = 31 + mm(11) = 30 + mm(12) = 31 + + mn(1) = '01_' + mn(2) = '02_' + mn(3) = '03_' + mn(4) = '04_' + mn(5) = '05_' + mn(6) = '06_' + mn(7) = '07_' + mn(8) = '08_' + mn(9) = '09_' + mn(10) = '10_' + mn(11) = '11_' + mn(12) = '12_' + + plev(1) = 1000. + plev(2) = 975. + plev(3) = 950. + plev(4) = 925. + plev(5) = 900. + plev(6) = 875. + plev(7) = 850. + plev(8) = 825. + plev(9) = 800. + plev(10) = 775. + plev(11) = 750. + plev(12) = 700. + plev(13) = 650. + plev(14) = 600. + plev(15) = 550. + plev(16) = 500. + plev(17) = 450. + plev(18) = 400. + plev(19) = 350. + plev(20) = 300. + plev(21) = 250. + plev(22) = 225. + plev(23) = 200. + plev(24) = 175. + plev(25) = 150. + plev(26) = 125. + plev(27) = 100. + plev(28) = 70. + plev(29) = 50. + plev(30) = 30. + plev(31) = 20. + plev(32) = 10. + plev(33) = 7. + plev(34) = 4. + plev(35) = 3. + plev(36) = 2. + plev(37) = 1. + + do k = 1,37 + zlev(k) = -hh*alog(plev(k)/1000.) + enddo + do kk = 2,kmax ! vertical interpolation + ttt = height(kk) + do k = 1,36 + tt2 = zlev(k+1) + tt1 = zlev(k) + if((ttt.ge.tt1).and.(ttt.lt.tt2)) then + k0(kk) = k + kp(kk) = k+1 + dd1(kk) = (ttt-tt1)/(tt2-tt1) + dd2(kk) = 1.-dd1(kk) + endif + enddo + enddo + +do m = 11,11 + + nn = mm(m)*4 + yr = yy//mn(m) + + file1 = '/data2/nnn/ERA5/'//y00//'/'//yr//'U' + file2 = '/data2/nnn/ERA5/'//y00//'/'//yr//'V' + file3 = '/data2/nnn/ERA5/'//y00//'/'//yr//'W' + file4 = '/data2/nnn/ERA5/'//y00//'/'//yr//'T' + file5 = '/data2/nnn/ERA5/'//y00//'/'//yr//'Z' + file6 = '/data2/nnn/ERA5/'//y00//'/'//yr//'QVORT' + file7 = '/data2/nnn/ERA5/'//y00//'/'//yr//'QGPV' + file8 = '/data2/nnn/ERA5/'//y00//'/'//yr//'QGU' + file9 = '/data2/nnn/ERA5/'//y00//'/'//yr//'QGV' + file10 = '/data2/nnn/ERA5/'//y00//'/'//yr//'QGW' + file11 = '/data2/nnn/ERA5/'//y00//'/'//yr//'QGT' + file12 = '/data2/nnn/ERA5/'//y00//'/'//yr//'QGZ' + + open(31,file=file1,form='unformatted',status='old') + open(32,file=file2,form='unformatted',status='old') + open(33,file=file3,form='unformatted',status='old') + open(34,file=file4,form='unformatted',status='old') + open(35,file=file5,form='unformatted',status='old') + open(36,file=file6,form='unformatted',status='new') + open(37,file=file7,form='unformatted',status='new') + open(38,file=file8,form='unformatted',status='new') + open(39,file=file9,form='unformatted',status='new') + open(40,file=file10,form='unformatted',status='new') + open(41,file=file11,form='unformatted',status='new') + open(42,file=file12,form='unformatted',status='new') + +do l = 1,nn + + read(31) uu + read(32) vv + read(33) ww + read(34) tt + read(35) zz + +! ==== vertical interpolation ==== + + do i = 1,360 + do j = 1,181 + + st(i,j) = tt(i,j,1) ! surface pot. temp + + do kk = 2,kmax ! vertical interpolation + uq(i,j,kk) = uu(i,j,k0(kk))*dd2(kk) + uu(i,j,kp(kk))*dd1(kk) + vq(i,j,kk) = vv(i,j,k0(kk))*dd2(kk) + vv(i,j,kp(kk))*dd1(kk) + wq(i,j,kk) = ww(i,j,k0(kk))*dd2(kk) + ww(i,j,kp(kk))*dd1(kk) + tq(i,j,kk) = tt(i,j,k0(kk))*dd2(kk) + tt(i,j,kp(kk))*dd1(kk) + tq(i,j,kk) = tq(i,j,kk)*pks(kk) ! potential temperature + zq(i,j,kk) = zz(i,j,k0(kk))*dd2(kk) + zz(i,j,kp(kk))*dd1(kk) + enddo + + tq(i,j,1) = tt(i,j,1) + uq(i,j,1) = uu(i,j,1) + vq(i,j,1) = vv(i,j,1) + wq(i,j,1) = ww(i,j,1) + zq(i,j,1) = zz(i,j,1) + enddo + enddo + +! **** compute zonal mean **** + + tzd = 0. + + do j = 1,181 + do k = 1,kmax + do i = 1,360 + tzd(j,k) = tzd(j,k) + tq(i,j,k)/360. + enddo + enddo + enddo + + +! reference theta + do kk = 1,kmax + ts0(kk) = 0. + tn0(kk) = 0. + csm = 0. + cnm = 0. + do j = 1,91 + phi0 = -90.+float(j-1) + phi0 = phi0*pi/180. + ts0(kk) = ts0(kk) + tzd(j,kk)*cos(phi0) + csm = csm + cos(phi0) + enddo + ts0(kk) = ts0(kk)/csm + do j = 91,181 + phi0 = -90.+float(j-1) + phi0 = phi0*pi/180. + tn0(kk) = tn0(kk) + tzd(j,kk)*cos(phi0) + cnm = cnm + cos(phi0) + enddo + tn0(kk) = tn0(kk)/cnm + enddo + +! static stability + do kk = 2,kmax-1 + stats(kk) = (ts0(kk+1)-ts0(kk-1))/(height(kk+1)-height(kk-1)) + statn(kk) = (tn0(kk+1)-tn0(kk-1))/(height(kk+1)-height(kk-1)) + enddo + stats(kmax) = 2.*stats(kmax-1)-stats(kmax-2) + statn(kmax) = 2.*statn(kmax-1)-statn(kmax-2) + stats(1) = 2.*stats(2)-stats(3) + statn(1) = 2.*statn(2)-statn(3) + +! surface temp + + do j = 1,181 + zmst(j) = 0. + do i = 1,360 + zmst(j) = zmst(j) + st(i,j)/360. + enddo + enddo + +! interior abs. vort + + do kk = 1,kmax + do j = 2,180 + phi0 = -90.+float(j-1) + phi0 = phi0*pi/180. + phim = -90.+float(j-2) + phim = phim*pi/180. + phip = -90.+float(j) + phip = phip*pi/180. + + do i = 2,359 + av1 = 2.*omega*sin(phi0) + av2 = (vq(i+1,j,kk)-vq(i-1,j,kk))/(2.*aa*cos(phi0)*dphi) + av3 = -(uq(i,j+1,kk)*cos(phip)-uq(i,j-1,kk)*cos(phim))/(2.*aa*cos(phi0)*dphi) + avort(i,j,kk) = av1+av2+av3 + enddo + + av1 = 2.*omega*sin(phi0) + av2 = (vq(2,j,kk)-vq(360,j,kk))/(2.*aa*cos(phi0)*dphi) + av3 = -(uq(1,j+1,kk)*cos(phip)-uq(1,j-1,kk)*cos(phim))/(2.*aa*cos(phi0)*dphi) + avort(1,j,kk) = av1+av2+av3 + av4 = 2.*omega*sin(phi0) + av5 = (vq(1,j,kk)-vq(359,j,kk))/(2.*aa*cos(phi0)*dphi) + av6 = & +-(uq(360,j+1,kk)*cos(phip)-uq(360,j-1,kk)*cos(phim))/(2.*aa*cos(phi0)*dphi) + avort(360,j,kk) = av4+av5+av6 + enddo + + avs = 0. + avn = 0. + do i = 1,360 + avs = avs + avort(i,2,kk)/360. + avn = avn + avort(i,180,kk)/360. + enddo + avort(:,1,kk) = avs + avort(:,181,kk) = avn + enddo + +! zonal mean vort + + do kk = 1,kmax + do j = 1,181 + zmav(j,kk) = 0. + do i = 1,360 + zmav(j,kk) = zmav(j,kk)+avort(i,j,kk)/360. + enddo + enddo + enddo + +! interior pv + + do kk = 2,kmax-1 + do j = 1,181 + phi0 = -90.+float(j-1) + phi0 = phi0*pi/180. + f = 2.*omega*sin(phi0) + if(j.le.91) then + statp = stats(kk+1) + statm = stats(kk-1) + t00p = ts0(kk+1) + t00m = ts0(kk-1) + else + statp = statn(kk+1) + statm = statn(kk-1) + t00p = tn0(kk+1) + t00m = tn0(kk-1) + endif + + do i = 1,360 + thetap = tq(i,j,kk+1) + thetam = tq(i,j,kk-1) + altp = exp(-height(kk+1)/hh)*(thetap-t00p)/statp + altm = exp(-height(kk-1)/hh)*(thetam-t00m)/statm + strc = (altp-altm)*f/(height(kk+1)-height(kk-1)) + pv(i,j,kk) = avort(i,j,kk) + exp(height(kk)/hh)*strc + enddo + enddo + enddo + +! zonal mean pv + + do kk = 1,kmax + do j = 1,181 + zmpv(j,kk) = 0. + do i = 1,360 + zmpv(j,kk) = zmpv(j,kk)+pv(i,j,kk)/360. + enddo + enddo + enddo + + write(36) avort + write(37) pv + write(38) uq + write(39) vq + write(40) wq + write(41) tq,tn0,ts0,statn,stats + write(42) zq + !write(40) tt0,ts0,tn0,stats,statn + + +!hape(1) = 121 +!hape(2) = 37 +!fn = '/data/nnn/ERA_Interim/'//yr +! ret = dsadata(fn//'uz.df',2,shape,uz) +! ret = dsadata(fn//'vz.df',2,shape,vz) +! ret = dsadata(fn//'tz.df',2,shape,tz) +! ret = dsadata(fn//'zz.df',2,shape,zzz) + + write(6,*) 'month =',m,' file =',l +enddo + close(31) + close(32) + close(33) + close(34) + close(35) + close(36) + close(37) + close(38) + close(39) + close(40) + close(41) + close(42) + +enddo +enddo + +!do k = 1,kmax +! write(6,*) k,height(k),statn(k),stats(k) +!enddo + +stop +end diff --git a/scripts/nhn_grl2022/era4000n.f90 b/scripts/nhn_grl2022/era4000n.f90 new file mode 100644 index 0000000..e07fbd3 --- /dev/null +++ b/scripts/nhn_grl2022/era4000n.f90 @@ -0,0 +1,239 @@ + program main + +! **** take QGPV and compute LWA and fluxes for +! NH *** +! Only barotropic fluxes are saved + + integer,parameter :: imax = 360, JMAX = 181, KMAX = 97 + integer,parameter :: nd = 91,nnd=181,jd = 86 + common /array/ pv(imax,jmax,kmax) + common /brray/ uu(imax,jmax,kmax) + common /bbray/ vv(imax,jmax,kmax) + common /bcray/ pt(imax,jmax,kmax) + common /bdray/ stats(kmax),statn(kmax),ts0(kmax),tn0(kmax) + common /crray/ tb(kmax),tg(kmax) + common /erray/ astar1(imax,nd,kmax) + common /errayy/ astar2(imax,nd,kmax) + common /errayx/ ua1(imax,nd),ua2(imax,nd),ep1(imax,nd) + common /frrayx/ ep2(imax,nd),ep3(imax,nd) + common /errayz/ qe(imax,nd),ue(imax,nd) + common /frray/ z(kmax),ep4(imax,nd) + common /grray/ ubaro(imax,nd),urefbaro(nd),astarbaro(imax,nd) + common /hrray/ ua1baro(imax,nd),ua2baro(imax,nd) + common /hrray/ ep1baro(imax,nd),ep2baro(imax,nd) + common /hrray/ ep3baro(imax,nd) + common /irray/ qref(91,kmax),u(91,kmax) + common /jrray/ qbar(91,kmax),ubar(91,kmax),tbar(91,kmax) + common /krray/ uref(jd,kmax),tref(jd,kmax),fawa(91,kmax) + integer :: md(12) + + character*35 fn,fn0,fn1 + character*34 fu + character*34 ft,fv + character*38 fx + character*4 fn2(12),fy,fy1,fy2 + character*18 f1,f2 + character*19 f3 + character*36 fr + character*37 fm + + a = 6378000. + pi = acos(-1.) + om = 7.29e-5 + dp = pi/180. + dz = 500. + h = 7000. + r = 287. + rkappa = r/1004. + + do k = 1,kmax + z(k) = dz*float(k-1) + enddo + + do m = 2021,2021 + + md(1) = 31 + md(2) = 28 + if(mod(m,4).eq.0) md(2) = 29 + md(3) = 31 + md(4) = 30 + md(5) = 31 + md(6) = 30 + md(7) = 31 + md(8) = 31 + md(9) = 30 + md(10) = 31 + md(11) = 30 + md(12) = 31 + + fn2(1) = '_01_' + fn2(2) = '_02_' + fn2(3) = '_03_' + fn2(4) = '_04_' + fn2(5) = '_05_' + fn2(6) = '_06_' + fn2(7) = '_07_' + fn2(8) = '_08_' + fn2(9) = '_09_' + fn2(10) = '_10_' + fn2(11) = '_11_' + fn2(12) = '_12_' + + write(fy,266) m + 266 format(i4) + + do n = 10,10 + fn = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGPV' + fu = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGU' + ft = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGT' + fv = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGV' + fx = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGREF_N' + fr = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'LWA_N' + fm = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'BARO_N' + write(6,*) fn,md(n) + open(35,file =fn, & + form='unformatted',status = 'old') + open(36,file =fu, & + form='unformatted',status = 'old') + open(37,file =ft, & + form='unformatted',status = 'old') + open(38,file =fr, & + form='unformatted',status = 'new') + open(39,file =fv, & + form='unformatted',status = 'old') + open(40,file =fx, & + form='unformatted',status = 'old') + open(41,file =fm, & + form='unformatted',status = 'new') + + do mm = 1,md(n)*4 + + read(35) pv + read(36) uu + read(39) vv + read(37) pt,tn0,ts0,statn,stats + read(40) qref,uref,tref,fawa,ubar,tbar + + +! **** hemispheric-mean potential temperature **** + tg(:) = tn0(:) + +! **** wave activity and nonlinear zonal flux F2 **** + + astarbaro(:,:) = 0. + ubaro(:,:) = 0. + urefbaro(:) = 0. + ua1baro(:,:) = 0. + ua2baro(:,:) = 0. + ep1baro(:,:) = 0. + ep2baro(:,:) = 0. + ep3baro(:,:) = 0. + ep4(:,:) = 0. + dc = dz/6745.348 + + do k = 2,96 + zk = dz*float(k-1) + do i = 1,imax + do j = 6,nd-1 ! 5N and higher latitude + astar1(i,j,k) = 0. ! LWA*cos(phi) + astar2(i,j,k) = 0. ! LWA*cos(phi) + ua2(i,j) = 0. !F2 + phi0 = dp*float(j-1) !latitude + cor = 2.*om*sin(phi0) !Coriolis parameter + do jj = 1,nd + phi1 = dp*float(jj-1) + qe(i,jj) = pv(i,jj+90,k)-qref(j,k) !qe; Q = qref + ue(i,jj) = uu(i,jj+90,k)-uref(j-5,k) !ue; shift uref 5N + aa = a*dp*cos(phi1) !length element + if((qe(i,jj).le.0.).and.(jj.ge.j)) then !LWA*cos and F2 + astar2(i,j,k)=astar2(i,j,k)-qe(i,jj)*aa !anticyclonic + ua2(i,j) = ua2(i,j)-qe(i,jj)*ue(i,jj)*aa + endif + if((qe(i,jj).gt.0.).and.(jj.lt.j)) then + astar1(i,j,k)=astar1(i,j,k)+qe(i,jj)*aa !cyclonic + ua2(i,j) = ua2(i,j)+qe(i,jj)*ue(i,jj)*aa + endif + enddo + +! ******** Other fluxes ****** + + ua1(i,j) = uref(j-5,k)*(astar1(i,j,k) + & + astar2(i,j,k)) !F1 + ep1(i,j) = -0.5*(uu(i,j+90,k)-uref(j-5,k))**2 !F3a + ep1(i,j) = ep1(i,j)+0.5*vv(i,j+90,k)**2 !F3a+b + ep11 = 0.5*(pt(i,j+90,k)-tref(j-5,k))**2 !F3c + zz = dz*float(k-1) + ep11 = ep11*(r/h)*exp(-rkappa*zz/h) + ep11 = ep11*2.*dz/(tg(k+1)-tg(k-1)) + ep1(i,j) = ep1(i,j)-ep11 !F3 + phip = dp*float(j) + cosp = cos(phip) ! cosine for one grid north + phi0 = dp*float(j-1) + cos0 = cos(phi0) ! cosine for latitude grid + sin0 = sin(phi0) ! sine for latitude grid + phim = dp*float(j-2) + cosm = cos(phim) ! cosine for one grid south + ep1(i,j) = ep1(i,j)*cos0 ! correct for cosine factor + + + ! meridional eddy momentum flux one grid north and south + ep2(i,j)=(uu(i,j+91,k)-uref(j-5,k))*vv(i,j+91,k)*cosp*cosp + ep3(i,j)=(uu(i,j+89,k)-uref(j-5,k))*vv(i,j+89,k)*cosm*cosm + + ! low-level meridional eddy heat flux + if(k.eq.2) then ! (26) of SI-HN17 + ep41 = 2.*om*sin0*cos0*dz/6745.348 ! prefactor + ep42 = exp(-dz/h)*vv(i,j+90,2)*(pt(i,j+90,2)-tref(j-5,2)) + ep42 = ep42/(tg(3)-tg(1)) + ep43 = vv(i,j+90,1)*(pt(i,j+90,1)-tref(j-5,1)) + ep43 = 0.5*ep43/(tg(2)-tg(1)) + ep4(i,j) = ep41*(ep42+ep43) ! low-level heat flux + endif + enddo + enddo + +! ******** Column average: (25) of SI-HN17 ******** + + astarbaro(:,:) = astarbaro(:,:)+(astar1(:,:,k) & + + astar2(:,:,k))*exp(-zk/h)*dc + ua1baro(:,:) = ua1baro(:,:)+ua1(:,:)*exp(-zk/h)*dc + ua2baro(:,:) = ua2baro(:,:)+ua2(:,:)*exp(-zk/h)*dc + ep1baro(:,:) = ep1baro(:,:)+ep1(:,:)*exp(-zk/h)*dc + ep2baro(:,:) = ep2baro(:,:)+ep2(:,:)*exp(-zk/h)*dc + ep3baro(:,:) = ep3baro(:,:)+ep3(:,:)*exp(-zk/h)*dc + do j = 6,nd ! ### yet to be multiplied by cosine + ubaro(:,j) = ubaro(:,j)+uu(:,j+90,k)*exp(-zk/h)*dc + urefbaro(j) = urefbaro(j)+uref(j-5,k)*exp(-zk/h)*dc + enddo + enddo + + +! write(6,*) dh + + write(41) astarbaro,ubaro,urefbaro,ua1baro,ua2baro,ep1baro,& + ep2baro,& + ep3baro,ep4 + + write(38) astar1,astar2 + +! ******************************** + + + write(6,*) fy,n,mm + +! ******************************** + enddo + + close(35) + close(36) + close(37) + close(38) + close(39) + close(40) + close(41) + + enddo + enddo + + stop + end diff --git a/scripts/nhn_grl2022/era4000n_nc.f90 b/scripts/nhn_grl2022/era4000n_nc.f90 new file mode 100644 index 0000000..88645e8 --- /dev/null +++ b/scripts/nhn_grl2022/era4000n_nc.f90 @@ -0,0 +1,312 @@ + program main + + use NETCDF + +! **** convert barotropic LWA and fluxes for +! NH into netCDF files *** + + integer,parameter :: imax = 360 + integer,parameter :: nd = 91 + common /frray/ ep4(imax,nd) + common /grray/ ubaro(imax,nd),urefbaro(nd),astarbaro(imax,nd) + common /hrray/ ua1baro(imax,nd),ua2baro(imax,nd) + common /hrray/ ep1baro(imax,nd),ep2baro(imax,nd) + common /hrray/ ep3baro(imax,nd),wa2(nd,124) + common /array/ astar(imax,nd,124),ub(imax,nd,124) + common /brray/ urb(nd,124),ua1(imax,nd,124) + common /crray/ ua2(imax,nd,124),ep1(imax,nd,124) + common /drray/ ep2(imax,nd,124),ep3(imax,nd,124) + common /erray/ ep44(imax,nd,124),wa1(imax,nd,124) + integer :: md(12) + + character*35 fn,fn0,fn1 + character*34 fu + character*34 ft,fv + character*38 fx + character*4 fn2(12),fy,fy1,fy2 + character*19 f3 + character*36 fr + character*37 fm + character*39 fd,fe,ff,fg,fh,fi + character*40 fa + character*41 fc + character*38 fb + + integer :: ncid, status,nDim,nVar,nAtt,uDimID,inq + integer :: lonID,latID,vid2,varID + integer :: l1,l2,l3,l4,l5,l6,xtype,len,attnum + + a = 6378000. + pi = acos(-1.) + om = 7.29e-5 + dp = pi/180. + dz = 500. + h = 7000. + r = 287. + rkappa = r/1004. + + do m = 2021,2021 + + md(1) = 31 + md(2) = 28 + if(mod(m,4).eq.0) md(2) = 29 + md(3) = 31 + md(4) = 30 + md(5) = 31 + md(6) = 30 + md(7) = 31 + md(8) = 31 + md(9) = 30 + md(10) = 31 + md(11) = 30 + md(12) = 31 + + fn2(1) = '_01_' + fn2(2) = '_02_' + fn2(3) = '_03_' + fn2(4) = '_04_' + fn2(5) = '_05_' + fn2(6) = '_06_' + fn2(7) = '_07_' + fn2(8) = '_08_' + fn2(9) = '_09_' + fn2(10) = '_10_' + fn2(11) = '_11_' + fn2(12) = '_12_' + + write(fy,266) m + 266 format(i4) + + do n = 6,6 + fm = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'BARO_N' + fa = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'LWAb_N.nc' + fb = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'Ub_N.nc' + fc = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'Urefb_N.nc' + fd = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'ua1_N.nc' + fe = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'ua2_N.nc' + ff = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'ep1_N.nc' + fg = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'ep2_N.nc' + fh = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'ep3_N.nc' + fi = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'ep4_N.nc' + write(6,*) fn,md(n) + open(41,file =fm, & + form='unformatted',status = 'old') + + do mm = 1,md(n)*4 + + read(41) astarbaro,ubaro,urefbaro,ua1baro,ua2baro,ep1baro,& + ep2baro,& + ep3baro,ep4 + + astar(:,:,mm) = astarbaro(:,:) + ub(:,:,mm) = ubaro(:,:) + urb(:,mm) = urefbaro(:) + ua1(:,:,mm) = ua1baro(:,:) + ua2(:,:,mm) = ua2baro(:,:) + ep1(:,:,mm) = ep1baro(:,:) + ep2(:,:,mm) = ep2baro(:,:) + ep3(:,:,mm) = ep3baro(:,:) + ep44(:,:,mm) = ep4(:,:) + +! ******************************** + + write(6,*) fy,n,mm + +! ******************************** + enddo + + status = nf90_create(fa,nf90_noclobber,ncid2) + status = nf90_def_dim(ncid2,"longitude",imax,ix) + status = nf90_def_dim(ncid2,"latitude",nd,iy) + status = nf90_def_dim(ncid2,"time",124,it) + status = nf90_def_var(ncid2,"lwa",nf90_float, & + (/ix,iy,it/), vid2) + status = nf90_put_att(ncid2,vid2,"title",fa) + status = nf90_enddef(ncid2) + status = nf90_put_var(ncid2,vid2,astar) + status = nf90_close(ncid2) + + status = nf90_open(fa,nf90_nowrite,ncid) + status = nf90_inquire(ncid,nDim,nVar,nAtt,uDimID) + write(6,*) 'ndim,nvar,natt,uDimID =',nDim,nVar,nAtt,uDimID + status = nf90_inq_varid(ncid,"lwa",varID) + write(6,*) 'Variable ID for LWA = ',varID + status = nf90_get_var(ncid,varID,wa1) + status = nf90_close(ncid) + + write(6,*) astar(200,47,30),wa1(200,47,30) + + status = nf90_create(fb,nf90_noclobber,ncid2) + status = nf90_def_dim(ncid2,"longitude",imax,ix) + status = nf90_def_dim(ncid2,"latitude",nd,iy) + status = nf90_def_dim(ncid2,"time",124,it) + status = nf90_def_var(ncid2,"u",nf90_float, & + (/ix,iy,it/), vid2) + status = nf90_put_att(ncid2,vid2,"title",fb) + status = nf90_enddef(ncid2) + status = nf90_put_var(ncid2,vid2,ub) + status = nf90_close(ncid2) + + status = nf90_open(fb,nf90_nowrite,ncid) + status = nf90_inquire(ncid,nDim,nVar,nAtt,uDimID) + write(6,*) 'ndim,nvar,natt,uDimID =',nDim,nVar,nAtt,uDimID + status = nf90_inq_varid(ncid,"u",varID) + write(6,*) 'Variable ID for U = ',varID + status = nf90_get_var(ncid,varID,wa1) + status = nf90_close(ncid) + + write(6,*) ub(200,47,30),wa1(200,47,30) + + status = nf90_create(fd,nf90_noclobber,ncid2) + status = nf90_def_dim(ncid2,"longitude",imax,ix) + status = nf90_def_dim(ncid2,"latitude",nd,iy) + status = nf90_def_dim(ncid2,"time",124,it) + status = nf90_def_var(ncid2,"ua1",nf90_float, & + (/ix,iy,it/), vid2) + status = nf90_put_att(ncid2,vid2,"title",fd) + status = nf90_enddef(ncid2) + status = nf90_put_var(ncid2,vid2,ua1) + status = nf90_close(ncid2) + + status = nf90_open(fd,nf90_nowrite,ncid) + status = nf90_inquire(ncid,nDim,nVar,nAtt,uDimID) + write(6,*) 'ndim,nvar,natt,uDimID =',nDim,nVar,nAtt,uDimID + status = nf90_inq_varid(ncid,"ua1",varID) + write(6,*) 'Variable ID for ua1 = ',varID + status = nf90_get_var(ncid,varID,wa1) + status = nf90_close(ncid) + + write(6,*) ua1(200,47,30),wa1(200,47,30) + + status = nf90_create(fe,nf90_noclobber,ncid2) + status = nf90_def_dim(ncid2,"longitude",imax,ix) + status = nf90_def_dim(ncid2,"latitude",nd,iy) + status = nf90_def_dim(ncid2,"time",124,it) + status = nf90_def_var(ncid2,"ua2",nf90_float, & + (/ix,iy,it/), vid2) + status = nf90_put_att(ncid2,vid2,"title",fe) + status = nf90_enddef(ncid2) + status = nf90_put_var(ncid2,vid2,ua2) + status = nf90_close(ncid2) + + status = nf90_open(fe,nf90_nowrite,ncid) + status = nf90_inquire(ncid,nDim,nVar,nAtt,uDimID) + write(6,*) 'ndim,nvar,natt,uDimID =',nDim,nVar,nAtt,uDimID + status = nf90_inq_varid(ncid,"ua2",varID) + write(6,*) 'Variable ID for ua2 = ',varID + status = nf90_get_var(ncid,varID,wa1) + status = nf90_close(ncid) + + write(6,*) ua2(200,47,30),wa1(200,47,30) + + status = nf90_create(ff,nf90_noclobber,ncid2) + status = nf90_def_dim(ncid2,"longitude",imax,ix) + status = nf90_def_dim(ncid2,"latitude",nd,iy) + status = nf90_def_dim(ncid2,"time",124,it) + status = nf90_def_var(ncid2,"ep1",nf90_float, & + (/ix,iy,it/), vid2) + status = nf90_put_att(ncid2,vid2,"title",ff) + status = nf90_enddef(ncid2) + status = nf90_put_var(ncid2,vid2,ep1) + status = nf90_close(ncid2) + + status = nf90_open(ff,nf90_nowrite,ncid) + status = nf90_inquire(ncid,nDim,nVar,nAtt,uDimID) + write(6,*) 'ndim,nvar,natt,uDimID =',nDim,nVar,nAtt,uDimID + status = nf90_inq_varid(ncid,"ep1",varID) + write(6,*) 'Variable ID for ep1 = ',varID + status = nf90_get_var(ncid,varID,wa1) + status = nf90_close(ncid) + + write(6,*) ep1(200,47,30),wa1(200,47,30) + + status = nf90_create(fg,nf90_noclobber,ncid2) + status = nf90_def_dim(ncid2,"longitude",imax,ix) + status = nf90_def_dim(ncid2,"latitude",nd,iy) + status = nf90_def_dim(ncid2,"time",124,it) + status = nf90_def_var(ncid2,"ep2",nf90_float, & + (/ix,iy,it/), vid2) + status = nf90_put_att(ncid2,vid2,"title",fg) + status = nf90_enddef(ncid2) + status = nf90_put_var(ncid2,vid2,ep2) + status = nf90_close(ncid2) + + status = nf90_open(fg,nf90_nowrite,ncid) + status = nf90_inquire(ncid,nDim,nVar,nAtt,uDimID) + write(6,*) 'ndim,nvar,natt,uDimID =',nDim,nVar,nAtt,uDimID + status = nf90_inq_varid(ncid,"ep2",varID) + write(6,*) 'Variable ID for ep2 = ',varID + status = nf90_get_var(ncid,varID,wa1) + status = nf90_close(ncid) + + write(6,*) ep2(200,47,30),wa1(200,47,30) + + status = nf90_create(fh,nf90_noclobber,ncid2) + status = nf90_def_dim(ncid2,"longitude",imax,ix) + status = nf90_def_dim(ncid2,"latitude",nd,iy) + status = nf90_def_dim(ncid2,"time",124,it) + status = nf90_def_var(ncid2,"ep3",nf90_float, & + (/ix,iy,it/), vid2) + status = nf90_put_att(ncid2,vid2,"title",fh) + status = nf90_enddef(ncid2) + status = nf90_put_var(ncid2,vid2,ep3) + status = nf90_close(ncid2) + + status = nf90_open(fh,nf90_nowrite,ncid) + status = nf90_inquire(ncid,nDim,nVar,nAtt,uDimID) + write(6,*) 'ndim,nvar,natt,uDimID =',nDim,nVar,nAtt,uDimID + status = nf90_inq_varid(ncid,"ep3",varID) + write(6,*) 'Variable ID for ep3 = ',varID + status = nf90_get_var(ncid,varID,wa1) + status = nf90_close(ncid) + + write(6,*) ep3(200,47,30),wa1(200,47,30) + + status = nf90_create(fi,nf90_noclobber,ncid2) + status = nf90_def_dim(ncid2,"longitude",imax,ix) + status = nf90_def_dim(ncid2,"latitude",nd,iy) + status = nf90_def_dim(ncid2,"time",124,it) + status = nf90_def_var(ncid2,"ep4",nf90_float, & + (/ix,iy,it/), vid2) + status = nf90_put_att(ncid2,vid2,"title",fi) + status = nf90_enddef(ncid2) + status = nf90_put_var(ncid2,vid2,ep44) + status = nf90_close(ncid2) + + status = nf90_open(fi,nf90_nowrite,ncid) + status = nf90_inquire(ncid,nDim,nVar,nAtt,uDimID) + write(6,*) 'ndim,nvar,natt,uDimID =',nDim,nVar,nAtt,uDimID + status = nf90_inq_varid(ncid,"ep4",varID) + write(6,*) 'Variable ID for ep4 = ',varID + status = nf90_get_var(ncid,varID,wa1) + status = nf90_close(ncid) + + write(6,*) ep44(200,47,30),wa1(200,47,30) + + status = nf90_create(fc,nf90_noclobber,ncid2) + status = nf90_def_dim(ncid2,"latitude",nd,iy) + status = nf90_def_dim(ncid2,"time",124,it) + status = nf90_def_var(ncid2,"uref",nf90_float, & + (/iy,it/), vid2) + status = nf90_put_att(ncid2,vid2,"title",fc) + status = nf90_enddef(ncid2) + status = nf90_put_var(ncid2,vid2,urb) + status = nf90_close(ncid2) + + status = nf90_open(fc,nf90_nowrite,ncid) + status = nf90_inquire(ncid,nDim,nVar,nAtt,uDimID) + write(6,*) 'ndim,nvar,natt,uDimID =',nDim,nVar,nAtt,uDimID + status = nf90_inq_varid(ncid,"uref",varID) + write(6,*) 'Variable ID for uref = ',varID + status = nf90_get_var(ncid,varID,wa2) + status = nf90_close(ncid) + + write(6,*) urb(47,30),wa2(47,30) + + close(41) + + enddo + enddo + + stop + end diff --git a/scripts/nhn_grl2022/era4004n.f90 b/scripts/nhn_grl2022/era4004n.f90 new file mode 100644 index 0000000..71acc4d --- /dev/null +++ b/scripts/nhn_grl2022/era4004n.f90 @@ -0,0 +1,460 @@ + program main + +! USE mkl95_BLAS, ONLY: GEMM,GEMV + USE mkl95_LAPACK, ONLY: GETRF,GETRI + + +! **** take QG analysis and compute Q_ref and invert for +! U_ref & Theta_ref for NH (Direct solver) *** + + integer,parameter :: imax = 360, JMAX = 181, KMAX = 97 + integer,parameter :: nd = 91,nnd=181 + integer,parameter :: jb = 5 ! lower bounding latitude + integer,parameter :: jd = 86 ! nd - lower bounding latitude + common /array/ pv(imax,jmax,kmax),pv2(imax,jmax) + common /brray/ uu(imax,jmax,kmax) + common /bbray/ vort(imax,jmax,kmax),vort2(imax,jmax) + common /bcray/ pt(imax,jmax,kmax) + common /bdray/ stats(kmax),statn(kmax),ts0(kmax),tn0(kmax) + common /crray/ qn(nnd),an(nnd),aan(nnd),tb(kmax),tg(kmax) + common /drray/ cn(nnd),ccn(nnd),tref(jd,kmax) + common /frray/ alat(nd),phi(nd),z(kmax),cbar(nd,kmax) + common /krray/ tjk(jd-2,kmax-1),tj(jd-2),rj(jd-2) + common /lrray/ qjj(jd-2,jd-2),cjj(jd-2,jd-2) + common /orray/ xjj(jd-2,jd-2),yj(jd-2) + common /mrray/ djj(jd-2,jd-2),sjj(jd-2,jd-2) + common /nrray/ sjk(jd-2,jd-2,kmax-1) + common /prray/ pjk(jd-2,kmax),pj(jd-2) + common /irray/ qref(nd,kmax),u(jd,kmax),cref(nd,kmax) + common /krray/ fawa(nd,kmax),ckref(nd,kmax) + common /jrray/ qbar(nd,kmax),ubar(nd,kmax),tbar(nd,kmax) + integer :: md(12),ipiv(jd-2) + + character*35 fn,fn0,fn1 + character*34 fu + character*34 ft + character*4 fn2(12),fy,fy1,fy2 + character*18 f1,f2 + character*19 f3 + character*36 fv + character*38 fr + + a = 6378000. + pi = acos(-1.) + om = 7.29e-5 + dp = pi/180. + dz = 500. + h = 7000. + r = 287. + rkappa = r/1004. + + do nn = 1,nd + phi(nn) = dp*float(nn-1) + alat(nn) = 2.*pi*a*a*(1.-sin(phi(nn))) + enddo + + do k = 1,kmax + z(k) = dz*float(k-1) + enddo + + do m = 2021,2021 + + md(1) = 31 + md(2) = 28 + if(mod(m,4).eq.0) md(2) = 29 + md(3) = 31 + md(4) = 30 + md(5) = 31 + md(6) = 30 + md(7) = 31 + md(8) = 31 + md(9) = 30 + md(10) = 31 + md(11) = 30 + md(12) = 31 + + fn2(1) = '_01_' + fn2(2) = '_02_' + fn2(3) = '_03_' + fn2(4) = '_04_' + fn2(5) = '_05_' + fn2(6) = '_06_' + fn2(7) = '_07_' + fn2(8) = '_08_' + fn2(9) = '_09_' + fn2(10) = '_10_' + fn2(11) = '_11_' + fn2(12) = '_12_' + + write(fy,266) m + 266 format(i4) + + do n = 10,10 + fn = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGPV' + fu = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGU' + ft = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGT' + fr = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGREF_N' + fv = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QVORT' + write(6,*) fn,md(n) + open(35,file =fn, & + form='unformatted',status = 'old') + open(36,file =fu, & + form='unformatted',status = 'old') + open(37,file =ft, & + form='unformatted',status = 'old') + open(38,file =fr, & + form='unformatted',status = 'new') + open(39,file =fv, & + form='unformatted',status = 'old') +! ********************** Analysis starts here ********************** +do mm = 1,md(n)*4 + +read(35) pv +read(36) uu +read(39) vort +read(37) pt,tn0,ts0,statn,stats + +! **** Zonal-mean field **** +do j = 91,jmax + qbar(j-90,:) = 0. + tbar(j-90,:) = 0. + ubar(j-90,:) = 0. +do i = 1,imax + qbar(j-90,:) = qbar(j-90,:)+pv(i,j,:)/float(imax) + tbar(j-90,:) = tbar(j-90,:)+pt(i,j,:)/float(imax) + ubar(j-90,:) = ubar(j-90,:)+uu(i,j,:)/float(imax) +enddo +enddo + +! **** hemispheric-mean potential temperature **** +tb(:) = tn0(:) + +do k = 2,96 + pv2(:,:) = pv(:,:,k) + vort2(:,:) = vort(:,:,k) + + ! **** compute qref via area analysis **** + qmax = maxval(pv2) + qmin = minval(pv2) + dq = (qmax-qmin)/float(nnd-1) + qn(:) = 0. + an(:) = 0. + cn(:) = 0. + do nn = 1,nnd + qn(nn) = qmax - dq*float(nn-1) + enddo + do j = 1,jmax + phi0 = -0.5*pi+dp*float(j-1) + do i = 1,imax + ind = 1+int((qmax-pv2(i,j))/dq) + da = a*a*dp*dp*cos(phi0) + an(ind) = an(ind) + da + cn(ind) = cn(ind) + da*pv2(i,j) + enddo + enddo + aan(1) = 0. + ccn(1) = 0. + do nn = 2,nnd + aan(nn) = aan(nn-1)+an(nn) + ccn(nn) = ccn(nn-1)+cn(nn) + enddo + do j = 1,nd-1 + do nn = 1,nnd-1 + if(aan(nn).le.alat(j).and.aan(nn+1).gt.alat(j)) then + dd = (alat(j)-aan(nn))/(aan(nn+1)-aan(nn)) + qref(j,k) = qn(nn)*(1.-dd)+qn(nn+1)*dd + cref(j,k) = ccn(nn)*(1.-dd)+ccn(nn+1)*dd + endif + enddo + enddo + + qref(nd,k) = qmax + + cbar(nd,k) = 0. + do j=nd-1,1,-1 + phi0 = dp*(float(j)-0.5) + cbar(j,k) = cbar(j+1,k)+0.5*(qbar(j+1,k)+qbar(j,k)) & + *a*dp*2.*pi*a*cos(phi0) + enddo + +! **** compute Kelvin's circulation based on absolute vorticity (for b.c.) **** + + + qmax = maxval(vort2) + qmin = minval(vort2) + dq = (qmax-qmin)/float(nnd-1) + qn(:) = 0. + an(:) = 0. + cn(:) = 0. + do nn = 1,nnd + qn(nn) = qmax - dq*float(nn-1) + enddo + do j = 1,jmax + phi0 = -0.5*pi+dp*float(j-1) + do i = 1,imax + ind = 1+int((qmax-vort2(i,j))/dq) + da = a*a*dp*dp*cos(phi0) + an(ind) = an(ind) + da + cn(ind) = cn(ind) + da*vort2(i,j) + enddo + enddo + aan(1) = 0. + ccn(1) = 0. + do nn = 2,nnd + aan(nn) = aan(nn-1)+an(nn) + ccn(nn) = ccn(nn-1)+cn(nn) + enddo + do j = 1,nd-1 + do nn = 1,nnd-1 + if(aan(nn).le.alat(j).and.aan(nn+1).gt.alat(j)) then + dd = (alat(j)-aan(nn))/(aan(nn+1)-aan(nn)) + ckref(j,k) = ccn(nn)*(1.-dd)+ccn(nn+1)*dd + endif + enddo + enddo + +enddo + +! ***** normalize QGPV by sine (latitude) **** + +do j = 2,nd + phi0 = dp*float(j-1) + cor = sin(phi0) + qref(j,:) = qref(j,:)/cor +enddo + +do k = 2,kmax-1 + qref(1,k) = 2.*qref(2,k)-qref(3,k) +enddo + +! ***** FAWA ***** +fawa(:,:) = (cref(:,:)-cbar(:,:))/(2.*pi*a) + +! ***** Direct solver to invert Q_ref ***** + +! *** downward sweep *** + +! **** top boundary condition (Eqs. 24-25) ***** +tjk(:,:) = 0. +sjk(:,:,:) = 0. +do jj = jb+2,90 + j = jj-jb + phi0 = float(jj-1)*dp + cos0 = cos(phi0) + sin0 = sin(phi0) + tjk(j-1,kmax-1) = -dz*r*cos0*exp(-z(kmax-1)*rkappa/h) + tjk(j-1,kmax-1) = tjk(j-1,kmax-1)*(tbar(j+1,kmax)-tbar(j-1,kmax)) + tjk(j-1,kmax-1) = tjk(j-1,kmax-1)/(4.*om*sin0*dp*h*a) + sjk(j-1,j-1,kmax-1) = 1. +enddo + +! **** Evaluate Eqs. 22-23 downward *** + +do k = kmax-1,2,-1 + zp = 0.5*(z(k+1)+z(k)) + zm = 0.5*(z(k-1)+z(k)) + statp = 0.5*(statn(k+1)+statn(k)) + statm = 0.5*(statn(k-1)+statn(k)) + cjj(:,:) = 0. + djj(:,:) = 0. + qjj(:,:) = 0. + sjj(:,:) = sjk(:,:,k) + tj(:) = tjk(:,k) + do jj = jb+2,90 + j = jj - jb + phi0 = float(jj-1)*dp + phip = (float(jj)-0.5)*dp + phim = (float(jj)-1.5)*dp + cos0 = cos(phi0) + cosp = cos(phip) + cosm = cos(phim) + sin0 = sin(phi0) + sinp = sin(phip) + sinm = sin(phim) + + fact = 4.*om*om*h*a*a*sin0*dp*dp/(dz*dz*r*cos0) + amp = exp(-zp/h)*exp(rkappa*zp/h)/statp + amp = amp*fact*exp(z(k)/h) + amm = exp(-zm/h)*exp(rkappa*zm/h)/statm + amm = amm*fact*exp(z(k)/h) + + ! ***** Specify A, B, C, D, E, F (Eqs. 4-9) ***** + ajk = 1./(sinp*cosp) + bjk = 1./(sinm*cosm) + cjk = amp + djk = amm + ejk = ajk+bjk+cjk+djk + fjk = -0.5*a*dp*(qref(jj+1,k)-qref(jj-1,k)) + + ! ***** Specify rk (Eq. 15) **** + + ! **** North-south boundary conditions **** + u(jd,k) = 0. + phi0 = dp*float(jb) + ! u(1,k) = ubar(jb+1,k)*cos(phi0) + u(1,k) = ckref(jb+1,k)/(2.*pi*a)-om*a*cos(phi0) + + rj(j-1) = fjk + if(j.eq.2) rj(j-1) = fjk - bjk*u(1,k) + if(j.eq.jd-1) rj(j-1) = fjk - ajk*u(jd,k) + + ! ***** Specify Ck & Dk (Eqs. 18-19) ***** + cjj(j-1,j-1) = cjk + djj(j-1,j-1) = djk + + ! **** Specify Qk (Eq. 17) ***** + qjj(j-1,j-1) = -ejk + if(j-1.ge.1.and.j-1.lt.jd-2) then + qjj(j-1,j) = ajk + endif + if(j-1.gt.1.and.j-1.le.jd-2) then + qjj(j-1,j-2) = bjk + endif + enddo + + ! **** Compute Qk + Ck Sk ******* + do i = 1,jd-2 + do j = 1,jd-2 + xjj(i,j) = 0. + do kk = 1,jd-2 + xjj(i,j) = xjj(i,j)+cjj(i,kk)*sjj(kk,j) + enddo + qjj(i,j) = qjj(i,j)+xjj(i,j) + enddo + enddo + ! call gemm(cjj,sjj,xjj) + ! qjj(:,:) = qjj(:,:)+xjj(:,:) + + ! **** Invert (Qk + Ck Sk) ******** + call getrf(qjj,ipiv) + call getri(qjj,ipiv) + + ! **** Evaluate Eq. 22 **** + do i = 1,jd-2 + do j = 1,jd-2 + xjj(i,j) = 0. + do kk = 1,jd-2 + xjj(i,j) = xjj(i,j)+qjj(i,kk)*djj(kk,j) + enddo + sjk(i,j,k-1) = -xjj(i,j) + enddo + enddo + + ! call gemm(qjj,djj,xjj) + ! sjk(:,:,k-1) = -xjj(:,:) + + ! **** Evaluate rk - Ck Tk **** + do i = 1,jd-2 + yj(i) = 0. + do kk = 1,jd-2 + yj(i) = yj(i)+cjj(i,kk)*tj(kk) + enddo + yj(i) = rj(i)-yj(i) + enddo + + ! call gemv(cjj,tj,yj) + ! yj(:) = rj(:)-yj(:) + ! call gemv(qjj,yj,tj) + ! tjk(:,k-1) = tj(:) + + + ! ***** Evaluate Eq. 23 ******* + do i = 1,jd-2 + tj(i) = 0. + do kk = 1,jd-2 + tj(i) = tj(i)+qjj(i,kk)*yj(kk) + enddo + tjk(i,k-1) = tj(i) + enddo + +enddo + +! ***** upward sweep (Eq. 20) **** + +pjk(:,1) = 0. +do k = 1,kmax-1 + pj(:) = pjk(:,k) + sjj(:,:) = sjk(:,:,k) + tj(:) = tjk(:,k) + + do i = 1,jd-2 + yj(i) = 0. + do kk = 1,jd-2 + yj(i) = yj(i)+sjj(i,kk)*pj(kk) + enddo + pjk(i,k+1) = yj(i)+tj(i) + enddo + ! call gemv(sjj,pj,yj) + ! pjk(:,k+1) = yj(:) + tj(:) +enddo + +! **** Recover u ***** +do k = 1,kmax + do j = 2,jd-1 + u(j,k) = pjk(j-1,k) + enddo +enddo + +! *** Corner boundary conditions *** +u(1,1) = 0. +u(jd,1) = 0. +! u(1,kmax) = ubar(1+jb,kmax)*cos(dp*float(jb)) +u(1,kmax) = ckref(1+jb,kmax)/(2.*pi*a)-om*a*cos(dp*float(jb)) +u(jd,kmax) = 0. + +! *** Divide by cos phi to revover Uref **** +do jj = jb+1,nd-1 + j = jj-jb + phi0 = dp*float(jj-1) + u(j,:) = u(j,:)/cos(phi0) +enddo +u(jd,:) = 2.*u(jd-1,:)-u(jd-2,:) + +! ******** compute tref ******* + +do k = 2,96 + t00 = 0. + zz = dz*float(k-1) + tref(1,k) = t00 + tref(2,k) = t00 + do j = 2,jd-1 + phi0 = dp*float(j-1) + cor = 2.*om*sin(phi0) + uz = (u(j,k+1)-u(j,k-1))/(2.*dz) + ty = -cor*uz*a*h*exp(rkappa*zz/h) + ty = ty/r + tref(j+1,k) = tref(j-1,k)+2.*ty*dp + qref(j-1,k) = qref(j-1,k)*sin(phi0) + enddo + tg(k) = 0. + wt = 0. + do jj = 6,91 + j = jj-5 + phi0 = dp*float(jj-1) + tg(k) = tg(k)+cos(phi0)*tref(j,k) + wt = wt + cos(phi0) + enddo + tg(k) = tg(k)/wt + tres = tb(k)-tg(k) + tref(:,k) = tref(:,k)+tres +enddo +tref(:,1) = tref(:,2)-tb(2)+tb(1) +tref(:,97) = tref(:,96)-tb(96)+tb(97) + +write(38) qref,u,tref,fawa,ubar,tbar + +write(6,*) m,n,mm + +! ******************************** +enddo + +close(35) +close(36) +close(37) +close(38) +! ********************** Analysis ends here ********************** + enddo + enddo + + stop + end diff --git a/scripts/nhn_grl2022/lwa_flux_computation.py b/scripts/nhn_grl2022/lwa_flux_computation.py new file mode 100644 index 0000000..326a222 --- /dev/null +++ b/scripts/nhn_grl2022/lwa_flux_computation.py @@ -0,0 +1,174 @@ +import numpy as np +from math import pi +from netCDF4 import Dataset +from hn2016_falwa.oopinterface import QGField +import datetime as dt +import matplotlib.pyplot as plt + +data_dir = "grl2022_data/" + +# --- Load the zonal wind and QGPV at 240hPa --- # +u_file = Dataset(data_dir + '2021_06_u.nc', mode='r') +v_file = Dataset(data_dir + '2021_06_v.nc', mode='r') +t_file = Dataset(data_dir + '2021_06_t.nc', mode='r') + +time_array = u_file.variables['time'][:] +time_units = u_file.variables['time'].units +time_calendar = u_file.variables['time'].calendar +ntimes = time_array.shape[0] + +print('Dimension of time: {}'.format(time_array.size)) + +# --- Longitude, latitude and pressure grid --- +xlon = u_file.variables['longitude'][:] + +# latitude has to be in ascending order +ylat = u_file.variables['latitude'][:] +if np.diff(ylat)[0]<0: + print('Flip ylat.') + ylat = ylat[::-1] + +# pressure level has to be in descending order (ascending height) +plev = u_file.variables['level'][:] +if np.diff(plev)[0]>0: + print('Flip plev.') + plev = plev[::-1] + +nlon = xlon.size +nlat = ylat.size +nlev = plev.size + +# --- Coordinates --- +clat = np.cos(np.deg2rad(ylat)) # cosine latitude +p0 = 1000. # surface pressure [hPa] +kmax = 97 # number of grid points for vertical extrapolation (dimension of height) +dz = 500. # differential height element +height = np.arange(0,kmax)*dz # pseudoheight [m] +dphi = np.diff(ylat)[0]*pi/180. # differential latitudinal element +dlambda = np.diff(xlon)[0]*pi/180. # differential latitudinal element +hh = 7000. # scale height +cp = 1004. # heat capacity of dry air +rr = 287. # gas constant +omega = 7.29e-5 # rotation rate of the earth +aa = 6.378e+6 # earth radius +prefactor = np.array([np.exp(-z/hh) for z in height[1:]]).sum() # integrated sum of density from the level + #just above the ground (z=1km) to aloft +npart = nlat # number of partitions to construct the equivalent latitude grids +maxits = 100000 # maximum number of iteration in the SOR solver to solve for reference state +tol = 1.e-5 # tolerance that define convergence of solution +rjac = 0.95 # spectral radius of the Jacobi iteration in the SOR solver. +jd = nlat//2+1 # (one plus) index of latitude grid point with value 0 deg + # This is to be input to fortran code. The index convention is different. + + +# --- Outputing files --- +output_fname = '2021-06-01_to_2021-06-30_output3.nc' +output_file = Dataset(output_fname, 'w') +output_file.createDimension('latitude',nlat//2+1) +output_file.createDimension('longitude',nlon) +output_file.createDimension('time',ntimes+4) +lats = output_file.createVariable('latitude',np.dtype('float32').char,('latitude',)) # Define the coordinate variables +lons = output_file.createVariable('longitude',np.dtype('float32').char,('longitude',)) +times = output_file.createVariable('time',np.dtype('int').char,('time',)) +lats.units = 'degrees_north' +lons.units = 'degrees_east' +times.units = time_units +times.calendar = time_calendar +lats[:] = ylat[90:] +lons[:] = xlon +# times[:] = time_array +lwa_baro = output_file.createVariable('lwa', np.dtype('float32').char, ('time', 'latitude', 'longitude')) +lwa_baro.units = 'm/s' +ua1 = output_file.createVariable('ua1', np.dtype('float32').char, ('time', 'latitude', 'longitude')) +ua1.units = 'm/s' +ua2 = output_file.createVariable('ua2', np.dtype('float32').char, ('time', 'latitude', 'longitude')) +ua2.units = 'm/s' +ep1 = output_file.createVariable('ep1', np.dtype('float32').char, ('time', 'latitude', 'longitude')) +ep1.units = 'm/s' +ep2 = output_file.createVariable('ep2', np.dtype('float32').char, ('time', 'latitude', 'longitude')) +ep2.units = 'm/s' +ep3 = output_file.createVariable('ep3', np.dtype('float32').char, ('time', 'latitude', 'longitude')) +ep3.units = 'm/s' +ep4 = output_file.createVariable('ep4', np.dtype('float32').char, ('time', 'latitude', 'longitude')) +ep4.units = 'm/s' + + +print(f'ylat[90:].size = {ylat[90:].size}.') + +# --- Set timestamp and pressure level to display --- +tstamp = [dt.datetime(2005,1,23,0,0) + dt.timedelta(seconds=6*3600) * tt for tt in range(ntimes)] +plev_selected = 10 # selected pressure level to display +tstep_selected = 0 + +# --- Compute LWA and fluxes --- +for tstep in range(ntimes): # or ntimes + + uu = u_file.variables['u'][tstep, ::-1, ::-1, :].data + vv = v_file.variables['v'][tstep, ::-1, ::-1, :].data + tt = t_file.variables['t'][tstep, ::-1, ::-1, :].data + + qgfield_object = QGField(xlon, ylat, plev, uu, vv, tt, kmax=kmax, dz=dz) + + qgpv_temp, interpolated_u_temp, interpolated_v_temp, interpolated_avort_temp, interpolated_theta_temp, \ + static_stability_n, static_stability_s, tn0, ts0 = qgfield_object._interpolate_field_dirinv() + + # plt.contourf(xlon, ylat, np.swapaxes(qgpv_temp[:, :, 40], 0, 1), cmap='rainbow') + # plt.colorbar() + # plt.savefig("test_qgpv.jpg") + # plt.clf() + # plt.plot(ylat, interpolated_u_temp[:, :, 40].mean(axis=0)) + # # plt.colorbar() + # plt.savefig("test_zm_u.jpg") + # plt.clf() + # plt.contourf(xlon, ylat, np.swapaxes(interpolated_theta_temp[:, :, 20], 0, 1), cmap='rainbow') + # plt.colorbar() + # plt.savefig("test_pt.jpg") + + print("Before compute_qref_fawa_and_bc") + qref, uref, tref, fawa, ubar, tbar = qgfield_object._compute_qref_fawa_and_bc() + + # print(f"qref.shape = {qref.shape}") + # plt.contourf(np.arange(91), np.arange(0, 48500, 500), np.swapaxes(qref, 0, 1), cmap='rainbow') + # plt.colorbar() + # plt.ylabel("height") + # plt.xlabel("latitude") + # plt.savefig("qref.png") + + print("After compute_qref_fawa_and_bc") + astarbaro, ubaro, urefbaro, ua1baro, ua2baro, ep1baro, ep2baro, ep3baro, ep4baro, astar1, astar2 = \ + qgfield_object._compute_lwa_flux_dirinv(qref, uref, tref, fawa, ubar, tbar) + + for k in range(0, 96): + astar1_nan = np.count_nonzero(astar1[:, 80:, k]>1000) + astar2_nan = np.count_nonzero(astar2[:, 80:, k]>1000) + fawa_nan = np.count_nonzero(fawa[80:, k]>1000) + if astar1_nan + astar2_nan + fawa_nan > 0: + print(f"k = {k}. nan in astar1 = {astar1_nan}. nan in astar2 = {astar2_nan}. nan in fawa = {fawa_nan}.") + + + # print(f"ans2[0].shape = {ans2[0].shape}") + # print(f"ans2[1].shape = {ans2[1].shape}") + # print(f"ans2[0] = {ans2[0]}") + # print(f"ans2[1] = {ans2[1]}") + + # print(f"qref.shape = {qref.shape}") + # print(f"qref[:, 40] = {qref[:, 40]}") + # print(f"fawa.shape = {fawa.shape}") + # print(f"fawa[:, 40] = {fawa[:, 40]}") + # print(f"tstep = {tstep}") + + # qref, uref, ptref = qgfield_object.compute_reference_states(northern_hemisphere_results_only=False) + # + # barotropic_fluxes = qgfield_object.compute_lwa_and_barotropic_fluxes(northern_hemisphere_results_only=False) + # + lwa_baro[tstep, :, :] = np.swapaxes(astarbaro, 0, 1) + ua1[tstep, :, :] = np.swapaxes(ua1baro, 0, 1) + ua2[tstep, :, :] = np.swapaxes(ua2baro, 0, 1) + ep1[tstep, :, :] = np.swapaxes(ep1baro, 0, 1) + ep2[tstep, :, :] = np.swapaxes(ep2baro, 0, 1) + ep3[tstep, :, :] = np.swapaxes(ep3baro, 0, 1) + ep4[tstep, :, :] = np.swapaxes(ep4baro, 0, 1) + + print(f'tstep = {tstep}/{ntimes}.') + +# output_file.close() diff --git a/setup.py b/setup.py index 7ad1898..bb75c85 100644 --- a/setup.py +++ b/setup.py @@ -31,6 +31,29 @@ sources=['hn2016_falwa/compute_lwa_and_barotropic_fluxes.f90'], f2py_options=['--quiet']) +ext4 = Extension(name='interpolate_fields_direct_inv', + sources=['hn2016_falwa/interpolate_fields_dirinv.f90'], + f2py_options=['--quiet']) + +ext5 = Extension(name='compute_qref_and_fawa_first', + sources=['hn2016_falwa/compute_qref_and_fawa_first.f90'], + f2py_options=['--quiet']) + +ext6 = Extension(name='matrix_b4_inversion', + sources=['hn2016_falwa/matrix_b4_inversion.f90'], + f2py_options=['--quiet']) + +ext7 = Extension(name='matrix_after_inversion', + sources=['hn2016_falwa/matrix_after_inversion.f90'], + f2py_options=['--quiet']) + +ext8 = Extension(name='upward_sweep', + sources=['hn2016_falwa/upward_sweep.f90'], + f2py_options=['--quiet']) + +ext9 = Extension(name='compute_flux_dirinv', + sources=['hn2016_falwa/compute_flux_dirinv.f90'], + f2py_options=['--quiet']) setup( name='hn2016_falwa', @@ -44,6 +67,6 @@ packages=find_packages(), setup_requires=['pytest-runner'], tests_require=['pytest'], - ext_modules=[ext1, ext2, ext3], + ext_modules=[ext1, ext2, ext3, ext4, ext5, ext6, ext7, ext8, ext9], zip_safe=False ) From f50f7a54ea3df66c1107e4eacd50ae7818dcc790 Mon Sep 17 00:00:00 2001 From: csyhuang Date: Wed, 19 Jan 2022 21:57:49 -0600 Subject: [PATCH 02/19] test git --- show_noboru/era4004n.f90 | 460 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 460 insertions(+) create mode 100644 show_noboru/era4004n.f90 diff --git a/show_noboru/era4004n.f90 b/show_noboru/era4004n.f90 new file mode 100644 index 0000000..731014d --- /dev/null +++ b/show_noboru/era4004n.f90 @@ -0,0 +1,460 @@ + program main + +! USE mkl95_BLAS, ONLY: GEMM,GEMV + USE mkl95_LAPACK, ONLY: GETRF,GETRI + + +! **** take QG analysis and compute Q_ref and invert for +! U_ref & Theta_ref for NH (Direct solver) *** + + integer,parameter :: imax = 360, JMAX = 181, KMAX = 97 + integer,parameter :: nd = 91,nnd=181 + integer,parameter :: jb = 5 ! lower bounding latitude + integer,parameter :: jd = 86 ! nd - lower bounding latitude + common /array/ pv(imax,jmax,kmax),pv2(imax,jmax) + common /brray/ uu(imax,jmax,kmax) + common /bbray/ vort(imax,jmax,kmax),vort2(imax,jmax) + common /bcray/ pt(imax,jmax,kmax) + common /bdray/ stats(kmax),statn(kmax),ts0(kmax),tn0(kmax) + common /crray/ qn(nnd),an(nnd),aan(nnd),tb(kmax),tg(kmax) + common /drray/ cn(nnd),ccn(nnd),tref(jd,kmax) + common /frray/ alat(nd),phi(nd),z(kmax),cbar(nd,kmax) + common /krray/ tjk(jd-2,kmax-1),tj(jd-2),rj(jd-2) + common /lrray/ qjj(jd-2,jd-2),cjj(jd-2,jd-2) + common /orray/ xjj(jd-2,jd-2),yj(jd-2) + common /mrray/ djj(jd-2,jd-2),sjj(jd-2,jd-2) + common /nrray/ sjk(jd-2,jd-2,kmax-1) + common /prray/ pjk(jd-2,kmax),pj(jd-2) + common /irray/ qref(nd,kmax),u(jd,kmax),cref(nd,kmax) + common /krray/ fawa(nd,kmax),ckref(nd,kmax) + common /jrray/ qbar(nd,kmax),ubar(nd,kmax),tbar(nd,kmax) + integer :: md(12),ipiv(jd-2) + + character*35 fn,fn0,fn1 + character*34 fu + character*34 ft + character*4 fn2(12),fy,fy1,fy2 + character*18 f1,f2 + character*19 f3 + character*36 fv + character*38 fr + + a = 6378000. + pi = acos(-1.) + om = 7.29e-5 + dp = pi/180. + dz = 500. + h = 7000. + r = 287. + rkappa = r/1004. + + do nn = 1,nd + phi(nn) = dp*float(nn-1) + alat(nn) = 2.*pi*a*a*(1.-sin(phi(nn))) + enddo + + do k = 1,kmax + z(k) = dz*float(k-1) + enddo + + do m = 2021,2021 + + md(1) = 31 + md(2) = 28 + if(mod(m,4).eq.0) md(2) = 29 + md(3) = 31 + md(4) = 30 + md(5) = 31 + md(6) = 30 + md(7) = 31 + md(8) = 31 + md(9) = 30 + md(10) = 31 + md(11) = 30 + md(12) = 31 + + fn2(1) = '_01_' + fn2(2) = '_02_' + fn2(3) = '_03_' + fn2(4) = '_04_' + fn2(5) = '_05_' + fn2(6) = '_06_' + fn2(7) = '_07_' + fn2(8) = '_08_' + fn2(9) = '_09_' + fn2(10) = '_10_' + fn2(11) = '_11_' + fn2(12) = '_12_' + + write(fy,266) m + 266 format(i4) + + do n = 10,10 + fn = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGPV' + fu = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGU' + ft = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGT' + fr = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGREF_N' + fv = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QVORT' + write(6,*) fn,md(n) + open(35,file =fn, & + form='unformatted',status = 'old') + open(36,file =fu, & + form='unformatted',status = 'old') + open(37,file =ft, & + form='unformatted',status = 'old') + open(38,file =fr, & + form='unformatted',status = 'new') + open(39,file =fv, & + form='unformatted',status = 'old') + + do mm = 1,md(n)*4 + + read(35) pv + read(36) uu + read(39) vort + read(37) pt,tn0,ts0,statn,stats + +! **** Zonal-mean field **** + do j = 91,jmax + qbar(j-90,:) = 0. + tbar(j-90,:) = 0. + ubar(j-90,:) = 0. + do i = 1,imax + qbar(j-90,:) = qbar(j-90,:)+pv(i,j,:)/float(imax) + tbar(j-90,:) = tbar(j-90,:)+pt(i,j,:)/float(imax) + ubar(j-90,:) = ubar(j-90,:)+uu(i,j,:)/float(imax) + enddo + enddo + +! **** hemispheric-mean potential temperature **** + tb(:) = tn0(:) + + do k = 2,96 + pv2(:,:) = pv(:,:,k) + vort2(:,:) = vort(:,:,k) + +! **** compute qref via area analysis **** + qmax = maxval(pv2) + qmin = minval(pv2) + dq = (qmax-qmin)/float(nnd-1) + qn(:) = 0. + an(:) = 0. + cn(:) = 0. + do nn = 1,nnd + qn(nn) = qmax - dq*float(nn-1) + enddo + do j = 1,jmax + phi0 = -0.5*pi+dp*float(j-1) + do i = 1,imax + ind = 1+int((qmax-pv2(i,j))/dq) + da = a*a*dp*dp*cos(phi0) + an(ind) = an(ind) + da + cn(ind) = cn(ind) + da*pv2(i,j) + enddo + enddo + aan(1) = 0. + ccn(1) = 0. + do nn = 2,nnd + aan(nn) = aan(nn-1)+an(nn) + ccn(nn) = ccn(nn-1)+cn(nn) + enddo + do j = 1,nd-1 + do nn = 1,nnd-1 + if(aan(nn).le.alat(j).and.aan(nn+1).gt.alat(j)) then + dd = (alat(j)-aan(nn))/(aan(nn+1)-aan(nn)) + qref(j,k) = qn(nn)*(1.-dd)+qn(nn+1)*dd + cref(j,k) = ccn(nn)*(1.-dd)+ccn(nn+1)*dd + endif + enddo + enddo + + qref(nd,k) = qmax + + cbar(nd,k) = 0. + do j=nd-1,1,-1 + phi0 = dp*(float(j)-0.5) + cbar(j,k) = cbar(j+1,k)+0.5*(qbar(j+1,k)+qbar(j,k)) & + *a*dp*2.*pi*a*cos(phi0) + enddo + +! **** compute Kelvin's circulation based on absolute vorticity (for +! b.c.) **** + + qmax = maxval(vort2) + qmin = minval(vort2) + dq = (qmax-qmin)/float(nnd-1) + qn(:) = 0. + an(:) = 0. + cn(:) = 0. + do nn = 1,nnd + qn(nn) = qmax - dq*float(nn-1) + enddo + do j = 1,jmax + phi0 = -0.5*pi+dp*float(j-1) + do i = 1,imax + ind = 1+int((qmax-vort2(i,j))/dq) + da = a*a*dp*dp*cos(phi0) + an(ind) = an(ind) + da + cn(ind) = cn(ind) + da*vort2(i,j) + enddo + enddo + aan(1) = 0. + ccn(1) = 0. + do nn = 2,nnd + aan(nn) = aan(nn-1)+an(nn) + ccn(nn) = ccn(nn-1)+cn(nn) + enddo + do j = 1,nd-1 + do nn = 1,nnd-1 + if(aan(nn).le.alat(j).and.aan(nn+1).gt.alat(j)) then + dd = (alat(j)-aan(nn))/(aan(nn+1)-aan(nn)) + ckref(j,k) = ccn(nn)*(1.-dd)+ccn(nn+1)*dd + endif + enddo + enddo + + enddo + +! ***** normalize QGPV by sine (latitude) **** + + do j = 2,nd + phi0 = dp*float(j-1) + cor = sin(phi0) + qref(j,:) = qref(j,:)/cor + enddo + + do k = 2,kmax-1 + qref(1,k) = 2.*qref(2,k)-qref(3,k) + enddo + +! ***** FAWA ***** + fawa(:,:) = (cref(:,:)-cbar(:,:))/(2.*pi*a) + +! ***** Direct solver to invert Q_ref ***** + +! *** downward sweep *** + +! **** top boundary condition (Eqs. 24-25) ***** + tjk(:,:) = 0. + sjk(:,:,:) = 0. + do jj = jb+2,90 + j = jj-jb + phi0 = float(jj-1)*dp + cos0 = cos(phi0) + sin0 = sin(phi0) + tjk(j-1,kmax-1) = -dz*r*cos0*exp(-z(kmax-1)*rkappa/h) + tjk(j-1,kmax-1) = tjk(j-1,kmax-1)*(tbar(j+1,kmax)-tbar(j-1,kmax)) + tjk(j-1,kmax-1) = tjk(j-1,kmax-1)/(4.*om*sin0*dp*h*a) + sjk(j-1,j-1,kmax-1) = 1. + enddo + +! **** Evaluate Eqs. 22-23 downward *** + + do k = kmax-1,2,-1 + zp = 0.5*(z(k+1)+z(k)) + zm = 0.5*(z(k-1)+z(k)) + statp = 0.5*(statn(k+1)+statn(k)) + statm = 0.5*(statn(k-1)+statn(k)) + cjj(:,:) = 0. + djj(:,:) = 0. + qjj(:,:) = 0. + sjj(:,:) = sjk(:,:,k) + tj(:) = tjk(:,k) + do jj = jb+2,90 + j = jj - jb + phi0 = float(jj-1)*dp + phip = (float(jj)-0.5)*dp + phim = (float(jj)-1.5)*dp + cos0 = cos(phi0) + cosp = cos(phip) + cosm = cos(phim) + sin0 = sin(phi0) + sinp = sin(phip) + sinm = sin(phim) + + fact = 4.*om*om*h*a*a*sin0*dp*dp/(dz*dz*r*cos0) + amp = exp(-zp/h)*exp(rkappa*zp/h)/statp + amp = amp*fact*exp(z(k)/h) + amm = exp(-zm/h)*exp(rkappa*zm/h)/statm + amm = amm*fact*exp(z(k)/h) + +! ***** Specify A, B, C, D, E, F (Eqs. 4-9) ***** + ajk = 1./(sinp*cosp) + bjk = 1./(sinm*cosm) + cjk = amp + djk = amm + ejk = ajk+bjk+cjk+djk + fjk = -0.5*a*dp*(qref(jj+1,k)-qref(jj-1,k)) + +! ***** Specify rk (Eq. 15) **** + + ! **** North-south boundary conditions **** + u(jd,k) = 0. + phi0 = dp*float(jb) +! u(1,k) = ubar(jb+1,k)*cos(phi0) + u(1,k) = ckref(jb+1,k)/(2.*pi*a)-om*a*cos(phi0) + + rj(j-1) = fjk + if(j.eq.2) rj(j-1) = fjk - bjk*u(1,k) + if(j.eq.jd-1) rj(j-1) = fjk - ajk*u(jd,k) + +! ***** Specify Ck & Dk (Eqs. 18-19) ***** + cjj(j-1,j-1) = cjk + djj(j-1,j-1) = djk + +! **** Specify Qk (Eq. 17) ***** + qjj(j-1,j-1) = -ejk + if(j-1.ge.1.and.j-1.lt.jd-2) then + qjj(j-1,j) = ajk + endif + if(j-1.gt.1.and.j-1.le.jd-2) then + qjj(j-1,j-2) = bjk + endif + enddo + +! **** Compute Qk + Ck Sk ******* + do i = 1,jd-2 + do j = 1,jd-2 + xjj(i,j) = 0. + do kk = 1,jd-2 + xjj(i,j) = xjj(i,j)+cjj(i,kk)*sjj(kk,j) + enddo + qjj(i,j) = qjj(i,j)+xjj(i,j) + enddo + enddo +! call gemm(cjj,sjj,xjj) +! qjj(:,:) = qjj(:,:)+xjj(:,:) + +! **** Invert (Qk + Ck Sk) ******** + call getrf(qjj,ipiv) + call getri(qjj,ipiv) + +! **** Evaluate Eq. 22 **** + do i = 1,jd-2 + do j = 1,jd-2 + xjj(i,j) = 0. + do kk = 1,jd-2 + xjj(i,j) = xjj(i,j)+qjj(i,kk)*djj(kk,j) + enddo + sjk(i,j,k-1) = -xjj(i,j) + enddo + enddo + +! call gemm(qjj,djj,xjj) +! sjk(:,:,k-1) = -xjj(:,:) + +! **** Evaluate rk - Ck Tk **** + do i = 1,jd-2 + yj(i) = 0. + do kk = 1,jd-2 + yj(i) = yj(i)+cjj(i,kk)*tj(kk) + enddo + yj(i) = rj(i)-yj(i) + enddo + +! call gemv(cjj,tj,yj) +! yj(:) = rj(:)-yj(:) +! call gemv(qjj,yj,tj) +! tjk(:,k-1) = tj(:) + + +! ***** Evaluate Eq. 23 ******* + do i = 1,jd-2 + tj(i) = 0. + do kk = 1,jd-2 + tj(i) = tj(i)+qjj(i,kk)*yj(kk) + enddo + tjk(i,k-1) = tj(i) + enddo + + enddo + +! ***** upward sweep (Eq. 20) **** + + pjk(:,1) = 0. + do k = 1,kmax-1 + pj(:) = pjk(:,k) + sjj(:,:) = sjk(:,:,k) + tj(:) = tjk(:,k) + + do i = 1,jd-2 + yj(i) = 0. + do kk = 1,jd-2 + yj(i) = yj(i)+sjj(i,kk)*pj(kk) + enddo + pjk(i,k+1) = yj(i)+tj(i) + enddo +! call gemv(sjj,pj,yj) +! pjk(:,k+1) = yj(:) + tj(:) + enddo + +! **** Recover u ***** + do k = 1,kmax + do j = 2,jd-1 + u(j,k) = pjk(j-1,k) + enddo + enddo + +! *** Corner boundary conditions *** + u(1,1) = 0. + u(jd,1) = 0. +! u(1,kmax) = ubar(1+jb,kmax)*cos(dp*float(jb)) + u(1,kmax) = ckref(1+jb,kmax)/(2.*pi*a)-om*a*cos(dp*float(jb)) + u(jd,kmax) = 0. + +! *** Divide by cos phi to revover Uref **** + do jj = jb+1,nd-1 + j = jj-jb + phi0 = dp*float(jj-1) + u(j,:) = u(j,:)/cos(phi0) + enddo + u(jd,:) = 2.*u(jd-1,:)-u(jd-2,:) + +! ******** compute tref ******* + + do k = 2,96 + t00 = 0. + zz = dz*float(k-1) + tref(1,k) = t00 + tref(2,k) = t00 + do j = 2,jd-1 + phi0 = dp*float(j-1) + cor = 2.*om*sin(phi0) + uz = (u(j,k+1)-u(j,k-1))/(2.*dz) + ty = -cor*uz*a*h*exp(rkappa*zz/h) + ty = ty/r + tref(j+1,k) = tref(j-1,k)+2.*ty*dp + qref(j-1,k) = qref(j-1,k)*sin(phi0) + enddo + tg(k) = 0. + wt = 0. + do jj = 6,91 + j = jj-5 + phi0 = dp*float(jj-1) + tg(k) = tg(k)+cos(phi0)*tref(j,k) + wt = wt + cos(phi0) + enddo + tg(k) = tg(k)/wt + tres = tb(k)-tg(k) + tref(:,k) = tref(:,k)+tres + enddo + tref(:,1) = tref(:,2)-tb(2)+tb(1) + tref(:,97) = tref(:,96)-tb(96)+tb(97) + + write(38) qref,u,tref,fawa,ubar,tbar + + write(6,*) m,n,mm + +! ******************************** + enddo + + close(35) + close(36) + close(37) + close(38) + + enddo + enddo + + stop + end From 183dae3981d596ab4e8005ec2d13ad91a419cd74 Mon Sep 17 00:00:00 2001 From: csyhuang Date: Wed, 16 Mar 2022 17:52:34 -0500 Subject: [PATCH 03/19] save code first then try reverting to previous version --- hn2016_falwa/compute_flux_dirinv.f90 | 20 +- hn2016_falwa/upward_sweep.f90 | 17 +- scripts/nhn_grl2022/Fig1a.py | 80 +- scripts/nhn_grl2022/Fig1b.py | 63 +- scripts/nhn_grl2022/Fig1c.py | 62 +- scripts/nhn_grl2022/Fig1d-Fig2.py | 3 +- scripts/nhn_grl2022/Fig1d-Fig2a.py | 8 + scripts/nhn_grl2022/Fig2b.py | 59 + scripts/nhn_grl2022/Fig3a-d.py | 16 +- scripts/nhn_grl2022/Fig3e.py | 63 +- scripts/nhn_grl2022/Fig3f.py | 73 +- scripts/nhn_grl2022/Fig4.py | 216 +--- scripts/nhn_grl2022/Fig5.py | 312 +----- scripts/nhn_grl2022/graph_plot_module.py | 1088 +++++++++++++++++++ scripts/nhn_grl2022/lwa_flux_computation.py | 2 +- scripts/nhn_grl2022/sample_run_script.py | 157 +++ show_noboru/era4004n.f90 | 11 +- 17 files changed, 1370 insertions(+), 880 deletions(-) create mode 100644 scripts/nhn_grl2022/Fig1d-Fig2a.py create mode 100644 scripts/nhn_grl2022/Fig2b.py create mode 100644 scripts/nhn_grl2022/graph_plot_module.py create mode 100644 scripts/nhn_grl2022/sample_run_script.py diff --git a/hn2016_falwa/compute_flux_dirinv.f90 b/hn2016_falwa/compute_flux_dirinv.f90 index aeb09e6..4307558 100644 --- a/hn2016_falwa/compute_flux_dirinv.f90 +++ b/hn2016_falwa/compute_flux_dirinv.f90 @@ -135,7 +135,7 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa do k = 2,96 zk = dz*float(k-1) do i = 1,imax - do j = 6,nd-1 ! 5N and higher latitude + do j = jb+1,nd-1 ! 5N and higher latitude astar1(i,j,k) = 0. ! LWA*cos(phi) astar2(i,j,k) = 0. ! LWA*cos(phi) ua2(i,j) = 0. !F2 @@ -144,7 +144,7 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa do jj = 1,nd phi1 = dp*float(jj-1) qe(i,jj) = pv(i,jj+90,k)-qref(j,k) !qe; Q = qref - ue(i,jj) = uu(i,jj+90,k)-uref(j-5,k) !ue; shift uref 5N + ue(i,jj) = uu(i,jj+90,k)-uref(j-jb,k) !ue; shift uref 5N aa = a*dp*cos(phi1) !length element if((qe(i,jj).le.0.).and.(jj.ge.j)) then !LWA*cos and F2 astar2(i,j,k)=astar2(i,j,k)-qe(i,jj)*aa !anticyclonic @@ -158,11 +158,11 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ! ******** Other fluxes ****** - ua1(i,j) = uref(j-5,k)*(astar1(i,j,k) + & + ua1(i,j) = uref(j-jb,k)*(astar1(i,j,k) + & astar2(i,j,k)) !F1 - ep1(i,j) = -0.5*(uu(i,j+90,k)-uref(j-5,k))**2 !F3a + ep1(i,j) = -0.5*(uu(i,j+90,k)-uref(j-jb,k))**2 !F3a ep1(i,j) = ep1(i,j)+0.5*vv(i,j+90,k)**2 !F3a+b - ep11 = 0.5*(pt(i,j+90,k)-tref(j-5,k))**2 !F3c + ep11 = 0.5*(pt(i,j+90,k)-tref(j-jb,k))**2 !F3c zz = dz*float(k-1) ep11 = ep11*(r/h)*exp(-rkappa*zz/h) ep11 = ep11*2.*dz/(tg(k+1)-tg(k-1)) @@ -178,15 +178,15 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ! meridional eddy momentum flux one grid north and south - ep2(i,j)=(uu(i,j+91,k)-uref(j-5,k))*vv(i,j+91,k)*cosp*cosp - ep3(i,j)=(uu(i,j+89,k)-uref(j-5,k))*vv(i,j+89,k)*cosm*cosm + ep2(i,j)=(uu(i,j+91,k)-uref(j-jb,k))*vv(i,j+91,k)*cosp*cosp + ep3(i,j)=(uu(i,j+89,k)-uref(j-jb,k))*vv(i,j+89,k)*cosm*cosm ! low-level meridional eddy heat flux if(k.eq.2) then ! (26) of SI-HN17 ep41 = 2.*om*sin0*cos0*dz/6745.348 ! prefactor - ep42 = exp(-dz/h)*vv(i,j+90,2)*(pt(i,j+90,2)-tref(j-5,2)) + ep42 = exp(-dz/h)*vv(i,j+90,2)*(pt(i,j+90,2)-tref(j-jb,2)) ep42 = ep42/(tg(3)-tg(1)) - ep43 = vv(i,j+90,1)*(pt(i,j+90,1)-tref(j-5,1)) + ep43 = vv(i,j+90,1)*(pt(i,j+90,1)-tref(j-jb,1)) ep43 = 0.5*ep43/(tg(2)-tg(1)) ep4(i,j) = ep41*(ep42+ep43) ! low-level heat flux endif @@ -204,7 +204,7 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ep3baro(:,:) = ep3baro(:,:)+ep3(:,:)*exp(-zk/h)*dc do j = 6,nd ! ### yet to be multiplied by cosine ubaro(:,j) = ubaro(:,j)+uu(:,j+90,k)*exp(-zk/h)*dc - urefbaro(j) = urefbaro(j)+uref(j-5,k)*exp(-zk/h)*dc + urefbaro(j) = urefbaro(j)+uref(j-jb,k)*exp(-zk/h)*dc enddo enddo diff --git a/hn2016_falwa/upward_sweep.f90 b/hn2016_falwa/upward_sweep.f90 index 36edc47..9a12e6b 100644 --- a/hn2016_falwa/upward_sweep.f90 +++ b/hn2016_falwa/upward_sweep.f90 @@ -79,7 +79,7 @@ SUBROUTINE upward_sweep(jmax, kmax, nd, nnd, jb, jd, sjk, tjk, ckref, tb, qref_o ! ******** compute tref ******* qref(:, :) = qref_over_cor(:, :) ! modify for f2py wrapping purpose - do k = 2,96 + do k = 2,kmax-1 t00 = 0. zz = dz*float(k-1) tref(1,k) = t00 @@ -91,17 +91,16 @@ SUBROUTINE upward_sweep(jmax, kmax, nd, nnd, jb, jd, sjk, tjk, ckref, tb, qref_o ty = -cor*uz*a*h*exp(rkappa*zz/h) ty = ty/rr tref(j+1,k) = tref(j-1,k)+2.*ty*dp - qref(j-1+jb,k) = qref_over_cor(j-1+jb,k)*sin(phi0) enddo -! do j = jd, nd ! Add after checking code -! qref(j-1,k) = qref_over_cor(j-1,k)*sin(dp*float(j-1)) -! end do -! qref(nd,k) = 2 * qref(nd-1,k) - qref(nd-2,k) ! Linear interpolation + do j = 1,nd + phi0 = dp*float(j-1) + qref(j,k) = qref(j,k)*sin(phi0) + enddo tg(k) = 0. wt = 0. - do jj = 6,91 - j = jj-5 + do jj = jb+1,nd + j = jj-jb phi0 = dp*float(jj-1) tg(k) = tg(k)+cos(phi0)*tref(j,k) wt = wt + cos(phi0) @@ -111,6 +110,6 @@ SUBROUTINE upward_sweep(jmax, kmax, nd, nnd, jb, jd, sjk, tjk, ckref, tb, qref_o tref(:,k) = tref(:,k)+tres enddo tref(:,1) = tref(:,2)-tb(2)+tb(1) - tref(:,97) = tref(:,96)-tb(96)+tb(97) + tref(:,kmax) = tref(:,kmax-1)-tb(kmax-1)+tb(kmax) END SUBROUTINE upward_sweep \ No newline at end of file diff --git a/scripts/nhn_grl2022/Fig1a.py b/scripts/nhn_grl2022/Fig1a.py index 8b6aa4d..30b2459 100644 --- a/scripts/nhn_grl2022/Fig1a.py +++ b/scripts/nhn_grl2022/Fig1a.py @@ -1,81 +1,11 @@ -#This script reads in netCDF data for ERA5 -from netCDF4 import Dataset -import numpy as np -import matplotlib.pyplot as plot -import cartopy.crs as ccrs -from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter +#This script reads in netCDF data for ERA5 ==> Figure 1 Column a #----------------- # read netCDF files #----------------- +data_dir = "grl2021_data/" +z_filename = data_dir + "2021_06_z.nc" +u_filename = data_dir + "2021_06_u.nc" +v_filename = data_dir + "2021_06_v.nc" -data_dir = "grl2022_data/" -filename1 = data_dir + "2021_06_z.nc" -filename2 = data_dir + "2021_06_u.nc" -filename3 = data_dir + "2021_06_v.nc" -ncin1 = Dataset(filename1, 'r', format='NETCDF4') -ncin2 = Dataset(filename2, 'r', format='NETCDF4') -ncin3 = Dataset(filename3, 'r', format='NETCDF4') - -zmean = ncin1.variables['z'] -zmean = (np.array(zmean)) -umean = ncin2.variables['u'] -umean = (np.array(umean)) -vmean = ncin3.variables['v'] -vmean = (np.array(vmean)) - -print(zmean.shape) - -zz = np.zeros((44,181,360)) -z = np.zeros((181,360)) -uu = np.zeros((44,181,360)) -u = np.zeros((181,360)) -vv = np.zeros((44,181,360)) -v = np.zeros((181,360)) -m = 76 -while(m < 120): - zz[m-76,:,:] = zmean[m,16,:,:] - uu[m-76,:,:] = umean[m,16,:,:] - vv[m-76,:,:] = vmean[m,16,:,:] - m = m+1 -day = ['00 UTC 20 June 2021','00 UTC 21 June 2021','00 UTC 22 June 2021','00 UTC 23 June 2021','00 UTC 24 June 2021','00 UTC 25 June 2021','00 UTC 26 June 2021','00 UTC 27 June 2021','00 UTC 28 June 2021','00 UTC 29 June 2021','00 UTC 30 June 2021'] -b = ['0620.png','0621.png','0622.png','0623.png','0624.png','0625.png','0626.png','0627.png','0628.png','0629.png','0630.png'] -n = 0 -while(n < 11): - nn = n*4 - j = 0 - while(j < 181): - z[j,:]=zz[nn,180-j,:]/9.81 - u[j,:]=uu[nn,180-j,:] - v[j,:]=vv[nn,180-j,:] - j = j+1 - cl1 = np.arange(9600,11300,100) - cl2 = np.arange(0,95,5) - x = np.arange(0,360) - y = np.arange(0,181)-90. - plot.rcParams.update({'font.size':14,'text.usetex': False}) - fig = plot.figure(figsize=(8,4)) - ax5 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) - plot.xlim(140,280) - plot.ylim(10,80) - plot.title(''+day[n]) - plot.xlabel('Longitude') - plot.ylabel('Latitude') - ax5.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) - ax5.coastlines(color='white',alpha = 0.7) - ax5.set_aspect('auto', adjustable=None) - ax5.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) - ax5.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) - lon_formatter = LongitudeFormatter(zero_direction_label=True) - lat_formatter = LatitudeFormatter() - ax5.xaxis.set_major_formatter(lon_formatter) - ax5.yaxis.set_major_formatter(lat_formatter) - ott = ax5.contourf(x,y,np.sqrt(u*u+v*v),levels=cl2,transform=ccrs.PlateCarree(),cmap='rainbow') - fig.colorbar(ott,ax=ax5,label='wind speed (m/s)') - ott = ax5.contour(x,y,z,levels=cl1,colors='black',transform=ccrs.PlateCarree(),linewidths=1) - ax5.clabel(ott, ott.levels,fmt='%5i') - plot.savefig(b[n],bbox_inches='tight',dpi =600) - # plot.show() - - n = n+1 \ No newline at end of file diff --git a/scripts/nhn_grl2022/Fig1b.py b/scripts/nhn_grl2022/Fig1b.py index a93d17f..6559444 100644 --- a/scripts/nhn_grl2022/Fig1b.py +++ b/scripts/nhn_grl2022/Fig1b.py @@ -1,66 +1,9 @@ -#This script reads in netCDF data for ERA5 -from netCDF4 import Dataset -import numpy as np -import matplotlib.pyplot as plot -import cartopy.crs as ccrs -from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter +#This script reads in netCDF data for ERA5 ==> Figure 1 column b #----------------- # read netCDF files #----------------- +data_dir = "grl2021_data/" +t_filename = data_dir + "2021_06_t.nc" -data_dir = "grl2022_data/" -filename1 = data_dir + "2021_06_t.nc" -ncin1 = Dataset(filename1, 'r', format='NETCDF4') - -tmean = ncin1.variables['t'] -tmean = (np.array(tmean)) - -print(tmean.shape) - -tt = np.zeros((44,181,360)) -t = np.zeros((181,360)) - -r = 287. -cp = 1004. -kappa = r/cp -m = 76 -while(m < 120): -# tt[m-76,:,:] = tmean[m,36,:,:] - tt[m-76,:,:] = tmean[m,20,:,:]*np.power((1000./450.),kappa) - m = m+1 -day = ['00 UTC 20 June 2021','00 UTC 21 June 2021','00 UTC 22 June 2021','00 UTC 23 June 2021','00 UTC 24 June 2021','00 UTC 25 June 2021','00 UTC 26 June 2021','00 UTC 27 June 2021','00 UTC 28 June 2021','00 UTC 29 June 2021','00 UTC 30 June 2021'] -b = ['T_0620.png','T_0621.png','T_0622.png','T_0623.png','T_0624.png','T_0625.png','T_0626.png','T_0627.png','T_0628.png','T_0629.png','T_0630.png'] -n = 0 -while(n < 11): - nn = n*4 - j = 0 - while(j < 181): - t[j,:]=tt[nn,180-j,:] - j = j+1 - cl1 = np.arange(290,342,2) # 450 hPa - cl2 = np.arange(0,95,5) - x = np.arange(0,360) - y = np.arange(0,181)-90. - fig = plot.figure(figsize=(8,4)) - ax5 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) - plot.xlim(140,280) - plot.ylim(10,80) - plot.title(''+day[n]) - plot.xlabel('Longitude') - plot.ylabel('Latitude') - ax5.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) - ax5.coastlines(color='black',alpha = 0.7) - ax5.set_aspect('auto', adjustable=None) - ax5.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) - ax5.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) - lon_formatter = LongitudeFormatter(zero_direction_label=True) - lat_formatter = LatitudeFormatter() - ax5.xaxis.set_major_formatter(lon_formatter) - ax5.yaxis.set_major_formatter(lat_formatter) - ott = ax5.contourf(x,y,t,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') - fig.colorbar(ott,ax=ax5,label='Kelvin') - plot.savefig(b[n],bbox_inches='tight',dpi =600) - - n = n+1 \ No newline at end of file diff --git a/scripts/nhn_grl2022/Fig1c.py b/scripts/nhn_grl2022/Fig1c.py index 42dff97..cd3ed7e 100644 --- a/scripts/nhn_grl2022/Fig1c.py +++ b/scripts/nhn_grl2022/Fig1c.py @@ -1,64 +1,8 @@ -#This script reads in netCDF data for ERA5 -from netCDF4 import Dataset -import numpy as np -import matplotlib.pyplot as plot -import cartopy.crs as ccrs -from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter +#This script reads in netCDF data for ERA5 ==> Figure 1 Column c #----------------- # read netCDF files #----------------- +data_dir = "grl2021_data/" +t2m_filename = data_dir + "2021_06_2t.nc" -data_dir = "grl2022_data/" -filename1 = data_dir + "2021_06_2t.nc" - -ncin1 = Dataset(filename1, 'r', format='NETCDF4') -tm = ncin1.variables['t2m'] -tm = (np.array(tm)) - -print(tm.shape) - -tt = np.zeros((44,181,360)) -t = np.zeros((181,360)) - -r = 287. -cp = 1004. -kappa = r/cp -m = 76 -while(m < 120): - tt[m-76,:,:] = tm[m,:,:] - m = m+1 -day = ['00 UTC 20 June 2021','00 UTC 21 June 2021','00 UTC 22 June 2021','00 UTC 23 June 2021','00 UTC 24 June 2021','00 UTC 25 June 2021','00 UTC 26 June 2021','00 UTC 27 June 2021','00 UTC 28 June 2021','00 UTC 29 June 2021','00 UTC 30 June 2021'] -b = ['2T_0620.png','2T_0621.png','2T_0622.png','2T_0623.png','2T_0624.png','2T_0625.png','2T_0626.png','2T_0627.png','2T_0628.png','2T_0629.png','2T_0630.png'] -n = 0 -while(n < 11): - nn = n*4 - j = 0 - while(j < 181): - t[j,:]=tt[nn,180-j,:] - j = j+1 - cl1 = np.arange(250,325,5) - cl2 = np.arange(0,95,5) - x = np.arange(0,360) - y = np.arange(0,181)-90. - fig = plot.figure(figsize=(8,4)) - ax5 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) - plot.xlim(140,280) - plot.ylim(10,80) - plot.title(''+day[n]) - plot.xlabel('Longitude') - plot.ylabel('Latitude') - ax5.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) - ax5.coastlines(color='black',alpha = 0.7) - ax5.set_aspect('auto', adjustable=None) - ax5.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) - ax5.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) - lon_formatter = LongitudeFormatter(zero_direction_label=True) - lat_formatter = LatitudeFormatter() - ax5.xaxis.set_major_formatter(lon_formatter) - ax5.yaxis.set_major_formatter(lat_formatter) - ott = ax5.contourf(x,y,t,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') - fig.colorbar(ott,ax=ax5,label='Kelvin') - plot.savefig(b[n],bbox_inches='tight',dpi =600) - - n = n+1 \ No newline at end of file diff --git a/scripts/nhn_grl2022/Fig1d-Fig2.py b/scripts/nhn_grl2022/Fig1d-Fig2.py index 3120161..79713fd 100644 --- a/scripts/nhn_grl2022/Fig1d-Fig2.py +++ b/scripts/nhn_grl2022/Fig1d-Fig2.py @@ -1,3 +1,4 @@ +# This is not used now. (March 16) #This script reads in netCDF data for ERA5 from netCDF4 import Dataset import numpy as np @@ -9,7 +10,7 @@ # read netCDF files #----------------- -data_dir = "grl2022_data/" +data_dir = "grl2021_data/" filename1 = data_dir + "2021_06_t.nc" ncin1 = Dataset(filename1, 'r', format='NETCDF4') diff --git a/scripts/nhn_grl2022/Fig1d-Fig2a.py b/scripts/nhn_grl2022/Fig1d-Fig2a.py new file mode 100644 index 0000000..f3ed239 --- /dev/null +++ b/scripts/nhn_grl2022/Fig1d-Fig2a.py @@ -0,0 +1,8 @@ +#This script reads in netCDF data for ERA5 ==> Figure 1 Column d + Figure 2 + +#----------------- +# read netCDF files +#----------------- +data_dir = "grl2021_data/" +t_filename = data_dir + "2021_06_t.nc" + diff --git a/scripts/nhn_grl2022/Fig2b.py b/scripts/nhn_grl2022/Fig2b.py new file mode 100644 index 0000000..8bf7df2 --- /dev/null +++ b/scripts/nhn_grl2022/Fig2b.py @@ -0,0 +1,59 @@ +#This script reads in netCDF data for ERA5 ==> Fig2b +from netCDF4 import Dataset +import numpy as np +import scipy.stats as stats +import matplotlib.pyplot as plot +import cartopy.crs as ccrs +import cartopy.feature as cf +from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter + +#----------------- +# read netCDF files +#----------------- +data_dir = "grl2021_data/" +filename3 = data_dir + "2021_06_str.nc" +filename5 = data_dir + "2021_06_ssr.nc" +filename6 = data_dir + "2021_06_sshf.nc" +filename7 = data_dir + "2021_06_slhf.nc" + + +ncin3 = Dataset(filename3, 'r', format='NETCDF4') +ncin5 = Dataset(filename5, 'r', format='NETCDF4') +ncin6 = Dataset(filename6, 'r', format='NETCDF4') +ncin7 = Dataset(filename7, 'r', format='NETCDF4') + + +irt = ncin3.variables["str"] +srad = ncin5.variables["ssr"] +shff = ncin6.variables["sshf"] +lhff = ncin7.variables["slhf"] + +irtt = np.zeros(720) +ssrad = np.zeros(720) +shf = np.zeros(720) +lhf = np.zeros(720) +zr = np.zeros(720) + +irtt[:] = irt[:,41,241]/3600. +ssrad[:] = srad[:,41,241]/3600. +shf[:] = shff[:,41,241]/3600. +lhf[:] = lhff[:,41,241]/3600. +zr[:] = 0. + +print() + +x = np.arange(0,720)/24.+1 + +plot.rcParams.update({'font.size': 16}) +fig = plot.figure(figsize=(8,4)) +plot.title('Surface Heat Fluxes at 49$^\circ$N 119$^\circ$W') +plot.xlabel('Day') +plot.ylabel('Flux (Wm$^{-2}$)') +plot.xlim(20,31) +plot.ylim(-800,1000) +fig = plot.plot(x,ssrad,color='red') +fig = plot.plot(x,irtt,'r--') +fig = plot.plot(x,shf,color='blue') +fig = plot.plot(x,lhf,'b--') +plot.savefig('surface_F.png',bbox_inches='tight',dpi =600) + diff --git a/scripts/nhn_grl2022/Fig3a-d.py b/scripts/nhn_grl2022/Fig3a-d.py index 616a536..53d86c5 100644 --- a/scripts/nhn_grl2022/Fig3a-d.py +++ b/scripts/nhn_grl2022/Fig3a-d.py @@ -9,9 +9,9 @@ # read netCDF files #----------------- -data_dir = "grl2022_data/" +data_dir = "grl2021_data/" # filename0 = data_dir + "2021_06_LWAb_N.nc" -filename0 = "2021-06-01_to_2021-06-30_output3.nc" +filename0 = "2021-06-01_to_2021-06-30_output.nc" ncin1 = Dataset(filename0, 'r', format='NETCDF4') @@ -64,12 +64,12 @@ plot.savefig('dLWA.png',bbox_inches='tight',dpi =600) #plot.show() -filename1 = "2021-06-01_to_2021-06-30_output3.nc" -filename2 = "2021-06-01_to_2021-06-30_output3.nc" -filename3 = "2021-06-01_to_2021-06-30_output3.nc" -filename4 = "2021-06-01_to_2021-06-30_output3.nc" -filename5 = "2021-06-01_to_2021-06-30_output3.nc" -filename6 = "2021-06-01_to_2021-06-30_output3.nc" +filename1 = "2021-06-01_to_2021-06-30_output.nc" +filename2 = "2021-06-01_to_2021-06-30_output.nc" +filename3 = "2021-06-01_to_2021-06-30_output.nc" +filename4 = "2021-06-01_to_2021-06-30_output.nc" +filename5 = "2021-06-01_to_2021-06-30_output.nc" +filename6 = "2021-06-01_to_2021-06-30_output.nc" # filename1 = data_dir + "2021_06_ua1_N.nc" # filename2 = data_dir + "2021_06_ua2_N.nc" diff --git a/scripts/nhn_grl2022/Fig3e.py b/scripts/nhn_grl2022/Fig3e.py index 7ae6899..9bb728d 100644 --- a/scripts/nhn_grl2022/Fig3e.py +++ b/scripts/nhn_grl2022/Fig3e.py @@ -1,67 +1,10 @@ -#This script reads in netCDF data for ERA5 -from netCDF4 import Dataset -import numpy as np -import matplotlib.pyplot as plot -import cartopy.crs as ccrs -from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter +#This script reads in netCDF data for ERA5 ==> Figure 3e #----------------- # read netCDF files #----------------- -data_dir = "grl2022_data/" -filename1 = data_dir + "2021_06_mtnlwrf.nc" # net OLR -filename2 = data_dir + "2021_06_mtnlwrfcs.nc" # OLR clear sky +mtnlwrf_filename = "2021_06_mtnlwrf.nc" # net OLR +mtnlwrfcs_filename = "2021_06_mtnlwrfcs.nc" # OLR clear sky -ncin1 = Dataset(filename1, 'r', format='NETCDF4') -ncin2 = Dataset(filename2, 'r', format='NETCDF4') -olr = ncin1.variables['mtnlwrf'] -olr = (np.array(olr)) -olrcs = ncin2.variables['mtnlwrfcs'] -olrcs = (np.array(olrcs)) - -print(olr.shape) - -tt = np.zeros((44,181,360)) -t = np.zeros((181,360)) -m = 77 -while(m < 120): - tt[m-77,:,:] = olr[m,:,:] - m = m+1 -day = ['06 UTC 20 June 2021','06 UTC 21 June 2021','06 UTC 22 June 2021','06 UTC 23 June 2021','06 UTC 24 June 2021','06 UTC 25 June 2021','06 UTC 26 June 2021','06 UTC 27 June 2021','06 UTC 28 June 2021','06 UTC 29 June 2021','06 UTC 30 June 2021'] -b = ['OLR_0620.png','OLR_0621.png','OLR_0622.png','OLR_0623.png','OLR_0624.png','OLR_0625.png','OLR_0626.png','OLR_0627.png','OLR_0628.png','OLR_0629.png','OLR_0630.png'] -n = 0 -while(n < 11): - nn = n*4 - j = 0 - while(j < 181): - t[j,:]=tt[nn,180-j,:] - j = j+1 - cl1 = np.arange(80,390,10) - x = np.arange(0,360) - y = np.arange(0,181)-90. - plot.rcParams.update({'font.size':14,'text.usetex': False}) - fig = plot.figure(figsize=(8,4)) - ax5 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) - plot.xlim(140,280) - plot.ylim(10,80) - plot.title('OLR '+day[n]) - plot.xlabel('Longitude') - plot.ylabel('Latitude') - ax5.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) - ax5.coastlines(color='black',alpha = 0.7) - ax5.set_aspect('auto', adjustable=None) - ax5.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) - ax5.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) - lon_formatter = LongitudeFormatter(zero_direction_label=True) - lat_formatter = LatitudeFormatter() - ax5.xaxis.set_major_formatter(lon_formatter) - ax5.yaxis.set_major_formatter(lat_formatter) - ott = ax5.contourf(x,y,-t,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') - fig.colorbar(ott,ax=ax5,label='W/m$^2$') -# ott = ax5.contour(x,y,z,levels=cl1,colors='black',transform=ccrs.PlateCarree(),linewidths=1) -# ax5.clabel(ott, ott.levels,fmt='%5i') - plot.savefig(b[n],bbox_inches='tight',dpi =600) - - n = n+1 \ No newline at end of file diff --git a/scripts/nhn_grl2022/Fig3f.py b/scripts/nhn_grl2022/Fig3f.py index 695c0df..277fba8 100644 --- a/scripts/nhn_grl2022/Fig3f.py +++ b/scripts/nhn_grl2022/Fig3f.py @@ -1,75 +1,10 @@ -#This script reads in netCDF data for ERA5 -from netCDF4 import Dataset -import numpy as np -import matplotlib.pyplot as plot -import cartopy.crs as ccrs -from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter +#This script reads in netCDF data for ERA5 ==> Figure 3f #----------------- # read netCDF files #----------------- -data_dir = "grl2022_data/" -filename1 = data_dir + "2021_06_tcw.nc" # total column water (kg/m^2) -filename2 = data_dir + "2021_06_tcwv.nc" # total column water vapor (kg/m^2) -filename3 = data_dir + "2021_06_sp.nc" # sea level pressure (hPa) +tcw_filename = "2021_06_tcw.nc" # total column water (kg/m^2) +tcwv_filename = "2021_06_tcwv.nc" # total column water vapor (kg/m^2) +sp_filename = "2021_06_sp.nc" # sea level pressure (hPa) -ncin1 = Dataset(filename1, 'r', format='NETCDF4') -ncin2 = Dataset(filename2, 'r', format='NETCDF4') -ncin3 = Dataset(filename3, 'r', format='NETCDF4') -cw = ncin1.variables['tcw'] -cw = (np.array(cw)) -cwv = ncin2.variables['tcwv'] -cwv = (np.array(cwv)) -sp = ncin3.variables['sp'] -sp = (np.array(sp)) - -tt = np.zeros((44,181,360)) -pp = np.zeros((44,181,360)) -t = np.zeros((181,360)) -p = np.zeros((181,360)) -m = 77 -while(m < 120): - tt[m-77,:,:] = cw[m,:,:]-cwv[m,:,:] - pp[m-77,:,:] = sp[m,:,:]/100. - m = m+1 -day = ['06 UTC 20 June 2021','06 UTC 21 June 2021','06 UTC 22 June 2021','06 UTC 23 June 2021','06 UTC 24 June 2021','06 UTC 25 June 2021','06 UTC 26 June 2021','06 UTC 27 June 2021','06 UTC 28 June 2021','06 UTC 29 June 2021','06 UTC 30 June 2021'] -b = ['CW_0620.png','CW_0621.png','CW_0622.png','CW_0623.png','CW_0624.png','CW_0625.png','CW_0626.png','CW_0627.png','CW_0628.png','CW_0629.png','CW_0630.png'] -n = 0 -while(n < 11): - nn = n*4 - j = 0 - while(j < 181): - t[j,:]=tt[nn,180-j,:] - p[j,:]=pp[nn,180-j,:] - j = j+1 - cl1 = np.arange(-0.1,3.6,0.1) - c12 = np.arange(980,1032,4) - x = np.arange(0,360) - y = np.arange(0,181)-90. - fig = plot.figure(figsize=(8,4)) - ax5 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) - plot.xlim(140,280) - plot.ylim(10,80) - plot.title('Column water '+day[n]) - plot.xlabel('Longitude') - plot.ylabel('Latitude') - ax5.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) - ax5.coastlines(color='white',alpha = 0.7) - ax5.set_aspect('auto', adjustable=None) - ax5.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) - ax5.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) - lon_formatter = LongitudeFormatter(zero_direction_label=True) - lat_formatter = LatitudeFormatter() - ax5.xaxis.set_major_formatter(lon_formatter) - ax5.yaxis.set_major_formatter(lat_formatter) - ott = ax5.contourf(x,y,t,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') - fig.colorbar(ott,ax=ax5,label='kg/m$^2$') - ott = ax5.contour(x,y,p,levels=c12,colors='white',alpha=0.5,transform=ccrs.PlateCarree(),linewidths=1) - ax5.clabel(ott, ott.levels,fmt='%5i') -# ott = ax5.contour(x,y,z,levels=cl1,colors='black',transform=ccrs.PlateCarree(),linewidths=1) -# ax5.clabel(ott, ott.levels,fmt='%5i') - plot.savefig(b[n],bbox_inches='tight',dpi =600) - # plot.show() - - n = n+1 \ No newline at end of file diff --git a/scripts/nhn_grl2022/Fig4.py b/scripts/nhn_grl2022/Fig4.py index 2f1e0ee..dc0c800 100644 --- a/scripts/nhn_grl2022/Fig4.py +++ b/scripts/nhn_grl2022/Fig4.py @@ -1,225 +1,13 @@ -## This script reads in netCDF LWAb data for ERA5 -from netCDF4 import Dataset -import numpy as np -import matplotlib.pyplot as plot +## This script reads in netCDF LWAb data for ERA5 ==> Figure4 -dt = 3600.*6. -a = 6378000. -dl = 2.*np.pi/360. -dp = 2.*np.pi/360. - -jm = 49 -jp = 49 - #----------------- # read netCDF files #----------------- -data_dir = "grl2022_data/" -# filename1 = data_dir + "2021_06_LWAb_N.nc" -filename1 = "2021-06-01_to_2021-06-30_output3.nc" - -ncin1 = Dataset(filename1, 'r', format='NETCDF4') - -lwa = ncin1.variables['lwa'] -lwa = (np.array(lwa)) - -print(lwa.shape) - -z = np.zeros((124,360)) # wave activity tendency -w = np.zeros((124,360)) # wave activity -m = 1 -while(m < 119): - j = jm - cos0 = 0 - while(j < jp+1): - phi = dp*j - z[m,:] = z[m,:]+np.cos(phi)*(lwa[m+1,j,:]-lwa[m-1,j,:])/(2.*dt) # wave activity tendency at 49 N - w[m,:] = w[m,:]+np.cos(phi)*lwa[m,j,:] - cos0 = cos0 + np.cos(phi) - j = j+1 - z[m,:] = z[m,:]/cos0 - w[m,:] = w[m,:]/cos0 - m = m+1 - -filename1 = data_dir + "2021_06_ua1_N.nc" -filename2 = data_dir + "2021_06_ua2_N.nc" -filename3 = data_dir + "2021_06_ep1_N.nc" -filename4 = data_dir + "2021_06_ep2_N.nc" -filename5 = data_dir + "2021_06_ep3_N.nc" -filename6 = data_dir + "2021_06_ep4_N.nc" -# filename1 = "2021-06-01_to_2021-06-30_output2.nc" -# filename2 = "2021-06-01_to_2021-06-30_output2.nc" -# filename3 = "2021-06-01_to_2021-06-30_output2.nc" -# filename4 = "2021-06-01_to_2021-06-30_output2.nc" -# filename5 = "2021-06-01_to_2021-06-30_output2.nc" -# filename6 = "2021-06-01_to_2021-06-30_output2.nc" - -ncin1 = Dataset(filename1, 'r', format='NETCDF4') -ua1 = ncin1.variables['ua1'] -ua1 = (np.array(ua1)) -ncin2 = Dataset(filename2, 'r', format='NETCDF4') -ua2 = ncin2.variables['ua2'] -ua2 = (np.array(ua2)) -ncin3 = Dataset(filename3, 'r', format='NETCDF4') -ep1 = ncin3.variables['ep1'] -ep1 = (np.array(ep1)) -ncin4 = Dataset(filename4, 'r', format='NETCDF4') -ep2 = ncin4.variables['ep2'] -ep2 = (np.array(ep2)) -ncin5 = Dataset(filename5, 'r', format='NETCDF4') -ep3 = ncin5.variables['ep3'] -ep3 = (np.array(ep3)) -ncin6 = Dataset(filename6, 'r', format='NETCDF4') -ep4 = ncin6.variables['ep4'] -ep4 = (np.array(ep4)) - -f1 = np.zeros((124,360)) - -z1 = np.zeros((124,360)) -z2 = np.zeros((124,360)) -z3 = np.zeros((124,360)) -z4 = np.zeros((124,360)) - -#phi = dp*49. -#const = 1./(2.*a*np.cos(phi)*dl) -i = 1 -while(i < 359): - j = jm - while(j < jp+1): - phi = dp*j - const = 1./(2.*a*dl) - z1[:,i] = z1[:,i]-const*(ua1[:,j,i+1]+ua2[:,j,i+1]+ep1[:,j,i+1]-ua1[:,j,i-1]-ua2[:,j,i-1]-ep1[:,j,i-1]) - j = j+1 - z1[:,i] = z1[:,i]/cos0 - i = i+1 -i = 0 -while(i < 360): - j = jm - while(j < jp+1): - phi = dp*j - const = 1./(2.*a*dl) - f1[:,i]=f1[:,i]+(ua1[:,j,i]+ua2[:,j,i]+ep1[:,j,i])*np.cos(phi) # zonal wave activity flux - z2[:,i]=z2[:,i]+const*(ep2[:,j,i]-ep3[:,j,i]) # metisional convergence of wave activity flux - z3[:,i]=z3[:,i]+np.cos(phi)*ep4[:,j,i] # bottom source - j = j+1 - f1[:,i] = f1[:,i]/cos0 - z2[:,i] = z2[:,i]/cos0 - z3[:,i] = z3[:,i]/cos0 - i = i+1 - -zs = np.zeros((124,360)) # smoothed z # -ws = np.zeros((124,360)) # smoothed w # -f1s = np.zeros((124,360)) # smoothed f1 # -z1s = np.zeros((124,360)) # smoothed z1 # -z2s = np.zeros((124,360)) # smoothed z2 # -z3s = np.zeros((124,360)) # smoothed z3 # - -#### smoothing in longitude #### -n = 4 # smoothing width = 2n+1 -j = 0 -while(j < 124): - zx = np.zeros(360) - zx[:] = z[j,:] - wx = np.zeros(360) - wx[:] = w[j,:] - f1x = np.zeros(360) - f1x[:] = f1[j,:] - z1x = np.zeros(360) - z1x[:] = z1[j,:] - z2x = np.zeros(360) - z2x[:] = z2[j,:] - z3x = np.zeros(360) - z3x[:] = z3[j,:] - nn = -n - while(nn < n+1): - wy = np.roll(wx,nn) - ws[j,:] = ws[j,:] + wy[:]/(2*n+1) - f1y = np.roll(f1x,nn) - f1s[j,:] = f1s[j,:] + f1y[:]/(2*n+1) - zy = np.roll(zx,nn) - zs[j,:] = zs[j,:] + zy[:]/(2*n+1) - z1y = np.roll(z1x,nn) - z1s[j,:] = z1s[j,:] + z1y[:]/(2*n+1) - z2y = np.roll(z2x,nn) - z2s[j,:] = z2s[j,:] + z2y[:]/(2*n+1) - z3y = np.roll(z3x,nn) - z3s[j,:] = z3s[j,:] + z3y[:]/(2*n+1) - nn = nn+1 - j = j+1 -z4[:,:]=zs[:,:]-z1s[:,:]-z2s[:,:]-z3s[:,:] # residual - - - -############################################## - -cl2 = np.arange(0,135,5) -x = np.arange(0,360) -y = np.arange(0,124)*0.25 -plot.rcParams.update({'font.size': 20}) -fig,ax5 = plot.subplots(1,figsize=(8,8)) -plot.xlim(140,280) -plot.ylim(20,29.75) -plot.title('Column LWA 49$^\circ$N') -plot.xlabel('Longitude') -plot.ylabel('Day') -ott = ax5.contourf(x,y,w,levels=cl2,cmap='rainbow') -fig.colorbar(ott,ax=ax5,label='(ms$^{-1}$)') -plot.savefig('HovmollerLWA.png',bbox_inches='tight',dpi =600) -#plot.show() - - -############################################## - -cl2 = np.arange(-100,1500,100) -x = np.arange(0,360) -y = np.arange(0,124)*0.25 -plot.rcParams.update({'font.size': 20}) -fig,ax5 = plot.subplots(1,figsize=(8,8)) -plot.xlim(140,280) -plot.ylim(20,29.75) -plot.title(' 49$^\circ$N') -plot.xlabel('Longitude') -plot.ylabel('Day') -ott = ax5.contourf(x,y,f1,levels=cl2,cmap='rainbow') -fig.colorbar(ott,ax=ax5,label='(m$^2$s$^{-2}$)') -#ott = ax5.contourf(x,y,z4,levels=[0.0005,0.001]) -plot.savefig('HovmollerFx.png',bbox_inches='tight',dpi =600) -#plot.show() - +lwa_flux_filename = "2021_06_LWAb_N.nc" -############################################## -cl2 = np.arange(-10.,9,1) -x = np.arange(0,360) -y = np.arange(0,124)*0.25 -plot.rcParams.update({'font.size': 20}) -fig,ax5 = plot.subplots(1,figsize=(8,8)) -plot.xlim(140,280) -plot.ylim(20,29.5) -plot.title('Term (IV) 49$^\circ$N') -plot.xlabel('Longitude') -plot.ylabel('Day') -ott = ax5.contourf(x,y,z4*10000,levels=cl2,cmap='rainbow') -fig.colorbar(ott,ax=ax5,label='(10$^{-4}$ ms$^{-2}$)') -plot.savefig('HovmollerRes.png',bbox_inches='tight',dpi =600) -#plot.show() -############################################## -cl2 = np.arange(-10.,9,1) -x = np.arange(0,360) -y = np.arange(0,124)*0.25 -plot.rcParams.update({'font.size': 20}) -fig,ax5 = plot.subplots(1,figsize=(8,8)) -plot.xlim(140,280) -plot.ylim(20,29.75) -plot.title('Terms (I)+(II) 49$^\circ$N') -plot.xlabel('Longitude') -plot.ylabel('Day') -ott = ax5.contourf(x,y,(z1s+z2s+z3s)*10000,levels=cl2,cmap='rainbow') -fig.colorbar(ott,ax=ax5,label='(10$^{-4}$ ms$^{-2}$)') -plot.savefig('HovmollerFxy.png',bbox_inches='tight',dpi =600) -#plot.show() \ No newline at end of file diff --git a/scripts/nhn_grl2022/Fig5.py b/scripts/nhn_grl2022/Fig5.py index 324c00d..e23fc13 100644 --- a/scripts/nhn_grl2022/Fig5.py +++ b/scripts/nhn_grl2022/Fig5.py @@ -1,316 +1,8 @@ -## This script reads in netCDF LWAb data for ERA5 -from netCDF4 import Dataset -import numpy as np -import matplotlib.pyplot as plot +## This script reads in netCDF LWAb data for ERA5 and perform variation in wave forcing ==> Fig5 #----------------- # read netCDF files #----------------- -data_dir = "grl2022_data/" -filename1 = data_dir + "2021_06_LWAb_N.nc" +lwa_flux_filename = "2021_06_LWAb_N.nc" -ncin1 = Dataset(filename1, 'r', format='NETCDF4') - -lwa = ncin1.variables['lwa'] -lwa = (np.array(lwa)) - -print(lwa.shape) - -z = np.zeros((120,360)) -m = 0 -while(m < 120): - z[m,:] = lwa[m,49,:] # 49N LWA for June 1-30 - m = m+1 - -zs = np.zeros((120,360)) # smoothed z # - -#### smoothing in longitude #### -n = 5 # smoothing width # -m = 0 -while(m < 120): - zx = np.zeros(360) - zx[:] = z[m,:] - nn = -n - while(nn < n+1): - zy = np.roll(zx,nn) - zs[m,:] = zs[m,:] + zy[:]/(2*n+1) - nn = nn+1 - m = m+1 - -zx[:] = zs[100,:]-zs[76,:] -zy[:] = 0 - - -filename1 = data_dir + "2021_06_ua1_N.nc" -filename2 = data_dir + "2021_06_ua2_N.nc" -filename3 = data_dir + "2021_06_ep1_N.nc" -filename4 = data_dir + "2021_06_ep2_N.nc" -filename5 = data_dir + "2021_06_ep3_N.nc" -filename6 = data_dir + "2021_06_ep4_N.nc" - -ncin1 = Dataset(filename1, 'r', format='NETCDF4') -ua1 = ncin1.variables['ua1'] -ua1 = (np.array(ua1)) -ncin2 = Dataset(filename2, 'r', format='NETCDF4') -ua2 = ncin2.variables['ua2'] -ua2 = (np.array(ua2)) -ncin3 = Dataset(filename3, 'r', format='NETCDF4') -ep1 = ncin3.variables['ep1'] -ep1 = (np.array(ep1)) -ncin4 = Dataset(filename4, 'r', format='NETCDF4') -ep2 = ncin4.variables['ep2'] -ep2 = (np.array(ep2)) -ncin5 = Dataset(filename5, 'r', format='NETCDF4') -ep3 = ncin5.variables['ep3'] -ep3 = (np.array(ep3)) -ncin6 = Dataset(filename6, 'r', format='NETCDF4') -ep4 = ncin6.variables['ep4'] -ep4 = (np.array(ep4)) - -f1 = np.zeros((120,360)) -f2 = np.zeros((120,360)) -f11 = np.zeros((120,360)) -f22 = np.zeros((120,360)) - -z1 = np.zeros((120,360)) -z2 = np.zeros((120,360)) -z3 = np.zeros((120,360)) -dt = 3600.*6. -a = 6378000. -dl = 2.*np.pi/360. -dp = 2.*np.pi/360. -m = 0 # m = 76 is 20 June 2021 00 UTC -while(m < 120): # m = 100 is 26 June 2021 00 UTC - z3[m,:] = ep4[m,49,:] - f1[m,:] = ua1[m,49,:]+ua2[m,49,:]+ep1[m,49,:] - j = 49 - phi = dp*j - const = 1./(2.*a*np.cos(phi)*dl) - z2[m,:]=const*(ep2[m,49,:]-ep3[m,49,:]) - f2[m,:] = 0.5*(ep2[m,49,:]+ep3[m,49,:])/np.cos(phi) - i = 1 - while(i < 359): - z1[m,i] = -const*(f1[m,i+1]-f1[m,i-1]) - i = i+1 - z1[m,0] = -const*(f1[m,1]-f1[m,359]) - z1[m,359] = -const*(f1[m,0]-f1[m,358]) - m = m+1 - -z1s = np.zeros((120,360)) # smoothed z1 # -z2s = np.zeros((120,360)) # smoothed z2 # -z3s = np.zeros((120,360)) # smoothed z3 # -f1s = np.zeros((120,360)) # smoothed f1 # - -#### smoothing in longitude #### -m = 0 -while(m < 120): - z1x = np.zeros(360) - z1x[:] = z1[m,:] - z2x = np.zeros(360) - z2x[:] = z2[m,:] - z3x = np.zeros(360) - z3x[:] = z3[m,:] - f1x = np.zeros(360) - f1x[:] = f1[m,:] - - nn = -n - while(nn < n+1): - z1y = np.roll(z1x,nn) - z1s[m,:] = z1s[m,:] + z1y[:]/(2*n+1) - z2y = np.roll(z2x,nn) - z2s[m,:] = z2s[m,:] + z2y[:]/(2*n+1) - z3y = np.roll(z3x,nn) - z3s[m,:] = z3s[m,:] + z3y[:]/(2*n+1) - f1y = np.roll(f1x,nn) - f1s[m,:] = f1s[m,:] + f1y[:]/(2*n+1) - nn = nn+1 - m = m+1 - -##### Time integration test ###### - -lwa = np.zeros(360) -res = np.zeros((120,360)) -dlwa = np.zeros((120,360)) -gama = np.zeros((120,360)) -gama1 = np.zeros((120,360)) -gama2 = np.zeros((120,360)) -cgx = np.zeros((120,360)) - -m = 0 -while(m < 119): - dlwa[m,:] = zs[m+1,:]-zs[m,:] - cgx[m,:] = (f1s[m,:]+f1s[m+1,:])/(zs[m,:]+zs[m+1,:]) - res[m,:] = (dlwa[m,:] - 0.5*dt*(z1s[m,:]+z1s[m+1,:]+z2s[m,:]+z2s[m+1,:]+z3s[m,:]+z3s[m+1,:]))/dt - gama[m,:] = 2.*res[m,:]/(zs[m,:]+zs[m+1,:]) - m = m+1 - -m = 76 -while(m < 100): - lwa[:] = lwa[:] + 0.5*dt*(z1s[m,:]+z1s[m+1,:]+z2s[m,:]+z2s[m+1,:]+z3s[m,:]+z3s[m+1,:]) + dt*res[m,:] - m = m+1 - - -m = 76 -j = 49 -phi = dp*j -const = 1./(2.*a*np.cos(phi)*dl) -lwa0 = np.zeros((120,360)) -lwa1 = np.zeros((120,360)) - -lwa0[:,:] = zs[:,:] -lwa1[:,:] = zs[:,:] - - -while(m < 100): - i = 1 - while(i < 359): - d0 = -const*0.5*((lwa0[m,i+1]+lwa0[m+1,i+1])*cgx[m,i+1]-(lwa0[m,i-1]+lwa0[m+1,i-1])*cgx[m,i-1]) - d2 = 0.5*(z2s[m+1,i]+z2s[m,i]) - d3 = 0.5*(z3s[m+1,i]+z3s[m,i]) - d4 = gama[m,i]*0.5*(zs[m,i]+zs[m+1,i]) - lwa1[m+1,i] = lwa1[m,i]+dt*(d0+d2+d3+d4) - i = i+1 - d0 = -const*0.5*((lwa0[m,0]+lwa0[m+1,0])*cgx[m,0]-(lwa0[m,358]+lwa0[m+1,358])*cgx[m,358]) - d2 = 0.5*(z2s[m+1,359]+z2s[m,359]) - d3 = 0.5*(z3s[m+1,359]+z3s[m,359]) - d4 = gama[m,359]*0.5*(zs[m,359]+zs[m+1,359]) - lwa1[m+1,359] = lwa1[m,359]+dt*(d0+d2+d3+d4) - - d0 = -const*0.5*((lwa0[m,1]+lwa0[m+1,1])*cgx[m,1]-(lwa0[m,359]+lwa0[m+1,359])*cgx[m,359]) - d2 = 0.5*(z2s[m+1,0]+z2s[m,0]) - d3 = 0.5*(z3s[m+1,0]+z3s[m,0]) - d4 = gama[m,0]*0.5*(zs[m,0]+zs[m+1,0]) - lwa1[m+1,0] = lwa1[m,0]+dt*(d0+d2+d3+d4) - m = m+1 - -#### Modify gamma #### - -gama1[:,:] = gama[:,:] -gama2[:,:] = gama[:,:] -m = 76 -while(m < 100): - if((m >= 84) and (m <= 92)): - i = 200 - while(i < 221): - if(gama[m,i] > 0): - gama1[m,i] = gama[m,i]*0.7 - gama2[m,i] = gama[m,i]*0. - i = i+1 - m = m+1 - -gama1[:,:] = gama1[:,:]-gama[:,:] -gama2[:,:] = gama2[:,:]-gama[:,:] - -##### Interpolate gama, gama1, cgx onto finer tiem mesh dt = 30 min ##### - -gamap = np.zeros((8640,360)) -gama1p = np.zeros((8640,360)) -gama2p = np.zeros((8640,360)) -cgxp = np.zeros((8640,360)) -forcep = np.zeros((8640,360)) -lwap = np.zeros((8640,360)) - -m = 76 -while(m < 101): - i = 0 - while(i < 360): - mm = (m-76)*360+i-180 - if(mm >= 0): - if(mm < 8640): - gamap[mm,:] = gama[m,:]*(i/360.)+gama[m-1,:]*(1.-i/360.) - gama1p[mm,:] = gama1[m,:]*(i/360.)+gama1[m-1,:]*(1.-i/360.) - gama2p[mm,:] = gama2[m,:]*(i/360.)+gama2[m-1,:]*(1.-i/360.) - cgxp[mm,:] = cgx[m,:]*(i/360.)+cgx[m-1,:]*(1.-i/360.) - i = i+1 - m = m+1 - -m = 76 -while(m < 100): - i = 0 - while(i < 360): - mm = (m-76)*360+i - forcep[mm,:] = (z2s[m+1,:]+z3s[m+1,:])*(i/360.)+(z2s[m,:]+z3s[m,:])*(1.-i/360.) - lwap[mm,:] = zs[m+1,:]*(i/360.)+zs[m,:]*(1.-i/360.) - i = i+1 - m = m+1 - -##### Time integration #### - -dt = 60. -j = 49 -phi = dp*j -const = 1./(2.*a*np.cos(phi)*dl) -al = 0. -diff = 200000. -dlwap = np.zeros((8641,360)) -dlwap2 = np.zeros((8641,360)) - -m = 1 -while(m < 8640): - i = 1 - while(i < 359): - d1 = -const*(dlwap[m,i+1]*(cgxp[m,i+1]-al*(dlwap[m,i+1]+lwap[m,i+1]))-dlwap[m,i-1]*(cgxp[m,i-1]-al*(dlwap[m,i-1]+lwap[m,i-1]))) - d2 = gama1p[m,i]*dlwap[m,i] - d3 = gamap[m,i]*dlwap[m,i] - d4 = gama1p[m,i]*lwap[m,i] - d5 = diff*(dlwap[m-1,i+1]+dlwap[m-1,i-1]-2.*dlwap[m-1,i])/(a*a*dl*dl*np.cos(phi)*np.cos(phi)) - dlwap[m+1,i] = dlwap[m-1,i]+2.*dt*(d1+d2+d3+d4+d5) - - d12 = -const*(dlwap2[m,i+1]*(cgxp[m,i+1]-al*(dlwap2[m,i+1]+lwap[m,i+1]))-dlwap2[m,i-1]*(cgxp[m,i-1]-al*(dlwap2[m,i-1]+lwap[m,i-1]))) - d22 = gama2p[m,i]*dlwap2[m,i] - d32 = gamap[m,i]*dlwap2[m,i] - d42 = gama2p[m,i]*lwap[m,i] - d52 = diff*(dlwap2[m-1,i+1]+dlwap2[m-1,i-1]-2.*dlwap2[m-1,i])/(a*a*dl*dl*np.cos(phi)*np.cos(phi)) - dlwap2[m+1,i] = dlwap2[m-1,i]+2.*dt*(d12+d22+d32+d42+d52) - i = i+1 - - d1 = -const*(dlwap[m,0]*(cgxp[m,0]-al*(dlwap[m,0]+lwap[m,0]))-dlwap[m,358]*(cgxp[m,358]-al*(dlwap[m,358]+lwap[m,358]))) - d2 = gama1p[m,359]*dlwap[m,359] - d3 = gamap[m,359]*dlwap[m,359] - d4 = gama1p[m,359]*lwap[m,359] - d5 = diff*(dlwap[m-1,0]+dlwap[m-1,358]-2.*dlwap[m-1,359])/(a*a*dl*dl*np.cos(phi)*np.cos(phi)) - dlwap[m+1,359] = dlwap[m-1,359]+2.*dt*(d1+d2+d3+d4+d5) - - d12 = -const*(dlwap2[m,0]*(cgxp[m,0]-al*(dlwap2[m,0]+lwap[m,0]))-dlwap2[m,358]*(cgxp[m,358]-al*(dlwap2[m,358]+lwap[m,358]))) - d22 = gama2p[m,359]*dlwap2[m,359] - d32 = gamap[m,359]*dlwap2[m,359] - d42 = gama2p[m,359]*lwap[m,359] - d52 = diff*(dlwap2[m-1,0]+dlwap2[m-1,358]-2.*dlwap2[m-1,359])/(a*a*dl*dl*np.cos(phi)*np.cos(phi)) - dlwap2[m+1,359] = dlwap[m-1,359]+2.*dt*(d12+d22+d32+d42+d52) - - d1 = -const*(dlwap[m,1]*(cgxp[m,1]-al*(dlwap[m,1]+lwap[m,1]))-dlwap[m,359]*(cgxp[m,359]-al*(dlwap[m,359]+lwap[m,359]))) - d2 = gama1p[m,0]*dlwap[m,0] - d3 = gamap[m,0]*dlwap[m,0] - d4 = gama1p[m,0]*lwap[m,0] - d5 = diff*(dlwap[m-1,1]+dlwap[m-1,359]-2.*dlwap[m-1,0])/(a*a*dl*dl*np.cos(phi)*np.cos(phi)) - dlwap[m+1,0] = dlwap[m-1,0]+2.*dt*(d1+d2+d3+d4+d5) - - d12 = -const*(dlwap2[m,1]*(cgxp[m,1]-al*(dlwap2[m,1]+lwap[m,1]))-dlwap2[m,359]*(cgxp[m,359]-al*(dlwap2[m,359]+lwap[m,359]))) - d22 = gama2p[m,0]*dlwap2[m,0] - d32 = gamap[m,0]*dlwap2[m,0] - d42 = gama2p[m,0]*lwap[m,0] - d52 = diff*(dlwap2[m-1,1]+dlwap2[m-1,359]-2.*dlwap2[m-1,0])/(a*a*dl*dl*np.cos(phi)*np.cos(phi)) - dlwap2[m+1,0] = dlwap2[m-1,0]+2.*dt*(d12+d22+d32+d42+d52) - m = m+1 - -gm = np.zeros(360) -gm2 = np.zeros(360) -gm[:] = lwa[:]+dlwap[8640,:] -gm2[:] = lwa[:]+dlwap2[8640,:] -x = np.arange(0,360) -plot.rcParams.update({'font.size':14}) -fig = plot.figure(figsize=(8,4)) -plot.xlim(140,280) -plot.ylim(-80,80) -plot.title('Column LWA Change 49$^\circ$N June 20 - 26 00 UTC') -plot.xlabel('Longitude') -plot.ylabel('$\Delta$LWA (m/s)') -ott = plot.plot(x,zx) -ott = plot.plot(x,zy,color='black',alpha = 0.3) -ott = plot.plot(x,gm,color='red',alpha = 0.5) -ott = plot.plot(x,gm2,'r--',alpha = 0.5) -plot.savefig('dLWAp.png',bbox_inches='tight',dpi =600) -#plot.show() - -print(lwa[242],lwa[252]+dlwap[8640,252]) \ No newline at end of file diff --git a/scripts/nhn_grl2022/graph_plot_module.py b/scripts/nhn_grl2022/graph_plot_module.py new file mode 100644 index 0000000..176f990 --- /dev/null +++ b/scripts/nhn_grl2022/graph_plot_module.py @@ -0,0 +1,1088 @@ +""" +This module contains plot functions to reproduce the graphs in NHN GRL2021 +""" +import numpy as np +from cartopy import crs as ccrs +from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter +from matplotlib import pyplot as plt +from netCDF4._netCDF4 import Dataset + + +# *** Shared variables *** +date_stamp = [f'00 UTC {i} June 2021' for i in range(20, 31)] + + +def plot_figure1a(z_filename, u_filename, v_filename): + ncin1 = Dataset(z_filename, 'r', format='NETCDF4') + ncin2 = Dataset(u_filename, 'r', format='NETCDF4') + ncin3 = Dataset(v_filename, 'r', format='NETCDF4') + + zmean = ncin1.variables['z'] + zmean = (np.array(zmean)) + umean = ncin2.variables['u'] + umean = (np.array(umean)) + vmean = ncin3.variables['v'] + vmean = (np.array(vmean)) + + print(zmean.shape) + + zz = np.zeros((44,181,360)) + z = np.zeros((181,360)) + uu = np.zeros((44,181,360)) + u = np.zeros((181,360)) + vv = np.zeros((44,181,360)) + v = np.zeros((181,360)) + m = 76 + while(m < 120): + zz[m-76,:,:] = zmean[m,16,:,:] + uu[m-76,:,:] = umean[m,16,:,:] + vv[m-76,:,:] = vmean[m,16,:,:] + m = m+1 + b = [f'06{i}.png' for i in range(20, 31)] + for n in range(0, 11): + nn = n*4 + for j in range(0, 181): + z[j,:]=zz[nn,180-j,:]/9.81 + u[j,:]=uu[nn,180-j,:] + v[j,:]=vv[nn,180-j,:] + j = j+1 + cl1 = np.arange(9600,11300,100) + cl2 = np.arange(0,95,5) + plt.rcParams.update({'font.size': 15}) + x = np.arange(0,360) + y = np.arange(0,181)-90. + plt.rcParams.update({'font.size':15, 'text.usetex': False}) + fig = plt.figure(figsize=(8, 4)) + ax5 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) + plt.xlim(140, 280) + plt.ylim(10, 80) + # plot.title(''+day[n]) + if(n > 9): + plt.xlabel('Longitude', fontsize = 22) + plt.ylabel('Latitude', fontsize = 22) + ax5.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) + ax5.coastlines(color='white',alpha = 0.7) + ax5.set_aspect('auto', adjustable=None) + if(n > 9): + ax5.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) + ax5.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) + lon_formatter = LongitudeFormatter(zero_direction_label=True) + lat_formatter = LatitudeFormatter() + ax5.xaxis.set_major_formatter(lon_formatter) + ax5.yaxis.set_major_formatter(lat_formatter) + ott = ax5.contourf(x,y,np.sqrt(u*u+v*v),levels=cl2,transform=ccrs.PlateCarree(),cmap='rainbow') + fig.colorbar(ott,ax=ax5,label='wind speed (m/s)') + ott = ax5.contour(x,y,z,levels=cl1,colors='black',transform=ccrs.PlateCarree(),linewidths=1) + ax5.clabel(ott, ott.levels,fmt='%5i') + plt.savefig(b[n], bbox_inches='tight', dpi =600) + plt.close() + + +def plot_figure1b(t_filename): + ncin1 = Dataset(t_filename, 'r', format='NETCDF4') + + tmean = ncin1.variables['t'] + tmean = (np.array(tmean)) + + print(tmean.shape) + + tt = np.zeros((44,181,360)) + t = np.zeros((181,360)) + + r = 287. + cp = 1004. + kappa = r/cp + + for m in range(76, 120): + tt[m-76,:,:] = tmean[m,20,:,:]*np.power((1000./450.),kappa) + + b = [f'T_06{i}.png' for i in range(20, 31)] + + for n in range(0, 11): + nn = n*4 + for j in range(0, 181): + t[j,:]=tt[nn,180-j,:] + cl1 = np.arange(290,342,2) # 450 hPa + cl2 = np.arange(0,95,5) + x = np.arange(0,360) + y = np.arange(0,181)-90. + plt.rcParams.update({'font.size': 15}) + fig = plt.figure(figsize=(8, 4)) + ax5 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) + plt.xlim(140, 280) + plt.ylim(10, 80) + if(n > 9): + plt.xlabel('Longitude', fontsize = 22) + ax5.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) + ax5.coastlines(color='black',alpha = 0.7) + ax5.set_aspect('auto', adjustable=None) + if(n > 9): + ax5.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) + lon_formatter = LongitudeFormatter(zero_direction_label=True) + lat_formatter = LatitudeFormatter() + ax5.xaxis.set_major_formatter(lon_formatter) + ax5.yaxis.set_major_formatter(lat_formatter) + ott = ax5.contourf(x,y,t,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') + fig.colorbar(ott,ax=ax5,label='Kelvin') + plt.savefig(b[n], bbox_inches='tight', dpi =600) + plt.close() + + +def plot_figure1c(t2m_filename): + ncin1 = Dataset(t2m_filename, 'r', format='NETCDF4') + tm = ncin1.variables['t2m'] + tm = (np.array(tm)) + + print(tm.shape) + + tt = np.zeros((44,181,360)) + t = np.zeros((181,360)) + + r = 287. + cp = 1004. + kappa = r/cp + + for m in range(76, 120): + tt[m-76,:,:] = tm[m,:,:] + + b = [f'2T_06{i}.png' for i in range(20, 31)] + n = 0 + for n in range(0, 11): + nn = n*4 + + for j in range(0, 181): + t[j,:]=tt[nn,180-j,:] + + cl1 = np.arange(250,325,5) + cl2 = np.arange(0,95,5) + plt.rcParams.update({'font.size': 15}) + x = np.arange(0,360) + y = np.arange(0,181)-90. + fig = plt.figure(figsize=(8, 4)) + ax5 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) + plt.xlim(140, 280) + plt.ylim(10, 80) + if(n > 9): + plt.xlabel('Longitude', fontsize=22) + ax5.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) + ax5.coastlines(color='black',alpha = 0.7) + ax5.set_aspect('auto', adjustable=None) + if(n > 9): + ax5.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) + lon_formatter = LongitudeFormatter(zero_direction_label=True) + lat_formatter = LatitudeFormatter() + ax5.xaxis.set_major_formatter(lon_formatter) + ax5.yaxis.set_major_formatter(lat_formatter) + ott = ax5.contourf(x,y,t,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') + fig.colorbar(ott,ax=ax5,label='Kelvin') + plt.savefig(b[n], bbox_inches='tight', dpi =600) + plt.close() + + +def plot_figure1d_2a(t_filename): + ncin1 = Dataset(t_filename, 'r', format='NETCDF4') + + tmean = ncin1.variables['t'] + tmean = (np.array(tmean)) + + ttheta = np.zeros((44, 37, 360)) + theta = np.zeros((37, 360)) + z = np.zeros(37) + p = np.array([1., 2., 3., 5., 7., 10., 20., 30., 50., + 70., 100., 125., 150., 175., 200., 225., 250., 300., + 350., 400., 450., 500., 550., 600., 650., 700., 750., + 775., 800., 825., 850., 875., 900., 925., 950., 975., 1000.]) + r = 287. + cp = 1004. + kappa = r / cp + for m in range(76, 120): + for k in range(37): + z[36 - k] = -8000. * np.log(p[k] / 1000.) # pseudoheight + ttheta[m - 76, 36 - k, :] = tmean[m, k, 41, :] + ttheta[m - 76, 36 - k, :] = ttheta[m - 76, 36 - k, :] * np.power((1000. / p[k]), kappa) # potential temp + + b = [f'THETA_06{i}.png' for i in range(20, 31)] + for n in range(11): + nn = n * 4 + theta[:, :] = ttheta[nn, :, :] + cl1 = np.arange(250, 365, 5) + x = np.arange(0, 360) + plt.rcParams.update({'font.size': 15, 'text.usetex': False}) + fig = plt.figure(figsize=(8, 4)) + ax5 = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree(180)) + plt.xlim(140, 280) + plt.ylim(0, 10) + # plot.title('49$^\circ$N '+day[n]) + if (n > 9): + plt.xlabel('Longitude', fontsize=22) + plt.ylabel('pseudoheight (km)', fontsize=22) + ax5.set_extent([-220, -80, 0, 10], ccrs.PlateCarree()) + ax5.set_aspect('auto', adjustable=None) + if (n > 9): + ax5.set_xticks([140, 160, 180, 200, 220, 240, 260, 280], crs=ccrs.PlateCarree()) + ax5.set_yticks([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], crs=ccrs.PlateCarree()) + lon_formatter = LongitudeFormatter(zero_direction_label=True) + lat_formatter = LatitudeFormatter() + ax5.xaxis.set_major_formatter(lon_formatter) + ott = ax5.contourf(x, z / 1000., theta, levels=cl1, transform=ccrs.PlateCarree(), cmap='rainbow') + fig.colorbar(ott, ax=ax5, label='Kelvin') + ott = ax5.contour(x, z / 1000., theta, levels=cl1, transform=ccrs.PlateCarree(), colors='black', linewidths=0.5) + ott = ax5.contour(x, z / 1000., theta, levels=np.arange(320, 325, 5), transform=ccrs.PlateCarree(), + colors='black', linewidths=1) + ax5.clabel(ott, ott.levels, fmt='%5i') + plt.savefig(b[n], bbox_inches='tight', dpi=600) + plt.close() + + plt.rcParams.update({'font.size': 16}) + fig = plt.figure(figsize=(6, 4)) + ax5.set_yticks([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) + plt.title('49$^\circ$N 119$^\circ$W 00 UTC') + plt.xlabel('Kelvin') + plt.ylabel('pseudoheight (km)') + plt.xlim(290, 360) + plt.ylim(0, 10) + + lcolor = np.array(['blue', 'red', 'green', 'black']) + lstyle = np.array(['dotted', 'dashed', 'dashdot', 'solid']) + lalpha = np.array([1, 1, 1, 1]) + + for n in range(2, 6): + thetaz = np.zeros(37) + nn = n * 8 + thetaz[:] = ttheta[nn, :, 241] + + for i in range(37): + if (z[i] < 1000.): + thetaz[i] = np.nan + + fig = plt.plot(thetaz, z / 1000., color=lcolor[n - 2], linestyle=lstyle[n - 2], alpha=lalpha[n - 2]) + + plt.savefig('t_profile.png', bbox_inches='tight', dpi=600) + plt.close() + + +def plot_figure3_and_S1(lwa_flux_filename): + + ncin1 = Dataset(lwa_flux_filename, 'r', format='NETCDF4') + + lwa = ncin1.variables['lwa'] + lwa = (np.array(lwa)) + + z = np.zeros((91,360)) + z[:,:] = lwa[100,:,:]-lwa[76,:,:] # m = 100 is 00 UTC 26 June 2021, m = 76 is 00 UTC 20 June 2021 + + zs = np.zeros((91,360)) # smoothed z # + + #### smoothing in longitude #### + n = 5 # smoothing width # + j = 0 + while(j < 91): + zx = np.zeros(360) + zx[:] = z[j,:] + nn = -n + while(nn < n+1): + zy = np.roll(zx,nn) + zs[j,:] = zs[j,:] + zy[:]/(2*n+1) + nn = nn+1 + j = j+1 + + + cl2 = np.arange(-80,90,10) + x = np.arange(0,360) + y = np.arange(0,91) + plt.rcParams.update({'font.size': 16}) + fig = plt.figure(figsize=(10, 5)) + ax5 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) + plt.xlim(140, 280) + plt.ylim(10, 80) + plt.title('Column LWA Change 00 UTC 20 - 26 June 2021') + plt.ylabel('Latitude', fontsize=22) + ax5.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) + ax5.coastlines(alpha = 0.7) + ax5.set_aspect('auto', adjustable=None) + ax5.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) + ax5.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) + lon_formatter = LongitudeFormatter(zero_direction_label=True) + lat_formatter = LatitudeFormatter() + ax5.xaxis.set_major_formatter(lon_formatter) + ax5.yaxis.set_major_formatter(lat_formatter) + ott = ax5.contourf(x,y,zs,levels=cl2,transform=ccrs.PlateCarree(),cmap='rainbow') + fig.colorbar(ott,ax=ax5,label='LWA (m/s)') + plt.savefig('dLWA_0.png', bbox_inches='tight', dpi =600) + plt.close() + + lwa_flux_filename = lwa_flux_filename #"2021_06_ua1_N.nc" + filename2 = lwa_flux_filename #"2021_06_ua2_N.nc" + filename3 = lwa_flux_filename #"2021_06_ep1_N.nc" + filename4 = lwa_flux_filename #"2021_06_ep2_N.nc" + filename5 = lwa_flux_filename #"2021_06_ep3_N.nc" + filename6 = lwa_flux_filename #"2021_06_ep4_N.nc" + + ncin1 = Dataset(lwa_flux_filename, 'r', format='NETCDF4') + ua1 = ncin1.variables['ua1'] + ua2 = ncin1.variables['ua2'] + ep1 = ncin1.variables['ep1'] + ep2 = ncin1.variables['ep2'] + ep3 = ncin1.variables['ep3'] + ep4 = np.array(ncin1.variables['ep4']) + + f1 = np.zeros((91,360)) + f2 = np.zeros((91,360)) + f11 = np.zeros((91,360)) + f22 = np.zeros((91,360)) + + z1 = np.zeros((91,360)) + z2 = np.zeros((91,360)) + z3 = np.zeros((91,360)) + dt = 3600.*6. + a = 6378000. + dl = 2.*np.pi/360. + dp = 2.*np.pi/360. + m = 76 # m = 76 is 20 June 2021 00 UTC + while(m < 100): # m = 100 is 26 June 2021 00 UTC + #m = 52 # m = 52 is 14 June 2021 00 UTC + #while(m < 76): # m = 76 is 20 June 2021 00 UTC + + z3[:,:] = z3[:,:]+0.5*dt*ep4[m,:,:] + z3[:,:] = z3[:,:]+0.5*dt*ep4[m+1,:,:] + f1[:,:] = f1[:,:]+(0.5/24.)*(ua1[m,:,:]+ua2[m,:,:]+ep1[m,:,:]) + f1[:,:] = f1[:,:]+(0.5/24.)*(ua1[m+1,:,:]+ua2[m+1,:,:]+ep1[m+1,:,:]) + f11[:,:] = f11[:,:]+(0.5/24.)*(ua1[m-24,:,:]+ua2[m-24,:,:]+ep1[m-24,:,:]) + f11[:,:] = f11[:,:]+(0.5/24.)*(ua1[m-23,:,:]+ua2[m-23,:,:]+ep1[m-23,:,:]) + j = 0 + while(j < 90): + phi = dp*j + const = 0.5*dt/(2.*a*np.cos(phi)*dl) + z2[j,:]=z2[j,:]+const*(ep2[m,j,:]-ep3[m,j,:]) + z2[j,:]=z2[j,:]+const*(ep2[m+1,j,:]-ep3[m+1,j,:]) + f2[j,:] = f2[j,:]+(0.25/24.)*(ep2[m,j,:]+ep3[m,j,:])/np.cos(phi) + f2[j,:] = f2[j,:]+(0.25/24.)*(ep2[m+1,j,:]+ep3[m+1,j,:])/np.cos(phi) + f22[j,:] = f22[j,:]+(0.25/24.)*(ep2[m-24,j,:]+ep3[m-24,j,:])/np.cos(phi) + f22[j,:] = f22[j,:]+(0.25/24.)*(ep2[m-23,j,:]+ep3[m-23,j,:])/np.cos(phi) + i = 1 + while(i < 359): + z1[j,i] = z1[j,i]-const*(ua1[m,j,i+1]+ua2[m,j,i+1]+ep1[m,j,i+1]-ua1[m,j,i-1]-ua2[m,j,i-1]-ep1[m,j,i-1]) + z1[j,i] = z1[j,i]-const*(ua1[m+1,j,i+1]+ua2[m+1,j,i+1]+ep1[m+1,j,i+1]-ua1[m+1,j,i-1]-ua2[m+1,j,i-1]-ep1[m+1,j,i-1]) + i = i+1 + z1[j,0] = z1[j,0]-const*(ua1[m,j,1]+ua2[m,j,1]+ep1[m,j,1]-ua1[m,j,359]-ua2[m,j,359]-ep1[m,j,359]) + z1[j,0] = z1[j,0]-const*(ua1[m+1,j,1]+ua2[m+1,j,1]+ep1[m+1,j,1]-ua1[m+1,j,359]-ua2[m+1,j,359]-ep1[m+1,j,359]) + z1[j,359] = z1[j,359]-const*(ua1[m,j,0]+ua2[m,j,0]+ep1[m,j,0]-ua1[m,j,358]-ua2[m,j,358]-ep1[m,j,358]) + z1[j,359] = z1[j,359]-const*(ua1[m+1,j,0]+ua2[m+1,j,0]+ep1[m+1,j,0]-ua1[m+1,j,358]-ua2[m+1,j,358]-ep1[m+1,j,358]) + j = j+1 + m = m+1 + + z1s = np.zeros((91,360)) # smoothed z1 # + z2s = np.zeros((91,360)) # smoothed z2 # + z3s = np.zeros((91,360)) # smoothed z3 # + + #### smoothing in longitude #### + j = 0 + while(j < 91): + z1x = np.zeros(360) + z1x[:] = z1[j,:] + z2x = np.zeros(360) + z2x[:] = z2[j,:] + z3x = np.zeros(360) + z3x[:] = z3[j,:] + nn = -n + while(nn < n+1): + z1y = np.roll(z1x,nn) + z1s[j,:] = z1s[j,:] + z1y[:]/(2*n+1) + z2y = np.roll(z2x,nn) + z2s[j,:] = z2s[j,:] + z2y[:]/(2*n+1) + z3y = np.roll(z3x,nn) + z3s[j,:] = z3s[j,:] + z3y[:]/(2*n+1) + nn = nn+1 + j = j+1 + + ##### Wind vectors ###### + + x1 = np.arange(0,24)*15.+5. + y1 = np.arange(0,30)*3. + xx,yy = np.meshgrid(x1,y1) + uu = np.zeros((30,24)) + vv = np.zeros((30,24)) + + j = 0 + while(j < 30): + i = 0 + while(i < 24): + uu[j,i] = f1[j*3,i*15+5]-f11[j*3,i*15+5] + vv[j,i] = f2[j*3,i*15+5]-f22[j*3,i*15+5] + i = i+1 + j = j+1 + + + cl1 = np.arange(-200,220,20) + x = np.arange(0,360) + y = np.arange(0,91) + plt.rcParams.update({'font.size': 16}) + fig = plt.figure(figsize=(10, 5)) + ax6 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) + plt.xlim(0, 360) + plt.ylim(10, 80) + plt.title('Integrated column -div (Fx + Fy) 20 - 26 June 2021') + plt.ylabel('Latitude', fontsize=22) + ax6.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) + ax6.coastlines(alpha = 0.7) + ax6.set_aspect('auto', adjustable=None) + ax6.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) + ax6.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) + lon_formatter = LongitudeFormatter(zero_direction_label=True) + lat_formatter = LatitudeFormatter() + ax6.xaxis.set_major_formatter(lon_formatter) + ax6.yaxis.set_major_formatter(lat_formatter) + ott = ax6.contourf(x,y,z1s+z2s,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') + fig.colorbar(ott,ax=ax6,label='(m/s)') + ax6.quiver(xx[2:-2,:],yy[2:-2,:],uu[2:-2, :],vv[2:-2, :],transform=ccrs.PlateCarree()) + plt.savefig('divFx+Fy_0.png', bbox_inches='tight', dpi =600) + plt.close() + + cl1 = np.arange(-200,220,20) + x = np.arange(0,360) + y = np.arange(0,91) + plt.rcParams.update({'font.size': 16}) + fig = plt.figure(figsize=(10, 5)) + ax6 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) + #ax6 = fig.add_subplot(1,1,1) + plt.xlim(0, 360) + plt.ylim(10, 80) + plt.title('Integrated column -div Fy 20 - 26 June 2021') + plt.xlabel('Longitude', fontsize=22) + plt.ylabel('Latitude', fontsize=22) + ax6.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) + ax6.coastlines(alpha = 0.7) + ax6.set_aspect('auto', adjustable=None) + ax6.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) + ax6.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) + lon_formatter = LongitudeFormatter(zero_direction_label=True) + lat_formatter = LatitudeFormatter() + ax6.xaxis.set_major_formatter(lon_formatter) + ax6.yaxis.set_major_formatter(lat_formatter) + ott = ax6.contourf(x,y,z2s,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') + fig.colorbar(ott,ax=ax6,label='(m/s)') + ax6.quiver(xx[2:-2,:],yy[2:-2,:],uu[2:-2, :],vv[2:-2, :],transform=ccrs.PlateCarree()) + plt.savefig('divFy_0.png', bbox_inches='tight', dpi =600) + plt.close() + + cl1 = np.arange(-200,220,20) + x = np.arange(0,360) + y = np.arange(0,91) + plt.rcParams.update({'font.size': 16}) + fig = plt.figure(figsize=(10, 5)) + ax6 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) + plt.xlim(0, 360) + plt.ylim(10, 80) + plt.title('Integrated low-level source 20 - 26 June 2021') + #plot.xlabel('Longitude') + #plot.ylabel('Latitude') + ax6.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) + ax6.coastlines(alpha = 0.7) + ax6.set_aspect('auto', adjustable=None) + ax6.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) + ax6.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) + lon_formatter = LongitudeFormatter(zero_direction_label=True) + lat_formatter = LatitudeFormatter() + ax6.xaxis.set_major_formatter(lon_formatter) + ax6.yaxis.set_major_formatter(lat_formatter) + ott = ax6.contourf(x,y,z3s,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') + fig.colorbar(ott,ax=ax6,label='(m/s)') + plt.savefig('EP4_0.png', bbox_inches='tight', dpi =600) + plt.close() + + cl1 = np.arange(-200,220,20) + x = np.arange(0,360) + y = np.arange(0,91) + fig = plt.figure(figsize=(10, 5)) + ax6 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) + plt.xlim(0, 360) + plt.ylim(10, 80) + plt.title('Integrated residual 20 - 26 June 2021') + ax6.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) + ax6.coastlines(alpha = 0.7) + ax6.set_aspect('auto', adjustable=None) + ax6.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) + ax6.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) + lon_formatter = LongitudeFormatter(zero_direction_label=True) + lat_formatter = LatitudeFormatter() + ax6.xaxis.set_major_formatter(lon_formatter) + ax6.yaxis.set_major_formatter(lat_formatter) + ott = ax6.contourf(x,y,zs-z1s-z2s-z3s,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') + fig.colorbar(ott,ax=ax6,label='(m/s)') + ax6.quiver(xx[2:-2,:],yy[2:-2,:],uu[2:-2, :],vv[2:-2, :],transform=ccrs.PlateCarree()) + plt.savefig('Residual_0.png', bbox_inches='tight', dpi =600) + plt.close() + + +def plot_figure3e(mtnlwrf_filename, mtnlwrfcs_filename): + """ + :param mtnlwrf_filename: netCDF fileof net OLR data + :param mtnlwrfcs_filename: netCDF fileof clear sky OLR data + :return: + """ + ncin1 = Dataset(mtnlwrf_filename, 'r', format='NETCDF4') + ncin2 = Dataset(mtnlwrfcs_filename, 'r', format='NETCDF4') + olr = ncin1.variables['mtnlwrf'] + olr = (np.array(olr)) + olrcs = ncin2.variables['mtnlwrfcs'] + olrcs = (np.array(olrcs)) + + tt = np.zeros((44,181,360)) + t = np.zeros((181,360)) + m = 77 + for m in range(77,120): + tt[m-77,:,:] = olr[m,:,:] + + b = [f'OLR_06{i}.png' for i in range(20, 31)] + + for n in range(0, 11): + nn = n*4 + + for j in range(0, 181): + t[j,:]=tt[nn,180-j,:] + + cl1 = np.arange(80,390,10) + x = np.arange(0,360) + y = np.arange(0,181)-90. + plt.rcParams.update({'font.size':16, 'text.usetex': False}) + fig = plt.figure(figsize=(10, 5)) + ax5 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) + plt.xlim(140, 280) + plt.ylim(10, 80) + plt.title('OLR ' + date_stamp[n]) + plt.xlabel('Longitude', fontsize=22) + plt.ylabel('Latitude', fontsize=22) + ax5.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) + ax5.coastlines(color='black',alpha = 0.7) + ax5.set_aspect('auto', adjustable=None) + ax5.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) + ax5.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) + lon_formatter = LongitudeFormatter(zero_direction_label=True) + lat_formatter = LatitudeFormatter() + ax5.xaxis.set_major_formatter(lon_formatter) + ax5.yaxis.set_major_formatter(lat_formatter) + ott = ax5.contourf(x,y,-t,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') + fig.colorbar(ott,ax=ax5,label='W/m$^2$') + plt.savefig(b[n], bbox_inches='tight', dpi =600) + plt.close() + + +def plot_figure3f(tcw_filename, tcwv_filename, sp_filename): + """ + :param tcw_filename: filename of netCDF file with total column water (kg/m^2) + :param tcwv_filename: filename of netCDF file with total column water vapor (kg/m^2) + :param sp_filename: filename of netCDF file with sea level pressure (hPa) + :return: + """ + ncin1 = Dataset(tcw_filename, 'r', format='NETCDF4') + ncin2 = Dataset(tcwv_filename, 'r', format='NETCDF4') + ncin3 = Dataset(sp_filename, 'r', format='NETCDF4') + cw = ncin1.variables['tcw'] + cw = (np.array(cw)) + cwv = ncin2.variables['tcwv'] + cwv = (np.array(cwv)) + sp = ncin3.variables['sp'] + sp = (np.array(sp)) + + tt = np.zeros((44,181,360)) + pp = np.zeros((44,181,360)) + t = np.zeros((181,360)) + p = np.zeros((181,360)) + + for m in range(77, 120): + tt[m-77,:,:] = cw[m,:,:]-cwv[m,:,:] + pp[m-77,:,:] = sp[m,:,:]/100. + + b = [f'CW_06{i}.png' for i in range(20, 31)] + + for n in range(0, 11): + nn = n*4 + + for j in range(0, 181): + t[j,:]=tt[nn,180-j,:] + p[j,:]=pp[nn,180-j,:] + + cl1 = np.arange(-0.1,3.6,0.1) + c12 = np.arange(980,1032,4) + x = np.arange(0,360) + y = np.arange(0,181)-90. + plt.rcParams.update({'font.size':16, 'text.usetex': False}) + fig = plt.figure(figsize=(10, 5)) + ax5 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) + plt.xlim(140, 280) + plt.ylim(10, 80) + plt.title('Column water ' + date_stamp[n]) + plt.xlabel('Longitude', fontsize=22) + #plot.ylabel('Latitude') + ax5.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) + ax5.coastlines(color='white',alpha = 0.7) + ax5.set_aspect('auto', adjustable=None) + ax5.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) + ax5.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) + lon_formatter = LongitudeFormatter(zero_direction_label=True) + lat_formatter = LatitudeFormatter() + ax5.xaxis.set_major_formatter(lon_formatter) + ax5.yaxis.set_major_formatter(lat_formatter) + ott = ax5.contourf(x,y,t,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') + fig.colorbar(ott,ax=ax5,label='kg/m$^2$') + ott = ax5.contour(x,y,p,levels=c12,colors='white',alpha=0.5,transform=ccrs.PlateCarree(),linewidths=1) + ax5.clabel(ott, ott.levels,fmt='%5i') + plt.savefig(b[n], bbox_inches='tight', dpi =600) + plt.close() + + +def plot_figure4(lwa_flux_filename): + dt = 3600. * 6. + a = 6378000. + dl = 2. * np.pi / 360. + dp = 2. * np.pi / 360. + + jm = 49 + jp = 49 + + ncin1 = Dataset(lwa_flux_filename, 'r', format='NETCDF4') + + lwa = ncin1.variables['lwa'] + lwa = (np.array(lwa)) + + z = np.zeros((124,360)) # wave activity tendency + w = np.zeros((124,360)) # wave activity + + for m in range(1, 120): + + cos0 = 0 + for j in range(jm, jp+1): + + phi = dp*j + z[m,:] = z[m,:]+np.cos(phi)*(lwa[m+1,j,:]-lwa[m-1,j,:])/(2.*dt) # wave activity tendency at 49 N + w[m,:] = w[m,:]+np.cos(phi)*lwa[m,j,:] + cos0 = cos0 + np.cos(phi) + + z[m,:] = z[m,:]/cos0 + w[m,:] = w[m,:]/cos0 + + ncin1 = Dataset(lwa_flux_filename, 'r', format='NETCDF4') + ua1 = ncin1.variables['ua1'] + ua2 = ncin1.variables['ua2'] + ep1 = ncin1.variables['ep1'] + ep2 = ncin1.variables['ep2'] + ep3 = ncin1.variables['ep3'] + ep4 = (np.array(ncin1.variables['ep4'])) + + f1 = np.zeros((124,360)) + + z1 = np.zeros((124,360)) + z2 = np.zeros((124,360)) + z3 = np.zeros((124,360)) + z4 = np.zeros((124,360)) + + + for i in range(1, 359): + + for j in range(jm, jp+1): + phi = dp*j + const = 1./(2.*a*dl) + z1[:,i] = z1[:,i]-const*(ua1[:,j,i+1]+ua2[:,j,i+1]+ep1[:,j,i+1]-ua1[:,j,i-1]-ua2[:,j,i-1]-ep1[:,j,i-1]) + + z1[:,i] = z1[:,i]/cos0 + + + for i in range(0, 360): + + for j in range(jm, jp+1): + phi = dp*j + const = 1./(2.*a*dl) + f1[:,i]=f1[:,i]+(ua1[:,j,i]+ua2[:,j,i]+ep1[:,j,i])*np.cos(phi) # zonal wave activity flux + z2[:,i]=z2[:,i]+const*(ep2[:,j,i]-ep3[:,j,i]) # metisional convergence of wave activity flux + z3[:,i]=z3[:,i]+np.cos(phi)*ep4[:,j,i] # bottom source + + f1[:,i] = f1[:,i]/cos0 + z2[:,i] = z2[:,i]/cos0 + z3[:,i] = z3[:,i]/cos0 + + + zs = np.zeros((124,360)) # smoothed z # + ws = np.zeros((124,360)) # smoothed w # + f1s = np.zeros((124,360)) # smoothed f1 # + z1s = np.zeros((124,360)) # smoothed z1 # + z2s = np.zeros((124,360)) # smoothed z2 # + z3s = np.zeros((124,360)) # smoothed z3 # + + #### smoothing in longitude #### + n = 4 # smoothing width = 2n+1 + + for j in range(0, 124): + zx = np.zeros(360) + zx[:] = z[j,:] + wx = np.zeros(360) + wx[:] = w[j,:] + f1x = np.zeros(360) + f1x[:] = f1[j,:] + z1x = np.zeros(360) + z1x[:] = z1[j,:] + z2x = np.zeros(360) + z2x[:] = z2[j,:] + z3x = np.zeros(360) + z3x[:] = z3[j,:] + + for nn in range(-n, n+1): + + wy = np.roll(wx,nn) + ws[j,:] = ws[j,:] + wy[:]/(2*n+1) + f1y = np.roll(f1x,nn) + f1s[j,:] = f1s[j,:] + f1y[:]/(2*n+1) + zy = np.roll(zx,nn) + zs[j,:] = zs[j,:] + zy[:]/(2*n+1) + z1y = np.roll(z1x,nn) + z1s[j,:] = z1s[j,:] + z1y[:]/(2*n+1) + z2y = np.roll(z2x,nn) + z2s[j,:] = z2s[j,:] + z2y[:]/(2*n+1) + z3y = np.roll(z3x,nn) + z3s[j,:] = z3s[j,:] + z3y[:]/(2*n+1) + + z4[:,:]=zs[:,:]-z1s[:,:]-z2s[:,:]-z3s[:,:] # residual + + ############################################## + + cl2 = np.arange(0,135,5) + x = np.arange(0,360) + y = np.arange(0,124)*0.25 + plt.rcParams.update({'font.size': 28}) + fig,ax5 = plt.subplots(1, figsize=(8, 8)) + plt.xlim(140, 280) + plt.ylim(20, 29.75) + plt.title('Column LWA 49$^\circ$N') + plt.xlabel('Longitude') + plt.ylabel('Day') + ott = ax5.contourf(x,y,w,levels=cl2,cmap='rainbow') + fig.colorbar(ott,ax=ax5,label='(ms$^{-1}$)') + plt.savefig('HovmollerLWA.png', bbox_inches='tight', dpi =600) + + ############################################## + + cl2 = np.arange(-100,1500,100) + x = np.arange(0,360) + y = np.arange(0,124)*0.25 + plt.rcParams.update({'font.size': 28}) + fig,ax5 = plt.subplots(1, figsize=(8, 8)) + plt.xlim(140, 280) + plt.ylim(20, 29.75) + plt.title(' 49$^\circ$N') + plt.xlabel('Longitude') + plt.ylabel('Day') + ott = ax5.contourf(x,y,f1,levels=cl2,cmap='rainbow') + fig.colorbar(ott,ax=ax5,label='(m$^2$s$^{-2}$)') + plt.savefig('HovmollerFx.png', bbox_inches='tight', dpi =600) + + + ############################################## + + cl2 = np.arange(-10.,9,1) + x = np.arange(0,360) + y = np.arange(0,124)*0.25 + plt.rcParams.update({'font.size': 28}) + fig,ax5 = plt.subplots(1, figsize=(8, 8)) + plt.xlim(140, 280) + plt.ylim(20, 29.5) + plt.title('Term (IV) 49$^\circ$N') + plt.xlabel('Longitude') + plt.ylabel('Day') + ott = ax5.contourf(x,y,z4*10000,levels=cl2,cmap='rainbow') + fig.colorbar(ott,ax=ax5,label='(10$^{-4}$ ms$^{-2}$)') + plt.savefig('HovmollerRes.png', bbox_inches='tight', dpi =600) + #plot.show() + + + ############################################## + + cl2 = np.arange(-10.,9,1) + x = np.arange(0,360) + y = np.arange(0,124)*0.25 + plt.rcParams.update({'font.size': 28}) + fig,ax5 = plt.subplots(1, figsize=(8, 8)) + plt.xlim(140, 280) + plt.ylim(20, 29.75) + plt.title('Terms (I)+(II) 49$^\circ$N') + plt.xlabel('Longitude') + plt.ylabel('Day') + ott = ax5.contourf(x,y,(z1s+z2s+z3s)*10000,levels=cl2,cmap='rainbow') + fig.colorbar(ott,ax=ax5,label='(10$^{-4}$ ms$^{-2}$)') + plt.savefig('HovmollerFxy.png', bbox_inches='tight', dpi =600) + + +def plot_figure5(lwa_flux_filename): + + ncin1 = Dataset(lwa_flux_filename, 'r', format='NETCDF4') + + lwa = ncin1.variables['lwa'] + lwa = (np.array(lwa)) + + print(lwa.shape) + + z = np.zeros((120,360)) + for m in range(0, 120): + z[m,:] = lwa[m,49,:] # 49N LWA for June 1-30 + + zs = np.zeros((120,360)) # smoothed z # + + #### smoothing in longitude #### + n = 5 # smoothing width # + for m in range(0, 120): + zx = np.zeros(360) + zx[:] = z[m,:] + + for nn in range(-n, n+1): + zy = np.roll(zx,nn) + zs[m,:] = zs[m,:] + zy[:]/(2*n+1) + + zx[:] = zs[100,:]-zs[76,:] + zy[:] = 0 + + ncin1 = Dataset(lwa_flux_filename, 'r', format='NETCDF4') + ua1 = ncin1.variables['ua1'] + ua1 = (np.array(ua1)) + ncin2 = Dataset(lwa_flux_filename, 'r', format='NETCDF4') + ua2 = ncin2.variables['ua2'] + ua2 = (np.array(ua2)) + ncin3 = Dataset(lwa_flux_filename, 'r', format='NETCDF4') + ep1 = ncin3.variables['ep1'] + ep1 = (np.array(ep1)) + ncin4 = Dataset(lwa_flux_filename, 'r', format='NETCDF4') + ep2 = ncin4.variables['ep2'] + ep2 = (np.array(ep2)) + ncin5 = Dataset(lwa_flux_filename, 'r', format='NETCDF4') + ep3 = ncin5.variables['ep3'] + ep3 = (np.array(ep3)) + ncin6 = Dataset(lwa_flux_filename, 'r', format='NETCDF4') + ep4 = ncin6.variables['ep4'] + ep4 = (np.array(ep4)) + + f1 = np.zeros((120,360)) + f2 = np.zeros((120,360)) + f11 = np.zeros((120,360)) + f22 = np.zeros((120,360)) + + z1 = np.zeros((120,360)) + z2 = np.zeros((120,360)) + z3 = np.zeros((120,360)) + dt = 3600.*6. + a = 6378000. + dl = 2.*np.pi/360. + dp = 2.*np.pi/360. + # m = 76 is 20 June 2021 00 UTC + for m in range(0, 120): # m = 100 is 26 June 2021 00 UTC + z3[m,:] = ep4[m,49,:] + f1[m,:] = ua1[m,49,:]+ua2[m,49,:]+ep1[m,49,:] + j = 49 + phi = dp*j + const = 1./(2.*a*np.cos(phi)*dl) + z2[m,:]=const*(ep2[m,49,:]-ep3[m,49,:]) + f2[m,:] = 0.5*(ep2[m,49,:]+ep3[m,49,:])/np.cos(phi) + + for i in range(1, 359): + z1[m,i] = -const*(f1[m,i+1]-f1[m,i-1]) + + z1[m,0] = -const*(f1[m,1]-f1[m,359]) + z1[m,359] = -const*(f1[m,0]-f1[m,358]) + + + z1s = np.zeros((120,360)) # smoothed z1 # + z2s = np.zeros((120,360)) # smoothed z2 # + z3s = np.zeros((120,360)) # smoothed z3 # + f1s = np.zeros((120,360)) # smoothed f1 # + + #### smoothing in longitude #### + + for m in range(0, 120): + z1x = np.zeros(360) + z1x[:] = z1[m,:] + z2x = np.zeros(360) + z2x[:] = z2[m,:] + z3x = np.zeros(360) + z3x[:] = z3[m,:] + f1x = np.zeros(360) + f1x[:] = f1[m,:] + + nn = -n + for nn in range(-n, n+1): + z1y = np.roll(z1x,nn) + z1s[m,:] = z1s[m,:] + z1y[:]/(2*n+1) + z2y = np.roll(z2x,nn) + z2s[m,:] = z2s[m,:] + z2y[:]/(2*n+1) + z3y = np.roll(z3x,nn) + z3s[m,:] = z3s[m,:] + z3y[:]/(2*n+1) + f1y = np.roll(f1x,nn) + f1s[m,:] = f1s[m,:] + f1y[:]/(2*n+1) + + + + ##### Time integration test ###### + + lwa = np.zeros(360) + res = np.zeros((120,360)) + dlwa = np.zeros((120,360)) + gama = np.zeros((120,360)) + gama1 = np.zeros((120,360)) + gama2 = np.zeros((120,360)) + cgx = np.zeros((120,360)) + + m = 0 + for m in range(0, 119): + dlwa[m,:] = zs[m+1,:]-zs[m,:] + cgx[m,:] = (f1s[m,:]+f1s[m+1,:])/(zs[m,:]+zs[m+1,:]) + res[m,:] = (dlwa[m,:] - 0.5*dt*(z1s[m,:]+z1s[m+1,:]+z2s[m,:]+z2s[m+1,:]+z3s[m,:]+z3s[m+1,:]))/dt + gama[m,:] = 2.*res[m,:]/(zs[m,:]+zs[m+1,:]) + + + for m in range(76, 100): + lwa[:] = lwa[:] + 0.5*dt*(z1s[m,:]+z1s[m+1,:]+z2s[m,:]+z2s[m+1,:]+z3s[m,:]+z3s[m+1,:]) + dt*res[m,:] + m = m+1 + + j = 49 + phi = dp*j + const = 1./(2.*a*np.cos(phi)*dl) + lwa0 = np.zeros((120,360)) + lwa1 = np.zeros((120,360)) + + lwa0[:,:] = zs[:,:] + lwa1[:,:] = zs[:,:] + + + for m in range(76, 100): + + for i in range(1, 359): + d0 = -const*0.5*((lwa0[m,i+1]+lwa0[m+1,i+1])*cgx[m,i+1]-(lwa0[m,i-1]+lwa0[m+1,i-1])*cgx[m,i-1]) + d2 = 0.5*(z2s[m+1,i]+z2s[m,i]) + d3 = 0.5*(z3s[m+1,i]+z3s[m,i]) + d4 = gama[m,i]*0.5*(zs[m,i]+zs[m+1,i]) + lwa1[m+1,i] = lwa1[m,i]+dt*(d0+d2+d3+d4) + + d0 = -const*0.5*((lwa0[m,0]+lwa0[m+1,0])*cgx[m,0]-(lwa0[m,358]+lwa0[m+1,358])*cgx[m,358]) + d2 = 0.5*(z2s[m+1,359]+z2s[m,359]) + d3 = 0.5*(z3s[m+1,359]+z3s[m,359]) + d4 = gama[m,359]*0.5*(zs[m,359]+zs[m+1,359]) + lwa1[m+1,359] = lwa1[m,359]+dt*(d0+d2+d3+d4) + + d0 = -const*0.5*((lwa0[m,1]+lwa0[m+1,1])*cgx[m,1]-(lwa0[m,359]+lwa0[m+1,359])*cgx[m,359]) + d2 = 0.5*(z2s[m+1,0]+z2s[m,0]) + d3 = 0.5*(z3s[m+1,0]+z3s[m,0]) + d4 = gama[m,0]*0.5*(zs[m,0]+zs[m+1,0]) + lwa1[m+1,0] = lwa1[m,0]+dt*(d0+d2+d3+d4) + + + #### Modify gamma #### + + gama1[:,:] = gama[:,:] + gama2[:,:] = gama[:,:] + + for m in range(76, 100): + if((m >= 84) and (m <= 92)): + i = 200 + for i in range(200, 221): + if(gama[m,i] > 0): + gama1[m,i] = gama[m,i]*0.7 + gama2[m,i] = gama[m,i]*0. + + + gama1[:,:] = gama1[:,:]-gama[:,:] + gama2[:,:] = gama2[:,:]-gama[:,:] + + ##### Interpolate gama, gama1, cgx onto finer tiem mesh dt = 30 min ##### + + gamap = np.zeros((8640,360)) + gama1p = np.zeros((8640,360)) + gama2p = np.zeros((8640,360)) + cgxp = np.zeros((8640,360)) + forcep = np.zeros((8640,360)) + lwap = np.zeros((8640,360)) + + for m in range(76, 101): + for i in range(0, 360): + mm = (m-76)*360+i-180 + if(mm >= 0): + if(mm < 8640): + gamap[mm,:] = gama[m,:]*(i/360.)+gama[m-1,:]*(1.-i/360.) + gama1p[mm,:] = gama1[m,:]*(i/360.)+gama1[m-1,:]*(1.-i/360.) + gama2p[mm,:] = gama2[m,:]*(i/360.)+gama2[m-1,:]*(1.-i/360.) + cgxp[mm,:] = cgx[m,:]*(i/360.)+cgx[m-1,:]*(1.-i/360.) + + for m in range(76, 100): + for i in range(0, 360): + mm = (m-76)*360+i + forcep[mm,:] = (z2s[m+1,:]+z3s[m+1,:])*(i/360.)+(z2s[m,:]+z3s[m,:])*(1.-i/360.) + lwap[mm,:] = zs[m+1,:]*(i/360.)+zs[m,:]*(1.-i/360.) + + + ##### Time integration #### + + dt = 60. + j = 49 + phi = dp*j + const = 1./(2.*a*np.cos(phi)*dl) + al = 0. + diff = 200000. + dlwap = np.zeros((8641,360)) + dlwap2 = np.zeros((8641,360)) + + + for m in range(1, 8640): + for i in range(1, 359): + d1 = -const*(dlwap[m,i+1]*(cgxp[m,i+1]-al*(dlwap[m,i+1]+lwap[m,i+1]))-dlwap[m,i-1]*(cgxp[m,i-1]-al*(dlwap[m,i-1]+lwap[m,i-1]))) + d2 = gama1p[m,i]*dlwap[m,i] + d3 = gamap[m,i]*dlwap[m,i] + d4 = gama1p[m,i]*lwap[m,i] + d5 = diff*(dlwap[m-1,i+1]+dlwap[m-1,i-1]-2.*dlwap[m-1,i])/(a*a*dl*dl*np.cos(phi)*np.cos(phi)) + dlwap[m+1,i] = dlwap[m-1,i]+2.*dt*(d1+d2+d3+d4+d5) + + d12 = -const*(dlwap2[m,i+1]*(cgxp[m,i+1]-al*(dlwap2[m,i+1]+lwap[m,i+1]))-dlwap2[m,i-1]*(cgxp[m,i-1]-al*(dlwap2[m,i-1]+lwap[m,i-1]))) + d22 = gama2p[m,i]*dlwap2[m,i] + d32 = gamap[m,i]*dlwap2[m,i] + d42 = gama2p[m,i]*lwap[m,i] + d52 = diff*(dlwap2[m-1,i+1]+dlwap2[m-1,i-1]-2.*dlwap2[m-1,i])/(a*a*dl*dl*np.cos(phi)*np.cos(phi)) + dlwap2[m+1,i] = dlwap2[m-1,i]+2.*dt*(d12+d22+d32+d42+d52) + + d1 = -const*(dlwap[m,0]*(cgxp[m,0]-al*(dlwap[m,0]+lwap[m,0]))-dlwap[m,358]*(cgxp[m,358]-al*(dlwap[m,358]+lwap[m,358]))) + d2 = gama1p[m,359]*dlwap[m,359] + d3 = gamap[m,359]*dlwap[m,359] + d4 = gama1p[m,359]*lwap[m,359] + d5 = diff*(dlwap[m-1,0]+dlwap[m-1,358]-2.*dlwap[m-1,359])/(a*a*dl*dl*np.cos(phi)*np.cos(phi)) + dlwap[m+1,359] = dlwap[m-1,359]+2.*dt*(d1+d2+d3+d4+d5) + + d12 = -const*(dlwap2[m,0]*(cgxp[m,0]-al*(dlwap2[m,0]+lwap[m,0]))-dlwap2[m,358]*(cgxp[m,358]-al*(dlwap2[m,358]+lwap[m,358]))) + d22 = gama2p[m,359]*dlwap2[m,359] + d32 = gamap[m,359]*dlwap2[m,359] + d42 = gama2p[m,359]*lwap[m,359] + d52 = diff*(dlwap2[m-1,0]+dlwap2[m-1,358]-2.*dlwap2[m-1,359])/(a*a*dl*dl*np.cos(phi)*np.cos(phi)) + dlwap2[m+1,359] = dlwap[m-1,359]+2.*dt*(d12+d22+d32+d42+d52) + + d1 = -const*(dlwap[m,1]*(cgxp[m,1]-al*(dlwap[m,1]+lwap[m,1]))-dlwap[m,359]*(cgxp[m,359]-al*(dlwap[m,359]+lwap[m,359]))) + d2 = gama1p[m,0]*dlwap[m,0] + d3 = gamap[m,0]*dlwap[m,0] + d4 = gama1p[m,0]*lwap[m,0] + d5 = diff*(dlwap[m-1,1]+dlwap[m-1,359]-2.*dlwap[m-1,0])/(a*a*dl*dl*np.cos(phi)*np.cos(phi)) + dlwap[m+1,0] = dlwap[m-1,0]+2.*dt*(d1+d2+d3+d4+d5) + + d12 = -const*(dlwap2[m,1]*(cgxp[m,1]-al*(dlwap2[m,1]+lwap[m,1]))-dlwap2[m,359]*(cgxp[m,359]-al*(dlwap2[m,359]+lwap[m,359]))) + d22 = gama2p[m,0]*dlwap2[m,0] + d32 = gamap[m,0]*dlwap2[m,0] + d42 = gama2p[m,0]*lwap[m,0] + d52 = diff*(dlwap2[m-1,1]+dlwap2[m-1,359]-2.*dlwap2[m-1,0])/(a*a*dl*dl*np.cos(phi)*np.cos(phi)) + dlwap2[m+1,0] = dlwap2[m-1,0]+2.*dt*(d12+d22+d32+d42+d52) + + gm = np.zeros(360) + gm2 = np.zeros(360) + gm[:] = lwa[:]+dlwap[8640,:] + gm2[:] = lwa[:]+dlwap2[8640,:] + x = np.arange(0,360) + plt.rcParams.update({'font.size':14}) + fig = plt.figure(figsize=(8, 4)) + plt.xlim(140, 280) + plt.ylim(-80, 80) + plt.title('Column LWA Change 49$^\circ$N June 20 - 26 00 UTC') + plt.xlabel('Longitude') + plt.ylabel('$\Delta$LWA (m/s)') + ott = plt.plot(x, zx) + ott = plt.plot(x, zy, color='black', alpha = 0.3) + ott = plt.plot(x, gm, color='red', alpha = 0.5) + ott = plt.plot(x, gm2, 'r--', alpha = 0.5) + plt.savefig('dLWAp.png', bbox_inches='tight', dpi =600) diff --git a/scripts/nhn_grl2022/lwa_flux_computation.py b/scripts/nhn_grl2022/lwa_flux_computation.py index 326a222..cb2e44c 100644 --- a/scripts/nhn_grl2022/lwa_flux_computation.py +++ b/scripts/nhn_grl2022/lwa_flux_computation.py @@ -5,7 +5,7 @@ import datetime as dt import matplotlib.pyplot as plt -data_dir = "grl2022_data/" +data_dir = "grl2021_data/" # --- Load the zonal wind and QGPV at 240hPa --- # u_file = Dataset(data_dir + '2021_06_u.nc', mode='r') diff --git a/scripts/nhn_grl2022/sample_run_script.py b/scripts/nhn_grl2022/sample_run_script.py new file mode 100644 index 0000000..665b29f --- /dev/null +++ b/scripts/nhn_grl2022/sample_run_script.py @@ -0,0 +1,157 @@ +import os +import sys +import numpy as np +from math import pi +from netCDF4 import Dataset +from hn2016_falwa.oopinterface import QGField + +sys.path.insert(0, os.getcwd()) +from graph_plot_module import plot_figure1a, plot_figure1b, plot_figure1c, plot_figure1d_2a, plot_figure3_and_S1, \ + plot_figure3e, plot_figure3f, plot_figure4, plot_figure5 +import datetime as dt +import matplotlib.pyplot as plt + +data_dir = "grl2021_data/" + +# --- Load the zonal wind and QGPV at 240hPa --- # +u_file = Dataset(data_dir + '2021_06_u.nc', mode='r') +v_file = Dataset(data_dir + '2021_06_v.nc', mode='r') +t_file = Dataset(data_dir + '2021_06_t.nc', mode='r') + +time_array = u_file.variables['time'][:] +time_units = u_file.variables['time'].units +time_calendar = u_file.variables['time'].calendar +ntimes = time_array.shape[0] + +print('Dimension of time: {}'.format(time_array.size)) + +# --- Longitude, latitude and pressure grid --- +xlon = u_file.variables['longitude'][:] + +# latitude has to be in ascending order +ylat = u_file.variables['latitude'][:] +if np.diff(ylat)[0]<0: + print('Flip ylat.') + ylat = ylat[::-1] + +# pressure level has to be in descending order (ascending height) +plev = u_file.variables['level'][:] +if np.diff(plev)[0]>0: + print('Flip plev.') + plev = plev[::-1] + +nlon = xlon.size +nlat = ylat.size +nlev = plev.size + +# --- Coordinates --- +clat = np.cos(np.deg2rad(ylat)) # cosine latitude +p0 = 1000. # surface pressure [hPa] +kmax = 97 # number of grid points for vertical extrapolation (dimension of height) +dz = 500. # differential height element +height = np.arange(0,kmax)*dz # pseudoheight [m] +dphi = np.diff(ylat)[0]*pi/180. # differential latitudinal element +dlambda = np.diff(xlon)[0]*pi/180. # differential latitudinal element +hh = 7000. # scale height +cp = 1004. # heat capacity of dry air +rr = 287. # gas constant +omega = 7.29e-5 # rotation rate of the earth +aa = 6.378e+6 # earth radius +prefactor = np.array([np.exp(-z/hh) for z in height[1:]]).sum() # integrated sum of density from the level + #just above the ground (z=1km) to aloft +npart = nlat # number of partitions to construct the equivalent latitude grids +maxits = 100000 # maximum number of iteration in the SOR solver to solve for reference state +tol = 1.e-5 # tolerance that define convergence of solution +rjac = 0.95 # spectral radius of the Jacobi iteration in the SOR solver. +jd = nlat//2+1 # (one plus) index of latitude grid point with value 0 deg + # This is to be input to fortran code. The index convention is different. + + +# --- Outputing files --- +output_fname = '2021-06-01_to_2021-06-30_output.nc' +if True: + output_file = Dataset(output_fname, 'w') + output_file.createDimension('latitude',nlat//2+1) + output_file.createDimension('longitude',nlon) + output_file.createDimension('time',ntimes+4) + lats = output_file.createVariable('latitude',np.dtype('float32').char,('latitude',)) # Define the coordinate variables + lons = output_file.createVariable('longitude',np.dtype('float32').char,('longitude',)) + times = output_file.createVariable('time',np.dtype('int').char,('time',)) + lats.units = 'degrees_north' + lons.units = 'degrees_east' + times.units = time_units + times.calendar = time_calendar + lats[:] = ylat[90:] + lons[:] = xlon + # times[:] = time_array + lwa_baro = output_file.createVariable('lwa', np.dtype('float32').char, ('time', 'latitude', 'longitude')) + lwa_baro.units = 'm/s' + ua1 = output_file.createVariable('ua1', np.dtype('float32').char, ('time', 'latitude', 'longitude')) + ua1.units = 'm/s' + ua2 = output_file.createVariable('ua2', np.dtype('float32').char, ('time', 'latitude', 'longitude')) + ua2.units = 'm/s' + ep1 = output_file.createVariable('ep1', np.dtype('float32').char, ('time', 'latitude', 'longitude')) + ep1.units = 'm/s' + ep2 = output_file.createVariable('ep2', np.dtype('float32').char, ('time', 'latitude', 'longitude')) + ep2.units = 'm/s' + ep3 = output_file.createVariable('ep3', np.dtype('float32').char, ('time', 'latitude', 'longitude')) + ep3.units = 'm/s' + ep4 = output_file.createVariable('ep4', np.dtype('float32').char, ('time', 'latitude', 'longitude')) + ep4.units = 'm/s' + + + # --- Compute LWA + fluxes and save the data into netCDF file --- + + for tstep in range(ntimes): # or ntimes + + uu = u_file.variables['u'][tstep, ::-1, ::-1, :].data + vv = v_file.variables['v'][tstep, ::-1, ::-1, :].data + tt = t_file.variables['t'][tstep, ::-1, ::-1, :].data + + qgfield_object = QGField(xlon, ylat, plev, uu, vv, tt, kmax=kmax, dz=dz) + + qgpv_temp, interpolated_u_temp, interpolated_v_temp, interpolated_avort_temp, interpolated_theta_temp, \ + static_stability_n, static_stability_s, tn0, ts0 = qgfield_object._interpolate_field_dirinv() + + qref, uref, tref, fawa, ubar, tbar = qgfield_object._compute_qref_fawa_and_bc() + + astarbaro, ubaro, urefbaro, ua1baro, ua2baro, ep1baro, ep2baro, ep3baro, ep4baro, astar1, astar2 = \ + qgfield_object._compute_lwa_flux_dirinv(qref, uref, tref, fawa, ubar, tbar) + + lwa_baro[tstep, :, :] = np.swapaxes(astarbaro, 0, 1) + ua1[tstep, :, :] = np.swapaxes(ua1baro, 0, 1) + ua2[tstep, :, :] = np.swapaxes(ua2baro, 0, 1) + ep1[tstep, :, :] = np.swapaxes(ep1baro, 0, 1) + ep2[tstep, :, :] = np.swapaxes(ep2baro, 0, 1) + ep3[tstep, :, :] = np.swapaxes(ep3baro, 0, 1) + ep4[tstep, :, :] = np.swapaxes(ep4baro, 0, 1) + + print(f'tstep = {tstep}/{ntimes}.') + output_file.close() + +# --- Graph plotting for GRL2021 --- + +# Location of data files +data_dir = "grl2021_data/" +z_filename = data_dir + "2021_06_z.nc" # geopotential height +u_filename = data_dir + "2021_06_u.nc" # u +v_filename = data_dir + "2021_06_v.nc" # v +t_filename = data_dir + "2021_06_t.nc" # temperature +t2m_filename = data_dir + "2021_06_2t.nc" # t2m +mtnlwrf_filename = data_dir + "2021_06_mtnlwrf.nc" # net OLR +mtnlwrfcs_filename = data_dir + "2021_06_mtnlwrfcs.nc" # OLR clear sky +tcw_filename = data_dir + "2021_06_tcw.nc" # total column water (kg/m^2) +tcwv_filename = data_dir + "2021_06_tcwv.nc" # total column water vapor (kg/m^2) +sp_filename = data_dir + "2021_06_sp.nc" # sea level pressure (hPa) +lwa_flux_filename = output_fname + +# Execute graph plotting functions +# plot_figure1a(z_filename, u_filename, v_filename) +# plot_figure1b(t_filename) +# plot_figure1c(t2m_filename) +# plot_figure1d_2a(t_filename) +plot_figure3_and_S1(lwa_flux_filename) +# plot_figure3e(mtnlwrf_filename, mtnlwrfcs_filename) +# plot_figure3f(tcw_filename, tcwv_filename, sp_filename) +# plot_figure4(lwa_flux_filename) +# plot_figure5(lwa_flux_filename) diff --git a/show_noboru/era4004n.f90 b/show_noboru/era4004n.f90 index 731014d..1c6d862 100644 --- a/show_noboru/era4004n.f90 +++ b/show_noboru/era4004n.f90 @@ -57,7 +57,7 @@ program main z(k) = dz*float(k-1) enddo - do m = 2021,2021 + do m = 1979,2020 md(1) = 31 md(2) = 28 @@ -89,7 +89,7 @@ program main write(fy,266) m 266 format(i4) - do n = 10,10 + do n = 1,12 fn = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGPV' fu = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGU' ft = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGT' @@ -418,13 +418,16 @@ program main tref(1,k) = t00 tref(2,k) = t00 do j = 2,jd-1 - phi0 = dp*float(j-1) + phi0 = dp*float(j-1+jb) cor = 2.*om*sin(phi0) uz = (u(j,k+1)-u(j,k-1))/(2.*dz) ty = -cor*uz*a*h*exp(rkappa*zz/h) ty = ty/r tref(j+1,k) = tref(j-1,k)+2.*ty*dp - qref(j-1,k) = qref(j-1,k)*sin(phi0) + enddo + do j = 1,nd + phi0 = dp*float(j-1) + qref(j,k) = qref(j,k)*sin(phi0) enddo tg(k) = 0. wt = 0. From 8a2c676fb890782c3c81e092b076c5e25294036e Mon Sep 17 00:00:00 2001 From: csyhuang Date: Wed, 16 Mar 2022 18:39:42 -0500 Subject: [PATCH 04/19] version that reproduced the plots --- hn2016_falwa/compute_flux_dirinv.f90 | 20 ++++++------ hn2016_falwa/upward_sweep.f90 | 17 +++++----- scripts/nhn_grl2022/graph_plot_module.py | 41 ++++++++++++------------ scripts/nhn_grl2022/sample_run_script.py | 24 +++++++------- 4 files changed, 50 insertions(+), 52 deletions(-) diff --git a/hn2016_falwa/compute_flux_dirinv.f90 b/hn2016_falwa/compute_flux_dirinv.f90 index 4307558..aeb09e6 100644 --- a/hn2016_falwa/compute_flux_dirinv.f90 +++ b/hn2016_falwa/compute_flux_dirinv.f90 @@ -135,7 +135,7 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa do k = 2,96 zk = dz*float(k-1) do i = 1,imax - do j = jb+1,nd-1 ! 5N and higher latitude + do j = 6,nd-1 ! 5N and higher latitude astar1(i,j,k) = 0. ! LWA*cos(phi) astar2(i,j,k) = 0. ! LWA*cos(phi) ua2(i,j) = 0. !F2 @@ -144,7 +144,7 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa do jj = 1,nd phi1 = dp*float(jj-1) qe(i,jj) = pv(i,jj+90,k)-qref(j,k) !qe; Q = qref - ue(i,jj) = uu(i,jj+90,k)-uref(j-jb,k) !ue; shift uref 5N + ue(i,jj) = uu(i,jj+90,k)-uref(j-5,k) !ue; shift uref 5N aa = a*dp*cos(phi1) !length element if((qe(i,jj).le.0.).and.(jj.ge.j)) then !LWA*cos and F2 astar2(i,j,k)=astar2(i,j,k)-qe(i,jj)*aa !anticyclonic @@ -158,11 +158,11 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ! ******** Other fluxes ****** - ua1(i,j) = uref(j-jb,k)*(astar1(i,j,k) + & + ua1(i,j) = uref(j-5,k)*(astar1(i,j,k) + & astar2(i,j,k)) !F1 - ep1(i,j) = -0.5*(uu(i,j+90,k)-uref(j-jb,k))**2 !F3a + ep1(i,j) = -0.5*(uu(i,j+90,k)-uref(j-5,k))**2 !F3a ep1(i,j) = ep1(i,j)+0.5*vv(i,j+90,k)**2 !F3a+b - ep11 = 0.5*(pt(i,j+90,k)-tref(j-jb,k))**2 !F3c + ep11 = 0.5*(pt(i,j+90,k)-tref(j-5,k))**2 !F3c zz = dz*float(k-1) ep11 = ep11*(r/h)*exp(-rkappa*zz/h) ep11 = ep11*2.*dz/(tg(k+1)-tg(k-1)) @@ -178,15 +178,15 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ! meridional eddy momentum flux one grid north and south - ep2(i,j)=(uu(i,j+91,k)-uref(j-jb,k))*vv(i,j+91,k)*cosp*cosp - ep3(i,j)=(uu(i,j+89,k)-uref(j-jb,k))*vv(i,j+89,k)*cosm*cosm + ep2(i,j)=(uu(i,j+91,k)-uref(j-5,k))*vv(i,j+91,k)*cosp*cosp + ep3(i,j)=(uu(i,j+89,k)-uref(j-5,k))*vv(i,j+89,k)*cosm*cosm ! low-level meridional eddy heat flux if(k.eq.2) then ! (26) of SI-HN17 ep41 = 2.*om*sin0*cos0*dz/6745.348 ! prefactor - ep42 = exp(-dz/h)*vv(i,j+90,2)*(pt(i,j+90,2)-tref(j-jb,2)) + ep42 = exp(-dz/h)*vv(i,j+90,2)*(pt(i,j+90,2)-tref(j-5,2)) ep42 = ep42/(tg(3)-tg(1)) - ep43 = vv(i,j+90,1)*(pt(i,j+90,1)-tref(j-jb,1)) + ep43 = vv(i,j+90,1)*(pt(i,j+90,1)-tref(j-5,1)) ep43 = 0.5*ep43/(tg(2)-tg(1)) ep4(i,j) = ep41*(ep42+ep43) ! low-level heat flux endif @@ -204,7 +204,7 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ep3baro(:,:) = ep3baro(:,:)+ep3(:,:)*exp(-zk/h)*dc do j = 6,nd ! ### yet to be multiplied by cosine ubaro(:,j) = ubaro(:,j)+uu(:,j+90,k)*exp(-zk/h)*dc - urefbaro(j) = urefbaro(j)+uref(j-jb,k)*exp(-zk/h)*dc + urefbaro(j) = urefbaro(j)+uref(j-5,k)*exp(-zk/h)*dc enddo enddo diff --git a/hn2016_falwa/upward_sweep.f90 b/hn2016_falwa/upward_sweep.f90 index 9a12e6b..36edc47 100644 --- a/hn2016_falwa/upward_sweep.f90 +++ b/hn2016_falwa/upward_sweep.f90 @@ -79,7 +79,7 @@ SUBROUTINE upward_sweep(jmax, kmax, nd, nnd, jb, jd, sjk, tjk, ckref, tb, qref_o ! ******** compute tref ******* qref(:, :) = qref_over_cor(:, :) ! modify for f2py wrapping purpose - do k = 2,kmax-1 + do k = 2,96 t00 = 0. zz = dz*float(k-1) tref(1,k) = t00 @@ -91,16 +91,17 @@ SUBROUTINE upward_sweep(jmax, kmax, nd, nnd, jb, jd, sjk, tjk, ckref, tb, qref_o ty = -cor*uz*a*h*exp(rkappa*zz/h) ty = ty/rr tref(j+1,k) = tref(j-1,k)+2.*ty*dp + qref(j-1+jb,k) = qref_over_cor(j-1+jb,k)*sin(phi0) enddo - do j = 1,nd - phi0 = dp*float(j-1) - qref(j,k) = qref(j,k)*sin(phi0) - enddo +! do j = jd, nd ! Add after checking code +! qref(j-1,k) = qref_over_cor(j-1,k)*sin(dp*float(j-1)) +! end do +! qref(nd,k) = 2 * qref(nd-1,k) - qref(nd-2,k) ! Linear interpolation tg(k) = 0. wt = 0. - do jj = jb+1,nd - j = jj-jb + do jj = 6,91 + j = jj-5 phi0 = dp*float(jj-1) tg(k) = tg(k)+cos(phi0)*tref(j,k) wt = wt + cos(phi0) @@ -110,6 +111,6 @@ SUBROUTINE upward_sweep(jmax, kmax, nd, nnd, jb, jd, sjk, tjk, ckref, tb, qref_o tref(:,k) = tref(:,k)+tres enddo tref(:,1) = tref(:,2)-tb(2)+tb(1) - tref(:,kmax) = tref(:,kmax-1)-tb(kmax-1)+tb(kmax) + tref(:,97) = tref(:,96)-tb(96)+tb(97) END SUBROUTINE upward_sweep \ No newline at end of file diff --git a/scripts/nhn_grl2022/graph_plot_module.py b/scripts/nhn_grl2022/graph_plot_module.py index 176f990..eb8d643 100644 --- a/scripts/nhn_grl2022/graph_plot_module.py +++ b/scripts/nhn_grl2022/graph_plot_module.py @@ -262,7 +262,6 @@ def plot_figure1d_2a(t_filename): def plot_figure3_and_S1(lwa_flux_filename): - ncin1 = Dataset(lwa_flux_filename, 'r', format='NETCDF4') lwa = ncin1.variables['lwa'] @@ -296,6 +295,7 @@ def plot_figure3_and_S1(lwa_flux_filename): plt.xlim(140, 280) plt.ylim(10, 80) plt.title('Column LWA Change 00 UTC 20 - 26 June 2021') + #plot.xlabel('Longitude') plt.ylabel('Latitude', fontsize=22) ax5.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) ax5.coastlines(alpha = 0.7) @@ -309,22 +309,25 @@ def plot_figure3_and_S1(lwa_flux_filename): ott = ax5.contourf(x,y,zs,levels=cl2,transform=ccrs.PlateCarree(),cmap='rainbow') fig.colorbar(ott,ax=ax5,label='LWA (m/s)') plt.savefig('dLWA_0.png', bbox_inches='tight', dpi =600) - plt.close() - - lwa_flux_filename = lwa_flux_filename #"2021_06_ua1_N.nc" - filename2 = lwa_flux_filename #"2021_06_ua2_N.nc" - filename3 = lwa_flux_filename #"2021_06_ep1_N.nc" - filename4 = lwa_flux_filename #"2021_06_ep2_N.nc" - filename5 = lwa_flux_filename #"2021_06_ep3_N.nc" - filename6 = lwa_flux_filename #"2021_06_ep4_N.nc" ncin1 = Dataset(lwa_flux_filename, 'r', format='NETCDF4') ua1 = ncin1.variables['ua1'] - ua2 = ncin1.variables['ua2'] - ep1 = ncin1.variables['ep1'] - ep2 = ncin1.variables['ep2'] - ep3 = ncin1.variables['ep3'] - ep4 = np.array(ncin1.variables['ep4']) + ua1 = (np.array(ua1)) + ncin2 = Dataset(lwa_flux_filename, 'r', format='NETCDF4') + ua2 = ncin2.variables['ua2'] + ua2 = (np.array(ua2)) + ncin3 = Dataset(lwa_flux_filename, 'r', format='NETCDF4') + ep1 = ncin3.variables['ep1'] + ep1 = (np.array(ep1)) + ncin4 = Dataset(lwa_flux_filename, 'r', format='NETCDF4') + ep2 = ncin4.variables['ep2'] + ep2 = (np.array(ep2)) + ncin5 = Dataset(lwa_flux_filename, 'r', format='NETCDF4') + ep3 = ncin5.variables['ep3'] + ep3 = (np.array(ep3)) + ncin6 = Dataset(lwa_flux_filename, 'r', format='NETCDF4') + ep4 = ncin6.variables['ep4'] + ep4 = (np.array(ep4)) f1 = np.zeros((91,360)) f2 = np.zeros((91,360)) @@ -436,7 +439,6 @@ def plot_figure3_and_S1(lwa_flux_filename): fig.colorbar(ott,ax=ax6,label='(m/s)') ax6.quiver(xx[2:-2,:],yy[2:-2,:],uu[2:-2, :],vv[2:-2, :],transform=ccrs.PlateCarree()) plt.savefig('divFx+Fy_0.png', bbox_inches='tight', dpi =600) - plt.close() cl1 = np.arange(-200,220,20) x = np.arange(0,360) @@ -444,7 +446,6 @@ def plot_figure3_and_S1(lwa_flux_filename): plt.rcParams.update({'font.size': 16}) fig = plt.figure(figsize=(10, 5)) ax6 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) - #ax6 = fig.add_subplot(1,1,1) plt.xlim(0, 360) plt.ylim(10, 80) plt.title('Integrated column -div Fy 20 - 26 June 2021') @@ -463,7 +464,6 @@ def plot_figure3_and_S1(lwa_flux_filename): fig.colorbar(ott,ax=ax6,label='(m/s)') ax6.quiver(xx[2:-2,:],yy[2:-2,:],uu[2:-2, :],vv[2:-2, :],transform=ccrs.PlateCarree()) plt.savefig('divFy_0.png', bbox_inches='tight', dpi =600) - plt.close() cl1 = np.arange(-200,220,20) x = np.arange(0,360) @@ -474,8 +474,6 @@ def plot_figure3_and_S1(lwa_flux_filename): plt.xlim(0, 360) plt.ylim(10, 80) plt.title('Integrated low-level source 20 - 26 June 2021') - #plot.xlabel('Longitude') - #plot.ylabel('Latitude') ax6.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) ax6.coastlines(alpha = 0.7) ax6.set_aspect('auto', adjustable=None) @@ -488,7 +486,6 @@ def plot_figure3_and_S1(lwa_flux_filename): ott = ax6.contourf(x,y,z3s,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') fig.colorbar(ott,ax=ax6,label='(m/s)') plt.savefig('EP4_0.png', bbox_inches='tight', dpi =600) - plt.close() cl1 = np.arange(-200,220,20) x = np.arange(0,360) @@ -511,7 +508,7 @@ def plot_figure3_and_S1(lwa_flux_filename): fig.colorbar(ott,ax=ax6,label='(m/s)') ax6.quiver(xx[2:-2,:],yy[2:-2,:],uu[2:-2, :],vv[2:-2, :],transform=ccrs.PlateCarree()) plt.savefig('Residual_0.png', bbox_inches='tight', dpi =600) - plt.close() + plt.close("all") def plot_figure3e(mtnlwrf_filename, mtnlwrfcs_filename): @@ -1086,3 +1083,5 @@ def plot_figure5(lwa_flux_filename): ott = plt.plot(x, gm, color='red', alpha = 0.5) ott = plt.plot(x, gm2, 'r--', alpha = 0.5) plt.savefig('dLWAp.png', bbox_inches='tight', dpi =600) + + diff --git a/scripts/nhn_grl2022/sample_run_script.py b/scripts/nhn_grl2022/sample_run_script.py index 665b29f..1215fe5 100644 --- a/scripts/nhn_grl2022/sample_run_script.py +++ b/scripts/nhn_grl2022/sample_run_script.py @@ -8,10 +8,9 @@ sys.path.insert(0, os.getcwd()) from graph_plot_module import plot_figure1a, plot_figure1b, plot_figure1c, plot_figure1d_2a, plot_figure3_and_S1, \ plot_figure3e, plot_figure3f, plot_figure4, plot_figure5 -import datetime as dt -import matplotlib.pyplot as plt data_dir = "grl2021_data/" +to_generate_data = False # --- Load the zonal wind and QGPV at 240hPa --- # u_file = Dataset(data_dir + '2021_06_u.nc', mode='r') @@ -68,8 +67,8 @@ # --- Outputing files --- -output_fname = '2021-06-01_to_2021-06-30_output.nc' -if True: +output_fname = '2021-06-01_to_2021-06-30_output_lwa_fluxes.nc' +if to_generate_data: output_file = Dataset(output_fname, 'w') output_file.createDimension('latitude',nlat//2+1) output_file.createDimension('longitude',nlon) @@ -101,7 +100,6 @@ # --- Compute LWA + fluxes and save the data into netCDF file --- - for tstep in range(ntimes): # or ntimes uu = u_file.variables['u'][tstep, ::-1, ::-1, :].data @@ -146,12 +144,12 @@ lwa_flux_filename = output_fname # Execute graph plotting functions -# plot_figure1a(z_filename, u_filename, v_filename) -# plot_figure1b(t_filename) -# plot_figure1c(t2m_filename) -# plot_figure1d_2a(t_filename) +plot_figure1a(z_filename, u_filename, v_filename) +plot_figure1b(t_filename) +plot_figure1c(t2m_filename) +plot_figure1d_2a(t_filename) plot_figure3_and_S1(lwa_flux_filename) -# plot_figure3e(mtnlwrf_filename, mtnlwrfcs_filename) -# plot_figure3f(tcw_filename, tcwv_filename, sp_filename) -# plot_figure4(lwa_flux_filename) -# plot_figure5(lwa_flux_filename) +plot_figure3e(mtnlwrf_filename, mtnlwrfcs_filename) +plot_figure3f(tcw_filename, tcwv_filename, sp_filename) +plot_figure4(lwa_flux_filename) +plot_figure5(lwa_flux_filename) From 2112fc7544de77b023b31cd74e37a1f4462d8f29 Mon Sep 17 00:00:00 2001 From: csyhuang Date: Wed, 16 Mar 2022 19:36:36 -0500 Subject: [PATCH 05/19] this version can reproduce --- hn2016_falwa/upward_sweep.f90 | 4 ---- scripts/nhn_grl2022/sample_run_script.py | 17 +++++++++-------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/hn2016_falwa/upward_sweep.f90 b/hn2016_falwa/upward_sweep.f90 index 36edc47..987d0b8 100644 --- a/hn2016_falwa/upward_sweep.f90 +++ b/hn2016_falwa/upward_sweep.f90 @@ -93,10 +93,6 @@ SUBROUTINE upward_sweep(jmax, kmax, nd, nnd, jb, jd, sjk, tjk, ckref, tb, qref_o tref(j+1,k) = tref(j-1,k)+2.*ty*dp qref(j-1+jb,k) = qref_over_cor(j-1+jb,k)*sin(phi0) enddo -! do j = jd, nd ! Add after checking code -! qref(j-1,k) = qref_over_cor(j-1,k)*sin(dp*float(j-1)) -! end do -! qref(nd,k) = 2 * qref(nd-1,k) - qref(nd-2,k) ! Linear interpolation tg(k) = 0. wt = 0. diff --git a/scripts/nhn_grl2022/sample_run_script.py b/scripts/nhn_grl2022/sample_run_script.py index 1215fe5..509e237 100644 --- a/scripts/nhn_grl2022/sample_run_script.py +++ b/scripts/nhn_grl2022/sample_run_script.py @@ -10,7 +10,7 @@ plot_figure3e, plot_figure3f, plot_figure4, plot_figure5 data_dir = "grl2021_data/" -to_generate_data = False +to_generate_data = True # --- Load the zonal wind and QGPV at 240hPa --- # u_file = Dataset(data_dir + '2021_06_u.nc', mode='r') @@ -67,7 +67,8 @@ # --- Outputing files --- -output_fname = '2021-06-01_to_2021-06-30_output_lwa_fluxes.nc' +output_fname = '2021-06-01_to_2021-06-30_output_stick_to_original_change.nc' +print(output_fname) if to_generate_data: output_file = Dataset(output_fname, 'w') output_file.createDimension('latitude',nlat//2+1) @@ -144,12 +145,12 @@ lwa_flux_filename = output_fname # Execute graph plotting functions -plot_figure1a(z_filename, u_filename, v_filename) -plot_figure1b(t_filename) -plot_figure1c(t2m_filename) -plot_figure1d_2a(t_filename) +# plot_figure1a(z_filename, u_filename, v_filename) +# plot_figure1b(t_filename) +# plot_figure1c(t2m_filename) +# plot_figure1d_2a(t_filename) plot_figure3_and_S1(lwa_flux_filename) -plot_figure3e(mtnlwrf_filename, mtnlwrfcs_filename) -plot_figure3f(tcw_filename, tcwv_filename, sp_filename) +# plot_figure3e(mtnlwrf_filename, mtnlwrfcs_filename) +# plot_figure3f(tcw_filename, tcwv_filename, sp_filename) plot_figure4(lwa_flux_filename) plot_figure5(lwa_flux_filename) From 70d5ef3ed3a2bde4685401ef1d2a71567a171e58 Mon Sep 17 00:00:00 2001 From: csyhuang Date: Wed, 16 Mar 2022 19:40:05 -0500 Subject: [PATCH 06/19] add back multiplying cor at all latitudes --- hn2016_falwa/upward_sweep.f90 | 5 ++++- scripts/nhn_grl2022/sample_run_script.py | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/hn2016_falwa/upward_sweep.f90 b/hn2016_falwa/upward_sweep.f90 index 987d0b8..7d60ecc 100644 --- a/hn2016_falwa/upward_sweep.f90 +++ b/hn2016_falwa/upward_sweep.f90 @@ -91,7 +91,10 @@ SUBROUTINE upward_sweep(jmax, kmax, nd, nnd, jb, jd, sjk, tjk, ckref, tb, qref_o ty = -cor*uz*a*h*exp(rkappa*zz/h) ty = ty/rr tref(j+1,k) = tref(j-1,k)+2.*ty*dp - qref(j-1+jb,k) = qref_over_cor(j-1+jb,k)*sin(phi0) + enddo + do j = 1,nd + phi0 = dp*float(j-1) + qref(j,k) = qref_over_cor(j,k)*sin(phi0) enddo tg(k) = 0. diff --git a/scripts/nhn_grl2022/sample_run_script.py b/scripts/nhn_grl2022/sample_run_script.py index 509e237..f96830e 100644 --- a/scripts/nhn_grl2022/sample_run_script.py +++ b/scripts/nhn_grl2022/sample_run_script.py @@ -67,7 +67,7 @@ # --- Outputing files --- -output_fname = '2021-06-01_to_2021-06-30_output_stick_to_original_change.nc' +output_fname = '2021-06-01_to_2021-06-30_output_change.nc' print(output_fname) if to_generate_data: output_file = Dataset(output_fname, 'w') From aa09859379a8e968699bc8174ccefcd98a4715c3 Mon Sep 17 00:00:00 2001 From: csyhuang Date: Wed, 16 Mar 2022 23:21:53 -0500 Subject: [PATCH 07/19] remove redundant input --- hn2016_falwa/compute_flux_dirinv.f90 | 121 +----- hn2016_falwa/interpolate_fields_dirinv.f90 | 6 - hn2016_falwa/inversion_refactored.f90 | 428 --------------------- hn2016_falwa/matrix_after_inversion.f90 | 9 - hn2016_falwa/matrix_b4_inversion.f90 | 1 - hn2016_falwa/oopinterface.py | 3 +- hn2016_falwa/upward_sweep.f90 | 22 +- scripts/nhn_grl2022/sample_run_script.py | 4 +- setup.py | 1 + 9 files changed, 11 insertions(+), 584 deletions(-) delete mode 100644 hn2016_falwa/inversion_refactored.f90 diff --git a/hn2016_falwa/compute_flux_dirinv.f90 b/hn2016_falwa/compute_flux_dirinv.f90 index aeb09e6..21f2c7e 100644 --- a/hn2016_falwa/compute_flux_dirinv.f90 +++ b/hn2016_falwa/compute_flux_dirinv.f90 @@ -9,34 +9,12 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa REAL, INTENT(OUT) :: astarbaro(imax,nd),ubaro(imax,nd),urefbaro(nd),ua1baro(imax,nd),ua2baro(imax,nd),& ep1baro(imax,nd),ep2baro(imax,nd),ep3baro(imax,nd),ep4(imax,nd),astar1(imax,nd,kmax),astar2(imax,nd,kmax) -! read(35) pv -! read(36) uu -! read(39) vv -! read(37) pt,tn0,ts0,statn,stats -! read(40) qref,uref,tref,fawa,ubar,tbar -! **** take QGPV and compute LWA and fluxes for -! NH *** -! Only barotropic fluxes are saved - - !integer,parameter :: imax = 360, JMAX = 181, KMAX = 97 - !integer,parameter :: nd = 91,nnd=181,jd = 86 REAL :: tb(kmax),tg(kmax) REAL :: ua1(imax,nd),ua2(imax,nd),ep1(imax,nd) REAL :: ep2(imax,nd),ep3(imax,nd) REAL :: qe(imax,nd),ue(imax,nd) REAL :: z(kmax) REAL :: u(nd,kmax) - !integer :: md(12) - -! character*35 fn,fn0,fn1 -! character*34 fu -! character*34 ft,fv -! character*38 fx -! character*4 fn2(12),fy,fy1,fy2 -! character*18 f1,f2 -! character*19 f3 -! character*36 fr -! character*37 fm a = 6378000. pi = acos(-1.) @@ -47,75 +25,15 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa r = 287. rkappa = r/1004. + ! *** Default values for boundary *** + !jb = 5 + !jd = 86 ! nd - lower bounding latitude + do k = 1,kmax z(k) = dz*float(k-1) enddo -! do m = 2021,2021 - -! md(1) = 31 -! md(2) = 28 -! if(mod(m,4).eq.0) md(2) = 29 -! md(3) = 31 -! md(4) = 30 -! md(5) = 31 -! md(6) = 30 -! md(7) = 31 -! md(8) = 31 -! md(9) = 30 -! md(10) = 31 -! md(11) = 30 -! md(12) = 31 -! -! fn2(1) = '_01_' -! fn2(2) = '_02_' -! fn2(3) = '_03_' -! fn2(4) = '_04_' -! fn2(5) = '_05_' -! fn2(6) = '_06_' -! fn2(7) = '_07_' -! fn2(8) = '_08_' -! fn2(9) = '_09_' -! fn2(10) = '_10_' -! fn2(11) = '_11_' -! fn2(12) = '_12_' -! -! write(fy,266) m -! 266 format(i4) - -! do n = 10,10 -! fn = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGPV' -! fu = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGU' -! ft = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGT' -! fv = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGV' -! fx = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGREF_N' -! fr = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'LWA_N' -! fm = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'BARO_N' -! write(6,*) fn,md(n) -! open(35,file =fn, & -! form='unformatted',status = 'old') -! open(36,file =fu, & -! form='unformatted',status = 'old') -! open(37,file =ft, & -! form='unformatted',status = 'old') -! open(38,file =fr, & -! form='unformatted',status = 'new') -! open(39,file =fv, & -! form='unformatted',status = 'old') -! open(40,file =fx, & -! form='unformatted',status = 'old') -! open(41,file =fm, & -! form='unformatted',status = 'new') - -! do mm = 1,md(n)*4 - -! read(35) pv -! read(36) uu -! read(39) vv -! read(37) pt,tn0,ts0,statn,stats -! read(40) qref,uref,tref,fawa,ubar,tbar - - + ! **** hemispheric-mean potential temperature **** tg(:) = tn0(:) @@ -208,33 +126,4 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa enddo enddo - -! write(6,*) dh - -! write(41) astarbaro,ubaro,urefbaro,ua1baro,ua2baro,ep1baro,& -! ep2baro,& -! ep3baro,ep4 -! -! write(38) astar1,astar2 - -! ******************************** - - -! write(6,*) fy,n,mm - -! ******************************** -! enddo - -! close(35) -! close(36) -! close(37) -! close(38) -! close(39) -! close(40) -! close(41) - -! enddo -! enddo - - END SUBROUTINE diff --git a/hn2016_falwa/interpolate_fields_dirinv.f90 b/hn2016_falwa/interpolate_fields_dirinv.f90 index 4da1a16..116dd60 100644 --- a/hn2016_falwa/interpolate_fields_dirinv.f90 +++ b/hn2016_falwa/interpolate_fields_dirinv.f90 @@ -26,15 +26,9 @@ SUBROUTINE interpolate_fields_direct_inv(nlon, nlat, nlev, kmax, jd, uu, vv, tt, character*3 :: mn(12) character*8 :: yr -! dz = 500. -! cp = 1004. -! rr = 287. rkappa = rr/cp pi = acos(-1.) -! omega = 7.29e-5 -! aa = 6378000. dphi = pi/float(nlat-1) -! hh = 7000. ! ====== Assign pseudoheight ===== diff --git a/hn2016_falwa/inversion_refactored.f90 b/hn2016_falwa/inversion_refactored.f90 deleted file mode 100644 index aa46c0c..0000000 --- a/hn2016_falwa/inversion_refactored.f90 +++ /dev/null @@ -1,428 +0,0 @@ -SUBROUTINE direct_solver_b4_lu_fact(tjk,sjk,qref,ubar,tbar,fawa,ckref,statn,tn0,imax,JMAX,KMAX,nd,jb,jd,& - a, om, dz, h, rr, cp, & - tref) - -! USE mkl95_BLAS, ONLY: GEMM,GEMV - !USE mkl95_LAPACK, ONLY: GETRF,GETRI - integer, INTENT(in) :: imax, JMAX, KMAX, nd, jb, jd - REAL, INTENT(in) :: tjk(jd-2,kmax-1),sjk(jd-2,jd-2,kmax-1),qref(jd,kmax), ubar(nd,kmax), & - tbar(nd,kmax),fawa(nd,kmax),ckref(nd,kmax),statn(kmax),tn0(kmax) - REAL, INTENT(in) :: a, om, dz,h, rr, cp - REAL, INTENT(out) :: tref(jd,kmax) - -! **** take QG analysis and compute Q_ref and invert for -! U_ref & Theta_ref for NH *** - - !integer,parameter :: imax = 360, JMAX = 181, KMAX = 97 - !integer,parameter :: nd = 91, nnd=181 - !integer,parameter :: jb = 5 ! lower bounding latitude - !integer,parameter :: jd = 86 ! nd - lower bounding latitude - !common /array/ pv(imax,jmax,kmax),pv2(imax,jmax) - !common /brray/ uu(imax,jmax,kmax) - !common /bcray/ pt(imax,jmax,kmax) - !common /bdray/ stats(kmax),ts0(kmax) - !common /crray/ qn(nnd),an(nnd),aan(nnd) - real :: tb(kmax),tg(kmax) - !common /drray/ cn(nnd),ccn(nnd),cbar(nd,kmax) - real :: alat(nd),phi(nd),z(kmax) - real :: tj(jd-2),rj(jd-2) - real :: qjj(jd-2,jd-2),cjj(jd-2,jd-2),qjj_k(jd-2,jd-2,kmax),djj_k(jd-2,jd-2,kmax) - real :: xjj(jd-2,jd-2),yj(jd-2) - real :: djj(jd-2,jd-2),sjj(jd-2,jd-2) - real :: pjk(jd-2,kmax),pj(jd-2) - real :: u(jd,kmax),cref(nd,kmax) - !real :: fawa(nd,kmax) - !real :: qbar(nd,kmax) - integer :: md(12),ipiv(jd-2),nnd - -! character*34 fn,fn0,fn1 -! character*33 fu -! character*33 ft -! character*4 fn2(12),fy,fy1,fy2 -! character*18 f1,f2 -! character*19 f3 -! character*35 fr - - nnd = JMAX - !a = 6378000. - pi = acos(-1.) - !om = 7.29e-5 - dp = pi/180. - !dz = 500. - !h = 7000. - !r = 287. - rkappa = r/cp - - do nn = 1,nd - phi(nn) = dp*float(nn-1) - alat(nn) = 2.*pi*a*a*(1.-sin(phi(nn))) - enddo - - do k = 1,kmax - z(k) = dz*float(k-1) - enddo - -! do m = 2021,2021 -! -! md(1) = 31 -! md(2) = 28 -! if(mod(m,4).eq.0) md(2) = 29 -! md(3) = 31 -! md(4) = 30 -! md(5) = 31 -! md(6) = 30 -! md(7) = 31 -! md(8) = 31 -! md(9) = 30 -! md(10) = 31 -! md(11) = 30 -! md(12) = 31 -! -! fn2(1) = '_01_' -! fn2(2) = '_02_' -! fn2(3) = '_03_' -! fn2(4) = '_04_' -! fn2(5) = '_05_' -! fn2(6) = '_06_' -! fn2(7) = '_07_' -! fn2(8) = '_08_' -! fn2(9) = '_09_' -! fn2(10) = '_10_' -! fn2(11) = '_11_' -! fn2(12) = '_12_' -! -! write(fy,266) m -! 266 format(i4) - -! do n = 1,1 -! fn = '/data/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGPV' -! fu = '/data/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGU' -! ft = '/data/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGT' -! fr = '/data/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGREF' -! write(6,*) fn,md(n) -! open(35,file =fn, & -! form='unformatted',status = 'old') -! open(36,file =fu, & -! form='unformatted',status = 'old') -! open(37,file =ft, & -! form='unformatted',status = 'old') -! open(38,file =fr, & -! form='unformatted',status = 'new') - -! do mm = 1,md(n)*4 -! -! read(35) pv -! read(36) uu -! read(37) pt,tn0,ts0,statn,stats - -! **** Zonal-mean field **** -! do j = 91,jmax -! qbar(j-90,:) = 0. -! tbar(j-90,:) = 0. -! ubar(j-90,:) = 0. -! do i = 1,imax -! qbar(j-90,:) = qbar(j-90,:)+pv(i,j,:)/float(imax) -! tbar(j-90,:) = tbar(j-90,:)+pt(i,j,:)/float(imax) -! ubar(j-90,:) = ubar(j-90,:)+uu(i,j,:)/float(imax) -! enddo -! enddo - -! **** hemispheric-mean potential temperature **** - tb(:) = tn0(:) - -! do k = 2,96 -! pv2(:,:) = pv(:,:,k) -! -!! **** compute qref via area analysis **** -! qmax = maxval(pv2) -! qmin = minval(pv2) -! dq = (qmax-qmin)/float(nnd-1) -! qn(:) = 0. -! an(:) = 0. -! cn(:) = 0. -! do nn = 1,nnd -! qn(nn) = qmax - dq*float(nn-1) -! enddo -! do j = 1,jmax -! phi0 = -0.5*pi+dp*float(j-1) -! do i = 1,imax -! ind = 1+int((qmax-pv2(i,j))/dq) -! da = a*a*dp*dp*cos(phi0) -! an(ind) = an(ind) + da -! cn(ind) = cn(ind) + da*pv2(i,j) -! enddo -! enddo -! aan(1) = 0. -! ccn(1) = 0. -! do nn = 2,nnd -! aan(nn) = aan(nn-1)+an(nn) -! ccn(nn) = ccn(nn-1)+cn(nn) -! enddo -! do j = 1,nd-1 -! do nn = 1,nnd-1 -! if(aan(nn).le.alat(j).and.aan(nn+1).gt.alat(j)) then -! dd = (alat(j)-aan(nn))/(aan(nn+1)-aan(nn)) -! qref(j,k) = qn(nn)*(1.-dd)+qn(nn+1)*dd -! cref(j,k) = ccn(nn)*(1.-dd)+ccn(nn+1)*dd -! endif -! enddo -! enddo -! -! qref(nd,k) = qmax -! -! cbar(nd,k) = 0. -! do j=nd-1,1,-1 -! phi0 = dp*(float(j)-0.5) -! cbar(j,k) = cbar(j+1,k)+0.5*(qbar(j+1,k)+qbar(j,k)) & -! *a*dp*2.*pi*a*cos(phi0) -! enddo -! -! enddo - -! ***** normalize QGPV by sine (latitude) **** - -! do j = 2,nd -! phi0 = dp*float(j-1) -! cor = sin(phi0) -! qref(j,:) = qref(j,:)/cor -! enddo -! -! do k = 2,kmax-1 -! qref(1,k) = 2.*qref(2,k)-qref(3,k) -! enddo - -! ***** FAWA ***** -! fawa(:,:) = (cref(:,:)-cbar(:,:))/(2.*pi*a) - -! ***** Direct solver to invert Q_ref ***** - -! *** downward sweep *** - -! **** top boundary condition (Eqs. 24-25) ***** -! tjk(:,:) = 0. -! sjk(:,:,:) = 0. -! do jj = jb+2,90 -! j = jj-jb -! phi0 = float(jj-1)*dp -! cos0 = cos(phi0) -! sin0 = sin(phi0) -! tjk(j-1,kmax-1) = -dz*r*cos0*exp(-z(kmax-1)*rkappa/h) -! tjk(j-1,kmax-1) = tjk(j-1,kmax-1)*(tbar(j+1,kmax)-tbar(j-1,kmax)) -! tjk(j-1,kmax-1) = tjk(j-1,kmax-1)/(4.*om*sin0*dp*h*a) -! sjk(j-1,j-1,kmax-1) = 1. -! enddo - -! **** Evaluate Eqs. 22-23 downward *** - - do k = kmax-1,2,-1 - zp = 0.5*(z(k+1)+z(k)) - zm = 0.5*(z(k-1)+z(k)) - statp = 0.5*(statn(k+1)+statn(k)) - statm = 0.5*(statn(k-1)+statn(k)) - cjj(:,:) = 0. - djj(:,:) = 0. - qjj(:,:) = 0. - sjj(:,:) = sjk(:,:,k) - tj(:) = tjk(:,k) - do jj = jb+2,90 - j = jj - jb - phi0 = float(jj-1)*dp - phip = (float(jj)-0.5)*dp - phim = (float(jj)-1.5)*dp - cos0 = cos(phi0) - cosp = cos(phip) - cosm = cos(phim) - sin0 = sin(phi0) - sinp = sin(phip) - sinm = sin(phim) - - fact = 4.*om*om*h*a*a*sin0*dp*dp/(dz*dz*rr*cos0) - amp = exp(-zp/h)*exp(rkappa*zp/h)/statp - amp = amp*fact*exp(z(k)/h) - amm = exp(-zm/h)*exp(rkappa*zm/h)/statm - amm = amm*fact*exp(z(k)/h) - - ! ***** Specify A, B, C, D, E, F (Eqs. 4-9) ***** - ajk = 1./(sinp*cosp) - bjk = 1./(sinm*cosm) - cjk = amp - djk = amm - ejk = ajk+bjk+cjk+djk - fjk = -0.5*a*dp*(qref(jj+1,k)-qref(jj-1,k)) - - ! ***** Specify rk (Eq. 15) **** - - ! **** North-south boundary conditions **** - u(jd,k) = 0. - phi0 = dp*float(jb) - u(1,k) = ubar(jb+1,k)*cos(phi0) - - rj(j-1) = fjk - if(j.eq.2) rj(j-1) = fjk - bjk*u(1,k) - if(j.eq.jd-1) rj(j-1) = fjk - ajk*u(jd,k) - - ! ***** Specify Ck & Dk (Eqs. 18-19) ***** - cjj(j-1,j-1) = cjk - djj(j-1,j-1) = djk - - ! **** Specify Qk (Eq. 17) ***** - qjj(j-1,j-1) = -ejk - if(j-1.ge.1.and.j-1.lt.jd-2) then - qjj(j-1,j) = ajk - endif - if(j-1.gt.1.and.j-1.le.jd-2) then - qjj(j-1,j-2) = bjk - endif - enddo - - ! **** Compute Qk + Ck Sk ******* - do i = 1,jd-2 - do j = 1,jd-2 - xjj(i,j) = 0. - do kk = 1,jd-2 - xjj(i,j) = xjj(i,j)+cjj(i,kk)*sjj(kk,j) - enddo - qjj(i,j) = qjj(i,j)+xjj(i,j) - enddo - enddo - qjj_k(:,:,k) = qjj(:,:) - djj_k(:,:,k) = djj(:,:) - enddo - ! call gemm(cjj,sjj,xjj) - ! qjj(:,:) = qjj(:,:)+xjj(:,:) - - do k = kmax-1,2,-1 - qjj = qjj_k(:,:,k) - djj = djj_k(:,:,k) - ! **** Invert (Qk + Ck Sk) ******** - call getrf(qjj,ipiv) - call getri(qjj,ipiv) - - ! **** Evaluate Eq. 22 **** - do i = 1,jd-2 - do j = 1,jd-2 - xjj(i,j) = 0. - do kk = 1,jd-2 - xjj(i,j) = xjj(i,j)+qjj(i,kk)*djj(kk,j) - enddo - sjk(i,j,k-1) = -xjj(i,j) - enddo - enddo - - ! call gemm(qjj,djj,xjj) - ! sjk(:,:,k-1) = -xjj(:,:) - - ! **** Evaluate rk - Ck Tk **** - do i = 1,jd-2 - yj(i) = 0. - do kk = 1,jd-2 - yj(i) = yj(i)+cjj(i,kk)*tj(kk) - enddo - yj(i) = rj(i)-yj(i) - enddo - - ! call gemv(cjj,tj,yj) - ! yj(:) = rj(:)-yj(:) - ! call gemv(qjj,yj,tj) - ! tjk(:,k-1) = tj(:) - - - ! ***** Evaluate Eq. 23 ******* - do i = 1,jd-2 - tj(i) = 0. - do kk = 1,jd-2 - tj(i) = tj(i)+qjj(i,kk)*yj(kk) - enddo - tjk(i,k-1) = tj(i) - enddo - - enddo - -! ***** upward sweep (Eq. 20) **** - - pjk(:,1) = 0. - do k = 1,kmax-1 - pj(:) = pjk(:,k) - sjj(:,:) = sjk(:,:,k) - tj(:) = tjk(:,k) - - do i = 1,jd-2 - yj(i) = 0. - do kk = 1,jd-2 - yj(i) = yj(i)+sjj(i,kk)*pj(kk) - enddo - pjk(i,k+1) = yj(i)+tj(i) - enddo -! call gemv(sjj,pj,yj) -! pjk(:,k+1) = yj(:) + tj(:) - enddo - -! **** Recover u ***** - do k = 1,kmax - do j = 2,jd-1 - u(j,k) = pjk(j-1,k) - enddo - enddo - -! *** Corner boundary conditions *** - u(1,1) = 0. - u(jd,1) = 0. - u(1,kmax) = ubar(1+jb,kmax)*cos(dp*float(jb)) - u(jd,kmax) = 0. - -! *** Divide by cos phi to revover Uref **** - do jj = jb+1,nd-1 - j = jj-jb - phi0 = dp*float(jj-1) - u(j,:) = u(j,:)/cos(phi0) - enddo - u(jd,:) = 2.*u(jd-1,:)-u(jd-2,:) - -! ******** compute tref ******* - - do k = 2,96 - t00 = 0. - zz = dz*float(k-1) - tref(1,k) = t00 - tref(2,k) = t00 - do j = 2,jd-1 - phi0 = dp*float(j-1) - cor = 2.*om*sin(phi0) - uz = (u(j,k+1)-u(j,k-1))/(2.*dz) - ty = -cor*uz*a*h*exp(rkappa*zz/h) - ty = ty/r - tref(j+1,k) = tref(j-1,k)+2.*ty*dp - qref(j-1,k) = qref(j-1,k)*sin(phi0) - enddo - tg(k) = 0. - wt = 0. - do jj = 6,91 - j = jj-5 - phi0 = dp*float(jj-1) - tg(k) = tg(k)+cos(phi0)*tref(j,k) - wt = wt + cos(phi0) - enddo - tg(k) = tg(k)/wt - tres = tb(k)-tg(k) - tref(:,k) = tref(:,k)+tres - enddo - tref(:,1) = tref(:,2)-tb(2)+tb(1) - tref(:,97) = tref(:,96)-tb(96)+tb(97) - - write(38) qref,u,tref,fawa,ubar,tbar - - write(6,*) m,n,mm - -! ******************************** - !enddo - - !close(35) - !close(36) - !close(37) - !close(38) - - !enddo - !enddo - - stop -END SUBROUTINE diff --git a/hn2016_falwa/matrix_after_inversion.f90 b/hn2016_falwa/matrix_after_inversion.f90 index 5798b42..1bd22fb 100644 --- a/hn2016_falwa/matrix_after_inversion.f90 +++ b/hn2016_falwa/matrix_after_inversion.f90 @@ -20,9 +20,6 @@ SUBROUTINE matrix_after_inversion(k,kmax,jb,jd,qjj,djj,cjj,tj,rj,sjk,tjk) enddo enddo - ! call gemm(qjj,djj,xjj) - ! sjk(:,:,k-1) = -xjj(:,:) - ! **** Evaluate rk - Ck Tk **** do i = 1,jd-2 yj(i) = 0. @@ -32,12 +29,6 @@ SUBROUTINE matrix_after_inversion(k,kmax,jb,jd,qjj,djj,cjj,tj,rj,sjk,tjk) yj(i) = rj(i)-yj(i) enddo - ! call gemv(cjj,tj,yj) - ! yj(:) = rj(:)-yj(:) - ! call gemv(qjj,yj,tj) - ! tjk(:,k-1) = tj(:) - - ! ***** Evaluate Eq. 23 ******* do i = 1,jd-2 tj(i) = 0. diff --git a/hn2016_falwa/matrix_b4_inversion.f90 b/hn2016_falwa/matrix_b4_inversion.f90 index 5b0586a..ccc7361 100644 --- a/hn2016_falwa/matrix_b4_inversion.f90 +++ b/hn2016_falwa/matrix_b4_inversion.f90 @@ -14,7 +14,6 @@ SUBROUTINE matrix_b4_inversion(k,jmax,kmax,nd,jb,jd,z,statn,qref,ckref,& REAL :: qn(jmax),an(jmax),aan(jmax),tb(kmax),tg(kmax) REAL :: cn(jmax),ccn(jmax),tref(jd,kmax) REAL :: alat(nd),phi(nd),cbar(nd,kmax) -! REAL :: tj(jd-2) REAL :: xjj(jd-2,jd-2) REAL :: sjj(jd-2,jd-2) diff --git a/hn2016_falwa/oopinterface.py b/hn2016_falwa/oopinterface.py index 457f6e7..e56d0e2 100644 --- a/hn2016_falwa/oopinterface.py +++ b/hn2016_falwa/oopinterface.py @@ -608,7 +608,7 @@ def _compute_qref_fawa_and_bc(self): tjk=tjk) # print(f"k = {k}. Run till here so far") - qref = upward_sweep( + qref, tref = upward_sweep( jmax=self.nlat, nnd=self.nlat, jb=5, @@ -618,7 +618,6 @@ def _compute_qref_fawa_and_bc(self): tb=self._tn0, qref_over_cor=qref_over_cor, u=u, - tref=tref, a=self.planet_radius, om=self.omega, dz=self.dz, diff --git a/hn2016_falwa/upward_sweep.f90 b/hn2016_falwa/upward_sweep.f90 index 7d60ecc..5ced5ca 100644 --- a/hn2016_falwa/upward_sweep.f90 +++ b/hn2016_falwa/upward_sweep.f90 @@ -5,34 +5,16 @@ SUBROUTINE upward_sweep(jmax, kmax, nd, nnd, jb, jd, sjk, tjk, ckref, tb, qref_o INTEGER, INTENT(IN) :: jmax, kmax, nd, nnd, jb, jd REAL, INTENT(IN) :: sjk(jd-2,jd-2,kmax-1),tjk(jd-2,kmax-1),ckref(nd,kmax),tb(kmax),qref_over_cor(nd,kmax) REAL, INTENT(IN) :: rr, cp - REAL, INTENT(INOUT) :: u(jd,kmax), tref(jd,kmax) - REAL, INTENT(OUT) :: qref(nd,kmax) - -! integer,parameter :: imax = 360, JMAX = 181, KMAX = 97 -! integer,parameter :: nd = 91,nnd=181 -! integer,parameter :: jb = 5 ! lower bounding latitude -! integer,parameter :: jd = 86 ! nd - lower bounding latitude - -! common /array/ pv(imax,jmax,kmax),pv2(imax,jmax) -! common /brray/ uu(imax,jmax,kmax) -! common /bbray/ vort(imax,jmax,kmax),vort2(imax,jmax) -! common /bcray/ pt(imax,jmax,kmax) -! common /bdray/ stats(kmax),statn(kmax),ts0(kmax),tn0(kmax) -! common /crray/ qn(nnd),an(nnd),aan(nnd) + REAL, INTENT(INOUT) :: u(jd,kmax) + REAL, INTENT(OUT) :: qref(nd,kmax), tref(jd,kmax) real :: tg(kmax) real :: pjk(jd-2,kmax) -! common /frray/ alat(nd),phi(nd),z(kmax),cbar(nd,kmax) real :: tj(jd-2),rj(jd-2) real :: qjj(jd-2,jd-2),cjj(jd-2,jd-2) real :: xjj(jd-2,jd-2),yj(jd-2) -! real :: djj(jd-2,jd-2) real :: sjj(jd-2,jd-2) real :: pj(jd-2) -! common /krray/ fawa(nd,kmax) -! common /jrray/ qbar(nd,kmax),ubar(nd,kmax),tbar(nd,kmax) -! integer :: md(12),ipiv(jd-2) - rkappa = rr/cp pi = acos(-1.) dp = pi/180. diff --git a/scripts/nhn_grl2022/sample_run_script.py b/scripts/nhn_grl2022/sample_run_script.py index f96830e..78e3dda 100644 --- a/scripts/nhn_grl2022/sample_run_script.py +++ b/scripts/nhn_grl2022/sample_run_script.py @@ -62,12 +62,12 @@ maxits = 100000 # maximum number of iteration in the SOR solver to solve for reference state tol = 1.e-5 # tolerance that define convergence of solution rjac = 0.95 # spectral radius of the Jacobi iteration in the SOR solver. -jd = nlat//2+1 # (one plus) index of latitude grid point with value 0 deg +nd = nlat//2+1 # (one plus) index of latitude grid point with value 0 deg # This is to be input to fortran code. The index convention is different. # --- Outputing files --- -output_fname = '2021-06-01_to_2021-06-30_output_change.nc' +output_fname = '2021-06-01_to_2021-06-30_output_70d5ef.nc' print(output_fname) if to_generate_data: output_file = Dataset(output_fname, 'w') diff --git a/setup.py b/setup.py index bb75c85..e102e21 100644 --- a/setup.py +++ b/setup.py @@ -31,6 +31,7 @@ sources=['hn2016_falwa/compute_lwa_and_barotropic_fluxes.f90'], f2py_options=['--quiet']) +# *** Extensions 4-9 are used by the direct inversion algorithm *** ext4 = Extension(name='interpolate_fields_direct_inv', sources=['hn2016_falwa/interpolate_fields_dirinv.f90'], f2py_options=['--quiet']) From 52bf9ac56e1c5a5a306d54956db17a7be8f3533e Mon Sep 17 00:00:00 2001 From: csyhuang Date: Wed, 16 Mar 2022 23:51:56 -0500 Subject: [PATCH 08/19] move tref.need further checking --- hn2016_falwa/compute_qref_and_fawa_first.f90 | 4 +- hn2016_falwa/oopinterface.py | 61 +++++++++++--------- scripts/nhn_grl2022/sample_run_script.py | 2 +- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/hn2016_falwa/compute_qref_and_fawa_first.f90 b/hn2016_falwa/compute_qref_and_fawa_first.f90 index 0cb109e..6a70594 100644 --- a/hn2016_falwa/compute_qref_and_fawa_first.f90 +++ b/hn2016_falwa/compute_qref_and_fawa_first.f90 @@ -1,5 +1,5 @@ SUBROUTINE compute_qref_and_fawa_first(pv, uu, vort, pt, tn0, ts0, statn, stats, imax, JMAX, kmax, nd, nnd, jb, jd, & - qref,u,tref,ubar,tbar,fawa,ckref,tjk,sjk) + qref,u,ubar,tbar,fawa,ckref,tjk,sjk) !USE mkl95_LAPACK, ONLY: GETRF,GETRI @@ -7,7 +7,7 @@ SUBROUTINE compute_qref_and_fawa_first(pv, uu, vort, pt, tn0, ts0, statn, stats, INTEGER, INTENT(IN) :: imax, JMAX, kmax, nd, nnd, jb, jd REAL, INTENT(IN) :: pv(imax,jmax,kmax),uu(imax,jmax,kmax),vort(imax,jmax,kmax),pt(imax,jmax,kmax),& stats(kmax),statn(kmax),ts0(kmax),tn0(kmax) - REAL, INTENT(OUT) :: qref(nd,kmax),u(jd,kmax),tref(jd,kmax),ubar(nd,kmax),tbar(nd,kmax),fawa(nd,kmax),ckref(nd,kmax),& + REAL, INTENT(OUT) :: qref(nd,kmax),u(jd,kmax),ubar(nd,kmax),tbar(nd,kmax),fawa(nd,kmax),ckref(nd,kmax),& tjk(jd-2,kmax-1),sjk(jd-2,jd-2,kmax-1) ! **** take QG analysis and compute Q_ref and invert for U_ref & Theta_ref for NH (Direct solver) *** diff --git a/hn2016_falwa/oopinterface.py b/hn2016_falwa/oopinterface.py index e56d0e2..5e110af 100644 --- a/hn2016_falwa/oopinterface.py +++ b/hn2016_falwa/oopinterface.py @@ -540,12 +540,11 @@ def _compute_qref_fawa_and_bc(self): nnd=181, jb=5, jd=86) - qref_over_cor, u, tref, ubar, tbar, fawa, ckref, tjk, sjk = ans # unpack tuple + qref_over_cor, u, ubar, tbar, fawa, ckref, tjk, sjk = ans # unpack tuple print("Line 535") self._check_nan("qref_over_cor", qref_over_cor) self._check_nan("u", u) - self._check_nan("tref", tref) self._check_nan("ubar", ubar) self._check_nan("tbar", tbar) self._check_nan("fawa", fawa) @@ -607,8 +606,10 @@ def _compute_qref_fawa_and_bc(self): sjk=sjk, tjk=tjk) # print(f"k = {k}. Run till here so far") + print("Line 609: sjk.shape = ", sjk.shape) + print("Line 610: u.shape = ", u.shape) - qref, tref = upward_sweep( + tref, qref = upward_sweep( jmax=self.nlat, nnd=self.nlat, jb=5, @@ -624,6 +625,10 @@ def _compute_qref_fawa_and_bc(self): h=self.scale_height, rr=self.dry_gas_constant, cp=self.cp) + print(f"qref.shape = {qref.shape}") + print(f"tref.shape = {tref.shape}") + print("tref = ") + print(tref) return qref, u, tref, fawa, ubar, tbar # uref = u @@ -779,31 +784,31 @@ def interpolate_fields_direct_inversion_old(self): # TODO: static stability in southern hemisphere has nan values?! return interpolated_fields - def compute_reference_states_direct_inversion(self, northern_hemisphere_results_only=True): - """ - Direct inversion algorithm for NHN GRL 2022 - """ - - ans = compute_qref_fawa_and_bc( - 5, - 91, - 91 - 5, - self._qgpv_temp, - self._interpolated_u_temp, - self._interpolated_avort_temp, - self._interpolated_theta_temp, - self._static_stability_n, - self._tn0, - self.planet_radius, - self.omega, - self.dz, - self.tol, # can remove - self.scale_height, - self.dry_gas_constant) - - self._f_qref, self._f_u, self._f_tref, self._f_ubar, self._f_tbar, self._f_fawa, self._f_ckref = ans - - return ans + # def compute_reference_states_direct_inversion(self, northern_hemisphere_results_only=True): + # """ + # Direct inversion algorithm for NHN GRL 2022 + # """ + # + # ans = compute_qref_fawa_and_bc( + # 5, + # 91, + # 91 - 5, + # self._qgpv_temp, + # self._interpolated_u_temp, + # self._interpolated_avort_temp, + # self._interpolated_theta_temp, + # self._static_stability_n, + # self._tn0, + # self.planet_radius, + # self.omega, + # self.dz, + # self.tol, # can remove + # self.scale_height, + # self.dry_gas_constant) + # + # self._f_qref, self._f_u, self._f_tref, self._f_ubar, self._f_tbar, self._f_fawa, self._f_ckref = ans + # + # return ans # def _compute_reference_states_direct_inversion_wrapper(self, qgpv, u, theta): # return compute_reference_states( diff --git a/scripts/nhn_grl2022/sample_run_script.py b/scripts/nhn_grl2022/sample_run_script.py index 78e3dda..0c60be5 100644 --- a/scripts/nhn_grl2022/sample_run_script.py +++ b/scripts/nhn_grl2022/sample_run_script.py @@ -67,7 +67,7 @@ # --- Outputing files --- -output_fname = '2021-06-01_to_2021-06-30_output_70d5ef.nc' +output_fname = '2021-06-01_to_2021-06-30_output_aa0985.nc' print(output_fname) if to_generate_data: output_file = Dataset(output_fname, 'w') From da7494b87bb8cda123dfa318244e43513940e060 Mon Sep 17 00:00:00 2001 From: csyhuang Date: Thu, 17 Mar 2022 13:23:22 -0500 Subject: [PATCH 09/19] add back physical parameter as input parameter --- hn2016_falwa/compute_flux_dirinv.f90 | 42 +- hn2016_falwa/compute_qref_and_fawa_first.f90 | 278 +--------- hn2016_falwa/matrix_b4_inversion.f90 | 2 +- hn2016_falwa/oopinterface.py | 504 ++++++------------- hn2016_falwa/upward_sweep.f90 | 6 +- scripts/nhn_grl2022/sample_run_script.py | 22 +- 6 files changed, 194 insertions(+), 660 deletions(-) diff --git a/hn2016_falwa/compute_flux_dirinv.f90 b/hn2016_falwa/compute_flux_dirinv.f90 index 21f2c7e..c9f703f 100644 --- a/hn2016_falwa/compute_flux_dirinv.f90 +++ b/hn2016_falwa/compute_flux_dirinv.f90 @@ -1,11 +1,12 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fawa,ubar,tbar,& - imax, JMAX, kmax, nd, nnd, jb, jd,& + imax, jmax, kmax, nd, nnd, jb, jd, aa, omega, dz, hh, rr, cp, prefac, & astarbaro,ubaro,urefbaro,ua1baro,ua2baro,ep1baro,ep2baro,ep3baro,ep4,astar1,astar2) - INTEGER, INTENT(IN) :: imax, JMAX, kmax, nd, nnd, jb, jd + INTEGER, INTENT(IN) :: imax, jmax, kmax, nd, nnd, jb, jd REAL, INTENT(IN) :: pv(imax,jmax,kmax),uu(imax,jmax,kmax),vv(imax,jmax,kmax),pt(imax,jmax,kmax),& tn0(kmax),ts0(kmax),statn(kmax),stats(kmax),qref(nd,kmax),uref(jd,kmax),tref(jd,kmax),& fawa(nd,kmax),ubar(nd,kmax),tbar(nd,kmax) + REAL, INTENT(in) :: aa, omega, dz, hh, rr, cp, prefac REAL, INTENT(OUT) :: astarbaro(imax,nd),ubaro(imax,nd),urefbaro(nd),ua1baro(imax,nd),ua2baro(imax,nd),& ep1baro(imax,nd),ep2baro(imax,nd),ep3baro(imax,nd),ep4(imax,nd),astar1(imax,nd,kmax),astar2(imax,nd,kmax) @@ -16,16 +17,13 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa REAL :: z(kmax) REAL :: u(nd,kmax) - a = 6378000. pi = acos(-1.) - om = 7.29e-5 - dp = pi/180. - dz = 500. - h = 7000. - r = 287. - rkappa = r/1004. + dp = pi/float(jmax-1) + rkappa = rr/cp + ! *** Default values for boundary *** + !prefac = 6745.348 !jb = 5 !jd = 86 ! nd - lower bounding latitude @@ -48,9 +46,9 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ep2baro(:,:) = 0. ep3baro(:,:) = 0. ep4(:,:) = 0. - dc = dz/6745.348 + dc = dz/prefac - do k = 2,96 + do k = 2,kmax-1 zk = dz*float(k-1) do i = 1,imax do j = 6,nd-1 ! 5N and higher latitude @@ -82,7 +80,7 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ep1(i,j) = ep1(i,j)+0.5*vv(i,j+90,k)**2 !F3a+b ep11 = 0.5*(pt(i,j+90,k)-tref(j-5,k))**2 !F3c zz = dz*float(k-1) - ep11 = ep11*(r/h)*exp(-rkappa*zz/h) + ep11 = ep11*(r/hh)*exp(-rkappa*zz/hh) ep11 = ep11*2.*dz/(tg(k+1)-tg(k-1)) ep1(i,j) = ep1(i,j)-ep11 !F3 phip = dp*float(j) @@ -101,8 +99,8 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ! low-level meridional eddy heat flux if(k.eq.2) then ! (26) of SI-HN17 - ep41 = 2.*om*sin0*cos0*dz/6745.348 ! prefactor - ep42 = exp(-dz/h)*vv(i,j+90,2)*(pt(i,j+90,2)-tref(j-5,2)) + ep41 = 2.*om*sin0*cos0*dz/prefac ! prefactor + ep42 = exp(-dz/hh)*vv(i,j+90,2)*(pt(i,j+90,2)-tref(j-5,2)) ep42 = ep42/(tg(3)-tg(1)) ep43 = vv(i,j+90,1)*(pt(i,j+90,1)-tref(j-5,1)) ep43 = 0.5*ep43/(tg(2)-tg(1)) @@ -114,15 +112,15 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ! ******** Column average: (25) of SI-HN17 ******** astarbaro(:,:) = astarbaro(:,:)+(astar1(:,:,k) & - + astar2(:,:,k))*exp(-zk/h)*dc - ua1baro(:,:) = ua1baro(:,:)+ua1(:,:)*exp(-zk/h)*dc - ua2baro(:,:) = ua2baro(:,:)+ua2(:,:)*exp(-zk/h)*dc - ep1baro(:,:) = ep1baro(:,:)+ep1(:,:)*exp(-zk/h)*dc - ep2baro(:,:) = ep2baro(:,:)+ep2(:,:)*exp(-zk/h)*dc - ep3baro(:,:) = ep3baro(:,:)+ep3(:,:)*exp(-zk/h)*dc + + astar2(:,:,k))*exp(-zk/hh)*dc + ua1baro(:,:) = ua1baro(:,:)+ua1(:,:)*exp(-zk/hh)*dc + ua2baro(:,:) = ua2baro(:,:)+ua2(:,:)*exp(-zk/hh)*dc + ep1baro(:,:) = ep1baro(:,:)+ep1(:,:)*exp(-zk/hh)*dc + ep2baro(:,:) = ep2baro(:,:)+ep2(:,:)*exp(-zk/hh)*dc + ep3baro(:,:) = ep3baro(:,:)+ep3(:,:)*exp(-zk/hh)*dc do j = 6,nd ! ### yet to be multiplied by cosine - ubaro(:,j) = ubaro(:,j)+uu(:,j+90,k)*exp(-zk/h)*dc - urefbaro(j) = urefbaro(j)+uref(j-5,k)*exp(-zk/h)*dc + ubaro(:,j) = ubaro(:,j)+uu(:,j+90,k)*exp(-zk/hh)*dc + urefbaro(j) = urefbaro(j)+uref(j-5,k)*exp(-zk/hh)*dc enddo enddo diff --git a/hn2016_falwa/compute_qref_and_fawa_first.f90 b/hn2016_falwa/compute_qref_and_fawa_first.f90 index 6a70594..d22cf21 100644 --- a/hn2016_falwa/compute_qref_and_fawa_first.f90 +++ b/hn2016_falwa/compute_qref_and_fawa_first.f90 @@ -1,10 +1,12 @@ SUBROUTINE compute_qref_and_fawa_first(pv, uu, vort, pt, tn0, ts0, statn, stats, imax, JMAX, kmax, nd, nnd, jb, jd, & + aa, omega, dz, h, rr, cp, & qref,u,ubar,tbar,fawa,ckref,tjk,sjk) !USE mkl95_LAPACK, ONLY: GETRF,GETRI INTEGER, INTENT(IN) :: imax, JMAX, kmax, nd, nnd, jb, jd + REAL, INTENT(in) :: aa, omega, dz, h, rr, cp REAL, INTENT(IN) :: pv(imax,jmax,kmax),uu(imax,jmax,kmax),vort(imax,jmax,kmax),pt(imax,jmax,kmax),& stats(kmax),statn(kmax),ts0(kmax),tn0(kmax) REAL, INTENT(OUT) :: qref(nd,kmax),u(jd,kmax),ubar(nd,kmax),tbar(nd,kmax),fawa(nd,kmax),ckref(nd,kmax),& @@ -39,14 +41,10 @@ SUBROUTINE compute_qref_and_fawa_first(pv, uu, vort, pt, tn0, ts0, statn, stats, character*36 fv character*38 fr - a = 6378000. + pi = acos(-1.) - om = 7.29e-5 - dp = pi/180. - dz = 500. - h = 7000. - r = 287. - rkappa = r/1004. + dp = pi/float(jmax-1) + rkappa = r/cp do nn = 1,nd phi(nn) = dp*float(nn-1) @@ -57,62 +55,6 @@ SUBROUTINE compute_qref_and_fawa_first(pv, uu, vort, pt, tn0, ts0, statn, stats, z(k) = dz*float(k-1) enddo -! do m = 2021,2021 -! -! md(1) = 31 -! md(2) = 28 -! if(mod(m,4).eq.0) md(2) = 29 -! md(3) = 31 -! md(4) = 30 -! md(5) = 31 -! md(6) = 30 -! md(7) = 31 -! md(8) = 31 -! md(9) = 30 -! md(10) = 31 -! md(11) = 30 -! md(12) = 31 -! -! fn2(1) = '_01_' -! fn2(2) = '_02_' -! fn2(3) = '_03_' -! fn2(4) = '_04_' -! fn2(5) = '_05_' -! fn2(6) = '_06_' -! fn2(7) = '_07_' -! fn2(8) = '_08_' -! fn2(9) = '_09_' -! fn2(10) = '_10_' -! fn2(11) = '_11_' -! fn2(12) = '_12_' -! -! write(fy,266) m -! 266 format(i4) -! -! do n = 10,10 -! fn = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGPV' -! fu = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGU' -! ft = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGT' -! fr = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGREF_N' -! fv = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QVORT' -! write(6,*) fn,md(n) -! open(35,file =fn, & -! form='unformatted',status = 'old') -! open(36,file =fu, & -! form='unformatted',status = 'old') -! open(37,file =ft, & -! form='unformatted',status = 'old') -! open(38,file =fr, & -! form='unformatted',status = 'new') -! open(39,file =fv, & -! form='unformatted',status = 'old') - ! ********************** Analysis starts here ********************** -! do mm = 1,md(n)*4 - -! read(35) pv -! read(36) uu -! read(39) vort -! read(37) pt,tn0,ts0,statn,stats ! **** Zonal-mean field **** do j = 91,jmax @@ -247,214 +189,4 @@ SUBROUTINE compute_qref_and_fawa_first(pv, uu, vort, pt, tn0, ts0, statn, stats, tjk(j-1,kmax-1) = tjk(j-1,kmax-1)/(4.*om*sin0*dp*h*a) sjk(j-1,j-1,kmax-1) = 1. enddo -! *** REFACTOR: COMMENT OUT ALL BELOW *** -! ! **** Evaluate Eqs. 22-23 downward *** -! -! do k = kmax-1,2,-1 -! zp = 0.5*(z(k+1)+z(k)) -! zm = 0.5*(z(k-1)+z(k)) -! statp = 0.5*(statn(k+1)+statn(k)) -! statm = 0.5*(statn(k-1)+statn(k)) -! cjj(:,:) = 0. -! djj(:,:) = 0. -! qjj(:,:) = 0. -! sjj(:,:) = sjk(:,:,k) -! tj(:) = tjk(:,k) -! do jj = jb+2,90 -! j = jj - jb -! phi0 = float(jj-1)*dp -! phip = (float(jj)-0.5)*dp -! phim = (float(jj)-1.5)*dp -! cos0 = cos(phi0) -! cosp = cos(phip) -! cosm = cos(phim) -! sin0 = sin(phi0) -! sinp = sin(phip) -! sinm = sin(phim) -! -! fact = 4.*om*om*h*a*a*sin0*dp*dp/(dz*dz*r*cos0) -! amp = exp(-zp/h)*exp(rkappa*zp/h)/statp -! amp = amp*fact*exp(z(k)/h) -! amm = exp(-zm/h)*exp(rkappa*zm/h)/statm -! amm = amm*fact*exp(z(k)/h) -! -! ! ***** Specify A, B, C, D, E, F (Eqs. 4-9) ***** -! ajk = 1./(sinp*cosp) -! bjk = 1./(sinm*cosm) -! cjk = amp -! djk = amm -! ejk = ajk+bjk+cjk+djk -! fjk = -0.5*a*dp*(qref(jj+1,k)-qref(jj-1,k)) -! -! ! ***** Specify rk (Eq. 15) **** -! -! ! **** North-south boundary conditions **** -! u(jd,k) = 0. -! phi0 = dp*float(jb) -! ! u(1,k) = ubar(jb+1,k)*cos(phi0) -! u(1,k) = ckref(jb+1,k)/(2.*pi*a)-om*a*cos(phi0) -! -! rj(j-1) = fjk -! if(j.eq.2) rj(j-1) = fjk - bjk*u(1,k) -! if(j.eq.jd-1) rj(j-1) = fjk - ajk*u(jd,k) -! -! ! ***** Specify Ck & Dk (Eqs. 18-19) ***** -! cjj(j-1,j-1) = cjk -! djj(j-1,j-1) = djk -! -! ! **** Specify Qk (Eq. 17) ***** -! qjj(j-1,j-1) = -ejk -! if(j-1.ge.1.and.j-1.lt.jd-2) then -! qjj(j-1,j) = ajk -! endif -! if(j-1.gt.1.and.j-1.le.jd-2) then -! qjj(j-1,j-2) = bjk -! endif -! enddo -! -! ! **** Compute Qk + Ck Sk ******* -! do i = 1,jd-2 -! do j = 1,jd-2 -! xjj(i,j) = 0. -! do kk = 1,jd-2 -! xjj(i,j) = xjj(i,j)+cjj(i,kk)*sjj(kk,j) -! enddo -! qjj(i,j) = qjj(i,j)+xjj(i,j) -! enddo -! enddo -! ! call gemm(cjj,sjj,xjj) -! ! qjj(:,:) = qjj(:,:)+xjj(:,:) -! -! ! **** Invert (Qk + Ck Sk) ******** -! call getrf(qjj,ipiv) -! call getri(qjj,ipiv) -! -! ! **** Evaluate Eq. 22 **** -! do i = 1,jd-2 -! do j = 1,jd-2 -! xjj(i,j) = 0. -! do kk = 1,jd-2 -! xjj(i,j) = xjj(i,j)+qjj(i,kk)*djj(kk,j) -! enddo -! sjk(i,j,k-1) = -xjj(i,j) -! enddo -! enddo -! -! ! call gemm(qjj,djj,xjj) -! ! sjk(:,:,k-1) = -xjj(:,:) -! -! ! **** Evaluate rk - Ck Tk **** -! do i = 1,jd-2 -! yj(i) = 0. -! do kk = 1,jd-2 -! yj(i) = yj(i)+cjj(i,kk)*tj(kk) -! enddo -! yj(i) = rj(i)-yj(i) -! enddo -! -! ! call gemv(cjj,tj,yj) -! ! yj(:) = rj(:)-yj(:) -! ! call gemv(qjj,yj,tj) -! ! tjk(:,k-1) = tj(:) -! -! -! ! ***** Evaluate Eq. 23 ******* -! do i = 1,jd-2 -! tj(i) = 0. -! do kk = 1,jd-2 -! tj(i) = tj(i)+qjj(i,kk)*yj(kk) -! enddo -! tjk(i,k-1) = tj(i) -! enddo -! -! enddo -! -! ! ***** upward sweep (Eq. 20) **** -! -! pjk(:,1) = 0. -! do k = 1,kmax-1 -! pj(:) = pjk(:,k) -! sjj(:,:) = sjk(:,:,k) -! tj(:) = tjk(:,k) -! -! do i = 1,jd-2 -! yj(i) = 0. -! do kk = 1,jd-2 -! yj(i) = yj(i)+sjj(i,kk)*pj(kk) -! enddo -! pjk(i,k+1) = yj(i)+tj(i) -! enddo -! ! call gemv(sjj,pj,yj) -! ! pjk(:,k+1) = yj(:) + tj(:) -! enddo -! -! ! **** Recover u ***** -! do k = 1,kmax -! do j = 2,jd-1 -! u(j,k) = pjk(j-1,k) -! enddo -! enddo -! -! ! *** Corner boundary conditions *** -! u(1,1) = 0. -! u(jd,1) = 0. -! ! u(1,kmax) = ubar(1+jb,kmax)*cos(dp*float(jb)) -! u(1,kmax) = ckref(1+jb,kmax)/(2.*pi*a)-om*a*cos(dp*float(jb)) -! u(jd,kmax) = 0. -! -! ! *** Divide by cos phi to revover Uref **** -! do jj = jb+1,nd-1 -! j = jj-jb -! phi0 = dp*float(jj-1) -! u(j,:) = u(j,:)/cos(phi0) -! enddo -! u(jd,:) = 2.*u(jd-1,:)-u(jd-2,:) -! -! ! ******** compute tref ******* -! -! do k = 2,96 -! t00 = 0. -! zz = dz*float(k-1) -! tref(1,k) = t00 -! tref(2,k) = t00 -! do j = 2,jd-1 -! phi0 = dp*float(j-1) -! cor = 2.*om*sin(phi0) -! uz = (u(j,k+1)-u(j,k-1))/(2.*dz) -! ty = -cor*uz*a*h*exp(rkappa*zz/h) -! ty = ty/r -! tref(j+1,k) = tref(j-1,k)+2.*ty*dp -! qref(j-1,k) = qref(j-1,k)*sin(phi0) -! enddo -! tg(k) = 0. -! wt = 0. -! do jj = 6,91 -! j = jj-5 -! phi0 = dp*float(jj-1) -! tg(k) = tg(k)+cos(phi0)*tref(j,k) -! wt = wt + cos(phi0) -! enddo -! tg(k) = tg(k)/wt -! tres = tb(k)-tg(k) -! tref(:,k) = tref(:,k)+tres -! enddo -! tref(:,1) = tref(:,2)-tb(2)+tb(1) -! tref(:,97) = tref(:,96)-tb(96)+tb(97) -! -! write(38) qref,u,tref,fawa,ubar,tbar -! -! write(6,*) m,n,mm -! -! ! ******************************** -! enddo -! -! close(35) -! close(36) -! close(37) -! close(38) -! ! ********************** Analysis ends here ********************** -! enddo -! enddo -! -! stop END diff --git a/hn2016_falwa/matrix_b4_inversion.f90 b/hn2016_falwa/matrix_b4_inversion.f90 index ccc7361..eeb277c 100644 --- a/hn2016_falwa/matrix_b4_inversion.f90 +++ b/hn2016_falwa/matrix_b4_inversion.f90 @@ -19,7 +19,7 @@ SUBROUTINE matrix_b4_inversion(k,jmax,kmax,nd,jb,jd,z,statn,qref,ckref,& rkappa = rr/cp pi = acos(-1.) - dp = pi/180. + dp = pi/float(jmax-1) zp = 0.5*(z(k+1)+z(k)) zm = 0.5*(z(k-1)+z(k)) diff --git a/hn2016_falwa/oopinterface.py b/hn2016_falwa/oopinterface.py index 5e110af..0157cf7 100644 --- a/hn2016_falwa/oopinterface.py +++ b/hn2016_falwa/oopinterface.py @@ -476,359 +476,6 @@ def interpolate_fields(self): self.static_stability) return interpolated_fields - def _interpolate_field_dirinv(self): - """ - Added for NHN 2022 GRL - :return: - """ - self._qgpv_temp, \ - self._interpolated_u_temp, \ - self._interpolated_v_temp, \ - self._interpolated_avort_temp, \ - self._interpolated_theta_temp, \ - self._static_stability_n, \ - self._static_stability_s,\ - self._tn0, self._ts0 = \ - interpolate_fields_direct_inv( - self.kmax, - self.nlat // 2 + self.nlat % 2, - np.swapaxes(self.u_field, 0, 2), - np.swapaxes(self.v_field, 0, 2), - np.swapaxes(self.t_field, 0, 2), - self.plev, - self.planet_radius, - self.omega, - self.dz, - self.scale_height, - self.dry_gas_constant, - self.cp) - - self._check_nan("self._qgpv_temp", self._qgpv_temp) - self._check_nan("self._interpolated_u_temp", self._interpolated_u_temp) - self._check_nan("self._interpolated_v_temp", self._interpolated_v_temp) - self._check_nan("self._interpolated_avort_temp", self._interpolated_avort_temp) - self._check_nan("self._interpolated_theta_temp", self._interpolated_theta_temp) - self._check_nan("self._static_stability_n", self._static_stability_n) - self._check_nan("self._static_stability_s", self._static_stability_s) - self._check_nan("self._tn0", self._tn0) - self._check_nan("self._ts0", self._ts0) - - return self._qgpv_temp, self._interpolated_u_temp, self._interpolated_v_temp, self._interpolated_avort_temp, \ - self._interpolated_theta_temp, self._static_stability_n, self._static_stability_s, self._tn0, self._ts0 - - @staticmethod - def _check_nan(name, var): - nan_num = np.count_nonzero(np.isnan(var)) - if nan_num > 0: - print(f"num of nan in {name}: {np.count_nonzero(np.isnan(var))}.") - - def _compute_qref_fawa_and_bc(self): - """ - Added for NHN 2022 GRL - :return: - """ - ans = compute_qref_and_fawa_first( - pv=self._qgpv_temp, - uu=self._interpolated_u_temp, - vort=self._interpolated_avort_temp, - pt=self._interpolated_theta_temp, - tn0=self._tn0, - ts0=self._ts0, - statn=self._static_stability_n, - stats=self._static_stability_s, - nd=91, - nnd=181, - jb=5, - jd=86) - qref_over_cor, u, ubar, tbar, fawa, ckref, tjk, sjk = ans # unpack tuple - - print("Line 535") - self._check_nan("qref_over_cor", qref_over_cor) - self._check_nan("u", u) - self._check_nan("ubar", ubar) - self._check_nan("tbar", tbar) - self._check_nan("fawa", fawa) - self._check_nan("ckref", ckref) - self._check_nan("tjk", tjk) - self._check_nan("sjk", sjk) - - for k in range(self.kmax-1, 1, -1): # Fortran indices - ans = matrix_b4_inversion( - k=k, - jmax=self.nlat, - jb=5, - jd=86, - z=np.arange(0, self.kmax*self.dz, self.dz), - statn=self._static_stability_n, - qref=qref_over_cor, - ckref=ckref, - a=self.planet_radius, - om=self.omega, - dz=self.dz, - h=self.scale_height, - rr=self.dry_gas_constant, - cp=self.cp, - u=u, - sjk=sjk, - tjk=tjk) - qjj, djj, cjj, rj, tj = ans - - #print("Line 567") - #self._check_nan("qjj", qjj) - #self._check_nan("djj", djj) - #self._check_nan("cjj", cjj) - #self._check_nan("rj", rj) - #self._check_nan("tj", tj) - - # *** Check dimension *** - # print(f"qjj.shape = {qjj.shape}") - # print(f"djj.shape = {djj.shape}") - # print(f"cjj.shape = {cjj.shape}") - # print(f"rj.shape = {rj.shape}") - # print(f"rj.shape = {tj.shape}") - # print(f"u.shape = {u.shape}") - # print(f"sjk.shape = {sjk.shape}") - # print(f"tjk.shape = {tjk.shape}") - lu, piv, info = dgetrf(qjj) - qjj, info = dgetri(lu, piv) - - #print("Line 586. After inversion:") - #self._check_nan("qjj", qjj) - - _ = matrix_after_inversion( - k=k, - jb=5, - qjj=qjj, - djj=djj, - cjj=cjj, - tj=tj, - rj=rj, - sjk=sjk, - tjk=tjk) - # print(f"k = {k}. Run till here so far") - print("Line 609: sjk.shape = ", sjk.shape) - print("Line 610: u.shape = ", u.shape) - - tref, qref = upward_sweep( - jmax=self.nlat, - nnd=self.nlat, - jb=5, - sjk=sjk, - tjk=tjk, - ckref=ckref, - tb=self._tn0, - qref_over_cor=qref_over_cor, - u=u, - a=self.planet_radius, - om=self.omega, - dz=self.dz, - h=self.scale_height, - rr=self.dry_gas_constant, - cp=self.cp) - print(f"qref.shape = {qref.shape}") - print(f"tref.shape = {tref.shape}") - print("tref = ") - print(tref) - - return qref, u, tref, fawa, ubar, tbar # uref = u - - # ans2 = direct_solver_b4_lu_fact( - # tjk=tjk, - # sjk=sjk, - # qref=qref_over_cor, - # ubar=ubar, - # tbar=tbar, - # fawa=fawa, - # ckref=ckref, - # statn=self._static_stability_n, - # tn0=self._tn0, - # jmax=self.nlat, - # jb=5, - # a=self.planet_radius, - # om=self.omega, - # dz=self.dz, - # h=self.scale_height, - # rr=self.dry_gas_constant, - # cp=self.cp) - # print(f"len(ans2) = {len(ans2)}.") - # # *** Do inversion here using SciPy package *** - # qjj_k, cjj_k, djj_k, tj, rj = ans2 - # qjj_output = np.zeros_like(qjj_k) - # - # for k in range(self.kmax-1, 2, -1): - # #print(f"In line 542 of oopinterface.py. k = {k}.") - # lu, piv, info = dgetrf(qjj_k[:, :, k]) - # inv_a, info = dgetri(lu, piv) - # #if np.count_nonzero(np.isnan(inv_a)) > 0: - # #print(f"================= k = {k} =================") - # #print(f"Number of nan in inv_a: {np.count_nonzero(np.isnan(inv_a))}") - # qjj_output[:, :, k] = inv_a - # - # ans3 = direct_solver_after_lu_fact( - # qjj_k=qjj_output, - # cjj_k=cjj_k, - # djj_k=djj_k, - # sjk=sjk, - # tjk=tjk, - # tj=tj, - # rj=rj, - # qref_over_cor=qref_over_cor, - # ubar=ubar, - # tbar=tbar, - # tn0=self._tn0, - # jmax=self.nlat, - # jb=5, - # a=self.planet_radius, - # om=self.omega, - # dz=self.dz, - # h=self.scale_height, - # rr=self.dry_gas_constant, - # cp=self.cp) - # uref, qref, tref = ans3 - # print(f"len(ans3) = {len(ans3)}") - # print(f"uref[:, 40] = {uref[:, 40]}") - # print(f"qref[:, 40] = {qref[:, 40]}") - # print(f"tref[:, 40] = {tref[:, 40]}") - - def _compute_lwa_flux_dirinv(self, qref, uref, tref, fawa, ubar, tbar): - """ - Added for NHN 2022 GRL - :return: - """ - ans = compute_flux_dirinv(pv=self._qgpv_temp, uu=self._interpolated_u_temp, vv=self._interpolated_v_temp, - pt=self._interpolated_theta_temp, tn0=self._tn0, ts0=self._ts0, - statn=self._static_stability_n, stats=self._static_stability_s, - qref=qref, uref=uref, tref=tref, fawa=fawa, ubar=ubar, tbar=tbar, - nnd=self.nlat, jb=5) - # astarbaro, ubaro, urefbaro, ua1baro, ua2baro, ep1baro, ep2baro, ep3baro, ep4, astar1, astar2 = ans - return ans - - def interpolate_fields_direct_inversion_old(self): - - """ - Interpolate zonal wind, maridional wind, and potential temperature field onto the uniform pseudoheight grids, - and compute QGPV on the same grids. This returns named tuple called "Interpolated_fields" that consists of - 5 elements as listed below. - - Returns - ------- - QGPV : numpy.ndarray - Three-dimensional array of quasi-geostrophic potential vorticity (QGPV) with dimension = [kmax, nlat, nlon] - - U : numpy.ndarray - Three-dimensional array of interpolated zonal wind with dimension = [kmax, nlat, nlon] - - V : numpy.ndarray - Three-dimensional array of interpolated meridional wind with dimension = [kmax, nlat, nlon] - - Theta : numpy.ndarray - Three-dimensional array of interpolated potential temperature with dimension = [kmax, nlat, nlon] - - Static_stability : numpy.array - One-dimension array of interpolated static stability with dimension = kmax - - - Examples - -------- - - >>> interpolated_fields = test_object.interpolate_fields() - >>> interpolated_fields.QGPV # This is to access the QGPV field - - """ - - if self._qref_ntemp is None: - - # === Interpolate fields and obtain qgpv === - self._qgpv_temp, \ - self._interpolated_u_temp, \ - self._interpolated_v_temp, \ - self._interpolated_avort_temp, \ - self._interpolated_theta_temp, \ - self._static_stability_n, \ - self._static_stability_s,\ - self._tn0, \ - self._ts0 = \ - interpolate_fields_direct_inv( - np.swapaxes(self.u_field, 0, 2), - np.swapaxes(self.v_field, 0, 2), - np.swapaxes(self.t_field, 0, 2), - self.plev, - self.height, - self.planet_radius, - self.omega, - self.dz, - self.scale_height, - self.dry_gas_constant, - self.cp - ) - - self._qgpv = np.swapaxes(self._qgpv_temp, 0, 2) - self._interpolated_u = np.swapaxes(self._interpolated_u_temp, 0, 2) - self._interpolated_v = np.swapaxes(self._interpolated_v_temp, 0, 2) - self._interpolated_theta = np.swapaxes( - self._interpolated_theta_temp, 0, 2 - ) - - print(f"num of nan in statN = {np.count_nonzero(np.isnan(self._static_stability_n))}") - print(f"num of nan in avort zonal mean = {np.count_nonzero(np.isnan(self._interpolated_avort_temp))}") - # Construct a named tuple # TODO: add absolute vorticity here? But only after testing - Interpolated_fields = namedtuple( - 'Interpolated_fields', ['QGPV', 'U', 'V', 'Theta', 'Static_stability_N', 'Static_stability_S']) - interpolated_fields = Interpolated_fields( - self.qgpv, - self.interpolated_u, - self.interpolated_v, - self.interpolated_theta, - self._static_stability_n, - self._static_stability_s) - # TODO: static stability in southern hemisphere has nan values?! - return interpolated_fields - - # def compute_reference_states_direct_inversion(self, northern_hemisphere_results_only=True): - # """ - # Direct inversion algorithm for NHN GRL 2022 - # """ - # - # ans = compute_qref_fawa_and_bc( - # 5, - # 91, - # 91 - 5, - # self._qgpv_temp, - # self._interpolated_u_temp, - # self._interpolated_avort_temp, - # self._interpolated_theta_temp, - # self._static_stability_n, - # self._tn0, - # self.planet_radius, - # self.omega, - # self.dz, - # self.tol, # can remove - # self.scale_height, - # self.dry_gas_constant) - # - # self._f_qref, self._f_u, self._f_tref, self._f_ubar, self._f_tbar, self._f_fawa, self._f_ckref = ans - # - # return ans - - # def _compute_reference_states_direct_inversion_wrapper(self, qgpv, u, theta): - # return compute_reference_states( - # qgpv, - # u, - # theta, - # self._static_stability, - # self.equator_idx, - # self.npart, - # self.maxit, - # self.planet_radius, - # self.omega, - # self.dz, - # self.tol, - # self.scale_height, - # self.dry_gas_constant, - # self.cp, - # self.rjac, - # ) - def compute_reference_states(self, northern_hemisphere_results_only=False): """ @@ -1114,6 +761,157 @@ def compute_lwa_and_barotropic_fluxes(self, northern_hemisphere_results_only=Fal self.divergence_eddy_momentum_flux, self.meridional_heat_flux, self.lwa_baro, self.u_baro, self.lwa) return lwa_and_fluxes + # *** Added in Release 0.6.0 *** + # The following internal functions are used to compute results in NHN (2022, GRL): + # - _interpolate_field_dirinv + # - _compute_qref_fawa_and_bc + # - _compute_lwa_flux_dirinv + # They will be refactored in the upcoming releases. + def _interpolate_field_dirinv(self): + """ + Added for NHN 2022 GRL + :return: + """ + self._qgpv_temp, \ + self._interpolated_u_temp, \ + self._interpolated_v_temp, \ + self._interpolated_avort_temp, \ + self._interpolated_theta_temp, \ + self._static_stability_n, \ + self._static_stability_s,\ + self._tn0, self._ts0 = \ + interpolate_fields_direct_inv( + self.kmax, + self.nlat // 2 + self.nlat % 2, + np.swapaxes(self.u_field, 0, 2), + np.swapaxes(self.v_field, 0, 2), + np.swapaxes(self.t_field, 0, 2), + self.plev, + self.planet_radius, + self.omega, + self.dz, + self.scale_height, + self.dry_gas_constant, + self.cp) + + self._check_nan("self._qgpv_temp", self._qgpv_temp) + self._check_nan("self._interpolated_u_temp", self._interpolated_u_temp) + self._check_nan("self._interpolated_v_temp", self._interpolated_v_temp) + self._check_nan("self._interpolated_avort_temp", self._interpolated_avort_temp) + self._check_nan("self._interpolated_theta_temp", self._interpolated_theta_temp) + self._check_nan("self._static_stability_n", self._static_stability_n) + self._check_nan("self._static_stability_s", self._static_stability_s) + self._check_nan("self._tn0", self._tn0) + self._check_nan("self._ts0", self._ts0) + + return self._qgpv_temp, self._interpolated_u_temp, self._interpolated_v_temp, self._interpolated_avort_temp, \ + self._interpolated_theta_temp, self._static_stability_n, self._static_stability_s, self._tn0, self._ts0 + + @staticmethod + def _check_nan(name, var): + nan_num = np.count_nonzero(np.isnan(var)) + if nan_num > 0: + print(f"num of nan in {name}: {np.count_nonzero(np.isnan(var))}.") + + def _compute_qref_fawa_and_bc(self): + """ + Added for NHN 2022 GRL + :return: + """ + ans = compute_qref_and_fawa_first( + pv=self._qgpv_temp, + uu=self._interpolated_u_temp, + vort=self._interpolated_avort_temp, + pt=self._interpolated_theta_temp, + tn0=self._tn0, + ts0=self._ts0, + statn=self._static_stability_n, + stats=self._static_stability_s, + nd=91, + nnd=181, + jb=5, + jd=86) + qref_over_cor, u, ubar, tbar, fawa, ckref, tjk, sjk = ans # unpack tuple + + print("Line 535") + self._check_nan("qref_over_cor", qref_over_cor) + self._check_nan("u", u) + self._check_nan("ubar", ubar) + self._check_nan("tbar", tbar) + self._check_nan("fawa", fawa) + self._check_nan("ckref", ckref) + self._check_nan("tjk", tjk) + self._check_nan("sjk", sjk) + + for k in range(self.kmax-1, 1, -1): # Fortran indices + ans = matrix_b4_inversion( + k=k, + jmax=self.nlat, + jb=5, + jd=86, + z=np.arange(0, self.kmax*self.dz, self.dz), + statn=self._static_stability_n, + qref=qref_over_cor, + ckref=ckref, + a=self.planet_radius, + om=self.omega, + dz=self.dz, + h=self.scale_height, + rr=self.dry_gas_constant, + cp=self.cp, + u=u, + sjk=sjk, + tjk=tjk) + qjj, djj, cjj, rj, tj = ans + + # TODO: The inversion algorithm is the bottleneck of the computation + # SciPy is very slow compared to MKL in Fortran... + lu, piv, info = dgetrf(qjj) + qjj, info = dgetri(lu, piv) + + _ = matrix_after_inversion( + k=k, + jb=5, + qjj=qjj, + djj=djj, + cjj=cjj, + tj=tj, + rj=rj, + sjk=sjk, + tjk=tjk) + + tref, qref = upward_sweep( + jmax=self.nlat, + nnd=self.nlat, + jb=5, + sjk=sjk, + tjk=tjk, + ckref=ckref, + tb=self._tn0, + qref_over_cor=qref_over_cor, + u=u, + a=self.planet_radius, + om=self.omega, + dz=self.dz, + h=self.scale_height, + rr=self.dry_gas_constant, + cp=self.cp) + + return qref, u, tref, fawa, ubar, tbar # uref = u + + def _compute_lwa_flux_dirinv(self, qref, uref, tref, fawa, ubar, tbar): + """ + Added for NHN 2022 GRL + :return: + """ + ans = compute_flux_dirinv(pv=self._qgpv_temp, uu=self._interpolated_u_temp, vv=self._interpolated_v_temp, + pt=self._interpolated_theta_temp, tn0=self._tn0, ts0=self._ts0, + statn=self._static_stability_n, stats=self._static_stability_s, + qref=qref, uref=uref, tref=tref, fawa=fawa, ubar=ubar, tbar=tbar, + nnd=self.nlat, jb=5) + # astarbaro, ubaro, urefbaro, ua1baro, ua2baro, ep1baro, ep2baro, ep3baro, ep4, astar1, astar2 = ans + return ans + @property def qgpv(self): """ diff --git a/hn2016_falwa/upward_sweep.f90 b/hn2016_falwa/upward_sweep.f90 index 5ced5ca..beb0dde 100644 --- a/hn2016_falwa/upward_sweep.f90 +++ b/hn2016_falwa/upward_sweep.f90 @@ -17,7 +17,7 @@ SUBROUTINE upward_sweep(jmax, kmax, nd, nnd, jb, jd, sjk, tjk, ckref, tb, qref_o rkappa = rr/cp pi = acos(-1.) - dp = pi/180. + dp = pi/float(jmax-1) pjk(:,1) = 0. @@ -61,7 +61,7 @@ SUBROUTINE upward_sweep(jmax, kmax, nd, nnd, jb, jd, sjk, tjk, ckref, tb, qref_o ! ******** compute tref ******* qref(:, :) = qref_over_cor(:, :) ! modify for f2py wrapping purpose - do k = 2,96 + do k = 2,kmax-1 t00 = 0. zz = dz*float(k-1) tref(1,k) = t00 @@ -92,6 +92,6 @@ SUBROUTINE upward_sweep(jmax, kmax, nd, nnd, jb, jd, sjk, tjk, ckref, tb, qref_o tref(:,k) = tref(:,k)+tres enddo tref(:,1) = tref(:,2)-tb(2)+tb(1) - tref(:,97) = tref(:,96)-tb(96)+tb(97) + tref(:,kmax) = tref(:,kmax-1)-tb(kmax-1)+tb(kmax) END SUBROUTINE upward_sweep \ No newline at end of file diff --git a/scripts/nhn_grl2022/sample_run_script.py b/scripts/nhn_grl2022/sample_run_script.py index 0c60be5..32e5366 100644 --- a/scripts/nhn_grl2022/sample_run_script.py +++ b/scripts/nhn_grl2022/sample_run_script.py @@ -1,3 +1,8 @@ +""" +This script reproduces analysis results from Neal et al. GRL 2022 +'The 2021 Pacific Northwest heat wave and associated blocking: Meteorology and the role of an +upstream cyclone as a diabatic source of wave activity' +""" import os import sys import numpy as np @@ -99,7 +104,6 @@ ep4 = output_file.createVariable('ep4', np.dtype('float32').char, ('time', 'latitude', 'longitude')) ep4.units = 'm/s' - # --- Compute LWA + fluxes and save the data into netCDF file --- for tstep in range(ntimes): # or ntimes @@ -130,7 +134,9 @@ # --- Graph plotting for GRL2021 --- -# Location of data files +# *** Location of data files *** +# These data files consist of fields with 6-hour time resolution and 1 deg space resolution in both latitude +# and longitude. data_dir = "grl2021_data/" z_filename = data_dir + "2021_06_z.nc" # geopotential height u_filename = data_dir + "2021_06_u.nc" # u @@ -145,12 +151,12 @@ lwa_flux_filename = output_fname # Execute graph plotting functions -# plot_figure1a(z_filename, u_filename, v_filename) -# plot_figure1b(t_filename) -# plot_figure1c(t2m_filename) -# plot_figure1d_2a(t_filename) +plot_figure1a(z_filename, u_filename, v_filename) +plot_figure1b(t_filename) +plot_figure1c(t2m_filename) +plot_figure1d_2a(t_filename) plot_figure3_and_S1(lwa_flux_filename) -# plot_figure3e(mtnlwrf_filename, mtnlwrfcs_filename) -# plot_figure3f(tcw_filename, tcwv_filename, sp_filename) +plot_figure3e(mtnlwrf_filename, mtnlwrfcs_filename) +plot_figure3f(tcw_filename, tcwv_filename, sp_filename) plot_figure4(lwa_flux_filename) plot_figure5(lwa_flux_filename) From cb1366b986a7ac1aaf19cf462b8267fe8e3f3027 Mon Sep 17 00:00:00 2001 From: csyhuang Date: Thu, 17 Mar 2022 13:36:35 -0500 Subject: [PATCH 10/19] Revert "add back physical parameter as input parameter in compute_flux_dirinv.f90" --- hn2016_falwa/compute_flux_dirinv.f90 | 42 +++++++++++++++------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/hn2016_falwa/compute_flux_dirinv.f90 b/hn2016_falwa/compute_flux_dirinv.f90 index c9f703f..21f2c7e 100644 --- a/hn2016_falwa/compute_flux_dirinv.f90 +++ b/hn2016_falwa/compute_flux_dirinv.f90 @@ -1,12 +1,11 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fawa,ubar,tbar,& - imax, jmax, kmax, nd, nnd, jb, jd, aa, omega, dz, hh, rr, cp, prefac, & + imax, JMAX, kmax, nd, nnd, jb, jd,& astarbaro,ubaro,urefbaro,ua1baro,ua2baro,ep1baro,ep2baro,ep3baro,ep4,astar1,astar2) - INTEGER, INTENT(IN) :: imax, jmax, kmax, nd, nnd, jb, jd + INTEGER, INTENT(IN) :: imax, JMAX, kmax, nd, nnd, jb, jd REAL, INTENT(IN) :: pv(imax,jmax,kmax),uu(imax,jmax,kmax),vv(imax,jmax,kmax),pt(imax,jmax,kmax),& tn0(kmax),ts0(kmax),statn(kmax),stats(kmax),qref(nd,kmax),uref(jd,kmax),tref(jd,kmax),& fawa(nd,kmax),ubar(nd,kmax),tbar(nd,kmax) - REAL, INTENT(in) :: aa, omega, dz, hh, rr, cp, prefac REAL, INTENT(OUT) :: astarbaro(imax,nd),ubaro(imax,nd),urefbaro(nd),ua1baro(imax,nd),ua2baro(imax,nd),& ep1baro(imax,nd),ep2baro(imax,nd),ep3baro(imax,nd),ep4(imax,nd),astar1(imax,nd,kmax),astar2(imax,nd,kmax) @@ -17,13 +16,16 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa REAL :: z(kmax) REAL :: u(nd,kmax) + a = 6378000. pi = acos(-1.) - dp = pi/float(jmax-1) - rkappa = rr/cp - + om = 7.29e-5 + dp = pi/180. + dz = 500. + h = 7000. + r = 287. + rkappa = r/1004. ! *** Default values for boundary *** - !prefac = 6745.348 !jb = 5 !jd = 86 ! nd - lower bounding latitude @@ -46,9 +48,9 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ep2baro(:,:) = 0. ep3baro(:,:) = 0. ep4(:,:) = 0. - dc = dz/prefac + dc = dz/6745.348 - do k = 2,kmax-1 + do k = 2,96 zk = dz*float(k-1) do i = 1,imax do j = 6,nd-1 ! 5N and higher latitude @@ -80,7 +82,7 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ep1(i,j) = ep1(i,j)+0.5*vv(i,j+90,k)**2 !F3a+b ep11 = 0.5*(pt(i,j+90,k)-tref(j-5,k))**2 !F3c zz = dz*float(k-1) - ep11 = ep11*(r/hh)*exp(-rkappa*zz/hh) + ep11 = ep11*(r/h)*exp(-rkappa*zz/h) ep11 = ep11*2.*dz/(tg(k+1)-tg(k-1)) ep1(i,j) = ep1(i,j)-ep11 !F3 phip = dp*float(j) @@ -99,8 +101,8 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ! low-level meridional eddy heat flux if(k.eq.2) then ! (26) of SI-HN17 - ep41 = 2.*om*sin0*cos0*dz/prefac ! prefactor - ep42 = exp(-dz/hh)*vv(i,j+90,2)*(pt(i,j+90,2)-tref(j-5,2)) + ep41 = 2.*om*sin0*cos0*dz/6745.348 ! prefactor + ep42 = exp(-dz/h)*vv(i,j+90,2)*(pt(i,j+90,2)-tref(j-5,2)) ep42 = ep42/(tg(3)-tg(1)) ep43 = vv(i,j+90,1)*(pt(i,j+90,1)-tref(j-5,1)) ep43 = 0.5*ep43/(tg(2)-tg(1)) @@ -112,15 +114,15 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ! ******** Column average: (25) of SI-HN17 ******** astarbaro(:,:) = astarbaro(:,:)+(astar1(:,:,k) & - + astar2(:,:,k))*exp(-zk/hh)*dc - ua1baro(:,:) = ua1baro(:,:)+ua1(:,:)*exp(-zk/hh)*dc - ua2baro(:,:) = ua2baro(:,:)+ua2(:,:)*exp(-zk/hh)*dc - ep1baro(:,:) = ep1baro(:,:)+ep1(:,:)*exp(-zk/hh)*dc - ep2baro(:,:) = ep2baro(:,:)+ep2(:,:)*exp(-zk/hh)*dc - ep3baro(:,:) = ep3baro(:,:)+ep3(:,:)*exp(-zk/hh)*dc + + astar2(:,:,k))*exp(-zk/h)*dc + ua1baro(:,:) = ua1baro(:,:)+ua1(:,:)*exp(-zk/h)*dc + ua2baro(:,:) = ua2baro(:,:)+ua2(:,:)*exp(-zk/h)*dc + ep1baro(:,:) = ep1baro(:,:)+ep1(:,:)*exp(-zk/h)*dc + ep2baro(:,:) = ep2baro(:,:)+ep2(:,:)*exp(-zk/h)*dc + ep3baro(:,:) = ep3baro(:,:)+ep3(:,:)*exp(-zk/h)*dc do j = 6,nd ! ### yet to be multiplied by cosine - ubaro(:,j) = ubaro(:,j)+uu(:,j+90,k)*exp(-zk/hh)*dc - urefbaro(j) = urefbaro(j)+uref(j-5,k)*exp(-zk/hh)*dc + ubaro(:,j) = ubaro(:,j)+uu(:,j+90,k)*exp(-zk/h)*dc + urefbaro(j) = urefbaro(j)+uref(j-5,k)*exp(-zk/h)*dc enddo enddo From 48990060d6bde02ff32c102c7fe2a2d3310eb13a Mon Sep 17 00:00:00 2001 From: csyhuang Date: Thu, 17 Mar 2022 13:53:19 -0500 Subject: [PATCH 11/19] make physical parameters input variable --- hn2016_falwa/compute_flux_dirinv.f90 | 25 +++++++++++--------- hn2016_falwa/compute_qref_and_fawa_first.f90 | 6 ++--- hn2016_falwa/oopinterface.py | 14 +++++++++-- hn2016_falwa/upward_sweep.f90 | 2 +- scripts/nhn_grl2022/sample_run_script.py | 22 +++++++---------- 5 files changed, 38 insertions(+), 31 deletions(-) diff --git a/hn2016_falwa/compute_flux_dirinv.f90 b/hn2016_falwa/compute_flux_dirinv.f90 index 21f2c7e..e0bb13b 100644 --- a/hn2016_falwa/compute_flux_dirinv.f90 +++ b/hn2016_falwa/compute_flux_dirinv.f90 @@ -1,11 +1,13 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fawa,ubar,tbar,& - imax, JMAX, kmax, nd, nnd, jb, jd,& + imax, JMAX, kmax, nd, nnd, jb, jd, & + a, om, dz, h, rr, cp, prefac,& astarbaro,ubaro,urefbaro,ua1baro,ua2baro,ep1baro,ep2baro,ep3baro,ep4,astar1,astar2) INTEGER, INTENT(IN) :: imax, JMAX, kmax, nd, nnd, jb, jd REAL, INTENT(IN) :: pv(imax,jmax,kmax),uu(imax,jmax,kmax),vv(imax,jmax,kmax),pt(imax,jmax,kmax),& tn0(kmax),ts0(kmax),statn(kmax),stats(kmax),qref(nd,kmax),uref(jd,kmax),tref(jd,kmax),& fawa(nd,kmax),ubar(nd,kmax),tbar(nd,kmax) + REAL, INTENT(IN) :: a, om, dz, h, rr, cp, prefac REAL, INTENT(OUT) :: astarbaro(imax,nd),ubaro(imax,nd),urefbaro(nd),ua1baro(imax,nd),ua2baro(imax,nd),& ep1baro(imax,nd),ep2baro(imax,nd),ep3baro(imax,nd),ep4(imax,nd),astar1(imax,nd,kmax),astar2(imax,nd,kmax) @@ -16,14 +18,15 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa REAL :: z(kmax) REAL :: u(nd,kmax) - a = 6378000. + !a = 6378000. pi = acos(-1.) - om = 7.29e-5 - dp = pi/180. - dz = 500. - h = 7000. - r = 287. - rkappa = r/1004. + !om = 7.29e-5 + dp = pi/float(jmax-1) + !dz = 500. + !h = 7000. + !r = 287. + rkappa = rr/cp + !prefac = 6745.348 ! *** Default values for boundary *** !jb = 5 @@ -48,7 +51,7 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ep2baro(:,:) = 0. ep3baro(:,:) = 0. ep4(:,:) = 0. - dc = dz/6745.348 + dc = dz/prefac do k = 2,96 zk = dz*float(k-1) @@ -82,7 +85,7 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ep1(i,j) = ep1(i,j)+0.5*vv(i,j+90,k)**2 !F3a+b ep11 = 0.5*(pt(i,j+90,k)-tref(j-5,k))**2 !F3c zz = dz*float(k-1) - ep11 = ep11*(r/h)*exp(-rkappa*zz/h) + ep11 = ep11*(rr/h)*exp(-rkappa*zz/h) ep11 = ep11*2.*dz/(tg(k+1)-tg(k-1)) ep1(i,j) = ep1(i,j)-ep11 !F3 phip = dp*float(j) @@ -101,7 +104,7 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ! low-level meridional eddy heat flux if(k.eq.2) then ! (26) of SI-HN17 - ep41 = 2.*om*sin0*cos0*dz/6745.348 ! prefactor + ep41 = 2.*om*sin0*cos0*dz/prefac ! prefactor ep42 = exp(-dz/h)*vv(i,j+90,2)*(pt(i,j+90,2)-tref(j-5,2)) ep42 = ep42/(tg(3)-tg(1)) ep43 = vv(i,j+90,1)*(pt(i,j+90,1)-tref(j-5,1)) diff --git a/hn2016_falwa/compute_qref_and_fawa_first.f90 b/hn2016_falwa/compute_qref_and_fawa_first.f90 index d22cf21..6947a31 100644 --- a/hn2016_falwa/compute_qref_and_fawa_first.f90 +++ b/hn2016_falwa/compute_qref_and_fawa_first.f90 @@ -1,12 +1,12 @@ SUBROUTINE compute_qref_and_fawa_first(pv, uu, vort, pt, tn0, ts0, statn, stats, imax, JMAX, kmax, nd, nnd, jb, jd, & - aa, omega, dz, h, rr, cp, & + a, omega, dz, h, rr, cp, & qref,u,ubar,tbar,fawa,ckref,tjk,sjk) !USE mkl95_LAPACK, ONLY: GETRF,GETRI INTEGER, INTENT(IN) :: imax, JMAX, kmax, nd, nnd, jb, jd - REAL, INTENT(in) :: aa, omega, dz, h, rr, cp + REAL, INTENT(in) :: a, omega, dz, h, rr, cp REAL, INTENT(IN) :: pv(imax,jmax,kmax),uu(imax,jmax,kmax),vort(imax,jmax,kmax),pt(imax,jmax,kmax),& stats(kmax),statn(kmax),ts0(kmax),tn0(kmax) REAL, INTENT(OUT) :: qref(nd,kmax),u(jd,kmax),ubar(nd,kmax),tbar(nd,kmax),fawa(nd,kmax),ckref(nd,kmax),& @@ -44,7 +44,7 @@ SUBROUTINE compute_qref_and_fawa_first(pv, uu, vort, pt, tn0, ts0, statn, stats, pi = acos(-1.) dp = pi/float(jmax-1) - rkappa = r/cp + rkappa = rr/cp do nn = 1,nd phi(nn) = dp*float(nn-1) diff --git a/hn2016_falwa/oopinterface.py b/hn2016_falwa/oopinterface.py index 0157cf7..0dd849d 100644 --- a/hn2016_falwa/oopinterface.py +++ b/hn2016_falwa/oopinterface.py @@ -818,6 +818,8 @@ def _compute_qref_fawa_and_bc(self): Added for NHN 2022 GRL :return: """ + # ans = compute_qref_and_fawa_first( + # pv, uu, vort, pt, tn0, ts0, statn, stats, nd, nnd, jb, jd, aa, omega, dz, h, rr, cp) ans = compute_qref_and_fawa_first( pv=self._qgpv_temp, uu=self._interpolated_u_temp, @@ -830,7 +832,14 @@ def _compute_qref_fawa_and_bc(self): nd=91, nnd=181, jb=5, - jd=86) + jd=86, + aa=self.planet_radius, + omega=self.omega, + dz=self.dz, + h=self.scale_height, + rr=self.dry_gas_constant, + cp=self.cp) + qref_over_cor, u, ubar, tbar, fawa, ckref, tjk, sjk = ans # unpack tuple print("Line 535") @@ -908,7 +917,8 @@ def _compute_lwa_flux_dirinv(self, qref, uref, tref, fawa, ubar, tbar): pt=self._interpolated_theta_temp, tn0=self._tn0, ts0=self._ts0, statn=self._static_stability_n, stats=self._static_stability_s, qref=qref, uref=uref, tref=tref, fawa=fawa, ubar=ubar, tbar=tbar, - nnd=self.nlat, jb=5) + nnd=self.nlat, jb=5, a=self.planet_radius, om=self.omega, dz=self.dz, + h=self.scale_height, rr=self.dry_gas_constant, cp=self.cp, prefac=6745.348) # astarbaro, ubaro, urefbaro, ua1baro, ua2baro, ep1baro, ep2baro, ep3baro, ep4, astar1, astar2 = ans return ans diff --git a/hn2016_falwa/upward_sweep.f90 b/hn2016_falwa/upward_sweep.f90 index beb0dde..009c5d6 100644 --- a/hn2016_falwa/upward_sweep.f90 +++ b/hn2016_falwa/upward_sweep.f90 @@ -4,7 +4,7 @@ SUBROUTINE upward_sweep(jmax, kmax, nd, nnd, jb, jd, sjk, tjk, ckref, tb, qref_o INTEGER, INTENT(IN) :: jmax, kmax, nd, nnd, jb, jd REAL, INTENT(IN) :: sjk(jd-2,jd-2,kmax-1),tjk(jd-2,kmax-1),ckref(nd,kmax),tb(kmax),qref_over_cor(nd,kmax) - REAL, INTENT(IN) :: rr, cp + REAL, INTENT(IN) :: a, om, dz, h, rr, cp REAL, INTENT(INOUT) :: u(jd,kmax) REAL, INTENT(OUT) :: qref(nd,kmax), tref(jd,kmax) real :: tg(kmax) diff --git a/scripts/nhn_grl2022/sample_run_script.py b/scripts/nhn_grl2022/sample_run_script.py index 32e5366..0c60be5 100644 --- a/scripts/nhn_grl2022/sample_run_script.py +++ b/scripts/nhn_grl2022/sample_run_script.py @@ -1,8 +1,3 @@ -""" -This script reproduces analysis results from Neal et al. GRL 2022 -'The 2021 Pacific Northwest heat wave and associated blocking: Meteorology and the role of an -upstream cyclone as a diabatic source of wave activity' -""" import os import sys import numpy as np @@ -104,6 +99,7 @@ ep4 = output_file.createVariable('ep4', np.dtype('float32').char, ('time', 'latitude', 'longitude')) ep4.units = 'm/s' + # --- Compute LWA + fluxes and save the data into netCDF file --- for tstep in range(ntimes): # or ntimes @@ -134,9 +130,7 @@ # --- Graph plotting for GRL2021 --- -# *** Location of data files *** -# These data files consist of fields with 6-hour time resolution and 1 deg space resolution in both latitude -# and longitude. +# Location of data files data_dir = "grl2021_data/" z_filename = data_dir + "2021_06_z.nc" # geopotential height u_filename = data_dir + "2021_06_u.nc" # u @@ -151,12 +145,12 @@ lwa_flux_filename = output_fname # Execute graph plotting functions -plot_figure1a(z_filename, u_filename, v_filename) -plot_figure1b(t_filename) -plot_figure1c(t2m_filename) -plot_figure1d_2a(t_filename) +# plot_figure1a(z_filename, u_filename, v_filename) +# plot_figure1b(t_filename) +# plot_figure1c(t2m_filename) +# plot_figure1d_2a(t_filename) plot_figure3_and_S1(lwa_flux_filename) -plot_figure3e(mtnlwrf_filename, mtnlwrfcs_filename) -plot_figure3f(tcw_filename, tcwv_filename, sp_filename) +# plot_figure3e(mtnlwrf_filename, mtnlwrfcs_filename) +# plot_figure3f(tcw_filename, tcwv_filename, sp_filename) plot_figure4(lwa_flux_filename) plot_figure5(lwa_flux_filename) From b8e1c4a6318d2cdc73a636b6b25c7579a924ed0f Mon Sep 17 00:00:00 2001 From: csyhuang Date: Thu, 17 Mar 2022 13:57:43 -0500 Subject: [PATCH 12/19] fix bugs --- hn2016_falwa/compute_qref_and_fawa_first.f90 | 4 ++-- hn2016_falwa/oopinterface.py | 2 +- scripts/nhn_grl2022/sample_run_script.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hn2016_falwa/compute_qref_and_fawa_first.f90 b/hn2016_falwa/compute_qref_and_fawa_first.f90 index 6947a31..7a9ff5a 100644 --- a/hn2016_falwa/compute_qref_and_fawa_first.f90 +++ b/hn2016_falwa/compute_qref_and_fawa_first.f90 @@ -184,9 +184,9 @@ SUBROUTINE compute_qref_and_fawa_first(pv, uu, vort, pt, tn0, ts0, statn, stats, phi0 = float(jj-1)*dp cos0 = cos(phi0) sin0 = sin(phi0) - tjk(j-1,kmax-1) = -dz*r*cos0*exp(-z(kmax-1)*rkappa/h) + tjk(j-1,kmax-1) = -dz*rr*cos0*exp(-z(kmax-1)*rkappa/h) tjk(j-1,kmax-1) = tjk(j-1,kmax-1)*(tbar(j+1,kmax)-tbar(j-1,kmax)) - tjk(j-1,kmax-1) = tjk(j-1,kmax-1)/(4.*om*sin0*dp*h*a) + tjk(j-1,kmax-1) = tjk(j-1,kmax-1)/(4.*omega*sin0*dp*h*a) sjk(j-1,j-1,kmax-1) = 1. enddo END diff --git a/hn2016_falwa/oopinterface.py b/hn2016_falwa/oopinterface.py index 0dd849d..6d8a9cd 100644 --- a/hn2016_falwa/oopinterface.py +++ b/hn2016_falwa/oopinterface.py @@ -833,7 +833,7 @@ def _compute_qref_fawa_and_bc(self): nnd=181, jb=5, jd=86, - aa=self.planet_radius, + a=self.planet_radius, omega=self.omega, dz=self.dz, h=self.scale_height, diff --git a/scripts/nhn_grl2022/sample_run_script.py b/scripts/nhn_grl2022/sample_run_script.py index 0c60be5..b4ca0fa 100644 --- a/scripts/nhn_grl2022/sample_run_script.py +++ b/scripts/nhn_grl2022/sample_run_script.py @@ -67,7 +67,7 @@ # --- Outputing files --- -output_fname = '2021-06-01_to_2021-06-30_output_aa0985.nc' +output_fname = '2021-06-01_to_2021-06-30_output_489900.nc' print(output_fname) if to_generate_data: output_file = Dataset(output_fname, 'w') From 881f341c08fbf2f527c73cadbb9e74feaf895e47 Mon Sep 17 00:00:00 2001 From: csyhuang Date: Thu, 17 Mar 2022 14:05:06 -0500 Subject: [PATCH 13/19] close to final touch-ups --- scripts/nhn_grl2022/sample_run_script.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/nhn_grl2022/sample_run_script.py b/scripts/nhn_grl2022/sample_run_script.py index b4ca0fa..f8b18f3 100644 --- a/scripts/nhn_grl2022/sample_run_script.py +++ b/scripts/nhn_grl2022/sample_run_script.py @@ -67,8 +67,10 @@ # --- Outputing files --- -output_fname = '2021-06-01_to_2021-06-30_output_489900.nc' +output_fname = '2021-06-01_to_2021-06-30_output_b8e1c4.nc' print(output_fname) + +# --- Generate analysis results --- if to_generate_data: output_file = Dataset(output_fname, 'w') output_file.createDimension('latitude',nlat//2+1) @@ -145,12 +147,12 @@ lwa_flux_filename = output_fname # Execute graph plotting functions -# plot_figure1a(z_filename, u_filename, v_filename) -# plot_figure1b(t_filename) -# plot_figure1c(t2m_filename) -# plot_figure1d_2a(t_filename) +plot_figure1a(z_filename, u_filename, v_filename) +plot_figure1b(t_filename) +plot_figure1c(t2m_filename) +plot_figure1d_2a(t_filename) plot_figure3_and_S1(lwa_flux_filename) -# plot_figure3e(mtnlwrf_filename, mtnlwrfcs_filename) -# plot_figure3f(tcw_filename, tcwv_filename, sp_filename) +plot_figure3e(mtnlwrf_filename, mtnlwrfcs_filename) +plot_figure3f(tcw_filename, tcwv_filename, sp_filename) plot_figure4(lwa_flux_filename) plot_figure5(lwa_flux_filename) From 30cf726e90edcf27968a13eb05a0a4d0156d9660 Mon Sep 17 00:00:00 2001 From: csyhuang Date: Thu, 17 Mar 2022 14:09:48 -0500 Subject: [PATCH 14/19] clear unused files --- scripts/nhn_grl2022/Fig1a.py | 11 - scripts/nhn_grl2022/Fig1b.py | 9 - scripts/nhn_grl2022/Fig1c.py | 8 - scripts/nhn_grl2022/Fig1d-Fig2.py | 133 -------- scripts/nhn_grl2022/Fig1d-Fig2a.py | 8 - scripts/nhn_grl2022/Fig2b.py | 59 ---- scripts/nhn_grl2022/Fig3a-d.py | 266 ---------------- scripts/nhn_grl2022/Fig3e.py | 10 - scripts/nhn_grl2022/Fig3f.py | 10 - scripts/nhn_grl2022/Fig4.py | 13 - scripts/nhn_grl2022/Fig5.py | 8 - scripts/nhn_grl2022/era1000.f90 | 435 -------------------------- scripts/nhn_grl2022/era4000n.f90 | 239 --------------- scripts/nhn_grl2022/era4000n_nc.f90 | 312 ------------------- scripts/nhn_grl2022/era4004n.f90 | 460 ---------------------------- 15 files changed, 1981 deletions(-) delete mode 100644 scripts/nhn_grl2022/Fig1a.py delete mode 100644 scripts/nhn_grl2022/Fig1b.py delete mode 100644 scripts/nhn_grl2022/Fig1c.py delete mode 100644 scripts/nhn_grl2022/Fig1d-Fig2.py delete mode 100644 scripts/nhn_grl2022/Fig1d-Fig2a.py delete mode 100644 scripts/nhn_grl2022/Fig2b.py delete mode 100644 scripts/nhn_grl2022/Fig3a-d.py delete mode 100644 scripts/nhn_grl2022/Fig3e.py delete mode 100644 scripts/nhn_grl2022/Fig3f.py delete mode 100644 scripts/nhn_grl2022/Fig4.py delete mode 100644 scripts/nhn_grl2022/Fig5.py delete mode 100644 scripts/nhn_grl2022/era1000.f90 delete mode 100644 scripts/nhn_grl2022/era4000n.f90 delete mode 100644 scripts/nhn_grl2022/era4000n_nc.f90 delete mode 100644 scripts/nhn_grl2022/era4004n.f90 diff --git a/scripts/nhn_grl2022/Fig1a.py b/scripts/nhn_grl2022/Fig1a.py deleted file mode 100644 index 30b2459..0000000 --- a/scripts/nhn_grl2022/Fig1a.py +++ /dev/null @@ -1,11 +0,0 @@ -#This script reads in netCDF data for ERA5 ==> Figure 1 Column a - -#----------------- -# read netCDF files -#----------------- -data_dir = "grl2021_data/" -z_filename = data_dir + "2021_06_z.nc" -u_filename = data_dir + "2021_06_u.nc" -v_filename = data_dir + "2021_06_v.nc" - - diff --git a/scripts/nhn_grl2022/Fig1b.py b/scripts/nhn_grl2022/Fig1b.py deleted file mode 100644 index 6559444..0000000 --- a/scripts/nhn_grl2022/Fig1b.py +++ /dev/null @@ -1,9 +0,0 @@ -#This script reads in netCDF data for ERA5 ==> Figure 1 column b - -#----------------- -# read netCDF files -#----------------- -data_dir = "grl2021_data/" -t_filename = data_dir + "2021_06_t.nc" - - diff --git a/scripts/nhn_grl2022/Fig1c.py b/scripts/nhn_grl2022/Fig1c.py deleted file mode 100644 index cd3ed7e..0000000 --- a/scripts/nhn_grl2022/Fig1c.py +++ /dev/null @@ -1,8 +0,0 @@ -#This script reads in netCDF data for ERA5 ==> Figure 1 Column c - -#----------------- -# read netCDF files -#----------------- -data_dir = "grl2021_data/" -t2m_filename = data_dir + "2021_06_2t.nc" - diff --git a/scripts/nhn_grl2022/Fig1d-Fig2.py b/scripts/nhn_grl2022/Fig1d-Fig2.py deleted file mode 100644 index 79713fd..0000000 --- a/scripts/nhn_grl2022/Fig1d-Fig2.py +++ /dev/null @@ -1,133 +0,0 @@ -# This is not used now. (March 16) -#This script reads in netCDF data for ERA5 -from netCDF4 import Dataset -import numpy as np -import matplotlib.pyplot as plot -import cartopy.crs as ccrs -from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter - -#----------------- -# read netCDF files -#----------------- - -data_dir = "grl2021_data/" -filename1 = data_dir + "2021_06_t.nc" - -ncin1 = Dataset(filename1, 'r', format='NETCDF4') - -tmean = ncin1.variables['t'] -tmean = (np.array(tmean)) - - -print(tmean.shape) - -ttheta = np.zeros((44,37,360)) -theta = np.zeros((37,360)) -p = np.zeros(37) -z = np.zeros(37) -p[36] = 1000. -p[35] = 975. -p[34] = 950. -p[33] = 925. -p[32] = 900. -p[31] = 875. -p[30] = 850. -p[29] = 825. -p[28] = 800. -p[27] = 775. -p[26] = 750. -p[25] = 700. -p[24] = 650. -p[23] = 600. -p[22] = 550. -p[21] = 500. -p[20] = 450. -p[19] = 400. -p[18] = 350. -p[17] = 200. -p[16] = 250. -p[15] = 225. -p[14] = 200. -p[13] = 175. -p[12] = 150. -p[11] = 125. -p[10] = 100. -p[9] = 70. -p[8] = 50. -p[7] = 30. -p[6] = 20. -p[5] = 10. -p[4] = 7. -p[3] = 5. -p[2] = 3. -p[1] = 2. -p[0] = 1. - -r = 287. -cp = 1004. -kappa = r/cp -m = 76 -while(m < 120): - k = 0 - while(k < 37): - z[36-k] = -8000.*np.log(p[k]/1000.) #pseudoheight - ttheta[m-76,36-k,:] = tmean[m,k,41,:] - ttheta[m-76,36-k,:] = ttheta[m-76,36-k,:]*np.power((1000./p[k]),kappa) # potential temp - k = k+1 - m = m+1 -day = ['00 UTC 20 June 2021','00 UTC 21 June 2021','00 UTC 22 June 2021','00 UTC 23 June 2021','00 UTC 24 June 2021','00 UTC 25 June 2021','00 UTC 26 June 2021','00 UTC 27 June 2021','00 UTC 28 June 2021','00 UTC 29 June 2021','00 UTC 30 June 2021'] -b = ['THETA_0620.png','THETA_0621.png','THETA_0622.png','THETA_0623.png','THETA_0624.png','THETA_0625.png','THETA_0626.png','THETA_0627.png','THETA_0628.png','THETA_0629.png','THETA_0630.png'] -n = 0 -while(n < 11): - nn = n*4 - theta[:,:]=ttheta[nn,:,:] - cl1 = np.arange(250,365,5) - x = np.arange(0,360) - plot.rcParams.update({'font.size':14,'text.usetex': False}) - fig = plot.figure(figsize=(8,4)) - ax5 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) - plot.xlim(140,280) - plot.ylim(0,10) - plot.title('49$^\circ$N '+day[n]) - plot.xlabel('Longitude') - plot.ylabel('pseudoheight (km)') - ax5.set_extent([-220, -80, 0, 10], ccrs.PlateCarree()) - ax5.set_aspect('auto', adjustable=None) - ax5.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) - ax5.set_yticks([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], crs=ccrs.PlateCarree()) - lon_formatter = LongitudeFormatter(zero_direction_label=True) - lat_formatter = LatitudeFormatter() - ax5.xaxis.set_major_formatter(lon_formatter) - ott = ax5.contourf(x,z/1000.,theta,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') - fig.colorbar(ott,ax=ax5,label='Kelvin') - ott = ax5.contour(x,z/1000.,theta,levels=cl1,transform=ccrs.PlateCarree(),colors='black',linewidths=0.5) - ott = ax5.contour(x,z/1000.,theta,levels=np.arange(320,325,5),transform=ccrs.PlateCarree(),colors='black',linewidths=1) - ax5.clabel(ott, ott.levels,fmt='%5i') - plot.savefig(b[n],bbox_inches='tight',dpi =600) - n = n+1 - -plot.rcParams.update({'font.size': 16}) -fig = plot.figure(figsize=(6,4)) -ax5.set_yticks([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) -plot.title('49$^\circ$N 119$^\circ$W 00 UTC') -plot.xlabel('Kelvin') -plot.ylabel('pseudoheight (km)') -plot.xlim(290,360) -plot.ylim(0,10) - -lcolor = np.array(['blue', 'red','green', 'black']) -lstyle = np.array(['dotted', 'dashed','dashdot', 'solid']) -lalpha = np.array([1,1,1,1]) -n = 2 -while(n < 6): - thetaz = np.zeros(37) - nn = n*8 - thetaz[:] = ttheta[nn,:,241] - i = 0 - while(i < 37): - if(z[i] < 1000.): - thetaz[i] = np.nan - i = i+1 - fig = plot.plot(thetaz,z/1000.,color=lcolor[n-2],linestyle = lstyle[n-2],alpha=lalpha[n-2]) - n = n+1 -plot.savefig('t_profile.png',bbox_inches='tight',dpi =600) \ No newline at end of file diff --git a/scripts/nhn_grl2022/Fig1d-Fig2a.py b/scripts/nhn_grl2022/Fig1d-Fig2a.py deleted file mode 100644 index f3ed239..0000000 --- a/scripts/nhn_grl2022/Fig1d-Fig2a.py +++ /dev/null @@ -1,8 +0,0 @@ -#This script reads in netCDF data for ERA5 ==> Figure 1 Column d + Figure 2 - -#----------------- -# read netCDF files -#----------------- -data_dir = "grl2021_data/" -t_filename = data_dir + "2021_06_t.nc" - diff --git a/scripts/nhn_grl2022/Fig2b.py b/scripts/nhn_grl2022/Fig2b.py deleted file mode 100644 index 8bf7df2..0000000 --- a/scripts/nhn_grl2022/Fig2b.py +++ /dev/null @@ -1,59 +0,0 @@ -#This script reads in netCDF data for ERA5 ==> Fig2b -from netCDF4 import Dataset -import numpy as np -import scipy.stats as stats -import matplotlib.pyplot as plot -import cartopy.crs as ccrs -import cartopy.feature as cf -from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter - -#----------------- -# read netCDF files -#----------------- -data_dir = "grl2021_data/" -filename3 = data_dir + "2021_06_str.nc" -filename5 = data_dir + "2021_06_ssr.nc" -filename6 = data_dir + "2021_06_sshf.nc" -filename7 = data_dir + "2021_06_slhf.nc" - - -ncin3 = Dataset(filename3, 'r', format='NETCDF4') -ncin5 = Dataset(filename5, 'r', format='NETCDF4') -ncin6 = Dataset(filename6, 'r', format='NETCDF4') -ncin7 = Dataset(filename7, 'r', format='NETCDF4') - - -irt = ncin3.variables["str"] -srad = ncin5.variables["ssr"] -shff = ncin6.variables["sshf"] -lhff = ncin7.variables["slhf"] - -irtt = np.zeros(720) -ssrad = np.zeros(720) -shf = np.zeros(720) -lhf = np.zeros(720) -zr = np.zeros(720) - -irtt[:] = irt[:,41,241]/3600. -ssrad[:] = srad[:,41,241]/3600. -shf[:] = shff[:,41,241]/3600. -lhf[:] = lhff[:,41,241]/3600. -zr[:] = 0. - -print() - -x = np.arange(0,720)/24.+1 - -plot.rcParams.update({'font.size': 16}) -fig = plot.figure(figsize=(8,4)) -plot.title('Surface Heat Fluxes at 49$^\circ$N 119$^\circ$W') -plot.xlabel('Day') -plot.ylabel('Flux (Wm$^{-2}$)') -plot.xlim(20,31) -plot.ylim(-800,1000) -fig = plot.plot(x,ssrad,color='red') -fig = plot.plot(x,irtt,'r--') -fig = plot.plot(x,shf,color='blue') -fig = plot.plot(x,lhf,'b--') -plot.savefig('surface_F.png',bbox_inches='tight',dpi =600) - diff --git a/scripts/nhn_grl2022/Fig3a-d.py b/scripts/nhn_grl2022/Fig3a-d.py deleted file mode 100644 index 53d86c5..0000000 --- a/scripts/nhn_grl2022/Fig3a-d.py +++ /dev/null @@ -1,266 +0,0 @@ -## This script reads in netCDF LWAb data for ERA5 -from netCDF4 import Dataset -import numpy as np -import matplotlib.pyplot as plot -import cartopy.crs as ccrs -from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter - -#----------------- -# read netCDF files -#----------------- - -data_dir = "grl2021_data/" -# filename0 = data_dir + "2021_06_LWAb_N.nc" -filename0 = "2021-06-01_to_2021-06-30_output.nc" - -ncin1 = Dataset(filename0, 'r', format='NETCDF4') - -lwa = ncin1.variables['lwa'] -lwa = (np.array(lwa)) - -#print(lwa.shape) - -z = np.zeros((91,360)) -z[:,:] = lwa[100,:,:]-lwa[76,:,:] # m = 100 is 00 UTC 26 June 2021, m = 76 is 00 UTC 20 June 2021 - -zs = np.zeros((91,360)) # smoothed z # - -#### smoothing in longitude #### -n = 5 # smoothing width # -j = 0 -while(j < 91): - zx = np.zeros(360) - zx[:] = z[j,:] - nn = -n - while(nn < n+1): - zy = np.roll(zx,nn) - zs[j,:] = zs[j,:] + zy[:]/(2*n+1) - nn = nn+1 - j = j+1 - - -cl2 = np.arange(-80,90,10) -x = np.arange(0,360) -y = np.arange(0,91) -plot.rcParams.update({'font.size':14}) -fig = plot.figure(figsize=(8,4)) -ax5 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) -plot.xlim(140,280) -plot.ylim(10,80) -plot.title('Column LWA Change June 20 - 26') -plot.xlabel('Longitude') -plot.ylabel('Latitude') -ax5.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) -ax5.coastlines(alpha = 0.3) -ax5.set_aspect('auto', adjustable=None) -ax5.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) -ax5.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) -lon_formatter = LongitudeFormatter(zero_direction_label=True) -lat_formatter = LatitudeFormatter() -ax5.xaxis.set_major_formatter(lon_formatter) -ax5.yaxis.set_major_formatter(lat_formatter) -ott = ax5.contourf(x,y,zs,levels=cl2,transform=ccrs.PlateCarree(),cmap='rainbow') -fig.colorbar(ott,ax=ax5,label='LWA (m/s)') -plot.savefig('dLWA.png',bbox_inches='tight',dpi =600) -#plot.show() - -filename1 = "2021-06-01_to_2021-06-30_output.nc" -filename2 = "2021-06-01_to_2021-06-30_output.nc" -filename3 = "2021-06-01_to_2021-06-30_output.nc" -filename4 = "2021-06-01_to_2021-06-30_output.nc" -filename5 = "2021-06-01_to_2021-06-30_output.nc" -filename6 = "2021-06-01_to_2021-06-30_output.nc" - -# filename1 = data_dir + "2021_06_ua1_N.nc" -# filename2 = data_dir + "2021_06_ua2_N.nc" -# filename3 = data_dir + "2021_06_ep1_N.nc" -# filename4 = data_dir + "2021_06_ep2_N.nc" -# filename5 = data_dir + "2021_06_ep3_N.nc" -# filename6 = data_dir + "2021_06_ep4_N.nc" - -ncin1 = Dataset(filename1, 'r', format='NETCDF4') -ua1 = ncin1.variables['ua1'] -ua1 = (np.array(ua1)) -ncin2 = Dataset(filename2, 'r', format='NETCDF4') -ua2 = ncin2.variables['ua2'] -ua2 = (np.array(ua2)) -ncin3 = Dataset(filename3, 'r', format='NETCDF4') -ep1 = ncin3.variables['ep1'] -ep1 = (np.array(ep1)) -ncin4 = Dataset(filename4, 'r', format='NETCDF4') -ep2 = ncin4.variables['ep2'] -ep2 = (np.array(ep2)) -ncin5 = Dataset(filename5, 'r', format='NETCDF4') -ep3 = ncin5.variables['ep3'] -ep3 = (np.array(ep3)) -ncin6 = Dataset(filename6, 'r', format='NETCDF4') -ep4 = ncin6.variables['ep4'] -ep4 = (np.array(ep4)) - -f1 = np.zeros((91,360)) -f2 = np.zeros((91,360)) -f11 = np.zeros((91,360)) -f22 = np.zeros((91,360)) - -z1 = np.zeros((91,360)) -z2 = np.zeros((91,360)) -z3 = np.zeros((91,360)) -dt = 3600.*6. -a = 6378000. -dl = 2.*np.pi/360. -dp = 2.*np.pi/360. -m = 76 # m = 76 is 20 June 2021 00 UTC -while(m < 100): # m = 100 is 26 June 2021 00 UTC - z3[:,:] = z3[:,:]+0.5*dt*ep4[m,:,:] - z3[:,:] = z3[:,:]+0.5*dt*ep4[m+1,:,:] - f1[:,:] = f1[:,:]+(0.5/24.)*(ua1[m,:,:]+ua2[m,:,:]+ep1[m,:,:]) - f1[:,:] = f1[:,:]+(0.5/24.)*(ua1[m+1,:,:]+ua2[m+1,:,:]+ep1[m+1,:,:]) - f11[:,:] = f11[:,:]+(0.5/24.)*(ua1[m-24,:,:]+ua2[m-24,:,:]+ep1[m-24,:,:]) - f11[:,:] = f11[:,:]+(0.5/24.)*(ua1[m-23,:,:]+ua2[m-23,:,:]+ep1[m-23,:,:]) - j = 0 - while(j < 90): - phi = dp*j - const = 0.5*dt/(2.*a*np.cos(phi)*dl) - z2[j,:]=z2[j,:]+const*(ep2[m,j,:]-ep3[m,j,:]) - z2[j,:]=z2[j,:]+const*(ep2[m+1,j,:]-ep3[m+1,j,:]) - f2[j,:] = f2[j,:]+(0.25/24.)*(ep2[m,j,:]+ep3[m,j,:])/np.cos(phi) - f2[j,:] = f2[j,:]+(0.25/24.)*(ep2[m+1,j,:]+ep3[m+1,j,:])/np.cos(phi) - f22[j,:] = f22[j,:]+(0.25/24.)*(ep2[m-24,j,:]+ep3[m-24,j,:])/np.cos(phi) - f22[j,:] = f22[j,:]+(0.25/24.)*(ep2[m-23,j,:]+ep3[m-23,j,:])/np.cos(phi) - i = 1 - while(i < 359): - z1[j,i] = z1[j,i]-const*(ua1[m,j,i+1]+ua2[m,j,i+1]+ep1[m,j,i+1]-ua1[m,j,i-1]-ua2[m,j,i-1]-ep1[m,j,i-1]) - z1[j,i] = z1[j,i]-const*(ua1[m+1,j,i+1]+ua2[m+1,j,i+1]+ep1[m+1,j,i+1]-ua1[m+1,j,i-1]-ua2[m+1,j,i-1]-ep1[m+1,j,i-1]) - i = i+1 - z1[j,0] = z1[j,0]-const*(ua1[m,j,1]+ua2[m,j,1]+ep1[m,j,1]-ua1[m,j,359]-ua2[m,j,359]-ep1[m,j,359]) - z1[j,0] = z1[j,0]-const*(ua1[m+1,j,1]+ua2[m+1,j,1]+ep1[m+1,j,1]-ua1[m+1,j,359]-ua2[m+1,j,359]-ep1[m+1,j,359]) - z1[j,359] = z1[j,359]-const*(ua1[m,j,0]+ua2[m,j,0]+ep1[m,j,0]-ua1[m,j,358]-ua2[m,j,358]-ep1[m,j,358]) - z1[j,359] = z1[j,359]-const*(ua1[m+1,j,0]+ua2[m+1,j,0]+ep1[m+1,j,0]-ua1[m+1,j,358]-ua2[m+1,j,358]-ep1[m+1,j,358]) - j = j+1 - m = m+1 - -z1s = np.zeros((91,360)) # smoothed z1 # -z2s = np.zeros((91,360)) # smoothed z2 # -z3s = np.zeros((91,360)) # smoothed z3 # - -#### smoothing in longitude #### -j = 0 -while(j < 91): - z1x = np.zeros(360) - z1x[:] = z1[j,:] - z2x = np.zeros(360) - z2x[:] = z2[j,:] - z3x = np.zeros(360) - z3x[:] = z3[j,:] - nn = -n - while(nn < n+1): - z1y = np.roll(z1x,nn) - z1s[j,:] = z1s[j,:] + z1y[:]/(2*n+1) - z2y = np.roll(z2x,nn) - z2s[j,:] = z2s[j,:] + z2y[:]/(2*n+1) - z3y = np.roll(z3x,nn) - z3s[j,:] = z3s[j,:] + z3y[:]/(2*n+1) - nn = nn+1 - j = j+1 - -##### Wind vectors ###### - -x1 = np.arange(0,24)*15.+5. -y1 = np.arange(0,30)*3. -xx,yy = np.meshgrid(x1,y1) -uu = np.zeros((30,24)) -vv = np.zeros((30,24)) - -j = 0 -while(j < 30): - i = 0 - while(i < 24): - uu[j,i] = f1[j*3,i*15+5]-f11[j*3,i*15+5] - vv[j,i] = f2[j*3,i*15+5]-f22[j*3,i*15+5] - i = i+1 - j = j+1 - -print(zs[49,242],z1s[49,242],z2s[49,242],z3s[49,242],zs[49,242]-z1s[49,242]-z2s[49,242]-z3s[49,242]) -print(z1s[60,248]+z2s[60,248]) - -cl1 = np.arange(-200,220,20) -x = np.arange(0,360) -y = np.arange(0,91) -plot.rcParams.update({'font.size':14}) -fig = plot.figure(figsize=(8,4)) -ax6 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) -#ax6 = fig.add_subplot(1,1,1) -plot.xlim(0,360) -plot.ylim(10,80) -plot.title('Integrated Terms (I)+(II) June 20 - 26') -plot.xlabel('Longitude') -plot.ylabel('Latitude') -ax6.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) -ax6.coastlines(alpha = 0.3) -ax6.set_aspect('auto', adjustable=None) -ax6.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) -ax6.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) -lon_formatter = LongitudeFormatter(zero_direction_label=True) -lat_formatter = LatitudeFormatter() -ax6.xaxis.set_major_formatter(lon_formatter) -ax6.yaxis.set_major_formatter(lat_formatter) -ott = ax6.contourf(x,y,z1s+z2s-0.1,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') -fig.colorbar(ott,ax=ax6,label='(m/s)') -ax6.quiver(xx,yy,uu,vv,transform=ccrs.PlateCarree()) -plot.savefig('divFx+Fy.png',bbox_inches='tight',dpi =600) -#plot.show() - -cl1 = np.arange(-200,220,20) -x = np.arange(0,360) -y = np.arange(0,91) -plot.rcParams.update({'font.size':14}) -fig = plot.figure(figsize=(8,4)) -ax6 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) -plot.xlim(0,360) -plot.ylim(10,80) -plot.title('Integrated Term (III) June 20 - 26') -plot.xlabel('Longitude') -plot.ylabel('Latitude') -ax6.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) -ax6.coastlines(alpha = 0.3) -ax6.set_aspect('auto', adjustable=None) -ax6.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) -ax6.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) -lon_formatter = LongitudeFormatter(zero_direction_label=True) -lat_formatter = LatitudeFormatter() -ax6.xaxis.set_major_formatter(lon_formatter) -ax6.yaxis.set_major_formatter(lat_formatter) -ott = ax6.contourf(x,y,z3s,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') -fig.colorbar(ott,ax=ax6,label='(m/s)') -#ax6.quiver(xx,yy,uu,vv,transform=ccrs.PlateCarree()) -plot.savefig('EP4.png',bbox_inches='tight',dpi =600) -#plot.show() - -cl1 = np.arange(-200,220,20) -x = np.arange(0,360) -y = np.arange(0,91) -plot.rcParams.update({'font.size':14}) -fig = plot.figure(figsize=(8,4)) -ax6 = fig.add_subplot(1,1,1,projection=ccrs.PlateCarree(180)) -plot.xlim(0,360) -plot.ylim(10,80) -plot.title('Integrated Term (IV) June 20 - 26') -plot.xlabel('Longitude') -plot.ylabel('Latitude') -ax6.set_extent([-220, -80, 10, 80], ccrs.PlateCarree()) -ax6.coastlines(alpha = 0.3) -ax6.set_aspect('auto', adjustable=None) -ax6.set_xticks([140,160,180,200,220,240,260,280], crs=ccrs.PlateCarree()) -ax6.set_yticks([10, 20, 30, 40, 50, 60, 70, 80], crs=ccrs.PlateCarree()) -lon_formatter = LongitudeFormatter(zero_direction_label=True) -lat_formatter = LatitudeFormatter() -ax6.xaxis.set_major_formatter(lon_formatter) -ax6.yaxis.set_major_formatter(lat_formatter) -ott = ax6.contourf(x,y,zs-z1s-z2s-z3s,levels=cl1,transform=ccrs.PlateCarree(),cmap='rainbow') -fig.colorbar(ott,ax=ax6,label='(m/s)') -ax6.quiver(xx,yy,uu,vv,transform=ccrs.PlateCarree()) -plot.savefig('Residual.png',bbox_inches='tight',dpi =600) -#plot.show() - - - diff --git a/scripts/nhn_grl2022/Fig3e.py b/scripts/nhn_grl2022/Fig3e.py deleted file mode 100644 index 9bb728d..0000000 --- a/scripts/nhn_grl2022/Fig3e.py +++ /dev/null @@ -1,10 +0,0 @@ -#This script reads in netCDF data for ERA5 ==> Figure 3e - -#----------------- -# read netCDF files -#----------------- - -mtnlwrf_filename = "2021_06_mtnlwrf.nc" # net OLR -mtnlwrfcs_filename = "2021_06_mtnlwrfcs.nc" # OLR clear sky - - diff --git a/scripts/nhn_grl2022/Fig3f.py b/scripts/nhn_grl2022/Fig3f.py deleted file mode 100644 index 277fba8..0000000 --- a/scripts/nhn_grl2022/Fig3f.py +++ /dev/null @@ -1,10 +0,0 @@ -#This script reads in netCDF data for ERA5 ==> Figure 3f - -#----------------- -# read netCDF files -#----------------- - -tcw_filename = "2021_06_tcw.nc" # total column water (kg/m^2) -tcwv_filename = "2021_06_tcwv.nc" # total column water vapor (kg/m^2) -sp_filename = "2021_06_sp.nc" # sea level pressure (hPa) - diff --git a/scripts/nhn_grl2022/Fig4.py b/scripts/nhn_grl2022/Fig4.py deleted file mode 100644 index dc0c800..0000000 --- a/scripts/nhn_grl2022/Fig4.py +++ /dev/null @@ -1,13 +0,0 @@ -## This script reads in netCDF LWAb data for ERA5 ==> Figure4 - - -#----------------- -# read netCDF files -#----------------- - -lwa_flux_filename = "2021_06_LWAb_N.nc" - - - - - diff --git a/scripts/nhn_grl2022/Fig5.py b/scripts/nhn_grl2022/Fig5.py deleted file mode 100644 index e23fc13..0000000 --- a/scripts/nhn_grl2022/Fig5.py +++ /dev/null @@ -1,8 +0,0 @@ -## This script reads in netCDF LWAb data for ERA5 and perform variation in wave forcing ==> Fig5 - -#----------------- -# read netCDF files -#----------------- - -lwa_flux_filename = "2021_06_LWAb_N.nc" - diff --git a/scripts/nhn_grl2022/era1000.f90 b/scripts/nhn_grl2022/era1000.f90 deleted file mode 100644 index 2384c41..0000000 --- a/scripts/nhn_grl2022/era1000.f90 +++ /dev/null @@ -1,435 +0,0 @@ - Program era - -! Read ERA5 binary files and computes QG fields. -! *** 6 hourly data *** - - integer,parameter :: kmax = 97 - character*30 :: file1,file2,file3,file4,file5 - character*34 :: file6 - character*33 :: file7 - character*32 :: file8,file9,file10,file11,file12 - character*30 :: fn - - common /arry/ tt(360,181,37),tzd(181,kmax) - common /crry/ uu(360,181,37) - common /drry/ vv(360,181,37) - common /brry/ ww(360,181,37) - common /erry/ zz(360,181,37) - common /brry/ xlon(360),ylat(181),plev(37) - common /frry/ height(kmax),statn(kmax),stats(kmax) - common /ffry/ ts0(kmax),tn0(kmax),zlev(37) - common /grry/ st(360,181),zmst(181),uq(360,181,kmax) - common /irry/ vq(360,181,kmax) - common /jrry/ wq(360,181,kmax) - common /krry/ tq(360,181,kmax) - common /lrry/ zq(360,181,kmax) - common /hhry/ tt0(360,181,kmax) - common /irry/ avort(360,181,kmax),zmav(181,kmax) - common /jrry/ pv(360,181,kmax),zmpv(181,kmax) - integer :: dsadata,mm(12),inverse(12,37) - integer :: k0(kmax),kp(kmax) - real :: dd2(kmax),dd1(kmax),pks(kmax) - character*5 :: yy - character*4 :: y0(44),y00 - character*3 :: mn(12) - character*8 :: yr - - y0(1) = '1978' - y0(2) = '1979' - y0(3) = '1980' - y0(4) = '1981' - y0(5) = '1982' - y0(6) = '1983' - y0(7) = '1984' - y0(8) = '1985' - y0(9) = '1986' - y0(10) = '1987' - y0(11) = '1988' - y0(12) = '1989' - y0(13) = '1990' - y0(14) = '1991' - y0(15) = '1992' - y0(16) = '1993' - y0(17) = '1994' - y0(18) = '1995' - y0(19) = '1996' - y0(20) = '1997' - y0(21) = '1998' - y0(22) = '1999' - y0(23) = '2000' - y0(24) = '2001' - y0(25) = '2002' - y0(26) = '2003' - y0(27) = '2004' - y0(28) = '2005' - y0(29) = '2006' - y0(30) = '2007' - y0(31) = '2008' - y0(32) = '2009' - y0(33) = '2010' - y0(34) = '2011' - y0(35) = '2012' - y0(36) = '2013' - y0(37) = '2014' - y0(38) = '2015' - y0(39) = '2016' - y0(40) = '2017' - y0(41) = '2018' - y0(42) = '2019' - y0(43) = '2020' - y0(44) = '2021' - - dz = 500. - cp = 1004. - rr = 287. - rkappa = rr/cp - grav = 9.81 - pi = acos(-1.) - omega = 7.29e-5 - aa = 6378000. - dphi = pi/180. - hh = 7000. - -! ====== Assign pseudoheight ===== - - do k = 1,kmax - height(k) = float(k-1)*dz - pks(k) = exp(rkappa*height(k)/hh) - enddo - - do mmm = 44,44 - mf = 28 ! 29 for leap year - if(mod(mmm,4).eq.3) mf = 29 - y00 = y0(mmm) - yy = y00//'_' ! Year to extract - mm(1) = 31 - mm(2) = mf ! Adjust for leap years - mm(3) = 31 - mm(4) = 30 - mm(5) = 31 - mm(6) = 30 - mm(7) = 31 - mm(8) = 31 - mm(9) = 30 - mm(10) = 31 - mm(11) = 30 - mm(12) = 31 - - mn(1) = '01_' - mn(2) = '02_' - mn(3) = '03_' - mn(4) = '04_' - mn(5) = '05_' - mn(6) = '06_' - mn(7) = '07_' - mn(8) = '08_' - mn(9) = '09_' - mn(10) = '10_' - mn(11) = '11_' - mn(12) = '12_' - - plev(1) = 1000. - plev(2) = 975. - plev(3) = 950. - plev(4) = 925. - plev(5) = 900. - plev(6) = 875. - plev(7) = 850. - plev(8) = 825. - plev(9) = 800. - plev(10) = 775. - plev(11) = 750. - plev(12) = 700. - plev(13) = 650. - plev(14) = 600. - plev(15) = 550. - plev(16) = 500. - plev(17) = 450. - plev(18) = 400. - plev(19) = 350. - plev(20) = 300. - plev(21) = 250. - plev(22) = 225. - plev(23) = 200. - plev(24) = 175. - plev(25) = 150. - plev(26) = 125. - plev(27) = 100. - plev(28) = 70. - plev(29) = 50. - plev(30) = 30. - plev(31) = 20. - plev(32) = 10. - plev(33) = 7. - plev(34) = 4. - plev(35) = 3. - plev(36) = 2. - plev(37) = 1. - - do k = 1,37 - zlev(k) = -hh*alog(plev(k)/1000.) - enddo - do kk = 2,kmax ! vertical interpolation - ttt = height(kk) - do k = 1,36 - tt2 = zlev(k+1) - tt1 = zlev(k) - if((ttt.ge.tt1).and.(ttt.lt.tt2)) then - k0(kk) = k - kp(kk) = k+1 - dd1(kk) = (ttt-tt1)/(tt2-tt1) - dd2(kk) = 1.-dd1(kk) - endif - enddo - enddo - -do m = 11,11 - - nn = mm(m)*4 - yr = yy//mn(m) - - file1 = '/data2/nnn/ERA5/'//y00//'/'//yr//'U' - file2 = '/data2/nnn/ERA5/'//y00//'/'//yr//'V' - file3 = '/data2/nnn/ERA5/'//y00//'/'//yr//'W' - file4 = '/data2/nnn/ERA5/'//y00//'/'//yr//'T' - file5 = '/data2/nnn/ERA5/'//y00//'/'//yr//'Z' - file6 = '/data2/nnn/ERA5/'//y00//'/'//yr//'QVORT' - file7 = '/data2/nnn/ERA5/'//y00//'/'//yr//'QGPV' - file8 = '/data2/nnn/ERA5/'//y00//'/'//yr//'QGU' - file9 = '/data2/nnn/ERA5/'//y00//'/'//yr//'QGV' - file10 = '/data2/nnn/ERA5/'//y00//'/'//yr//'QGW' - file11 = '/data2/nnn/ERA5/'//y00//'/'//yr//'QGT' - file12 = '/data2/nnn/ERA5/'//y00//'/'//yr//'QGZ' - - open(31,file=file1,form='unformatted',status='old') - open(32,file=file2,form='unformatted',status='old') - open(33,file=file3,form='unformatted',status='old') - open(34,file=file4,form='unformatted',status='old') - open(35,file=file5,form='unformatted',status='old') - open(36,file=file6,form='unformatted',status='new') - open(37,file=file7,form='unformatted',status='new') - open(38,file=file8,form='unformatted',status='new') - open(39,file=file9,form='unformatted',status='new') - open(40,file=file10,form='unformatted',status='new') - open(41,file=file11,form='unformatted',status='new') - open(42,file=file12,form='unformatted',status='new') - -do l = 1,nn - - read(31) uu - read(32) vv - read(33) ww - read(34) tt - read(35) zz - -! ==== vertical interpolation ==== - - do i = 1,360 - do j = 1,181 - - st(i,j) = tt(i,j,1) ! surface pot. temp - - do kk = 2,kmax ! vertical interpolation - uq(i,j,kk) = uu(i,j,k0(kk))*dd2(kk) + uu(i,j,kp(kk))*dd1(kk) - vq(i,j,kk) = vv(i,j,k0(kk))*dd2(kk) + vv(i,j,kp(kk))*dd1(kk) - wq(i,j,kk) = ww(i,j,k0(kk))*dd2(kk) + ww(i,j,kp(kk))*dd1(kk) - tq(i,j,kk) = tt(i,j,k0(kk))*dd2(kk) + tt(i,j,kp(kk))*dd1(kk) - tq(i,j,kk) = tq(i,j,kk)*pks(kk) ! potential temperature - zq(i,j,kk) = zz(i,j,k0(kk))*dd2(kk) + zz(i,j,kp(kk))*dd1(kk) - enddo - - tq(i,j,1) = tt(i,j,1) - uq(i,j,1) = uu(i,j,1) - vq(i,j,1) = vv(i,j,1) - wq(i,j,1) = ww(i,j,1) - zq(i,j,1) = zz(i,j,1) - enddo - enddo - -! **** compute zonal mean **** - - tzd = 0. - - do j = 1,181 - do k = 1,kmax - do i = 1,360 - tzd(j,k) = tzd(j,k) + tq(i,j,k)/360. - enddo - enddo - enddo - - -! reference theta - do kk = 1,kmax - ts0(kk) = 0. - tn0(kk) = 0. - csm = 0. - cnm = 0. - do j = 1,91 - phi0 = -90.+float(j-1) - phi0 = phi0*pi/180. - ts0(kk) = ts0(kk) + tzd(j,kk)*cos(phi0) - csm = csm + cos(phi0) - enddo - ts0(kk) = ts0(kk)/csm - do j = 91,181 - phi0 = -90.+float(j-1) - phi0 = phi0*pi/180. - tn0(kk) = tn0(kk) + tzd(j,kk)*cos(phi0) - cnm = cnm + cos(phi0) - enddo - tn0(kk) = tn0(kk)/cnm - enddo - -! static stability - do kk = 2,kmax-1 - stats(kk) = (ts0(kk+1)-ts0(kk-1))/(height(kk+1)-height(kk-1)) - statn(kk) = (tn0(kk+1)-tn0(kk-1))/(height(kk+1)-height(kk-1)) - enddo - stats(kmax) = 2.*stats(kmax-1)-stats(kmax-2) - statn(kmax) = 2.*statn(kmax-1)-statn(kmax-2) - stats(1) = 2.*stats(2)-stats(3) - statn(1) = 2.*statn(2)-statn(3) - -! surface temp - - do j = 1,181 - zmst(j) = 0. - do i = 1,360 - zmst(j) = zmst(j) + st(i,j)/360. - enddo - enddo - -! interior abs. vort - - do kk = 1,kmax - do j = 2,180 - phi0 = -90.+float(j-1) - phi0 = phi0*pi/180. - phim = -90.+float(j-2) - phim = phim*pi/180. - phip = -90.+float(j) - phip = phip*pi/180. - - do i = 2,359 - av1 = 2.*omega*sin(phi0) - av2 = (vq(i+1,j,kk)-vq(i-1,j,kk))/(2.*aa*cos(phi0)*dphi) - av3 = -(uq(i,j+1,kk)*cos(phip)-uq(i,j-1,kk)*cos(phim))/(2.*aa*cos(phi0)*dphi) - avort(i,j,kk) = av1+av2+av3 - enddo - - av1 = 2.*omega*sin(phi0) - av2 = (vq(2,j,kk)-vq(360,j,kk))/(2.*aa*cos(phi0)*dphi) - av3 = -(uq(1,j+1,kk)*cos(phip)-uq(1,j-1,kk)*cos(phim))/(2.*aa*cos(phi0)*dphi) - avort(1,j,kk) = av1+av2+av3 - av4 = 2.*omega*sin(phi0) - av5 = (vq(1,j,kk)-vq(359,j,kk))/(2.*aa*cos(phi0)*dphi) - av6 = & --(uq(360,j+1,kk)*cos(phip)-uq(360,j-1,kk)*cos(phim))/(2.*aa*cos(phi0)*dphi) - avort(360,j,kk) = av4+av5+av6 - enddo - - avs = 0. - avn = 0. - do i = 1,360 - avs = avs + avort(i,2,kk)/360. - avn = avn + avort(i,180,kk)/360. - enddo - avort(:,1,kk) = avs - avort(:,181,kk) = avn - enddo - -! zonal mean vort - - do kk = 1,kmax - do j = 1,181 - zmav(j,kk) = 0. - do i = 1,360 - zmav(j,kk) = zmav(j,kk)+avort(i,j,kk)/360. - enddo - enddo - enddo - -! interior pv - - do kk = 2,kmax-1 - do j = 1,181 - phi0 = -90.+float(j-1) - phi0 = phi0*pi/180. - f = 2.*omega*sin(phi0) - if(j.le.91) then - statp = stats(kk+1) - statm = stats(kk-1) - t00p = ts0(kk+1) - t00m = ts0(kk-1) - else - statp = statn(kk+1) - statm = statn(kk-1) - t00p = tn0(kk+1) - t00m = tn0(kk-1) - endif - - do i = 1,360 - thetap = tq(i,j,kk+1) - thetam = tq(i,j,kk-1) - altp = exp(-height(kk+1)/hh)*(thetap-t00p)/statp - altm = exp(-height(kk-1)/hh)*(thetam-t00m)/statm - strc = (altp-altm)*f/(height(kk+1)-height(kk-1)) - pv(i,j,kk) = avort(i,j,kk) + exp(height(kk)/hh)*strc - enddo - enddo - enddo - -! zonal mean pv - - do kk = 1,kmax - do j = 1,181 - zmpv(j,kk) = 0. - do i = 1,360 - zmpv(j,kk) = zmpv(j,kk)+pv(i,j,kk)/360. - enddo - enddo - enddo - - write(36) avort - write(37) pv - write(38) uq - write(39) vq - write(40) wq - write(41) tq,tn0,ts0,statn,stats - write(42) zq - !write(40) tt0,ts0,tn0,stats,statn - - -!hape(1) = 121 -!hape(2) = 37 -!fn = '/data/nnn/ERA_Interim/'//yr -! ret = dsadata(fn//'uz.df',2,shape,uz) -! ret = dsadata(fn//'vz.df',2,shape,vz) -! ret = dsadata(fn//'tz.df',2,shape,tz) -! ret = dsadata(fn//'zz.df',2,shape,zzz) - - write(6,*) 'month =',m,' file =',l -enddo - close(31) - close(32) - close(33) - close(34) - close(35) - close(36) - close(37) - close(38) - close(39) - close(40) - close(41) - close(42) - -enddo -enddo - -!do k = 1,kmax -! write(6,*) k,height(k),statn(k),stats(k) -!enddo - -stop -end diff --git a/scripts/nhn_grl2022/era4000n.f90 b/scripts/nhn_grl2022/era4000n.f90 deleted file mode 100644 index e07fbd3..0000000 --- a/scripts/nhn_grl2022/era4000n.f90 +++ /dev/null @@ -1,239 +0,0 @@ - program main - -! **** take QGPV and compute LWA and fluxes for -! NH *** -! Only barotropic fluxes are saved - - integer,parameter :: imax = 360, JMAX = 181, KMAX = 97 - integer,parameter :: nd = 91,nnd=181,jd = 86 - common /array/ pv(imax,jmax,kmax) - common /brray/ uu(imax,jmax,kmax) - common /bbray/ vv(imax,jmax,kmax) - common /bcray/ pt(imax,jmax,kmax) - common /bdray/ stats(kmax),statn(kmax),ts0(kmax),tn0(kmax) - common /crray/ tb(kmax),tg(kmax) - common /erray/ astar1(imax,nd,kmax) - common /errayy/ astar2(imax,nd,kmax) - common /errayx/ ua1(imax,nd),ua2(imax,nd),ep1(imax,nd) - common /frrayx/ ep2(imax,nd),ep3(imax,nd) - common /errayz/ qe(imax,nd),ue(imax,nd) - common /frray/ z(kmax),ep4(imax,nd) - common /grray/ ubaro(imax,nd),urefbaro(nd),astarbaro(imax,nd) - common /hrray/ ua1baro(imax,nd),ua2baro(imax,nd) - common /hrray/ ep1baro(imax,nd),ep2baro(imax,nd) - common /hrray/ ep3baro(imax,nd) - common /irray/ qref(91,kmax),u(91,kmax) - common /jrray/ qbar(91,kmax),ubar(91,kmax),tbar(91,kmax) - common /krray/ uref(jd,kmax),tref(jd,kmax),fawa(91,kmax) - integer :: md(12) - - character*35 fn,fn0,fn1 - character*34 fu - character*34 ft,fv - character*38 fx - character*4 fn2(12),fy,fy1,fy2 - character*18 f1,f2 - character*19 f3 - character*36 fr - character*37 fm - - a = 6378000. - pi = acos(-1.) - om = 7.29e-5 - dp = pi/180. - dz = 500. - h = 7000. - r = 287. - rkappa = r/1004. - - do k = 1,kmax - z(k) = dz*float(k-1) - enddo - - do m = 2021,2021 - - md(1) = 31 - md(2) = 28 - if(mod(m,4).eq.0) md(2) = 29 - md(3) = 31 - md(4) = 30 - md(5) = 31 - md(6) = 30 - md(7) = 31 - md(8) = 31 - md(9) = 30 - md(10) = 31 - md(11) = 30 - md(12) = 31 - - fn2(1) = '_01_' - fn2(2) = '_02_' - fn2(3) = '_03_' - fn2(4) = '_04_' - fn2(5) = '_05_' - fn2(6) = '_06_' - fn2(7) = '_07_' - fn2(8) = '_08_' - fn2(9) = '_09_' - fn2(10) = '_10_' - fn2(11) = '_11_' - fn2(12) = '_12_' - - write(fy,266) m - 266 format(i4) - - do n = 10,10 - fn = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGPV' - fu = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGU' - ft = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGT' - fv = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGV' - fx = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGREF_N' - fr = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'LWA_N' - fm = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'BARO_N' - write(6,*) fn,md(n) - open(35,file =fn, & - form='unformatted',status = 'old') - open(36,file =fu, & - form='unformatted',status = 'old') - open(37,file =ft, & - form='unformatted',status = 'old') - open(38,file =fr, & - form='unformatted',status = 'new') - open(39,file =fv, & - form='unformatted',status = 'old') - open(40,file =fx, & - form='unformatted',status = 'old') - open(41,file =fm, & - form='unformatted',status = 'new') - - do mm = 1,md(n)*4 - - read(35) pv - read(36) uu - read(39) vv - read(37) pt,tn0,ts0,statn,stats - read(40) qref,uref,tref,fawa,ubar,tbar - - -! **** hemispheric-mean potential temperature **** - tg(:) = tn0(:) - -! **** wave activity and nonlinear zonal flux F2 **** - - astarbaro(:,:) = 0. - ubaro(:,:) = 0. - urefbaro(:) = 0. - ua1baro(:,:) = 0. - ua2baro(:,:) = 0. - ep1baro(:,:) = 0. - ep2baro(:,:) = 0. - ep3baro(:,:) = 0. - ep4(:,:) = 0. - dc = dz/6745.348 - - do k = 2,96 - zk = dz*float(k-1) - do i = 1,imax - do j = 6,nd-1 ! 5N and higher latitude - astar1(i,j,k) = 0. ! LWA*cos(phi) - astar2(i,j,k) = 0. ! LWA*cos(phi) - ua2(i,j) = 0. !F2 - phi0 = dp*float(j-1) !latitude - cor = 2.*om*sin(phi0) !Coriolis parameter - do jj = 1,nd - phi1 = dp*float(jj-1) - qe(i,jj) = pv(i,jj+90,k)-qref(j,k) !qe; Q = qref - ue(i,jj) = uu(i,jj+90,k)-uref(j-5,k) !ue; shift uref 5N - aa = a*dp*cos(phi1) !length element - if((qe(i,jj).le.0.).and.(jj.ge.j)) then !LWA*cos and F2 - astar2(i,j,k)=astar2(i,j,k)-qe(i,jj)*aa !anticyclonic - ua2(i,j) = ua2(i,j)-qe(i,jj)*ue(i,jj)*aa - endif - if((qe(i,jj).gt.0.).and.(jj.lt.j)) then - astar1(i,j,k)=astar1(i,j,k)+qe(i,jj)*aa !cyclonic - ua2(i,j) = ua2(i,j)+qe(i,jj)*ue(i,jj)*aa - endif - enddo - -! ******** Other fluxes ****** - - ua1(i,j) = uref(j-5,k)*(astar1(i,j,k) + & - astar2(i,j,k)) !F1 - ep1(i,j) = -0.5*(uu(i,j+90,k)-uref(j-5,k))**2 !F3a - ep1(i,j) = ep1(i,j)+0.5*vv(i,j+90,k)**2 !F3a+b - ep11 = 0.5*(pt(i,j+90,k)-tref(j-5,k))**2 !F3c - zz = dz*float(k-1) - ep11 = ep11*(r/h)*exp(-rkappa*zz/h) - ep11 = ep11*2.*dz/(tg(k+1)-tg(k-1)) - ep1(i,j) = ep1(i,j)-ep11 !F3 - phip = dp*float(j) - cosp = cos(phip) ! cosine for one grid north - phi0 = dp*float(j-1) - cos0 = cos(phi0) ! cosine for latitude grid - sin0 = sin(phi0) ! sine for latitude grid - phim = dp*float(j-2) - cosm = cos(phim) ! cosine for one grid south - ep1(i,j) = ep1(i,j)*cos0 ! correct for cosine factor - - - ! meridional eddy momentum flux one grid north and south - ep2(i,j)=(uu(i,j+91,k)-uref(j-5,k))*vv(i,j+91,k)*cosp*cosp - ep3(i,j)=(uu(i,j+89,k)-uref(j-5,k))*vv(i,j+89,k)*cosm*cosm - - ! low-level meridional eddy heat flux - if(k.eq.2) then ! (26) of SI-HN17 - ep41 = 2.*om*sin0*cos0*dz/6745.348 ! prefactor - ep42 = exp(-dz/h)*vv(i,j+90,2)*(pt(i,j+90,2)-tref(j-5,2)) - ep42 = ep42/(tg(3)-tg(1)) - ep43 = vv(i,j+90,1)*(pt(i,j+90,1)-tref(j-5,1)) - ep43 = 0.5*ep43/(tg(2)-tg(1)) - ep4(i,j) = ep41*(ep42+ep43) ! low-level heat flux - endif - enddo - enddo - -! ******** Column average: (25) of SI-HN17 ******** - - astarbaro(:,:) = astarbaro(:,:)+(astar1(:,:,k) & - + astar2(:,:,k))*exp(-zk/h)*dc - ua1baro(:,:) = ua1baro(:,:)+ua1(:,:)*exp(-zk/h)*dc - ua2baro(:,:) = ua2baro(:,:)+ua2(:,:)*exp(-zk/h)*dc - ep1baro(:,:) = ep1baro(:,:)+ep1(:,:)*exp(-zk/h)*dc - ep2baro(:,:) = ep2baro(:,:)+ep2(:,:)*exp(-zk/h)*dc - ep3baro(:,:) = ep3baro(:,:)+ep3(:,:)*exp(-zk/h)*dc - do j = 6,nd ! ### yet to be multiplied by cosine - ubaro(:,j) = ubaro(:,j)+uu(:,j+90,k)*exp(-zk/h)*dc - urefbaro(j) = urefbaro(j)+uref(j-5,k)*exp(-zk/h)*dc - enddo - enddo - - -! write(6,*) dh - - write(41) astarbaro,ubaro,urefbaro,ua1baro,ua2baro,ep1baro,& - ep2baro,& - ep3baro,ep4 - - write(38) astar1,astar2 - -! ******************************** - - - write(6,*) fy,n,mm - -! ******************************** - enddo - - close(35) - close(36) - close(37) - close(38) - close(39) - close(40) - close(41) - - enddo - enddo - - stop - end diff --git a/scripts/nhn_grl2022/era4000n_nc.f90 b/scripts/nhn_grl2022/era4000n_nc.f90 deleted file mode 100644 index 88645e8..0000000 --- a/scripts/nhn_grl2022/era4000n_nc.f90 +++ /dev/null @@ -1,312 +0,0 @@ - program main - - use NETCDF - -! **** convert barotropic LWA and fluxes for -! NH into netCDF files *** - - integer,parameter :: imax = 360 - integer,parameter :: nd = 91 - common /frray/ ep4(imax,nd) - common /grray/ ubaro(imax,nd),urefbaro(nd),astarbaro(imax,nd) - common /hrray/ ua1baro(imax,nd),ua2baro(imax,nd) - common /hrray/ ep1baro(imax,nd),ep2baro(imax,nd) - common /hrray/ ep3baro(imax,nd),wa2(nd,124) - common /array/ astar(imax,nd,124),ub(imax,nd,124) - common /brray/ urb(nd,124),ua1(imax,nd,124) - common /crray/ ua2(imax,nd,124),ep1(imax,nd,124) - common /drray/ ep2(imax,nd,124),ep3(imax,nd,124) - common /erray/ ep44(imax,nd,124),wa1(imax,nd,124) - integer :: md(12) - - character*35 fn,fn0,fn1 - character*34 fu - character*34 ft,fv - character*38 fx - character*4 fn2(12),fy,fy1,fy2 - character*19 f3 - character*36 fr - character*37 fm - character*39 fd,fe,ff,fg,fh,fi - character*40 fa - character*41 fc - character*38 fb - - integer :: ncid, status,nDim,nVar,nAtt,uDimID,inq - integer :: lonID,latID,vid2,varID - integer :: l1,l2,l3,l4,l5,l6,xtype,len,attnum - - a = 6378000. - pi = acos(-1.) - om = 7.29e-5 - dp = pi/180. - dz = 500. - h = 7000. - r = 287. - rkappa = r/1004. - - do m = 2021,2021 - - md(1) = 31 - md(2) = 28 - if(mod(m,4).eq.0) md(2) = 29 - md(3) = 31 - md(4) = 30 - md(5) = 31 - md(6) = 30 - md(7) = 31 - md(8) = 31 - md(9) = 30 - md(10) = 31 - md(11) = 30 - md(12) = 31 - - fn2(1) = '_01_' - fn2(2) = '_02_' - fn2(3) = '_03_' - fn2(4) = '_04_' - fn2(5) = '_05_' - fn2(6) = '_06_' - fn2(7) = '_07_' - fn2(8) = '_08_' - fn2(9) = '_09_' - fn2(10) = '_10_' - fn2(11) = '_11_' - fn2(12) = '_12_' - - write(fy,266) m - 266 format(i4) - - do n = 6,6 - fm = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'BARO_N' - fa = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'LWAb_N.nc' - fb = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'Ub_N.nc' - fc = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'Urefb_N.nc' - fd = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'ua1_N.nc' - fe = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'ua2_N.nc' - ff = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'ep1_N.nc' - fg = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'ep2_N.nc' - fh = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'ep3_N.nc' - fi = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'ep4_N.nc' - write(6,*) fn,md(n) - open(41,file =fm, & - form='unformatted',status = 'old') - - do mm = 1,md(n)*4 - - read(41) astarbaro,ubaro,urefbaro,ua1baro,ua2baro,ep1baro,& - ep2baro,& - ep3baro,ep4 - - astar(:,:,mm) = astarbaro(:,:) - ub(:,:,mm) = ubaro(:,:) - urb(:,mm) = urefbaro(:) - ua1(:,:,mm) = ua1baro(:,:) - ua2(:,:,mm) = ua2baro(:,:) - ep1(:,:,mm) = ep1baro(:,:) - ep2(:,:,mm) = ep2baro(:,:) - ep3(:,:,mm) = ep3baro(:,:) - ep44(:,:,mm) = ep4(:,:) - -! ******************************** - - write(6,*) fy,n,mm - -! ******************************** - enddo - - status = nf90_create(fa,nf90_noclobber,ncid2) - status = nf90_def_dim(ncid2,"longitude",imax,ix) - status = nf90_def_dim(ncid2,"latitude",nd,iy) - status = nf90_def_dim(ncid2,"time",124,it) - status = nf90_def_var(ncid2,"lwa",nf90_float, & - (/ix,iy,it/), vid2) - status = nf90_put_att(ncid2,vid2,"title",fa) - status = nf90_enddef(ncid2) - status = nf90_put_var(ncid2,vid2,astar) - status = nf90_close(ncid2) - - status = nf90_open(fa,nf90_nowrite,ncid) - status = nf90_inquire(ncid,nDim,nVar,nAtt,uDimID) - write(6,*) 'ndim,nvar,natt,uDimID =',nDim,nVar,nAtt,uDimID - status = nf90_inq_varid(ncid,"lwa",varID) - write(6,*) 'Variable ID for LWA = ',varID - status = nf90_get_var(ncid,varID,wa1) - status = nf90_close(ncid) - - write(6,*) astar(200,47,30),wa1(200,47,30) - - status = nf90_create(fb,nf90_noclobber,ncid2) - status = nf90_def_dim(ncid2,"longitude",imax,ix) - status = nf90_def_dim(ncid2,"latitude",nd,iy) - status = nf90_def_dim(ncid2,"time",124,it) - status = nf90_def_var(ncid2,"u",nf90_float, & - (/ix,iy,it/), vid2) - status = nf90_put_att(ncid2,vid2,"title",fb) - status = nf90_enddef(ncid2) - status = nf90_put_var(ncid2,vid2,ub) - status = nf90_close(ncid2) - - status = nf90_open(fb,nf90_nowrite,ncid) - status = nf90_inquire(ncid,nDim,nVar,nAtt,uDimID) - write(6,*) 'ndim,nvar,natt,uDimID =',nDim,nVar,nAtt,uDimID - status = nf90_inq_varid(ncid,"u",varID) - write(6,*) 'Variable ID for U = ',varID - status = nf90_get_var(ncid,varID,wa1) - status = nf90_close(ncid) - - write(6,*) ub(200,47,30),wa1(200,47,30) - - status = nf90_create(fd,nf90_noclobber,ncid2) - status = nf90_def_dim(ncid2,"longitude",imax,ix) - status = nf90_def_dim(ncid2,"latitude",nd,iy) - status = nf90_def_dim(ncid2,"time",124,it) - status = nf90_def_var(ncid2,"ua1",nf90_float, & - (/ix,iy,it/), vid2) - status = nf90_put_att(ncid2,vid2,"title",fd) - status = nf90_enddef(ncid2) - status = nf90_put_var(ncid2,vid2,ua1) - status = nf90_close(ncid2) - - status = nf90_open(fd,nf90_nowrite,ncid) - status = nf90_inquire(ncid,nDim,nVar,nAtt,uDimID) - write(6,*) 'ndim,nvar,natt,uDimID =',nDim,nVar,nAtt,uDimID - status = nf90_inq_varid(ncid,"ua1",varID) - write(6,*) 'Variable ID for ua1 = ',varID - status = nf90_get_var(ncid,varID,wa1) - status = nf90_close(ncid) - - write(6,*) ua1(200,47,30),wa1(200,47,30) - - status = nf90_create(fe,nf90_noclobber,ncid2) - status = nf90_def_dim(ncid2,"longitude",imax,ix) - status = nf90_def_dim(ncid2,"latitude",nd,iy) - status = nf90_def_dim(ncid2,"time",124,it) - status = nf90_def_var(ncid2,"ua2",nf90_float, & - (/ix,iy,it/), vid2) - status = nf90_put_att(ncid2,vid2,"title",fe) - status = nf90_enddef(ncid2) - status = nf90_put_var(ncid2,vid2,ua2) - status = nf90_close(ncid2) - - status = nf90_open(fe,nf90_nowrite,ncid) - status = nf90_inquire(ncid,nDim,nVar,nAtt,uDimID) - write(6,*) 'ndim,nvar,natt,uDimID =',nDim,nVar,nAtt,uDimID - status = nf90_inq_varid(ncid,"ua2",varID) - write(6,*) 'Variable ID for ua2 = ',varID - status = nf90_get_var(ncid,varID,wa1) - status = nf90_close(ncid) - - write(6,*) ua2(200,47,30),wa1(200,47,30) - - status = nf90_create(ff,nf90_noclobber,ncid2) - status = nf90_def_dim(ncid2,"longitude",imax,ix) - status = nf90_def_dim(ncid2,"latitude",nd,iy) - status = nf90_def_dim(ncid2,"time",124,it) - status = nf90_def_var(ncid2,"ep1",nf90_float, & - (/ix,iy,it/), vid2) - status = nf90_put_att(ncid2,vid2,"title",ff) - status = nf90_enddef(ncid2) - status = nf90_put_var(ncid2,vid2,ep1) - status = nf90_close(ncid2) - - status = nf90_open(ff,nf90_nowrite,ncid) - status = nf90_inquire(ncid,nDim,nVar,nAtt,uDimID) - write(6,*) 'ndim,nvar,natt,uDimID =',nDim,nVar,nAtt,uDimID - status = nf90_inq_varid(ncid,"ep1",varID) - write(6,*) 'Variable ID for ep1 = ',varID - status = nf90_get_var(ncid,varID,wa1) - status = nf90_close(ncid) - - write(6,*) ep1(200,47,30),wa1(200,47,30) - - status = nf90_create(fg,nf90_noclobber,ncid2) - status = nf90_def_dim(ncid2,"longitude",imax,ix) - status = nf90_def_dim(ncid2,"latitude",nd,iy) - status = nf90_def_dim(ncid2,"time",124,it) - status = nf90_def_var(ncid2,"ep2",nf90_float, & - (/ix,iy,it/), vid2) - status = nf90_put_att(ncid2,vid2,"title",fg) - status = nf90_enddef(ncid2) - status = nf90_put_var(ncid2,vid2,ep2) - status = nf90_close(ncid2) - - status = nf90_open(fg,nf90_nowrite,ncid) - status = nf90_inquire(ncid,nDim,nVar,nAtt,uDimID) - write(6,*) 'ndim,nvar,natt,uDimID =',nDim,nVar,nAtt,uDimID - status = nf90_inq_varid(ncid,"ep2",varID) - write(6,*) 'Variable ID for ep2 = ',varID - status = nf90_get_var(ncid,varID,wa1) - status = nf90_close(ncid) - - write(6,*) ep2(200,47,30),wa1(200,47,30) - - status = nf90_create(fh,nf90_noclobber,ncid2) - status = nf90_def_dim(ncid2,"longitude",imax,ix) - status = nf90_def_dim(ncid2,"latitude",nd,iy) - status = nf90_def_dim(ncid2,"time",124,it) - status = nf90_def_var(ncid2,"ep3",nf90_float, & - (/ix,iy,it/), vid2) - status = nf90_put_att(ncid2,vid2,"title",fh) - status = nf90_enddef(ncid2) - status = nf90_put_var(ncid2,vid2,ep3) - status = nf90_close(ncid2) - - status = nf90_open(fh,nf90_nowrite,ncid) - status = nf90_inquire(ncid,nDim,nVar,nAtt,uDimID) - write(6,*) 'ndim,nvar,natt,uDimID =',nDim,nVar,nAtt,uDimID - status = nf90_inq_varid(ncid,"ep3",varID) - write(6,*) 'Variable ID for ep3 = ',varID - status = nf90_get_var(ncid,varID,wa1) - status = nf90_close(ncid) - - write(6,*) ep3(200,47,30),wa1(200,47,30) - - status = nf90_create(fi,nf90_noclobber,ncid2) - status = nf90_def_dim(ncid2,"longitude",imax,ix) - status = nf90_def_dim(ncid2,"latitude",nd,iy) - status = nf90_def_dim(ncid2,"time",124,it) - status = nf90_def_var(ncid2,"ep4",nf90_float, & - (/ix,iy,it/), vid2) - status = nf90_put_att(ncid2,vid2,"title",fi) - status = nf90_enddef(ncid2) - status = nf90_put_var(ncid2,vid2,ep44) - status = nf90_close(ncid2) - - status = nf90_open(fi,nf90_nowrite,ncid) - status = nf90_inquire(ncid,nDim,nVar,nAtt,uDimID) - write(6,*) 'ndim,nvar,natt,uDimID =',nDim,nVar,nAtt,uDimID - status = nf90_inq_varid(ncid,"ep4",varID) - write(6,*) 'Variable ID for ep4 = ',varID - status = nf90_get_var(ncid,varID,wa1) - status = nf90_close(ncid) - - write(6,*) ep44(200,47,30),wa1(200,47,30) - - status = nf90_create(fc,nf90_noclobber,ncid2) - status = nf90_def_dim(ncid2,"latitude",nd,iy) - status = nf90_def_dim(ncid2,"time",124,it) - status = nf90_def_var(ncid2,"uref",nf90_float, & - (/iy,it/), vid2) - status = nf90_put_att(ncid2,vid2,"title",fc) - status = nf90_enddef(ncid2) - status = nf90_put_var(ncid2,vid2,urb) - status = nf90_close(ncid2) - - status = nf90_open(fc,nf90_nowrite,ncid) - status = nf90_inquire(ncid,nDim,nVar,nAtt,uDimID) - write(6,*) 'ndim,nvar,natt,uDimID =',nDim,nVar,nAtt,uDimID - status = nf90_inq_varid(ncid,"uref",varID) - write(6,*) 'Variable ID for uref = ',varID - status = nf90_get_var(ncid,varID,wa2) - status = nf90_close(ncid) - - write(6,*) urb(47,30),wa2(47,30) - - close(41) - - enddo - enddo - - stop - end diff --git a/scripts/nhn_grl2022/era4004n.f90 b/scripts/nhn_grl2022/era4004n.f90 deleted file mode 100644 index 71acc4d..0000000 --- a/scripts/nhn_grl2022/era4004n.f90 +++ /dev/null @@ -1,460 +0,0 @@ - program main - -! USE mkl95_BLAS, ONLY: GEMM,GEMV - USE mkl95_LAPACK, ONLY: GETRF,GETRI - - -! **** take QG analysis and compute Q_ref and invert for -! U_ref & Theta_ref for NH (Direct solver) *** - - integer,parameter :: imax = 360, JMAX = 181, KMAX = 97 - integer,parameter :: nd = 91,nnd=181 - integer,parameter :: jb = 5 ! lower bounding latitude - integer,parameter :: jd = 86 ! nd - lower bounding latitude - common /array/ pv(imax,jmax,kmax),pv2(imax,jmax) - common /brray/ uu(imax,jmax,kmax) - common /bbray/ vort(imax,jmax,kmax),vort2(imax,jmax) - common /bcray/ pt(imax,jmax,kmax) - common /bdray/ stats(kmax),statn(kmax),ts0(kmax),tn0(kmax) - common /crray/ qn(nnd),an(nnd),aan(nnd),tb(kmax),tg(kmax) - common /drray/ cn(nnd),ccn(nnd),tref(jd,kmax) - common /frray/ alat(nd),phi(nd),z(kmax),cbar(nd,kmax) - common /krray/ tjk(jd-2,kmax-1),tj(jd-2),rj(jd-2) - common /lrray/ qjj(jd-2,jd-2),cjj(jd-2,jd-2) - common /orray/ xjj(jd-2,jd-2),yj(jd-2) - common /mrray/ djj(jd-2,jd-2),sjj(jd-2,jd-2) - common /nrray/ sjk(jd-2,jd-2,kmax-1) - common /prray/ pjk(jd-2,kmax),pj(jd-2) - common /irray/ qref(nd,kmax),u(jd,kmax),cref(nd,kmax) - common /krray/ fawa(nd,kmax),ckref(nd,kmax) - common /jrray/ qbar(nd,kmax),ubar(nd,kmax),tbar(nd,kmax) - integer :: md(12),ipiv(jd-2) - - character*35 fn,fn0,fn1 - character*34 fu - character*34 ft - character*4 fn2(12),fy,fy1,fy2 - character*18 f1,f2 - character*19 f3 - character*36 fv - character*38 fr - - a = 6378000. - pi = acos(-1.) - om = 7.29e-5 - dp = pi/180. - dz = 500. - h = 7000. - r = 287. - rkappa = r/1004. - - do nn = 1,nd - phi(nn) = dp*float(nn-1) - alat(nn) = 2.*pi*a*a*(1.-sin(phi(nn))) - enddo - - do k = 1,kmax - z(k) = dz*float(k-1) - enddo - - do m = 2021,2021 - - md(1) = 31 - md(2) = 28 - if(mod(m,4).eq.0) md(2) = 29 - md(3) = 31 - md(4) = 30 - md(5) = 31 - md(6) = 30 - md(7) = 31 - md(8) = 31 - md(9) = 30 - md(10) = 31 - md(11) = 30 - md(12) = 31 - - fn2(1) = '_01_' - fn2(2) = '_02_' - fn2(3) = '_03_' - fn2(4) = '_04_' - fn2(5) = '_05_' - fn2(6) = '_06_' - fn2(7) = '_07_' - fn2(8) = '_08_' - fn2(9) = '_09_' - fn2(10) = '_10_' - fn2(11) = '_11_' - fn2(12) = '_12_' - - write(fy,266) m - 266 format(i4) - - do n = 10,10 - fn = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGPV' - fu = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGU' - ft = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGT' - fr = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGREF_N' - fv = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QVORT' - write(6,*) fn,md(n) - open(35,file =fn, & - form='unformatted',status = 'old') - open(36,file =fu, & - form='unformatted',status = 'old') - open(37,file =ft, & - form='unformatted',status = 'old') - open(38,file =fr, & - form='unformatted',status = 'new') - open(39,file =fv, & - form='unformatted',status = 'old') -! ********************** Analysis starts here ********************** -do mm = 1,md(n)*4 - -read(35) pv -read(36) uu -read(39) vort -read(37) pt,tn0,ts0,statn,stats - -! **** Zonal-mean field **** -do j = 91,jmax - qbar(j-90,:) = 0. - tbar(j-90,:) = 0. - ubar(j-90,:) = 0. -do i = 1,imax - qbar(j-90,:) = qbar(j-90,:)+pv(i,j,:)/float(imax) - tbar(j-90,:) = tbar(j-90,:)+pt(i,j,:)/float(imax) - ubar(j-90,:) = ubar(j-90,:)+uu(i,j,:)/float(imax) -enddo -enddo - -! **** hemispheric-mean potential temperature **** -tb(:) = tn0(:) - -do k = 2,96 - pv2(:,:) = pv(:,:,k) - vort2(:,:) = vort(:,:,k) - - ! **** compute qref via area analysis **** - qmax = maxval(pv2) - qmin = minval(pv2) - dq = (qmax-qmin)/float(nnd-1) - qn(:) = 0. - an(:) = 0. - cn(:) = 0. - do nn = 1,nnd - qn(nn) = qmax - dq*float(nn-1) - enddo - do j = 1,jmax - phi0 = -0.5*pi+dp*float(j-1) - do i = 1,imax - ind = 1+int((qmax-pv2(i,j))/dq) - da = a*a*dp*dp*cos(phi0) - an(ind) = an(ind) + da - cn(ind) = cn(ind) + da*pv2(i,j) - enddo - enddo - aan(1) = 0. - ccn(1) = 0. - do nn = 2,nnd - aan(nn) = aan(nn-1)+an(nn) - ccn(nn) = ccn(nn-1)+cn(nn) - enddo - do j = 1,nd-1 - do nn = 1,nnd-1 - if(aan(nn).le.alat(j).and.aan(nn+1).gt.alat(j)) then - dd = (alat(j)-aan(nn))/(aan(nn+1)-aan(nn)) - qref(j,k) = qn(nn)*(1.-dd)+qn(nn+1)*dd - cref(j,k) = ccn(nn)*(1.-dd)+ccn(nn+1)*dd - endif - enddo - enddo - - qref(nd,k) = qmax - - cbar(nd,k) = 0. - do j=nd-1,1,-1 - phi0 = dp*(float(j)-0.5) - cbar(j,k) = cbar(j+1,k)+0.5*(qbar(j+1,k)+qbar(j,k)) & - *a*dp*2.*pi*a*cos(phi0) - enddo - -! **** compute Kelvin's circulation based on absolute vorticity (for b.c.) **** - - - qmax = maxval(vort2) - qmin = minval(vort2) - dq = (qmax-qmin)/float(nnd-1) - qn(:) = 0. - an(:) = 0. - cn(:) = 0. - do nn = 1,nnd - qn(nn) = qmax - dq*float(nn-1) - enddo - do j = 1,jmax - phi0 = -0.5*pi+dp*float(j-1) - do i = 1,imax - ind = 1+int((qmax-vort2(i,j))/dq) - da = a*a*dp*dp*cos(phi0) - an(ind) = an(ind) + da - cn(ind) = cn(ind) + da*vort2(i,j) - enddo - enddo - aan(1) = 0. - ccn(1) = 0. - do nn = 2,nnd - aan(nn) = aan(nn-1)+an(nn) - ccn(nn) = ccn(nn-1)+cn(nn) - enddo - do j = 1,nd-1 - do nn = 1,nnd-1 - if(aan(nn).le.alat(j).and.aan(nn+1).gt.alat(j)) then - dd = (alat(j)-aan(nn))/(aan(nn+1)-aan(nn)) - ckref(j,k) = ccn(nn)*(1.-dd)+ccn(nn+1)*dd - endif - enddo - enddo - -enddo - -! ***** normalize QGPV by sine (latitude) **** - -do j = 2,nd - phi0 = dp*float(j-1) - cor = sin(phi0) - qref(j,:) = qref(j,:)/cor -enddo - -do k = 2,kmax-1 - qref(1,k) = 2.*qref(2,k)-qref(3,k) -enddo - -! ***** FAWA ***** -fawa(:,:) = (cref(:,:)-cbar(:,:))/(2.*pi*a) - -! ***** Direct solver to invert Q_ref ***** - -! *** downward sweep *** - -! **** top boundary condition (Eqs. 24-25) ***** -tjk(:,:) = 0. -sjk(:,:,:) = 0. -do jj = jb+2,90 - j = jj-jb - phi0 = float(jj-1)*dp - cos0 = cos(phi0) - sin0 = sin(phi0) - tjk(j-1,kmax-1) = -dz*r*cos0*exp(-z(kmax-1)*rkappa/h) - tjk(j-1,kmax-1) = tjk(j-1,kmax-1)*(tbar(j+1,kmax)-tbar(j-1,kmax)) - tjk(j-1,kmax-1) = tjk(j-1,kmax-1)/(4.*om*sin0*dp*h*a) - sjk(j-1,j-1,kmax-1) = 1. -enddo - -! **** Evaluate Eqs. 22-23 downward *** - -do k = kmax-1,2,-1 - zp = 0.5*(z(k+1)+z(k)) - zm = 0.5*(z(k-1)+z(k)) - statp = 0.5*(statn(k+1)+statn(k)) - statm = 0.5*(statn(k-1)+statn(k)) - cjj(:,:) = 0. - djj(:,:) = 0. - qjj(:,:) = 0. - sjj(:,:) = sjk(:,:,k) - tj(:) = tjk(:,k) - do jj = jb+2,90 - j = jj - jb - phi0 = float(jj-1)*dp - phip = (float(jj)-0.5)*dp - phim = (float(jj)-1.5)*dp - cos0 = cos(phi0) - cosp = cos(phip) - cosm = cos(phim) - sin0 = sin(phi0) - sinp = sin(phip) - sinm = sin(phim) - - fact = 4.*om*om*h*a*a*sin0*dp*dp/(dz*dz*r*cos0) - amp = exp(-zp/h)*exp(rkappa*zp/h)/statp - amp = amp*fact*exp(z(k)/h) - amm = exp(-zm/h)*exp(rkappa*zm/h)/statm - amm = amm*fact*exp(z(k)/h) - - ! ***** Specify A, B, C, D, E, F (Eqs. 4-9) ***** - ajk = 1./(sinp*cosp) - bjk = 1./(sinm*cosm) - cjk = amp - djk = amm - ejk = ajk+bjk+cjk+djk - fjk = -0.5*a*dp*(qref(jj+1,k)-qref(jj-1,k)) - - ! ***** Specify rk (Eq. 15) **** - - ! **** North-south boundary conditions **** - u(jd,k) = 0. - phi0 = dp*float(jb) - ! u(1,k) = ubar(jb+1,k)*cos(phi0) - u(1,k) = ckref(jb+1,k)/(2.*pi*a)-om*a*cos(phi0) - - rj(j-1) = fjk - if(j.eq.2) rj(j-1) = fjk - bjk*u(1,k) - if(j.eq.jd-1) rj(j-1) = fjk - ajk*u(jd,k) - - ! ***** Specify Ck & Dk (Eqs. 18-19) ***** - cjj(j-1,j-1) = cjk - djj(j-1,j-1) = djk - - ! **** Specify Qk (Eq. 17) ***** - qjj(j-1,j-1) = -ejk - if(j-1.ge.1.and.j-1.lt.jd-2) then - qjj(j-1,j) = ajk - endif - if(j-1.gt.1.and.j-1.le.jd-2) then - qjj(j-1,j-2) = bjk - endif - enddo - - ! **** Compute Qk + Ck Sk ******* - do i = 1,jd-2 - do j = 1,jd-2 - xjj(i,j) = 0. - do kk = 1,jd-2 - xjj(i,j) = xjj(i,j)+cjj(i,kk)*sjj(kk,j) - enddo - qjj(i,j) = qjj(i,j)+xjj(i,j) - enddo - enddo - ! call gemm(cjj,sjj,xjj) - ! qjj(:,:) = qjj(:,:)+xjj(:,:) - - ! **** Invert (Qk + Ck Sk) ******** - call getrf(qjj,ipiv) - call getri(qjj,ipiv) - - ! **** Evaluate Eq. 22 **** - do i = 1,jd-2 - do j = 1,jd-2 - xjj(i,j) = 0. - do kk = 1,jd-2 - xjj(i,j) = xjj(i,j)+qjj(i,kk)*djj(kk,j) - enddo - sjk(i,j,k-1) = -xjj(i,j) - enddo - enddo - - ! call gemm(qjj,djj,xjj) - ! sjk(:,:,k-1) = -xjj(:,:) - - ! **** Evaluate rk - Ck Tk **** - do i = 1,jd-2 - yj(i) = 0. - do kk = 1,jd-2 - yj(i) = yj(i)+cjj(i,kk)*tj(kk) - enddo - yj(i) = rj(i)-yj(i) - enddo - - ! call gemv(cjj,tj,yj) - ! yj(:) = rj(:)-yj(:) - ! call gemv(qjj,yj,tj) - ! tjk(:,k-1) = tj(:) - - - ! ***** Evaluate Eq. 23 ******* - do i = 1,jd-2 - tj(i) = 0. - do kk = 1,jd-2 - tj(i) = tj(i)+qjj(i,kk)*yj(kk) - enddo - tjk(i,k-1) = tj(i) - enddo - -enddo - -! ***** upward sweep (Eq. 20) **** - -pjk(:,1) = 0. -do k = 1,kmax-1 - pj(:) = pjk(:,k) - sjj(:,:) = sjk(:,:,k) - tj(:) = tjk(:,k) - - do i = 1,jd-2 - yj(i) = 0. - do kk = 1,jd-2 - yj(i) = yj(i)+sjj(i,kk)*pj(kk) - enddo - pjk(i,k+1) = yj(i)+tj(i) - enddo - ! call gemv(sjj,pj,yj) - ! pjk(:,k+1) = yj(:) + tj(:) -enddo - -! **** Recover u ***** -do k = 1,kmax - do j = 2,jd-1 - u(j,k) = pjk(j-1,k) - enddo -enddo - -! *** Corner boundary conditions *** -u(1,1) = 0. -u(jd,1) = 0. -! u(1,kmax) = ubar(1+jb,kmax)*cos(dp*float(jb)) -u(1,kmax) = ckref(1+jb,kmax)/(2.*pi*a)-om*a*cos(dp*float(jb)) -u(jd,kmax) = 0. - -! *** Divide by cos phi to revover Uref **** -do jj = jb+1,nd-1 - j = jj-jb - phi0 = dp*float(jj-1) - u(j,:) = u(j,:)/cos(phi0) -enddo -u(jd,:) = 2.*u(jd-1,:)-u(jd-2,:) - -! ******** compute tref ******* - -do k = 2,96 - t00 = 0. - zz = dz*float(k-1) - tref(1,k) = t00 - tref(2,k) = t00 - do j = 2,jd-1 - phi0 = dp*float(j-1) - cor = 2.*om*sin(phi0) - uz = (u(j,k+1)-u(j,k-1))/(2.*dz) - ty = -cor*uz*a*h*exp(rkappa*zz/h) - ty = ty/r - tref(j+1,k) = tref(j-1,k)+2.*ty*dp - qref(j-1,k) = qref(j-1,k)*sin(phi0) - enddo - tg(k) = 0. - wt = 0. - do jj = 6,91 - j = jj-5 - phi0 = dp*float(jj-1) - tg(k) = tg(k)+cos(phi0)*tref(j,k) - wt = wt + cos(phi0) - enddo - tg(k) = tg(k)/wt - tres = tb(k)-tg(k) - tref(:,k) = tref(:,k)+tres -enddo -tref(:,1) = tref(:,2)-tb(2)+tb(1) -tref(:,97) = tref(:,96)-tb(96)+tb(97) - -write(38) qref,u,tref,fawa,ubar,tbar - -write(6,*) m,n,mm - -! ******************************** -enddo - -close(35) -close(36) -close(37) -close(38) -! ********************** Analysis ends here ********************** - enddo - enddo - - stop - end From acdf862669859ecc51796ca95c8920634d5b1cf7 Mon Sep 17 00:00:00 2001 From: csyhuang Date: Thu, 17 Mar 2022 14:16:20 -0500 Subject: [PATCH 15/19] change version number --- docs/source/conf.py | 6 +- readme.md | 2 +- scripts/nhn_grl2022/lwa_flux_computation.py | 174 -------------------- setup.py | 7 +- 4 files changed, 9 insertions(+), 180 deletions(-) delete mode 100644 scripts/nhn_grl2022/lwa_flux_computation.py diff --git a/docs/source/conf.py b/docs/source/conf.py index 6b79b68..40ec938 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -59,7 +59,7 @@ # General information about the project. project = u'hn2016_falwa' -copyright = u'2020, Clare S. Y. Huang' +copyright = u'2022, Clare S. Y. Huang' author = u'Clare S. Y. Huang' # The version info for the project you're documenting, acts as replacement for @@ -67,9 +67,9 @@ # built documents. # # The short X.Y version. -version = u'0.5.0' +version = u'0.6.0' # The full version, including alpha/beta/rc tags. -release = u'0.5.0' +release = u'0.6.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/readme.md b/readme.md index e62c072..cda1055 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -## Python Library: hn2016_falwa (v0.5.0) +## Python Library: hn2016_falwa (v0.6.0) [![Build Status](https://github.com/csyhuang/hn2016_falwa/actions/workflows/workflow.yml/badge.svg)](https://github.com/csyhuang/hn2016_falwa/actions/workflows/workflow.yml)[![codecov.io](https://codecov.io/gh/csyhuang/hn2016_falwa/branch/master/graph/badge.svg)](https://codecov.io/gh/csyhuang/hn2016_falwa)[![Documentation Status](https://readthedocs.org/projects/hn2016-falwa/badge/?version=latest)](http://hn2016-falwa.readthedocs.io/en/latest/?badge=latest) diff --git a/scripts/nhn_grl2022/lwa_flux_computation.py b/scripts/nhn_grl2022/lwa_flux_computation.py deleted file mode 100644 index cb2e44c..0000000 --- a/scripts/nhn_grl2022/lwa_flux_computation.py +++ /dev/null @@ -1,174 +0,0 @@ -import numpy as np -from math import pi -from netCDF4 import Dataset -from hn2016_falwa.oopinterface import QGField -import datetime as dt -import matplotlib.pyplot as plt - -data_dir = "grl2021_data/" - -# --- Load the zonal wind and QGPV at 240hPa --- # -u_file = Dataset(data_dir + '2021_06_u.nc', mode='r') -v_file = Dataset(data_dir + '2021_06_v.nc', mode='r') -t_file = Dataset(data_dir + '2021_06_t.nc', mode='r') - -time_array = u_file.variables['time'][:] -time_units = u_file.variables['time'].units -time_calendar = u_file.variables['time'].calendar -ntimes = time_array.shape[0] - -print('Dimension of time: {}'.format(time_array.size)) - -# --- Longitude, latitude and pressure grid --- -xlon = u_file.variables['longitude'][:] - -# latitude has to be in ascending order -ylat = u_file.variables['latitude'][:] -if np.diff(ylat)[0]<0: - print('Flip ylat.') - ylat = ylat[::-1] - -# pressure level has to be in descending order (ascending height) -plev = u_file.variables['level'][:] -if np.diff(plev)[0]>0: - print('Flip plev.') - plev = plev[::-1] - -nlon = xlon.size -nlat = ylat.size -nlev = plev.size - -# --- Coordinates --- -clat = np.cos(np.deg2rad(ylat)) # cosine latitude -p0 = 1000. # surface pressure [hPa] -kmax = 97 # number of grid points for vertical extrapolation (dimension of height) -dz = 500. # differential height element -height = np.arange(0,kmax)*dz # pseudoheight [m] -dphi = np.diff(ylat)[0]*pi/180. # differential latitudinal element -dlambda = np.diff(xlon)[0]*pi/180. # differential latitudinal element -hh = 7000. # scale height -cp = 1004. # heat capacity of dry air -rr = 287. # gas constant -omega = 7.29e-5 # rotation rate of the earth -aa = 6.378e+6 # earth radius -prefactor = np.array([np.exp(-z/hh) for z in height[1:]]).sum() # integrated sum of density from the level - #just above the ground (z=1km) to aloft -npart = nlat # number of partitions to construct the equivalent latitude grids -maxits = 100000 # maximum number of iteration in the SOR solver to solve for reference state -tol = 1.e-5 # tolerance that define convergence of solution -rjac = 0.95 # spectral radius of the Jacobi iteration in the SOR solver. -jd = nlat//2+1 # (one plus) index of latitude grid point with value 0 deg - # This is to be input to fortran code. The index convention is different. - - -# --- Outputing files --- -output_fname = '2021-06-01_to_2021-06-30_output3.nc' -output_file = Dataset(output_fname, 'w') -output_file.createDimension('latitude',nlat//2+1) -output_file.createDimension('longitude',nlon) -output_file.createDimension('time',ntimes+4) -lats = output_file.createVariable('latitude',np.dtype('float32').char,('latitude',)) # Define the coordinate variables -lons = output_file.createVariable('longitude',np.dtype('float32').char,('longitude',)) -times = output_file.createVariable('time',np.dtype('int').char,('time',)) -lats.units = 'degrees_north' -lons.units = 'degrees_east' -times.units = time_units -times.calendar = time_calendar -lats[:] = ylat[90:] -lons[:] = xlon -# times[:] = time_array -lwa_baro = output_file.createVariable('lwa', np.dtype('float32').char, ('time', 'latitude', 'longitude')) -lwa_baro.units = 'm/s' -ua1 = output_file.createVariable('ua1', np.dtype('float32').char, ('time', 'latitude', 'longitude')) -ua1.units = 'm/s' -ua2 = output_file.createVariable('ua2', np.dtype('float32').char, ('time', 'latitude', 'longitude')) -ua2.units = 'm/s' -ep1 = output_file.createVariable('ep1', np.dtype('float32').char, ('time', 'latitude', 'longitude')) -ep1.units = 'm/s' -ep2 = output_file.createVariable('ep2', np.dtype('float32').char, ('time', 'latitude', 'longitude')) -ep2.units = 'm/s' -ep3 = output_file.createVariable('ep3', np.dtype('float32').char, ('time', 'latitude', 'longitude')) -ep3.units = 'm/s' -ep4 = output_file.createVariable('ep4', np.dtype('float32').char, ('time', 'latitude', 'longitude')) -ep4.units = 'm/s' - - -print(f'ylat[90:].size = {ylat[90:].size}.') - -# --- Set timestamp and pressure level to display --- -tstamp = [dt.datetime(2005,1,23,0,0) + dt.timedelta(seconds=6*3600) * tt for tt in range(ntimes)] -plev_selected = 10 # selected pressure level to display -tstep_selected = 0 - -# --- Compute LWA and fluxes --- -for tstep in range(ntimes): # or ntimes - - uu = u_file.variables['u'][tstep, ::-1, ::-1, :].data - vv = v_file.variables['v'][tstep, ::-1, ::-1, :].data - tt = t_file.variables['t'][tstep, ::-1, ::-1, :].data - - qgfield_object = QGField(xlon, ylat, plev, uu, vv, tt, kmax=kmax, dz=dz) - - qgpv_temp, interpolated_u_temp, interpolated_v_temp, interpolated_avort_temp, interpolated_theta_temp, \ - static_stability_n, static_stability_s, tn0, ts0 = qgfield_object._interpolate_field_dirinv() - - # plt.contourf(xlon, ylat, np.swapaxes(qgpv_temp[:, :, 40], 0, 1), cmap='rainbow') - # plt.colorbar() - # plt.savefig("test_qgpv.jpg") - # plt.clf() - # plt.plot(ylat, interpolated_u_temp[:, :, 40].mean(axis=0)) - # # plt.colorbar() - # plt.savefig("test_zm_u.jpg") - # plt.clf() - # plt.contourf(xlon, ylat, np.swapaxes(interpolated_theta_temp[:, :, 20], 0, 1), cmap='rainbow') - # plt.colorbar() - # plt.savefig("test_pt.jpg") - - print("Before compute_qref_fawa_and_bc") - qref, uref, tref, fawa, ubar, tbar = qgfield_object._compute_qref_fawa_and_bc() - - # print(f"qref.shape = {qref.shape}") - # plt.contourf(np.arange(91), np.arange(0, 48500, 500), np.swapaxes(qref, 0, 1), cmap='rainbow') - # plt.colorbar() - # plt.ylabel("height") - # plt.xlabel("latitude") - # plt.savefig("qref.png") - - print("After compute_qref_fawa_and_bc") - astarbaro, ubaro, urefbaro, ua1baro, ua2baro, ep1baro, ep2baro, ep3baro, ep4baro, astar1, astar2 = \ - qgfield_object._compute_lwa_flux_dirinv(qref, uref, tref, fawa, ubar, tbar) - - for k in range(0, 96): - astar1_nan = np.count_nonzero(astar1[:, 80:, k]>1000) - astar2_nan = np.count_nonzero(astar2[:, 80:, k]>1000) - fawa_nan = np.count_nonzero(fawa[80:, k]>1000) - if astar1_nan + astar2_nan + fawa_nan > 0: - print(f"k = {k}. nan in astar1 = {astar1_nan}. nan in astar2 = {astar2_nan}. nan in fawa = {fawa_nan}.") - - - # print(f"ans2[0].shape = {ans2[0].shape}") - # print(f"ans2[1].shape = {ans2[1].shape}") - # print(f"ans2[0] = {ans2[0]}") - # print(f"ans2[1] = {ans2[1]}") - - # print(f"qref.shape = {qref.shape}") - # print(f"qref[:, 40] = {qref[:, 40]}") - # print(f"fawa.shape = {fawa.shape}") - # print(f"fawa[:, 40] = {fawa[:, 40]}") - # print(f"tstep = {tstep}") - - # qref, uref, ptref = qgfield_object.compute_reference_states(northern_hemisphere_results_only=False) - # - # barotropic_fluxes = qgfield_object.compute_lwa_and_barotropic_fluxes(northern_hemisphere_results_only=False) - # - lwa_baro[tstep, :, :] = np.swapaxes(astarbaro, 0, 1) - ua1[tstep, :, :] = np.swapaxes(ua1baro, 0, 1) - ua2[tstep, :, :] = np.swapaxes(ua2baro, 0, 1) - ep1[tstep, :, :] = np.swapaxes(ep1baro, 0, 1) - ep2[tstep, :, :] = np.swapaxes(ep2baro, 0, 1) - ep3[tstep, :, :] = np.swapaxes(ep3baro, 0, 1) - ep4[tstep, :, :] = np.swapaxes(ep4baro, 0, 1) - - print(f'tstep = {tstep}/{ntimes}.') - -# output_file.close() diff --git a/setup.py b/setup.py index e102e21..a2eb9c6 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,10 @@ Huang and Nakamura (2016, JAS): http://dx.doi.org/10.1175/JAS-D-15-0194.1 Huang and Nakamura (2017, GRL): http://onlinelibrary.wiley.com/doi/10.1002/2017GL073760/full Nakamura and Huang (2018, Science): https://doi.org/10.1126/science.aat0721 - The current version of the library handles calculation of FALWA in a spherical barotropic model and QGPV fields on isobaric surfaces. + Neal et al (submitted to GRL.) + + The current version of the library handles calculation of FALWA in a spherical barotropic model and QGPV fields on + isobaric surfaces. The functions in this library can compute the tracer equivalent-latitude relationship proposed in Nakamura (1996) (Also, see Allen and Nakamura (2003)) and the (zonal mean) @@ -58,7 +61,7 @@ setup( name='hn2016_falwa', - version='0.5.0', + version='0.6.0', description='python package to compute finite-amplitude local wave activity (Huang and Nakamura 2016, JAS)', long_description=LONG_DESCRIPTION, url='https://github.com/csyhuang/hn2016_falwa', From 92901f510975f706be9e85d765bee8d04333afe2 Mon Sep 17 00:00:00 2001 From: csyhuang Date: Thu, 17 Mar 2022 14:56:42 -0500 Subject: [PATCH 16/19] change jb to a tunable parameter --- hn2016_falwa/oopinterface.py | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/hn2016_falwa/oopinterface.py b/hn2016_falwa/oopinterface.py index 6d8a9cd..5b59b33 100644 --- a/hn2016_falwa/oopinterface.py +++ b/hn2016_falwa/oopinterface.py @@ -71,7 +71,10 @@ class QGField(object): planet_radius : float, optional Radius of the planet in meters. Default = 6.378e+6 (Earth's radius). - + eq_boundary_index: int, optional + The improved inversion algorithm of reference states allow modification of equatorward boundary + to be the absolute vorticity. This parameter specify the location of grid point (from equator) + which will be used as boundary. Default = 5. Examples -------- @@ -81,7 +84,7 @@ class QGField(object): def __init__(self, xlon, ylat, plev, u_field, v_field, t_field, kmax=49, maxit=100000, dz=1000., npart=None, tol=1.e-5, rjac=0.95, scale_height=SCALE_HEIGHT, cp=CP, dry_gas_constant=DRY_GAS_CONSTANT, - omega=EARTH_OMEGA, planet_radius=EARTH_RADIUS, prefactor=None): + omega=EARTH_OMEGA, planet_radius=EARTH_RADIUS, prefactor=None, eq_boundary_index=5): """ Create a QGField object. @@ -161,6 +164,7 @@ def __init__(self, xlon, ylat, plev, u_field, v_field, t_field, kmax=49, maxit=1 self.dz = dz self.tol = tol self.rjac = rjac + self.eq_boundary_index = eq_boundary_index # === Constants === self.scale_height = scale_height @@ -236,8 +240,11 @@ def _compute_prefactor(self): using rectangular rule consistent with the integral evaluation in compute_lwa_and_barotropic_fluxes.f90. TODO: evaluate numerical integration scheme used in the fortran module. """ - self.prefactor = sum([math.exp(-k * self.dz / self.scale_height) * self.dz for k in range(1, self.kmax-1)]) - return self.prefactor + self._prefactor = sum([math.exp(-k * self.dz / self.scale_height) * self.dz for k in range(1, self.kmax-1)]) + + @property + def prefactor(self): + return self._prefactor def _check_valid_plev(self, plev, scale_height, kmax, dz): """ @@ -829,10 +836,10 @@ def _compute_qref_fawa_and_bc(self): ts0=self._ts0, statn=self._static_stability_n, stats=self._static_stability_s, - nd=91, - nnd=181, - jb=5, - jd=86, + nd=self.nlat//2 + self.nlat % 2, # 91 + nnd=self.nlat, # 181 + jb=self.eq_boundary_index, # 5 + jd=self.nlat//2 + self.nlat % 2 - self.eq_boundary_index, # 86 TODO fix its formula a=self.planet_radius, omega=self.omega, dz=self.dz, @@ -856,8 +863,8 @@ def _compute_qref_fawa_and_bc(self): ans = matrix_b4_inversion( k=k, jmax=self.nlat, - jb=5, - jd=86, + jb=self.eq_boundary_index, # 5 + jd=self.nlat // 2 + self.nlat % 2 - self.eq_boundary_index, # 86 z=np.arange(0, self.kmax*self.dz, self.dz), statn=self._static_stability_n, qref=qref_over_cor, @@ -880,7 +887,7 @@ def _compute_qref_fawa_and_bc(self): _ = matrix_after_inversion( k=k, - jb=5, + jb=self.eq_boundary_index, qjj=qjj, djj=djj, cjj=cjj, @@ -892,7 +899,7 @@ def _compute_qref_fawa_and_bc(self): tref, qref = upward_sweep( jmax=self.nlat, nnd=self.nlat, - jb=5, + jb=self.eq_boundary_index, sjk=sjk, tjk=tjk, ckref=ckref, @@ -917,8 +924,9 @@ def _compute_lwa_flux_dirinv(self, qref, uref, tref, fawa, ubar, tbar): pt=self._interpolated_theta_temp, tn0=self._tn0, ts0=self._ts0, statn=self._static_stability_n, stats=self._static_stability_s, qref=qref, uref=uref, tref=tref, fawa=fawa, ubar=ubar, tbar=tbar, - nnd=self.nlat, jb=5, a=self.planet_radius, om=self.omega, dz=self.dz, - h=self.scale_height, rr=self.dry_gas_constant, cp=self.cp, prefac=6745.348) + nnd=self.nlat, jb=self.eq_boundary_index, a=self.planet_radius, om=self.omega, + dz=self.dz, h=self.scale_height, rr=self.dry_gas_constant, cp=self.cp, + prefac=self.prefactor) # astarbaro, ubaro, urefbaro, ua1baro, ua2baro, ep1baro, ep2baro, ep3baro, ep4, astar1, astar2 = ans return ans From ed09a7f45763ea3a0d779447d3089a8f17ba4354 Mon Sep 17 00:00:00 2001 From: csyhuang Date: Thu, 17 Mar 2022 15:06:51 -0500 Subject: [PATCH 17/19] put in nd jb jd into fortran --- hn2016_falwa/compute_flux_dirinv.f90 | 30 ++++++++++---------- hn2016_falwa/compute_qref_and_fawa_first.f90 | 11 ------- hn2016_falwa/oopinterface.py | 1 - hn2016_falwa/upward_sweep.f90 | 4 +-- scripts/nhn_grl2022/sample_run_script.py | 2 +- 5 files changed, 18 insertions(+), 30 deletions(-) diff --git a/hn2016_falwa/compute_flux_dirinv.f90 b/hn2016_falwa/compute_flux_dirinv.f90 index e0bb13b..6a3813d 100644 --- a/hn2016_falwa/compute_flux_dirinv.f90 +++ b/hn2016_falwa/compute_flux_dirinv.f90 @@ -53,10 +53,10 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ep4(:,:) = 0. dc = dz/prefac - do k = 2,96 + do k = 2,kmax-1 zk = dz*float(k-1) do i = 1,imax - do j = 6,nd-1 ! 5N and higher latitude + do j = jb+1,nd-1 ! 5N and higher latitude astar1(i,j,k) = 0. ! LWA*cos(phi) astar2(i,j,k) = 0. ! LWA*cos(phi) ua2(i,j) = 0. !F2 @@ -64,8 +64,8 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa cor = 2.*om*sin(phi0) !Coriolis parameter do jj = 1,nd phi1 = dp*float(jj-1) - qe(i,jj) = pv(i,jj+90,k)-qref(j,k) !qe; Q = qref - ue(i,jj) = uu(i,jj+90,k)-uref(j-5,k) !ue; shift uref 5N + qe(i,jj) = pv(i,jj+nd-1,k)-qref(j,k) !qe; Q = qref + ue(i,jj) = uu(i,jj+nd-1,k)-uref(j-jb,k) !ue; shift uref 5N aa = a*dp*cos(phi1) !length element if((qe(i,jj).le.0.).and.(jj.ge.j)) then !LWA*cos and F2 astar2(i,j,k)=astar2(i,j,k)-qe(i,jj)*aa !anticyclonic @@ -79,11 +79,11 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ! ******** Other fluxes ****** - ua1(i,j) = uref(j-5,k)*(astar1(i,j,k) + & + ua1(i,j) = uref(j-jb,k)*(astar1(i,j,k) + & astar2(i,j,k)) !F1 - ep1(i,j) = -0.5*(uu(i,j+90,k)-uref(j-5,k))**2 !F3a - ep1(i,j) = ep1(i,j)+0.5*vv(i,j+90,k)**2 !F3a+b - ep11 = 0.5*(pt(i,j+90,k)-tref(j-5,k))**2 !F3c + ep1(i,j) = -0.5*(uu(i,j+nd-1,k)-uref(j-jb,k))**2 !F3a + ep1(i,j) = ep1(i,j)+0.5*vv(i,j+nd-1,k)**2 !F3a+b + ep11 = 0.5*(pt(i,j+nd-1,k)-tref(j-jb,k))**2 !F3c zz = dz*float(k-1) ep11 = ep11*(rr/h)*exp(-rkappa*zz/h) ep11 = ep11*2.*dz/(tg(k+1)-tg(k-1)) @@ -99,15 +99,15 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ! meridional eddy momentum flux one grid north and south - ep2(i,j)=(uu(i,j+91,k)-uref(j-5,k))*vv(i,j+91,k)*cosp*cosp - ep3(i,j)=(uu(i,j+89,k)-uref(j-5,k))*vv(i,j+89,k)*cosm*cosm + ep2(i,j)=(uu(i,j+91,k)-uref(j-jb,k))*vv(i,j+91,k)*cosp*cosp + ep3(i,j)=(uu(i,j+89,k)-uref(j-jb,k))*vv(i,j+89,k)*cosm*cosm ! low-level meridional eddy heat flux if(k.eq.2) then ! (26) of SI-HN17 ep41 = 2.*om*sin0*cos0*dz/prefac ! prefactor - ep42 = exp(-dz/h)*vv(i,j+90,2)*(pt(i,j+90,2)-tref(j-5,2)) + ep42 = exp(-dz/h)*vv(i,j+nd-1,2)*(pt(i,j+nd-1,2)-tref(j-jb,2)) ep42 = ep42/(tg(3)-tg(1)) - ep43 = vv(i,j+90,1)*(pt(i,j+90,1)-tref(j-5,1)) + ep43 = vv(i,j+nd-1,1)*(pt(i,j+nd-1,1)-tref(j-jb,1)) ep43 = 0.5*ep43/(tg(2)-tg(1)) ep4(i,j) = ep41*(ep42+ep43) ! low-level heat flux endif @@ -123,9 +123,9 @@ SUBROUTINE compute_flux_dirinv(pv,uu,vv,pt,tn0,ts0,statn,stats,qref,uref,tref,fa ep1baro(:,:) = ep1baro(:,:)+ep1(:,:)*exp(-zk/h)*dc ep2baro(:,:) = ep2baro(:,:)+ep2(:,:)*exp(-zk/h)*dc ep3baro(:,:) = ep3baro(:,:)+ep3(:,:)*exp(-zk/h)*dc - do j = 6,nd ! ### yet to be multiplied by cosine - ubaro(:,j) = ubaro(:,j)+uu(:,j+90,k)*exp(-zk/h)*dc - urefbaro(j) = urefbaro(j)+uref(j-5,k)*exp(-zk/h)*dc + do j = jb+1,nd ! ### yet to be multiplied by cosine + ubaro(:,j) = ubaro(:,j)+uu(:,j+nd-1,k)*exp(-zk/h)*dc + urefbaro(j) = urefbaro(j)+uref(j-jb,k)*exp(-zk/h)*dc enddo enddo diff --git a/hn2016_falwa/compute_qref_and_fawa_first.f90 b/hn2016_falwa/compute_qref_and_fawa_first.f90 index 7a9ff5a..2fe9e16 100644 --- a/hn2016_falwa/compute_qref_and_fawa_first.f90 +++ b/hn2016_falwa/compute_qref_and_fawa_first.f90 @@ -30,17 +30,6 @@ SUBROUTINE compute_qref_and_fawa_first(pv, uu, vort, pt, tn0, ts0, statn, stats, REAL :: djj(jd-2,jd-2),sjj(jd-2,jd-2) REAL :: pjk(jd-2,kmax),pj(jd-2) REAL :: qbar(nd,kmax) - !integer :: md(12),ipiv(jd-2) - - character*35 fn,fn0,fn1 - character*34 fu - character*34 ft - character*4 fn2(12),fy,fy1,fy2 - character*18 f1,f2 - character*19 f3 - character*36 fv - character*38 fr - pi = acos(-1.) dp = pi/float(jmax-1) diff --git a/hn2016_falwa/oopinterface.py b/hn2016_falwa/oopinterface.py index 5b59b33..97c0cf8 100644 --- a/hn2016_falwa/oopinterface.py +++ b/hn2016_falwa/oopinterface.py @@ -849,7 +849,6 @@ def _compute_qref_fawa_and_bc(self): qref_over_cor, u, ubar, tbar, fawa, ckref, tjk, sjk = ans # unpack tuple - print("Line 535") self._check_nan("qref_over_cor", qref_over_cor) self._check_nan("u", u) self._check_nan("ubar", ubar) diff --git a/hn2016_falwa/upward_sweep.f90 b/hn2016_falwa/upward_sweep.f90 index 009c5d6..92f4b42 100644 --- a/hn2016_falwa/upward_sweep.f90 +++ b/hn2016_falwa/upward_sweep.f90 @@ -81,8 +81,8 @@ SUBROUTINE upward_sweep(jmax, kmax, nd, nnd, jb, jd, sjk, tjk, ckref, tb, qref_o tg(k) = 0. wt = 0. - do jj = 6,91 - j = jj-5 + do jj = jb+1,nd + j = jj-jb phi0 = dp*float(jj-1) tg(k) = tg(k)+cos(phi0)*tref(j,k) wt = wt + cos(phi0) diff --git a/scripts/nhn_grl2022/sample_run_script.py b/scripts/nhn_grl2022/sample_run_script.py index f8b18f3..58fd4fb 100644 --- a/scripts/nhn_grl2022/sample_run_script.py +++ b/scripts/nhn_grl2022/sample_run_script.py @@ -67,7 +67,7 @@ # --- Outputing files --- -output_fname = '2021-06-01_to_2021-06-30_output_b8e1c4.nc' +output_fname = '2021-06-01_to_2021-06-30_output_92901f5.nc' print(output_fname) # --- Generate analysis results --- From b701b0be781042a6d1263da69027c90996ff9ba9 Mon Sep 17 00:00:00 2001 From: csyhuang Date: Thu, 17 Mar 2022 15:45:57 -0500 Subject: [PATCH 18/19] update email address --- docs/source/index.rst | 2 +- hn2016_falwa/matrix_after_inversion.f90 | 2 - hn2016_falwa/matrix_b4_inversion.f90 | 2 - hn2016_falwa/upward_sweep.f90 | 2 - .../nhn_grl2022/download_data_nhn_grl2022.py | 59 ------------------- scripts/nhn_grl2022/readme.md | 35 +++++++++++ scripts/nhn_grl2022/sample_run_script.py | 6 +- setup.py | 2 +- 8 files changed, 40 insertions(+), 70 deletions(-) delete mode 100644 scripts/nhn_grl2022/download_data_nhn_grl2022.py create mode 100644 scripts/nhn_grl2022/readme.md diff --git a/docs/source/index.rst b/docs/source/index.rst index 63e1fad..b3f24d1 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -95,7 +95,7 @@ Issues Reporting Please make inquiries about / report issues / with the package and suggest feature extensions on the `Issues page `_. -If you need help analyzing output from particular model/analysis with our techniques, feel free to email me *csyhuang@uchicago.edu* with sample datasets and I can configure the code for you. +If you need help analyzing output from particular model/analysis with our techniques, feel free to email me *csyhuang@protonmail.com* with sample datasets and I can configure the code for you. Indices and tables diff --git a/hn2016_falwa/matrix_after_inversion.f90 b/hn2016_falwa/matrix_after_inversion.f90 index 1bd22fb..f126b5b 100644 --- a/hn2016_falwa/matrix_after_inversion.f90 +++ b/hn2016_falwa/matrix_after_inversion.f90 @@ -1,5 +1,3 @@ -! *** Copying from lines 333-368 from era4004n.f90 *** - SUBROUTINE matrix_after_inversion(k,kmax,jb,jd,qjj,djj,cjj,tj,rj,sjk,tjk) INTEGER, INTENT(in) :: k, kmax, jb, jd diff --git a/hn2016_falwa/matrix_b4_inversion.f90 b/hn2016_falwa/matrix_b4_inversion.f90 index eeb277c..cb32def 100644 --- a/hn2016_falwa/matrix_b4_inversion.f90 +++ b/hn2016_falwa/matrix_b4_inversion.f90 @@ -1,5 +1,3 @@ -! *** Copying from lines 254-324 from era4004n.f90 *** - SUBROUTINE matrix_b4_inversion(k,jmax,kmax,nd,jb,jd,z,statn,qref,ckref,& a, om, dz, h, rr, cp, & qjj,djj,cjj,rj,tj,u,sjk,tjk) diff --git a/hn2016_falwa/upward_sweep.f90 b/hn2016_falwa/upward_sweep.f90 index 92f4b42..c53ff78 100644 --- a/hn2016_falwa/upward_sweep.f90 +++ b/hn2016_falwa/upward_sweep.f90 @@ -1,5 +1,3 @@ -! *** Copying from lines 374-442 from era4004n.f90 *** - SUBROUTINE upward_sweep(jmax, kmax, nd, nnd, jb, jd, sjk, tjk, ckref, tb, qref_over_cor, u, tref, qref, a, om, dz, h, rr, cp) INTEGER, INTENT(IN) :: jmax, kmax, nd, nnd, jb, jd diff --git a/scripts/nhn_grl2022/download_data_nhn_grl2022.py b/scripts/nhn_grl2022/download_data_nhn_grl2022.py deleted file mode 100644 index 446fd6c..0000000 --- a/scripts/nhn_grl2022/download_data_nhn_grl2022.py +++ /dev/null @@ -1,59 +0,0 @@ -""" -Download data to reproduce plots in Neal et al. (submitted to GRL) -""" - -import json -from datetime import date, datetime -from calendar import monthrange -import cdsapi - - -def download_era5_pressure_level_data(filename): - cdsapi_client = cdsapi.Client() - all_pressure_level = [ - '1', '2', '3', '5', '7', '10', '20', '30', '50', '70', '100', '125', '150', '175', '200', - '225', '250', '300', '350', '400', '450', '500', '550', '600', '650', '700', '750', '775', - '800', '825', '850', '875', '900', '925', '950', '975', '1000'] - variable_names = [ - "geopotential", - "temperature", - "u_component_of_wind", - "v_component_of_wind", - "vertical_velocity"] - - cdsapi_client.retrieve( - 'reanalysis-era5-pressure-levels', - { - 'pressure_level': all_pressure_level, - 'variable': variable_names, - 'time': ["00:00", "06:00", "12:00", "18:00"], - 'grid': "1.0/1.0", - 'product_type': 'reanalysis', - 'year': '2021', - 'day': [f'{i}' for i in range(20, 31)], - 'month': '6', - 'format': 'netcdf' - }, - filename - ) - - -def download_single_level_data(self, filename): - self._cdsapi_client.retrieve( - 'reanalysis-era5-single-levels', - { - 'variable': ["2m_temperature"], - 'time': ["00:00", "06:00", "12:00", "18:00"], - 'grid': "1.0/1.0", - 'product_type': 'reanalysis', - 'year': '2021', - 'day': [f'{i}' for i in range(20, 31)], - 'month': '6', - 'format': 'netcdf' - }, - filename - ) - - -if __name__ == "__main__": - download_era5_pressure_level_data("pressure_level_data_20210620to30.nc") diff --git a/scripts/nhn_grl2022/readme.md b/scripts/nhn_grl2022/readme.md new file mode 100644 index 0000000..3b9cf83 --- /dev/null +++ b/scripts/nhn_grl2022/readme.md @@ -0,0 +1,35 @@ +## Demo script for the analyses done in Neal et al. (submitted to GRL) + +This repo contains the sample script to reproduce the plots in Neal et al. "The 2021 Pacific Northwest heat wave and +associated blocking: Meteorology and the role of an upstream cyclone as a diabatic source of wave activity". + +To produce all the plots, required ERA5 data (6-hourly, 1° x 1° spatial resolution at all pressure levels +(37 available levels), from June 1-30, 2021): + +- geopotential height (z) +- zonal wind (u) +- meridional wind (v) +- temperature (t) +- 2-m temperature (t2m) +- net OLR (mtnlwrf) +- clear-sky OLR (mtnlwrfcs) +- total column water (tcw) +- total column water vapor (tcwv) +- sea level pressure (sp) + +The run script `sample_run_script.py` called functions in `QGField` object (see `hn2016_falwa/oopinterface.py`) +to compute LWA and fluxes, while `scripts/graph_plot_module.py` contains the graph plotting functions to reproduce +all the figures in the paper. + +Note that there is a difference in computing reference state in this most recent manuscript. In the past, and also +the analysis in NH18 Science, we used equator as the latitudinal boundary. In this current version of the script +(release 0.6.0), we use absolute vorticity at 5°N as boundary condition such that the solution is no longer sensitive +to fields at the equator, which improves the quality of the analysis. + +We are in a hurry submitting the manuscript, so this version of code (v0.6.0) has not been properly refactored yet. +If you have any questions, please [submit an issue](https://github.com/csyhuang/hn2016_falwa/issues) or email me. +I'll get back ASAP. + +Thanks! + +Clare (csyhuang@protonmail.com) \ No newline at end of file diff --git a/scripts/nhn_grl2022/sample_run_script.py b/scripts/nhn_grl2022/sample_run_script.py index 58fd4fb..45feb74 100644 --- a/scripts/nhn_grl2022/sample_run_script.py +++ b/scripts/nhn_grl2022/sample_run_script.py @@ -67,8 +67,8 @@ # --- Outputing files --- -output_fname = '2021-06-01_to_2021-06-30_output_92901f5.nc' -print(output_fname) +output_fname = '2021-06-01_to_2021-06-30_output.nc' +print(f"output_fname: {output_fname}") # --- Generate analysis results --- if to_generate_data: @@ -109,7 +109,7 @@ vv = v_file.variables['v'][tstep, ::-1, ::-1, :].data tt = t_file.variables['t'][tstep, ::-1, ::-1, :].data - qgfield_object = QGField(xlon, ylat, plev, uu, vv, tt, kmax=kmax, dz=dz) + qgfield_object = QGField(xlon, ylat, plev, uu, vv, tt, kmax=kmax, dz=dz, eq_boundary_index=5) qgpv_temp, interpolated_u_temp, interpolated_v_temp, interpolated_avort_temp, interpolated_theta_temp, \ static_stability_n, static_stability_s, tn0, ts0 = qgfield_object._interpolate_field_dirinv() diff --git a/setup.py b/setup.py index a2eb9c6..6ff51d3 100644 --- a/setup.py +++ b/setup.py @@ -66,7 +66,7 @@ long_description=LONG_DESCRIPTION, url='https://github.com/csyhuang/hn2016_falwa', author='Clare S. Y. Huang', - author_email='csyhuang@uchicago.edu', + author_email='csyhuang@protonmail.com', license='MIT', packages=find_packages(), setup_requires=['pytest-runner'], From 524be0b2f3b3ac074b61bf8cfe12298545ea16b4 Mon Sep 17 00:00:00 2001 From: csyhuang Date: Thu, 17 Mar 2022 15:49:59 -0500 Subject: [PATCH 19/19] remove redundant files --- show_noboru/era4004n.f90 | 463 --------------------------------------- 1 file changed, 463 deletions(-) delete mode 100644 show_noboru/era4004n.f90 diff --git a/show_noboru/era4004n.f90 b/show_noboru/era4004n.f90 deleted file mode 100644 index 1c6d862..0000000 --- a/show_noboru/era4004n.f90 +++ /dev/null @@ -1,463 +0,0 @@ - program main - -! USE mkl95_BLAS, ONLY: GEMM,GEMV - USE mkl95_LAPACK, ONLY: GETRF,GETRI - - -! **** take QG analysis and compute Q_ref and invert for -! U_ref & Theta_ref for NH (Direct solver) *** - - integer,parameter :: imax = 360, JMAX = 181, KMAX = 97 - integer,parameter :: nd = 91,nnd=181 - integer,parameter :: jb = 5 ! lower bounding latitude - integer,parameter :: jd = 86 ! nd - lower bounding latitude - common /array/ pv(imax,jmax,kmax),pv2(imax,jmax) - common /brray/ uu(imax,jmax,kmax) - common /bbray/ vort(imax,jmax,kmax),vort2(imax,jmax) - common /bcray/ pt(imax,jmax,kmax) - common /bdray/ stats(kmax),statn(kmax),ts0(kmax),tn0(kmax) - common /crray/ qn(nnd),an(nnd),aan(nnd),tb(kmax),tg(kmax) - common /drray/ cn(nnd),ccn(nnd),tref(jd,kmax) - common /frray/ alat(nd),phi(nd),z(kmax),cbar(nd,kmax) - common /krray/ tjk(jd-2,kmax-1),tj(jd-2),rj(jd-2) - common /lrray/ qjj(jd-2,jd-2),cjj(jd-2,jd-2) - common /orray/ xjj(jd-2,jd-2),yj(jd-2) - common /mrray/ djj(jd-2,jd-2),sjj(jd-2,jd-2) - common /nrray/ sjk(jd-2,jd-2,kmax-1) - common /prray/ pjk(jd-2,kmax),pj(jd-2) - common /irray/ qref(nd,kmax),u(jd,kmax),cref(nd,kmax) - common /krray/ fawa(nd,kmax),ckref(nd,kmax) - common /jrray/ qbar(nd,kmax),ubar(nd,kmax),tbar(nd,kmax) - integer :: md(12),ipiv(jd-2) - - character*35 fn,fn0,fn1 - character*34 fu - character*34 ft - character*4 fn2(12),fy,fy1,fy2 - character*18 f1,f2 - character*19 f3 - character*36 fv - character*38 fr - - a = 6378000. - pi = acos(-1.) - om = 7.29e-5 - dp = pi/180. - dz = 500. - h = 7000. - r = 287. - rkappa = r/1004. - - do nn = 1,nd - phi(nn) = dp*float(nn-1) - alat(nn) = 2.*pi*a*a*(1.-sin(phi(nn))) - enddo - - do k = 1,kmax - z(k) = dz*float(k-1) - enddo - - do m = 1979,2020 - - md(1) = 31 - md(2) = 28 - if(mod(m,4).eq.0) md(2) = 29 - md(3) = 31 - md(4) = 30 - md(5) = 31 - md(6) = 30 - md(7) = 31 - md(8) = 31 - md(9) = 30 - md(10) = 31 - md(11) = 30 - md(12) = 31 - - fn2(1) = '_01_' - fn2(2) = '_02_' - fn2(3) = '_03_' - fn2(4) = '_04_' - fn2(5) = '_05_' - fn2(6) = '_06_' - fn2(7) = '_07_' - fn2(8) = '_08_' - fn2(9) = '_09_' - fn2(10) = '_10_' - fn2(11) = '_11_' - fn2(12) = '_12_' - - write(fy,266) m - 266 format(i4) - - do n = 1,12 - fn = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGPV' - fu = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGU' - ft = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGT' - fr = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QGREF_N' - fv = '/data2/nnn/ERA5/'//fy//'/'//fy//fn2(n)//'QVORT' - write(6,*) fn,md(n) - open(35,file =fn, & - form='unformatted',status = 'old') - open(36,file =fu, & - form='unformatted',status = 'old') - open(37,file =ft, & - form='unformatted',status = 'old') - open(38,file =fr, & - form='unformatted',status = 'new') - open(39,file =fv, & - form='unformatted',status = 'old') - - do mm = 1,md(n)*4 - - read(35) pv - read(36) uu - read(39) vort - read(37) pt,tn0,ts0,statn,stats - -! **** Zonal-mean field **** - do j = 91,jmax - qbar(j-90,:) = 0. - tbar(j-90,:) = 0. - ubar(j-90,:) = 0. - do i = 1,imax - qbar(j-90,:) = qbar(j-90,:)+pv(i,j,:)/float(imax) - tbar(j-90,:) = tbar(j-90,:)+pt(i,j,:)/float(imax) - ubar(j-90,:) = ubar(j-90,:)+uu(i,j,:)/float(imax) - enddo - enddo - -! **** hemispheric-mean potential temperature **** - tb(:) = tn0(:) - - do k = 2,96 - pv2(:,:) = pv(:,:,k) - vort2(:,:) = vort(:,:,k) - -! **** compute qref via area analysis **** - qmax = maxval(pv2) - qmin = minval(pv2) - dq = (qmax-qmin)/float(nnd-1) - qn(:) = 0. - an(:) = 0. - cn(:) = 0. - do nn = 1,nnd - qn(nn) = qmax - dq*float(nn-1) - enddo - do j = 1,jmax - phi0 = -0.5*pi+dp*float(j-1) - do i = 1,imax - ind = 1+int((qmax-pv2(i,j))/dq) - da = a*a*dp*dp*cos(phi0) - an(ind) = an(ind) + da - cn(ind) = cn(ind) + da*pv2(i,j) - enddo - enddo - aan(1) = 0. - ccn(1) = 0. - do nn = 2,nnd - aan(nn) = aan(nn-1)+an(nn) - ccn(nn) = ccn(nn-1)+cn(nn) - enddo - do j = 1,nd-1 - do nn = 1,nnd-1 - if(aan(nn).le.alat(j).and.aan(nn+1).gt.alat(j)) then - dd = (alat(j)-aan(nn))/(aan(nn+1)-aan(nn)) - qref(j,k) = qn(nn)*(1.-dd)+qn(nn+1)*dd - cref(j,k) = ccn(nn)*(1.-dd)+ccn(nn+1)*dd - endif - enddo - enddo - - qref(nd,k) = qmax - - cbar(nd,k) = 0. - do j=nd-1,1,-1 - phi0 = dp*(float(j)-0.5) - cbar(j,k) = cbar(j+1,k)+0.5*(qbar(j+1,k)+qbar(j,k)) & - *a*dp*2.*pi*a*cos(phi0) - enddo - -! **** compute Kelvin's circulation based on absolute vorticity (for -! b.c.) **** - - qmax = maxval(vort2) - qmin = minval(vort2) - dq = (qmax-qmin)/float(nnd-1) - qn(:) = 0. - an(:) = 0. - cn(:) = 0. - do nn = 1,nnd - qn(nn) = qmax - dq*float(nn-1) - enddo - do j = 1,jmax - phi0 = -0.5*pi+dp*float(j-1) - do i = 1,imax - ind = 1+int((qmax-vort2(i,j))/dq) - da = a*a*dp*dp*cos(phi0) - an(ind) = an(ind) + da - cn(ind) = cn(ind) + da*vort2(i,j) - enddo - enddo - aan(1) = 0. - ccn(1) = 0. - do nn = 2,nnd - aan(nn) = aan(nn-1)+an(nn) - ccn(nn) = ccn(nn-1)+cn(nn) - enddo - do j = 1,nd-1 - do nn = 1,nnd-1 - if(aan(nn).le.alat(j).and.aan(nn+1).gt.alat(j)) then - dd = (alat(j)-aan(nn))/(aan(nn+1)-aan(nn)) - ckref(j,k) = ccn(nn)*(1.-dd)+ccn(nn+1)*dd - endif - enddo - enddo - - enddo - -! ***** normalize QGPV by sine (latitude) **** - - do j = 2,nd - phi0 = dp*float(j-1) - cor = sin(phi0) - qref(j,:) = qref(j,:)/cor - enddo - - do k = 2,kmax-1 - qref(1,k) = 2.*qref(2,k)-qref(3,k) - enddo - -! ***** FAWA ***** - fawa(:,:) = (cref(:,:)-cbar(:,:))/(2.*pi*a) - -! ***** Direct solver to invert Q_ref ***** - -! *** downward sweep *** - -! **** top boundary condition (Eqs. 24-25) ***** - tjk(:,:) = 0. - sjk(:,:,:) = 0. - do jj = jb+2,90 - j = jj-jb - phi0 = float(jj-1)*dp - cos0 = cos(phi0) - sin0 = sin(phi0) - tjk(j-1,kmax-1) = -dz*r*cos0*exp(-z(kmax-1)*rkappa/h) - tjk(j-1,kmax-1) = tjk(j-1,kmax-1)*(tbar(j+1,kmax)-tbar(j-1,kmax)) - tjk(j-1,kmax-1) = tjk(j-1,kmax-1)/(4.*om*sin0*dp*h*a) - sjk(j-1,j-1,kmax-1) = 1. - enddo - -! **** Evaluate Eqs. 22-23 downward *** - - do k = kmax-1,2,-1 - zp = 0.5*(z(k+1)+z(k)) - zm = 0.5*(z(k-1)+z(k)) - statp = 0.5*(statn(k+1)+statn(k)) - statm = 0.5*(statn(k-1)+statn(k)) - cjj(:,:) = 0. - djj(:,:) = 0. - qjj(:,:) = 0. - sjj(:,:) = sjk(:,:,k) - tj(:) = tjk(:,k) - do jj = jb+2,90 - j = jj - jb - phi0 = float(jj-1)*dp - phip = (float(jj)-0.5)*dp - phim = (float(jj)-1.5)*dp - cos0 = cos(phi0) - cosp = cos(phip) - cosm = cos(phim) - sin0 = sin(phi0) - sinp = sin(phip) - sinm = sin(phim) - - fact = 4.*om*om*h*a*a*sin0*dp*dp/(dz*dz*r*cos0) - amp = exp(-zp/h)*exp(rkappa*zp/h)/statp - amp = amp*fact*exp(z(k)/h) - amm = exp(-zm/h)*exp(rkappa*zm/h)/statm - amm = amm*fact*exp(z(k)/h) - -! ***** Specify A, B, C, D, E, F (Eqs. 4-9) ***** - ajk = 1./(sinp*cosp) - bjk = 1./(sinm*cosm) - cjk = amp - djk = amm - ejk = ajk+bjk+cjk+djk - fjk = -0.5*a*dp*(qref(jj+1,k)-qref(jj-1,k)) - -! ***** Specify rk (Eq. 15) **** - - ! **** North-south boundary conditions **** - u(jd,k) = 0. - phi0 = dp*float(jb) -! u(1,k) = ubar(jb+1,k)*cos(phi0) - u(1,k) = ckref(jb+1,k)/(2.*pi*a)-om*a*cos(phi0) - - rj(j-1) = fjk - if(j.eq.2) rj(j-1) = fjk - bjk*u(1,k) - if(j.eq.jd-1) rj(j-1) = fjk - ajk*u(jd,k) - -! ***** Specify Ck & Dk (Eqs. 18-19) ***** - cjj(j-1,j-1) = cjk - djj(j-1,j-1) = djk - -! **** Specify Qk (Eq. 17) ***** - qjj(j-1,j-1) = -ejk - if(j-1.ge.1.and.j-1.lt.jd-2) then - qjj(j-1,j) = ajk - endif - if(j-1.gt.1.and.j-1.le.jd-2) then - qjj(j-1,j-2) = bjk - endif - enddo - -! **** Compute Qk + Ck Sk ******* - do i = 1,jd-2 - do j = 1,jd-2 - xjj(i,j) = 0. - do kk = 1,jd-2 - xjj(i,j) = xjj(i,j)+cjj(i,kk)*sjj(kk,j) - enddo - qjj(i,j) = qjj(i,j)+xjj(i,j) - enddo - enddo -! call gemm(cjj,sjj,xjj) -! qjj(:,:) = qjj(:,:)+xjj(:,:) - -! **** Invert (Qk + Ck Sk) ******** - call getrf(qjj,ipiv) - call getri(qjj,ipiv) - -! **** Evaluate Eq. 22 **** - do i = 1,jd-2 - do j = 1,jd-2 - xjj(i,j) = 0. - do kk = 1,jd-2 - xjj(i,j) = xjj(i,j)+qjj(i,kk)*djj(kk,j) - enddo - sjk(i,j,k-1) = -xjj(i,j) - enddo - enddo - -! call gemm(qjj,djj,xjj) -! sjk(:,:,k-1) = -xjj(:,:) - -! **** Evaluate rk - Ck Tk **** - do i = 1,jd-2 - yj(i) = 0. - do kk = 1,jd-2 - yj(i) = yj(i)+cjj(i,kk)*tj(kk) - enddo - yj(i) = rj(i)-yj(i) - enddo - -! call gemv(cjj,tj,yj) -! yj(:) = rj(:)-yj(:) -! call gemv(qjj,yj,tj) -! tjk(:,k-1) = tj(:) - - -! ***** Evaluate Eq. 23 ******* - do i = 1,jd-2 - tj(i) = 0. - do kk = 1,jd-2 - tj(i) = tj(i)+qjj(i,kk)*yj(kk) - enddo - tjk(i,k-1) = tj(i) - enddo - - enddo - -! ***** upward sweep (Eq. 20) **** - - pjk(:,1) = 0. - do k = 1,kmax-1 - pj(:) = pjk(:,k) - sjj(:,:) = sjk(:,:,k) - tj(:) = tjk(:,k) - - do i = 1,jd-2 - yj(i) = 0. - do kk = 1,jd-2 - yj(i) = yj(i)+sjj(i,kk)*pj(kk) - enddo - pjk(i,k+1) = yj(i)+tj(i) - enddo -! call gemv(sjj,pj,yj) -! pjk(:,k+1) = yj(:) + tj(:) - enddo - -! **** Recover u ***** - do k = 1,kmax - do j = 2,jd-1 - u(j,k) = pjk(j-1,k) - enddo - enddo - -! *** Corner boundary conditions *** - u(1,1) = 0. - u(jd,1) = 0. -! u(1,kmax) = ubar(1+jb,kmax)*cos(dp*float(jb)) - u(1,kmax) = ckref(1+jb,kmax)/(2.*pi*a)-om*a*cos(dp*float(jb)) - u(jd,kmax) = 0. - -! *** Divide by cos phi to revover Uref **** - do jj = jb+1,nd-1 - j = jj-jb - phi0 = dp*float(jj-1) - u(j,:) = u(j,:)/cos(phi0) - enddo - u(jd,:) = 2.*u(jd-1,:)-u(jd-2,:) - -! ******** compute tref ******* - - do k = 2,96 - t00 = 0. - zz = dz*float(k-1) - tref(1,k) = t00 - tref(2,k) = t00 - do j = 2,jd-1 - phi0 = dp*float(j-1+jb) - cor = 2.*om*sin(phi0) - uz = (u(j,k+1)-u(j,k-1))/(2.*dz) - ty = -cor*uz*a*h*exp(rkappa*zz/h) - ty = ty/r - tref(j+1,k) = tref(j-1,k)+2.*ty*dp - enddo - do j = 1,nd - phi0 = dp*float(j-1) - qref(j,k) = qref(j,k)*sin(phi0) - enddo - tg(k) = 0. - wt = 0. - do jj = 6,91 - j = jj-5 - phi0 = dp*float(jj-1) - tg(k) = tg(k)+cos(phi0)*tref(j,k) - wt = wt + cos(phi0) - enddo - tg(k) = tg(k)/wt - tres = tb(k)-tg(k) - tref(:,k) = tref(:,k)+tres - enddo - tref(:,1) = tref(:,2)-tb(2)+tb(1) - tref(:,97) = tref(:,96)-tb(96)+tb(97) - - write(38) qref,u,tref,fawa,ubar,tbar - - write(6,*) m,n,mm - -! ******************************** - enddo - - close(35) - close(36) - close(37) - close(38) - - enddo - enddo - - stop - end