#PBS -N process_co2 #PBS -S /bin/bash #PBS -q week # there exist: short, day, days3, week... #PBS -k eo # to write the output of stdin ### Max memory #PBS -l vmem=10gb # virtual memory #PBS -l mem=10gb #--updated on 4/5/2017 with improved Sheng & Zwiers algorithm, ThL #--corrected some interpolation preprocessing (compared to v4) #--updated on 9/5/2017 with output separation BB/anthro for SO2, NOx and NH3 #--corrected on 22/6/2017 for BB: undef values zeroed before remapping # #--input directory for anthropogenic (non-BB) emissions dirinPNNL_2D="/prodigfs/project/input4MIPs/CMIP6/CMIP/PNNL-JGCRI/CEDS-2017-05-18/" dirinPNNL_3D="/prodigfs/project/input4MIPs/CMIP6/CMIP/PNNL-JGCRI/CEDS-2017-08-30/" #--LMDz grid information #grid="144x143" #nbpoint=$((144*141+2)) grid="48x36" nbpoint=$((48*35+2)) gridfile="/home/oboucher/CMIP6/GRID/grid-lmdz-lonlat_"${grid} #--output directory dirout="/data/obolmd/CMIP6/CO2_EMISSIONS_"${grid}"/" if [ ! -d ${dirout} ] ; then mkdir -p ${dirout} ; fi #--year for year in {1850..2014} #for year in {2000..2000} do #--species for species in "CO2" do #--finding correct file for PNNL data if [ $year -ge 1750 -a $year -lt 1800 ]; then year1=1750 year2=1799 elif [ $year -ge 1800 -a $year -lt 1850 ]; then year1=1800 year2=1849 elif [ $year == 1850 ]; then year1=1850 year2=1850 elif [ $year -ge 1851 -a $year -lt 1900 ]; then year1=1851 year2=1899 elif [ $year -ge 1900 -a $year -lt 1950 ]; then year1=1900 year2=1949 elif [ $year -ge 1950 -a $year -lt 2000 ]; then year1=1950 year2=1999 elif [ $year -ge 2000 -a $year -lt 2015 ]; then year1=2000 year2=2014 else echo 'Houston we have a problem for the PNNL data' exit 1 fi #--input file PNNL surface emissions filename2D=${dirinPNNL_2D}/atmos/mon/${species}-em-anthro/gn/v20170519/${species}-em-anthro_input4MIPs_emissions_CMIP_CEDS-2017-05-18_gn_${year1}01-${year2}12.nc #--input file PNNL air emissions filename3D=${dirinPNNL_3D}/atmos/mon/${species}-em-AIR-anthro/gn/v20170907/${species}-em-AIR-anthro_input4MIPs_emissions_CMIP_CEDS-2017-08-30_gn_${year1}01-${year2}12.nc #--output files filenameout1=${dirout}flux_${species}_${year}.nc filenameout2=${dirout}flux_2D_${species}_${year}.nc filenameout3=${dirout}flux_1D_${species}_${year}.nc echo ${filename2D} ${filename3D} ${filenameout1} ${filenameout2} ${filenameout3} rm -f ${filenameout1} ${filenameout2} ${filenameout3} #--unfortunately idl not happy with PNNL netcdf files so need to ferretize files #--I also sum over sectors for the 2D file and over altitude for the 3D file and I extract the correct year as well rm -f rewrite.jnl cat << eod > rewrite.jnl use "${filename2D}" use "${filename3D}" set region/t=16-jan-${year}:16-dec-${year} let flux=${species}_EM_ANTHRO[d=1,k=@sum]+${species}_EM_AIR_ANTHRO[d=2,k=@sum] save/clobber/file="${filenameout1}" flux eod #--run ferret script ferret << eod go rewrite.jnl exit eod rm -f rewrite.jnl ferret.jnl #--remap to LMDz grid echo cdo remapcon,${gridfile} -chname,FLUX,flux ${filenameout1} ${filenameout2} cdo remapcon,${gridfile} -chname,FLUX,flux ${filenameout1} ${filenameout2} #--Improved Sheng & Zwiers algorithm + transform into vector rm -f regrid.pro cat << eod >> regrid.pro pro regrid filename='${filenameout2}' print, filename NETCDFREAD,filename,'flux',flux,dimflux NETCDFREAD,filename,'lat',lat,dimlat0 NETCDFREAD,filename,'lon',lon,dimlon0 NETCDFREAD,filename,'TIME',time,dimtime0 dimlat=dimlat0(0) dimlon=dimlon0(0) dimtime=dimtime0(0) print, 'dim flux=', dimflux A = float([ [3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8.],$ [1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0.],$ [0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0., 0.],$ [0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0., 0.],$ [0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0., 0.],$ [0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0., 0.],$ [0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0., 0.],$ [0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0., 0.],$ [0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0., 0.],$ [0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8., 0.],$ [0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4., 1./8.],$ [1./8., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1./8., 3./4.] ]) A = float([ [1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],$ [0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],$ [0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.],$ [0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.],$ [0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.],$ [0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0.],$ [0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.],$ [0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0.],$ [0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0.],$ [0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0.],$ [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.],$ [0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.] ]) fluxinit=flux fluxinit=flux flux_check=flux for lo=0,dimlon-1 do begin for la=0,dimlat-1 do begin flux_check(lo,la,*) = invert(A) ## transpose(fluxinit(lo,la,*)) endfor endfor m_bloq = make_array(dimlon,dimlat,12,value=0) ; Matrice booléenne "mois à bloquer ou non" if total(where(flux_check lt 0)) ne -1 then m_bloq(where(flux_check lt 0)) = 1 ; Correction/adaptation de la matrice S&Z en fonction du masque booléen m_bloq for lo=0,dimlon-1 do begin for la=0,dimlat-1 do begin whereneg = where(flux_check(lo,la,*) lt 0) ; (12 pts max) Identification de potentiels points à problèmes, corrigés négativement nbannul=n_elements(whereneg)*(total(whereneg) ne -1) flux_corr=flux_check(lo,la,*) ; Création d'un vecteur pour recevoir les valeurs corrigées, initialisé à flux_check au cas où on n'ait rien à faire d'autre qu'une seule itération A2 = A ; Je repars de la matrice A initiale, ce pour chaque point de grille ; ; Potentiellement plusieurs passages pour éliminer toutes les valeurs négatives while nbannul ne 0 do begin ; Si l'on a effectivement des émissions corrigées négativement... m_bloq(lo,la,whereneg) = 1 ; Update de la matrice m_bloq for m=0,11 do begin if m eq 11 then begin ; Pour plus de facilité, mois précédents et suivants codés ici p=10 s=0 endif else if m eq 0 then begin p=11 s=1 endif else begin p = m-1 s = m+1 endelse if m_bloq(lo,la,m) then begin ; Je traite les mois bloqués en eux-mêmes A2(p,m) = 0. A2(m,m) = 1. A2(s,m) = 0. endif ; Fin du cas si l'on est sur un mois bloqué if ~m_bloq(lo,la,m) then begin ; Je traite les mois non bloqués, pour ceux adjacents à un mois bloqué if m_bloq(lo,la,p) and m_bloq(lo,la,s) then begin ; Mois encadré de deux mois bloqués A2(p,m) = 1./4. A2(m,m) = 1./2. A2(s,m) = 1./4. endif else if m_bloq(lo,la,p) and ~m_bloq(lo,la,s) then begin ; Mois précédent bloqué (uniquement) A2(p,m) = 2./8. A2(m,m) = 5./8. A2(s,m) = 1./8. endif else if ~m_bloq(lo,la,p) and m_bloq(lo,la,s) then begin ; Mois suivant bloqué (uniquement) A2(p,m) = 1./8. A2(m,m) = 5./8. A2(s,m) = 2./8. endif endif ; Fin du cas mois non bloqué endfor ; Fin de la boucle sur les mois, balayage de la matrice flux_corr = invert(A2) ## transpose(fluxinit(lo,la,*)) ; Ré-itération de la multiplication matricielle avec la matrice A modifiée (A2) whereneg = where(flux_corr lt 0) ; (12 pts max) Ré-identification de potentiels nouveaux points à problèmes, corrigés négativement nbannul=n_elements(whereneg)*(total(whereneg) ne -1) endwhile ; Fin du cas où l'on avait des problèmes d'émissions corrigées négativement ; *** IMPORTANT ! *** Pour signaler les mois bloqués, on prend la convention suivante : ; valeur négative ou nulle <=> mois bloqué ; valeur positive <=> mois à interpolation classique flux(lo,la,*) = flux_corr ; En sortie de la boucle while, normalement flux_corr est complètement positif endfor ; Fin boucle lat endfor ; Fin boucle lon nbnegtotal = n_elements(where(m_bloq eq 1)) * (total(where(m_bloq eq 1)) ne -1) if nbnegtotal ne 0 then flux(where(m_bloq eq 1)) = -flux(where(m_bloq eq 1)) ; Je force à des valeurs négatives ; month_in_year=12 nbpoint=${nbpoint} flux2=fltarr(nbpoint,month_in_year) flux2(*,*)=0.0 ; for l=0,month_in_year-1 do begin flux2(0,l)=TOTAL(flux(*,0,l))/float(dimlon) flux2(nbpoint-1,l)=TOTAL(flux(*,dimlat-1,l))/float(dimlon) endfor ; pt=1 for j=1,dimlat-2 do begin for i=0,dimlon-1 do begin for l=0,month_in_year-1 do begin flux2(pt,l)=flux(i,j,l) endfor pt=pt+1 endfor endfor ; ;saving netcdf file ; fluxstruct={vector:fltarr(nbpoint),time:fltarr(month_in_year), $ flx_${species}:fltarr(nbpoint,month_in_year) } ; fluxstruct.vector=float(indgen(nbpoint)+1) ;;fluxstruct.time=float(indgen(month_in_year)+1) fluxstruct.time=[15, 45, 75, 105, 135, 165, 195, 225, 255, 285, 315, 345] fluxstruct.flx_${species}=flux2 ; attributes = {units:strarr(3),long_name:strarr(3)} attributes.units = ['vector','days since 1960-01-01','flux'] attributes.long_name = ['vector', 'time', 'flux'] ; dimensions = {isdim:intarr(3), links:intarr(2,3)} dimensions.isdim = [1,1,0] ; (1=dimension, 0=variable) dimensions.links = [ [-1,-1],[-1,-1],[0,1] ] ; netcdfwrite,'${filenameout3}',fluxstruct,clobber=1, attributes=attributes, dimensions=dimensions ; end eod # #--calling IDL # /opt/idl-6.4/idl/bin/idl << eod .r netcdf .r netcdfwrite .r struct_dims .r regrid regrid exit eod # #--end loop on species done #--deleting output file if already there #rm -f ${dirout}co2ff_lmdz_cmip6_${year}.nc #--rename a few things #cdo expr,'flx_co2=FLX_CO2' ${dirout}flux_vector_CO2_${year}.nc ${dirout}co2ff_lmdz_cmip6_${year}.nc #ncrename -d VECTOR,vector -v VECTOR,vector ${dirout}co2ff_lmdz_cmip6_${year}.nc #ncrename -d TIME,time -v TIME,time ${dirout}co2ff_lmdz_cmip6_${year}.nc #--cleaning up #rm -f ${dirout}flux*_${year}.nc rm -f ${filenameout1} #--end loop on years done #--cleaning the mess rm -f ferret* rm -f regrid.pro rm -f rewrite.jnl