| 
 
	积分16贡献 精华在线时间 小时注册时间2024-7-13最后登录1970-1-1 
 | 
 
NCL
| 系统平台: | ubuntu 22.04 |  
| 问题截图: | - |  
| 问题概况: | 使用NCL(6.6.2)生成netCDF4文件出现ncl开头的未定义变量,其值与已定义的变量存在重复。 |  
| 我看过提问的智慧: | 看过 |  
| 自己思考时长(天): | 8 |  
| 
由于EDGAR CO2排放的网格数据是二维的,需要加上时间维度才能被anthro_emis识别,所有我采用NCL来对nc文件进行处理,维度是加上了,但是最终处理出来的结果出现了很多ncl开头的未定义变量,希望能够将多余的变量去掉,在emissions维度那一栏显示(time.lat.lon)。生成ncl的脚本如下:
x
登录后查看更多精彩内容~您需要 登录 才可以下载或查看,没有帐号?立即注册 
  
 load "/usr/lib/ncarg/nclscripts/csm/gsn_code.ncl"
 load "/usr/lib/ncarg/nclscripts/csm/contributed.ncl"
 system("cd /home/lxy/Downloads/ANTHRO/data/edgar/")
 input_file = "v8.0_FT2022_GHG_CO2_2022_TOTALS_emi.nc"
 output_files = (/ "v8.0_FT2022_GHG_CO2_2022_TOTALS_emi_new.nc", \
 "v8.0_FT2022_GHG_CO2_2023_TOTALS_emi_new.nc", \
 "v8.0_FT2022_GHG_CO2_2024_TOTALS_emi_new.nc" /)
 nc_in = addfile(input_file, "r")
 
 lat = tofloat(nc_in->lat)
 lon = tofloat(nc_in->lon)
 emissions = nc_in->emissions
 lat_dim = dimsizes(lat)
 lon_dim = dimsizes(lon)
 time_dim = 1
 
 delete(nc_in)
 
 begin
 dimnames = (/"lat", "lon", "time"/)
 dim_sizes = (/lat_dim,lon_dim,time_dim/)
 varnames = (/"lat", "lon", "time", "emissions"/)
 vartypes = (/"float", "float", "double", "float"/)
 
 years = (/2022,2023,2024 /)
 do iy = 0, dimsizes(years)-1
 year = years(iy)
 output_file = output_files(iy)
 
 system("rm -f " + output_file)  ; Ensure the output file does not already exist
 nc_out = addfile(output_file, "c")
 do i = 0, dimsizes(dimnames) - 1
 filedimdef(nc_out, dimnames(i), dim_sizes(i),False)
 end do
 
 do i = 0, dimsizes(varnames) - 1
 if (varnames(i) .eq. "emissions") then
 
 nc_out->$varnames(i)$ = new((/dim_sizes(2), dim_sizes(0), dim_sizes(1)/), vartypes(i))
 else
 
 nc_out->$varnames(i)$ = new(dim_sizes(i), vartypes(i))
 end if
 end do
 
 time_units = "hours since "+year+"-01-01 00:00:00"
 time_value = cd_inv_calendar(year, 1, 1, 0, 0, 0, time_units,0)
 nc_out->time = time_value
 
 emissions_var = new((/time_dim, lat_dim, lon_dim/), typeof(emissions))
 nc_out->emissions = emissions_var
 
 ; Set variable attributes
 nc_out->lat@units = "degrees_north"
 nc_out->lat@standard_name = "latitude"
 nc_out->lat@long_name = "latitude"
 
 nc_out->lon@units = "degrees_east"
 nc_out->lon@standard_name = "longitude"
 nc_out->lon@long_name = "longitude"
 
 nc_out->time@long_name = "time"
 nc_out->time@standard_name = "time"
 
 nc_out->emissions@units = "Tonnes"
 nc_out->emissions@long_name = "TOTALS"
 nc_out->emissions@description = "TOTALS"
 nc_out->emissions@substance = "CO2"
 delete(nc_out)
 end do
 end
 
 ###############################################
 生成的netcdf头文件如下:
 
 netcdf v8.0_FT2022_GHG_CO2_2024_TOTALS_emi_new {
 dimensions:
 lat = 1800 ;
 lon = 3600 ;
 time = 1 ;
 ncl3 = 1800 ;
 ncl4 = 3600 ;
 ncl5 = 1 ;
 ncl6 = 1 ;
 ncl7 = 1800 ;
 ncl8 = 3600 ;
 ncl9 = 1 ;
 ncl10 = 1 ;
 ncl11 = 1800 ;
 ncl12 = 3600 ;
 variables:
 float lat(ncl3) ;
 lat:units = "degrees_north" ;
 lat:standard_name = "latitude" ;
 lat:long_name = "latitude" ;
 float lon(ncl4) ;
 lon:units = "degrees_east" ;
 lon:standard_name = "longitude" ;
 lon:long_name = "longitude" ;
 double time(ncl5) ;
 time:units = "hours since 2024-01-01 00:00:00" ;
 time:calendar = "standard" ;
 time:long_name = "time" ;
 time:standard_name = "time" ;
 float emissions(ncl6, ncl7, ncl8) ;
 emissions:_FillValue = 9.96921e+36f ;
 emissions:units = "Tonnes" ;
 emissions:long_name = "TOTALS" ;
 emissions:description = "TOTALS" ;
 emissions:substance = "CO2" ;
 }
 
 
 
 
 
 | 
 
  |