修改大气模型(Meso-NH)文件的空间分辨率,将其与另一个netCDF文件进行比较



我用一个用于研究的大气模型(Meso-NH(进行了模拟,输出文件是netCDF(.nc(文件。

我想比较我的文件中包含的一个来自Meso-NH的变量和另一个netCDF文件中的变量。不幸的是,这些文件没有相同的结构,我无法轻松地从Meso-NH修改我的文件。

这就是我的模板文件的样子:

ncdump -h /home/mcms/le-galln/Téléchargements/albedo/re_albedo_12mnh_200618.nc
netcdf re_albedo_12mnh_200618 {
dimensions:
ni = 182 ;
nj = 224 ;
variables:
double longitude(nj, ni) ;
longitude:standard_name = "longitude" ;
longitude:long_name = "longitude" ;
longitude:units = "degrees_east" ;
longitude:_CoordinateAxisType = "Lon" ;
double latitude(nj, ni) ;
latitude:standard_name = "latitude" ;
latitude:long_name = "latitude" ;
latitude:units = "degrees_north" ;
latitude:_CoordinateAxisType = "Lat" ;
double ni(ni) ;
ni:standard_name = "projection_x_coordinate" ;
ni:long_name = "x-dimension of the grid" ;
ni:units = "m" ;
ni:axis = "X" ;
double nj(nj) ;
nj:standard_name = "projection_y_coordinate" ;
nj:long_name = "y-dimension of the grid" ;
nj:units = "m" ;
nj:axis = "Y" ;
double TALB_ISBA(nj, ni) ;
TALB_ISBA:long_name = "TALB_ISBA" ;
TALB_ISBA:coordinates = "latitude longitude" ;
TALB_ISBA:_FillValue = 9.96920996838687e+36 ;
TALB_ISBA:missing_value = 9.96920996838687e+36 ;
TALB_ISBA:grid = 4 ;
TALB_ISBA:comment = "total albedo over tile nature (-)" ;
// global attributes:
:CDI = "Climate Data Interface version 1.9.8 (https://mpimet.mpg.de/cdi)" ;
:history = "Thu Aug 04 13:29:39 2022: cdo sellonlatbox,-6,-3,47,49.5 albedo_12_200618.nc re_albedo_12_200618.ncnThu Aug  4 13:29:23 2022: ncks -v TALB_ISBA NLRE3.1.SEG01.012.nc albedo_12_200618.ncn2022-03-21T18:52:59-0000: MESONH-LXifort-R8I4-MNH-V5-4-2-MON_DOSSIER-MPIAUTO-O2" ;
:Conventions = "CF-1.7 COMODO-1.4" ;
:MNH_REAL = "8" ;
:MNH_INT = "4" ;
:MNH_cleanly_closed = "yes" ;
:NCO = "netCDF Operators version 4.9.2 (Homepage = http://nco.sf.net, Code = http://github.com/nco/nco)" ;
:CDO = "Climate Data Operators version 1.9.8 (https://mpimet.mpg.de/cdo)" ;

这就是我的另一个文件的样子:

ncdump -h re_alb20juin.nc
netcdf re_alb20juin {
dimensions:
time = UNLIMITED ; // (1 currently)
lon = 720 ;
lat = 600 ;
variables:
int time(time) ;
time:standard_name = "time" ;
time:units = "days since 2000-01-01 00:00:00" ;
time:calendar = "standard" ;
time:axis = "T" ;
double lon(lon) ;
lon:standard_name = "longitude" ;
lon:long_name = "longitude" ;
lon:units = "degrees_east" ;
lon:axis = "X" ;
double lat(lat) ;
lat:standard_name = "latitude" ;
lat:long_name = "latitude" ;
lat:units = "degrees_north" ;
lat:axis = "Y" ;
short Albedo_BSA_shortwave(time, lat, lon) ;
Albedo_BSA_shortwave:long_name = "Albedo_BSA_shortwave" ;
Albedo_BSA_shortwave:units = "reflectance, no units" ;
Albedo_BSA_shortwave:add_offset = 0. ;
Albedo_BSA_shortwave:scale_factor = 0.001 ;
Albedo_BSA_shortwave:_FillValue = 32767s ;
Albedo_BSA_shortwave:missing_value = 32767s ;
Albedo_BSA_shortwave:scale_factor_err = 0. ;
Albedo_BSA_shortwave:add_offset_err = 0. ;
Albedo_BSA_shortwave:calibrated_nt = 5 ;
short BRDF_Albedo_Band_Mandatory_Quality_shortwave(time, lat, lon) ;
BRDF_Albedo_Band_Mandatory_Quality_shortwave:long_name = "BRDF_Albedo_Band_Mandatory_Quality_shortwave" ;
BRDF_Albedo_Band_Mandatory_Quality_shortwave:units = "concatenated flags" ;
BRDF_Albedo_Band_Mandatory_Quality_shortwave:_FillValue = 255s ;
BRDF_Albedo_Band_Mandatory_Quality_shortwave:missing_value = 255s ;
BRDF_Albedo_Band_Mandatory_Quality_shortwave:Description = "Mandatory QA:n  0 = processed, good quality (full BRDF inversions)n  1 = processed, see other QA (magnitude BRDF inversions)n" ;
// global attributes:
:CDI = "Climate Data Interface version 1.9.8 (https://mpimet.mpg.de/cdi)" ;
:history = "Thu Aug 04 13:26:41 2022: cdo sellonlatbox,-6,-3,47,49.5 /home/mcms/le-galln/Téléchargements/alb_20juin.nc re_alb20juin.ncnSee README.md" ;
:source = "AppEEARS v3.7" ;
:institution = "Land Processes Distributed Active Archive Center (LP DAAC)" ;
:Conventions = "CF-1.6" ;
:title = "MCD43A3.006 for aid0001" ;
:references = "See README.md" ;
:CDO = "Climate Data Operators version 1.9.8 (https://mpimet.mpg.de/cdo)" ;

我想将空间分辨率(纬度、经度(为1.5km的第一个文件的网格修改为500米分辨率的网格。我的第二个文件有一个500米分辨率的网格

事实上,最终我想在我的模型的反照率(TALB_ISBA(nj,ni((和卫星的反照度(反照率_BSA_shortwave(time,lat,lon((之间做出区分。不幸的是,这些文件的组成非常不同,我有点不知所措,我不能做我想做的事。为了在python上操作netcdf文件,我使用xarray模块:

sat_file=xr.open_dataset('/home/mcms/le-galln/Téléchargements/albedo/re_albedo_12mnh_200618.nc')
model_file=xr.open_dataset('/home/mcms/le-galln/Téléchargements/albedo/re_re_albedo_12mnh_200618.nc')
sat_file
Out[55]: 
<xarray.Dataset>
Dimensions:    (ni: 182, nj: 224)
Coordinates:
longitude  (nj, ni) float64 ...
latitude   (nj, ni) float64 ...
* ni         (ni) float64 3.75e+04 3.875e+04 4e+04 ... 2.625e+05 2.638e+05
* nj         (nj) float64 3.25e+04 3.375e+04 3.5e+04 ... 3.1e+05 3.112e+05
Data variables:
TALB_ISBA  (nj, ni) float64 ...
Attributes:
CDI:                 Climate Data Interface version 1.9.8 (https://mpimet...
history:             Thu Aug 04 13:29:39 2022: cdo sellonlatbox,-6,-3,47,...
Conventions:         CF-1.7 COMODO-1.4
MNH_REAL:            8
MNH_INT:             4
MNH_cleanly_closed:  yes
NCO:                 netCDF Operators version 4.9.2 (Homepage = http://nc...
CDO:                 Climate Data Operators version 1.9.8 (https://mpimet...
model_file
Out[58]: 
<xarray.Dataset>
Dimensions:    (ni: 182, nj: 224)
Coordinates:
longitude  (nj, ni) float64 ...
latitude   (nj, ni) float64 ...
* ni         (ni) float64 3.75e+04 3.875e+04 4e+04 ... 2.625e+05 2.638e+05
* nj         (nj) float64 3.25e+04 3.375e+04 3.5e+04 ... 3.1e+05 3.112e+05
Data variables:
TALB_ISBA  (nj, ni) float64 ...
Attributes:
CDI:                 Climate Data Interface version 1.9.8 (https://mpimet...
history:             Thu Aug 04 13:29:39 2022: cdo sellonlatbox,-6,-3,47,...
Conventions:         CF-1.7 COMODO-1.4
MNH_REAL:            8
MNH_INT:             4
MNH_cleanly_closed:  yes
NCO:                 netCDF Operators version 4.9.2 (Homepage = http://nc...
CDO:                 Climate Data Operators version 1.9.8 (https://mpimet...

你有解决方案吗?我的计算机科学水平很有限,所以如果可能的话,这是一种相当简单的技术。

在Python中有不同的方法来实现这一点。由于这些文件似乎是使用CDO裁剪的,您可能想尝试使用我的包nctoolkit(它使用CDO作为后端(。要将一个文件重新划分为另一个文件的网格,您只需要执行以下操作:

import nctoolkit as nc
ds = nc.open_data("/home/mcms/le-galln/Téléchargements/albedo/re_albedo_12mnh_200618.nc")
ds.regrid('/home/mcms/le-galln/Téléchargements/albedo/re_re_albedo_12mnh_200618.nc')

如果你想将其导出到xarray,你可以这样做:

ds_xr = ds.to_xarray()

默认情况下,nctoolkit使用双线性插值,这可能就足够了。但是,您可能需要尝试其他重新分级方法,例如最近邻居:https://nctoolkit.readthedocs.io/en/latest/generated/nctoolkit.DataSet.regrid.html?highlight=regrid#nctoolkit.DataSet.regrid

相关内容

最新更新