Error combining netcdf files
显示 更早的评论
- FUN_nc_varget_sub_genStartCount_from_presaved_data.m
- FUN_nc_varget_sub_genStartCount_from_file.m
- FUN_nc_varget_sub_genStartCount.m
- FUN_nc_varget_enhanced_region_2_multifile.m
- FUN_nc_varget_enhanced_region_2.m
- FUN_nc_varget_enhanced_region.m
- FUN_nc_varget_enhanced_from_multifiles.m
- FUN_nc_varget_enhanced.m
- FUN_nc_varget.m
- FUN_nc_time_select_from_multi_files.m
- FUN_nc_rename_var.m
- FUN_nc_merge_save_mean.m
- FUN_nc_merge.m
- FUN_nc_is_variable_dimensionless.m
- FUN_nc_is_exist_variable.m
- FUN_nc_is_exist_dimension.m
- FUN_nc_is_exist_attibute.m
- FUN_nc_internal_calc_chunk.m
- FUN_nc_internal_bytes_per_value.m
- FUN_nc_get_time_in_matlab_format.m
- FUN_nc_get_time0_from_str.m
- FUN_nc_get_dims_from_varname.m
- FUN_nc_get_dim_length.m
- FUN_nc_gen_time_val_limit.m
- FUN_nc_gen_presaved_netcdf_info.m
- FUN_nc_exist_var.m
- FUN_nc_easywrite_write_var.m
- FUN_nc_easywrite_enhanced.m
- FUN_nc_easywrite_add_var.m
- FUN_nc_easywrite_add_att.m
- FUN_nc_easywrite_LonLatDepthTime.m
- FUN_nc_easywrite.m
- FUN_nc_defVar_datatypeconvert.m
- FUN_nc_copy_with_limit_SP_select_by_layer.m
- FUN_nc_copy_with_limit.m
- FUN_nc_convert_time_to_time_in_matlab.m
- FUN_nc_comparison_exactly.m
- FUN_nc_attget.m
- FUN_nc_OpenDAP_with_limit.m
I'm having a problem when processing this netcdf data
When I run the commands, at the end the following message appears:,
Unrecognized field name "all".
Error in FUN_nc_merge (line 223)
MV.all = [ MV.all ; tem(:) ];
The function I used is attached here with the name FUN_nc_merge.m and can be obtained through this link https://github.com/HappySpring/Easy_NetCDF
The script I used is just below and the link with google drive is the NetCDF files I used https://drive.google.com/drive/folders/1yts62Bbd5P1N_O3we3R2iQi0PgYbkJNT?usp=share_link
% input_dir: path for the folder containing the files
input_dir = '/home/augusto/Documentos/Dados_Mensais_CHIRPS';
% filelist
filelist = dir(fullfile(input_dir,'Merge_Demo*.nc'));
% output filename
output_fn = 'Merged_Output.nc';
% name of the demension to be merged.
merge_dim_name = 'time';
% compatibility_mode:
% compatibility_mode = 1: write netCDF in 'CLOBBER'; Compression would be disabled.
% compatibility_mode = 0: write netCDF in 'NETCDF4'.
compatibility_mode = 0;
strvcat( filelist(:).name )
cd /home/augusto/Downloads/Easy_NetCDF-main
FUN_nc_merge( input_dir, filelist, output_fn, merge_dim_name, compatibility_mode )
采纳的回答
更多回答(2 个)
L Chi
2023-1-27
1 个投票
I guess I figured out what happened. I happened to introduce a bug in a recent commit on Dec 14, 2022, which does not define the variable MV.all correclty if is_overlap_allowed is false. I found it a few days later and fix it in a following commit (480d64d) on Dec 28, 2022. If you happened to download the latest toolbox between Dec 14 and Dec 28, this is probably the case. Please download the latest toolbox from github and try it again. It should work, you're welcomed to email me/open an issue on github/replay this post if you still have problems in using the toolbox.
1 个评论
L Chi
2023-1-27
编辑:Walter Roberson
2023-1-27
By the way, I always try to make sure the releases ( https://github.com/HappySpring/Easy_NetCDF/releases ) are free of bugs. The latest release currently is version 1.12 released on July 27, 2022. I add experimental features in commits after the latest release, however, this may also include bugs. My suggestion would be that the latest release would always be a better choice unless you need new features introduced after it.
Walter Roberson
2023-1-14
You have the code structure
if is_overlap_allowed
%stuff here
MV.all = cell2mat( MV.val(:) );
else
for ii = 1:length( filepath_list )
fprintf('Checking: %s\n', filepath_list{ii} );
tem = FUN_nc_varget( filepath_list{ii}, merge_dim_var_name );
MV.all = [ MV.all ; tem(:) ];
%more stuff
Notice that MV.all is not assigned to before the if and inside the if it is assigned to only if is_overlap_allowed; in the case that is_overlap_allowed is false, it is not assigned to before it is used inside the for ii loop.
11 个评论
Augusto Gabriel da Costa Pereira
2023-1-14
Walter Roberson
2023-1-14
I did not suggest any particular modification, so I do not know what you did.
Have you considered assigning
MV.all = [];
before the if is_overlap_allowed ?
Augusto Gabriel da Costa Pereira
2023-1-14
Walter Roberson
2023-1-14
In the case that is_overlap_allowed is true, you assign to MV.all
In the case that is_overlap_allowed is false, you loop appending to MV.all . If that code worked, then at the end of the loop, you would have an MV.all .
So either way, after the end of the if else if the code worked, MV.all would be assigned to.
Is there any situation in which you deliberately want MV.all to not exist after the if/else ? For example if filepath_list was empty you would not execute the loop body: is it a deliberate choice on your part that after the end of the else that MV.all would not exist in that case?
Is there any situation in which MV.all could exist before the if/else and have data that you wanted to preserve ?
Augusto Gabriel da Costa Pereira
2023-1-14
编辑:Augusto Gabriel da Costa Pereira
2023-1-14
Walter Roberson
2023-1-14
Suppose you took a census of everyone living on your block. You end up with a structure of data, one entry per person, with information listing their name, age, and address. The structure describes the people in the block.
What you are asking for is how to take the census of people and turn that into the people themselves. You cannot do that.
The variable ncfiles in the above code is a struct array, one entry for each file found. Each entry has information about the file, including its name and size and date and location. You would have no reason to convert the struct array into an .nc file itself.
If you want to know the names of the files, then they are accessible as ncfiles(INDEX).name . The code above illustrates reading one particular variable time from each variable; by adding more ncread commands inside the loop you could read additional variables.
If you want to know the names of the files ahead of time (there are various reasons to do that) then you can extract just the names as
filenames = fullfile({ncfiles.folder}, {ncfiles.name});
The result would be a cell array of character vectors, with each entry being a complete path to one .nc file.
Augusto Gabriel da Costa Pereira
2023-1-16
Walter Roberson
2023-1-17
Not enough information.
.nc files generally consist of a number of different "groups" with subgroups (essentially subdirectories), some of which might have multiple variables.
It is unclear what form you would want the combined results to be. For example should a new high-level group be formed for each input file, with the contents of the individual files placed under that top level? Or should the same group structures be preserved but one new variable be created for each input file, such as time_Qz7b18 time_Qz7b19 time_Qz7b20 variables where now you have variable time in Qz7b18.nc, Qz7b19.nc, Qz7b20.nc ? Or should nearly the same variables be preserved, but a new dimension should be added for each variable with an "index" element for the dimension being the filename? So for example instead of a 2D rainfall variable the same variable name rainfall would be used except it would become 3D instead of 2D with the third dimension being indexed by file name?
Augusto Gabriel da Costa Pereira
2023-1-17
Walter Roberson
2023-1-17
Can we assume that the latitude and longitude will be exactly the same for all three files?
Augusto Gabriel da Costa Pereira
2023-1-17
类别
在 帮助中心 和 File Exchange 中查找有关 NetCDF 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!