;------------------------------------------------------------------------------ ; NCL4GC: NCL Tools for use with the GEOS-Chem Chemical Transport Model ! ;------------------------------------------------------------------------------ ;BOP ; ; !ROUTINE: adj_arcmap ; ; !DESCRIPTION: Routine to adjust a netCDF file created by ArcMap. ; ; Note: Prior to running this script, did "cdo -s setmisstoc,0" to change ; all missing values to zero. ;\\ ;\\ ; !USES: ; ; NCL routines load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" ; Local routines load "$NCL4GC/file_io/add_coards_var_atts.ncl" load "$NCL4GC/file_io/add_coards_global_atts.ncl" ; ; !REMARKS: ; ; !REVISION HISTORY: ; 27 Mar 2015 - M. Sulprizio- Initial version ;EOP ;------------------------------------------------------------------------------ ;BOC begin ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ; For testing Dir = "./" inFile = Dir+"arcmap/ResME_SfcEmis_01x01.nc" outFile = Dir+"ResME_Surface_Emissions.0.1x0.1.nc" ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ;========================================================================= ; Error check inputs ;========================================================================= ; Make sure inFile is passed if ( .not. isvar( "inFile" ) ) then print( "Argument 'inFile' not specified...exiting!" ) end if ; Make sure inFile is passed if ( .not. isvar( "outFile" ) ) then print( "Argument 'outFile' not specified...exiting!" ) end if ;========================================================================= ; Read data from the input file ;========================================================================= fIn = addfile( inFile, "r" ) inLon = fIn->lon inLat = fIn->lat inData = fIn->CH4_Emis ;========================================================================= ; Define grid ;========================================================================= ; Lat and lon centers ; For global 0.1x0.1 grid outLon := fspan( -179.95, 179.95, 3600 ) outLat := fspan( -89.95, 89.95, 1800 ) ; Dimensions nLonIn = dimsizes( inLon ) nLatIn = dimsizes( inLat ) nLonOut = dimsizes( outLon ) nLatOut = dimsizes( outLat ) DeltaLon = decimalPlaces((outLon(1)-outLon(0)),2,True) DeltaLat = decimalPlaces((outLat(1)-outLat(0)),2,True) ;========================================================================= ; Add modifications for COARDS compliance ;========================================================================= ;--------------- ; Var atts ;--------------- lon = new( (/nLonOut/), float ) lon = outLon lon!0 = "lon" lon&lon = lon lon@standard_name = "longitude" lon@long_name = "longitude" lon@units = "degrees_east" lon@axis = "X" lat = new( (/nLatOut/), float ) lat = outLat lat!0 = "lat" lat&lat = lat lat@standard_name = "latitude" lat@long_name = "latitude" lat@units = "degrees_north" lat@axis = "Y" ;%%% Create variable %%% Data = new( (/ nLatOut, nLonOut /), float ) Data!0 = "lat" Data!1 = "lon" Data&lat = lat Data&lon = lon Data@missing_value = 1e+15 Data@_FillValue = 1e+15 Data@scale_factor = 1.0 Data@add_offset = 0.0 Data@long_name = "CH4 surface emissions from hydroelectric reservoir" Data@units = "kg m-2 s-1" Data(:,:) = 0.0 ;========================================================================= ; Put data onto grid ;========================================================================= ; Fix latitude and longitude dimensions so they have the proper values inLat = (/inLat - 0.02/) inLon = (/inLon + 0.04/) inLat = decimalPlaces(inLat,2,True) inLon = decimalPlaces(inLon,2,True) ; Flip latitude dimension inLat = inLat(::-1) inData = inData(::-1,:) inData&lat = inLat inData&lon = inLon ; Debug ;print(nLonIn) ;print(nLonOut) ;print("current lon 1 = "+inLon(0)) ;print("new lon 1 = "+lon(270)) ;print("current lon 2 = "+inLon(3298)) ;print("new lon 2 = "+lon(3568)) ; ;print(nLatIn) ;print(nLatOut) ;print("current lat 1 = "+inLat(0)) ;print("new lat 1 = "+lat(441)) ;print("current lat 2 = "+inLat(1162)) ;print("new lat 3 = "+lat(1603)) ; ;print(dimsizes(inData(0:1162,0:3298))) ;print(dimsizes(Data(441:1603,270:3568))) ; ;printVarSummary(Data) ;printVarSummary(inData) ; Copy ArcMap data onto full nested NA grid Data(441:1603,270:3568) = doubletofloat((/inData(0:1162,0:3298)/)) Data = where( Data .lt. 0.0, 0.0, Data) printMinMax(Data,0) ;========================================================================= ; Save to output file ;========================================================================= ; Print data (uncomment for debugging) ;printVarSummary( lon ) ;printVarSummary( lat ) ;printVarSummary( Data ) ;printMinMax( Data,0 ) ; Open output file (remove prior version) system( "rm -f " + outFile ) fOut = addfile( outFile, "c" ) fOut->lon = lon fOut->lat = lat fOut->CH4emis = Data ; Make time unlimited ; Add global file attributes ; Redefine the title string fOut@Title = "Methane emissions from hydroelectric reservoirs" fOut@reference = "Delwiche, K. B., Harrison, J. A., Maasakkers, J. D., Sulprizio, M. P., Worden, J., Jacob, D. J., & Sunderland, E. M. (2022). Estimating drivers and pathways for hydroelectric reservoir methane emissions using a new mechanistic model. Journal of Geophysical Research: Biogeosciences, 127, e2022JG006908." fOut@Conventions = "COARDS" fOut@history = "Created on: " + systemfunc( "date" ) end ;EOC