-
Notifications
You must be signed in to change notification settings - Fork 383
Enable missing_value to override default_value for fields #562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
This PR closes issue #562. As mentioned in the initial comment of this PR, if both |
|
@MiCurry This looks good so far. I think the same logic as you've implemented for |
7247204 to
9b6bc75
Compare
Ah, I forgot about I just pushed an update that contains the same changes for |
9b6bc75 to
6fc82f0
Compare
|
All, I have updated the commit and PR message for this PR to be more explicit as to what occurs when |
|
@MiCurry Is it possible that your last force-push of 6fc82f0 removed the changes for |
6fc82f0 to
e382fcb
Compare
|
As part of testing this PR, I tried to assign a missing value to one <var name="testMissingVar" type="real" dimensions="nVertLevels nCells Time" units="unitless" missing_value="9.969209968386869e36"
description="A variable that is zero where valid and missing_value where not"
/>
<var_array name="testMissingArray" type="real" dimensions="nVertLevels nCells Time">
<var name="testMissingArrayVar" array_group="testMissingGroup" units="unitless" missing_value="9.969209968386869e36"
description="A variable that is one where valid and missing_value where not"
/>
</var_array>This didn't work as expected -- when I look in |
|
Thanks for this great work, @MiCurry! I tested using a branch (which I will keep around only until this PR gets merged into I found that everything worked as expected if I assigned a real to This is because if (strcmp(vartype, "real") == 0){
(*type) = REAL;
if(!varval){
snprintf(default_value, 1024, "0.0");
} else if(strcmp(varmissval, "FILLVAL") == 0) {
snprintf(missing_value, 1024, "MPAS_REAL_FILLVAL");
} else {
snprintf(default_value, 1024, "%s", varval);
}
} else if (strcmp(vartype, "integer") == 0){
(*type) = INTEGER;
if(!varval){
snprintf(default_value, 1024, "0");
} else if(strcmp(varmissval, "FILLVAL") == 0) {
snprintf(missing_value, 1024, "MPAS_INT_FILLVAL");
} else {
snprintf(default_value, 1024, "%s", varval);
}
} else if (strcmp(vartype, "text") == 0){
(*type) = CHARACTER;
if(!varval){
snprintf(default_value, 1024, "''");
} else if(strcmp(varmissval, "FILLVAL") == 0) {
snprintf(missing_value, 1024, "MPAS_CHAR_FILLVAL");
} else {
snprintf(default_value, 1024, "%s", varval);
}
}(Boy, would this code be more elegant and readable in python...) |
That was the expected behavior of my implementation and I think the current behavior of master. r3Ptr(1) % dimNames(1) = 'num_scalars'
r3Ptr(1) % dimNames(2) = 'nVertLevels'
r3Ptr(1) % dimNames(3) = 'nCells'
r3Ptr(1) % defaultValue = 0.0
allocate(r3Ptr(1) % attLists(size(r3Ptr(1) % constituentNames, dim=1)))
do index_counter = 1, size(r3Ptr(1) % constituentNames, dim=1)
allocate(r3Ptr(1) % attLists(index_counter) % attList)
end do
if (associated(newSubPool)) then
call mpas_pool_get_dimension(newSubPool, 'index_qv', const_index)
end if
if (const_index > 0) then
call mpas_add_att(r3Ptr(1) % attLists(const_index) % attList, 'long_name', 'Water vapor mixing ratio')
call mpas_add_att(r3Ptr(1) % attLists(const_index) % attList, 'units', 'kg kg^{-1}')
r3Ptr(1) % missingValue = MPAS_REAL_FILLVAL
r3Ptr(1) % constituentNames(const_index) = 'qv'
end if
if (associated(newSubPool)) then
call mpas_pool_get_dimension(newSubPool, 'index_qc', const_index)
end if
if (const_index > 0) then
call mpas_add_att(r3Ptr(1) % attLists(const_index) % attList, 'long_name', 'Cloud water mixing ratio')
call mpas_add_att(r3Ptr(1) % attLists(const_index) % attList, 'units', 'kg kg^{-1}')
r3Ptr(1) % missingValue = MPAS_REAL_FILLVAL
r3Ptr(1) % constituentNames(const_index) = 'qc'
end if
if (associated(newSubPool)) then
r3Ptr(1) % block => blockI believe |
@xylar, ah I did not realize one could use |
You're welcome, with the caveat that I didn't test that code at all so it could be completely useless. |
|
I think the fix may be as simple as changing @@ -1066,7 +1066,7 @@ int parse_var_array(FILE *fd, ezxml_t registry, ezxml_t superStruct, ezxml_t var
// If a default_value is not specified, but a missing_value is, then set the
// default_value (defaultValue) to missing_value
if(!vararrdefaultval && vararrmissingval) {
- snprintf(default_value, 1024, "%s ! defaultValue taking specified missing_value", vararrmissingval);
+ snprintf(default_value, 1024, "%s ! defaultValue taking specified missing_value", missing_value);
} |
@mgduda, ah, you're exactly right! Thanks for catching this. My suggestion is wrong because |
This commit allows missing_value to override the default value of a field if default_value is not specified for a field in a core's Registry.xml file. If missing_value and default_value are both present for a field, then the field will be initialized to default_value. Specifying missing_value for a field in the Registry.xml will still create a missing_value NetCDF attribute if that field is written (even if default_value is also specified).
e382fcb to
ec55a1d
Compare
|
Thanks @MiCurry. I'll test this again later tonight. |
xylar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MiCurry, yep, tested on my laptop with my test_missing_values branch and it worked like a charm! Thanks!
@mark-petersen, if you want to use my test branch (see my earlier comment) to run init and daily_output from QU240, you should see the output in test_missing.nc and see that the missing values are indeed there with an ncdump. If you test on LANL IC, I think we're good.
mark-petersen
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Started with branch xylar/MPAS-Model/ocean/test_missing_value and merged this in. Tested on LANL IC grizzly with both intel and gnu. Runs as expected. Test output now includes missing_value attribute and underscore for land cells.
details
ncdump -h test_missing.nc |grep miss
netcdf test_missing {
testMissingVar:long_name = "A variable that is zero where valid and missing_value where not" ;
testMissingVar:missing_value = 9.96920996838687e+36 ;
testMissingArrayVar:long_name = "A variable that is one where valid and missing_value where not" ;
testMissingArrayVar:missing_value = 9.96920996838687e+36 ;
(compass_0.1.6) gr0539:test$ ncdump -v testMissingArrayVar test_missing.nc|tail
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _, _, _, _, _, _,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _, _, _ ;
}
(compass_0.1.6) gr0539:test$ ncdump -v testMissingVar test_missing.nc|tail
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _, _, _, _, _, _,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _, _, _ ;
|
@matthewhoffman is my ocean test sufficient for approval, or would you like to test as well? |
|
@MiCurry thanks for your work on this. Please merge, or I can if you prefer. |
|
@mark-petersen I don't think @MiCurry is able to push to the |
#3737) Update MPAS framework This PR brings in a new mpas-source submodule with updates to the mpas framework itself, plus changes to the cores supporting the framework update. Some changes are made to the atmosphere core, even though it is not used by E3SM, in order to maintain consistency with the framework. This update includes the following individual branches and PRs, many of which are additions to the makefiles for summit, or optional libraries: * az/azamat/mpas-cmake/mpas-tool-dir (MPAS-Dev/MPAS-Model#629) * init_atmosphere/kd_tree_ties (MPAS-Dev/MPAS-Model#630) * mark-petersen/framework/add_FillValue (MPAS-Dev/MPAS-Model#616) * mark-petersen/framework/add_lapack_option (MPAS-Dev/MPAS-Model#613) * amametjanov/framework/nullify-field-pointers (MPAS-Dev/MPAS-Model#578) * framework/makefile_e3sm (MPAS-Dev/MPAS-Model#603) * xylar/framework/make_shell_bash (MPAS-Dev/MPAS-Model#594) * registry/missing_value (MPAS-Dev/MPAS-Model#562) * pwolfram/updates_make_intel_stack (MPAS-Dev/MPAS-Model#592) * azamat/framework/pgi-cpr-omp-workaround (MPAS-Dev/MPAS-Model#449) * az/framework/e3sm-cmake-qnosmp-typo (MPAS-Dev/MPAS-Model#579) * xylar/compass/add_prerequisite_tag * atmosphere/fix_timekeeping_imports (MPAS-Dev/MPAS-Model#582) * xylar/fix_docs_ci (MPAS-Dev/MPAS-Model#575) * xylar/add_compass_docs (MPAS-Dev/MPAS-Model#472) * philipwjones/framework/summitmake (MPAS-Dev/MPAS-Model#536) * atmosphere/atm_core_cleanup (MPAS-Dev/MPAS-Model#548) * init_atmosphere/parse_geoindex (MPAS-Dev/MPAS-Model#459) * xylar/compass/add_copy_file (MPAS-Dev/MPAS-Model#467) * init_atmosphere/kd_tree (MPAS-Dev/MPAS-Model#438) * init_atmosphere/mpas_stack (MPAS-Dev/MPAS-Model#426) * operators/add_mpas_in_cell (MPAS-Dev/MPAS-Model#400) Fixes #3396 Fixes #3236 [BFB]
Update MPAS framework This PR brings in a new mpas-source submodule with updates to the mpas framework itself, plus changes to the cores supporting the framework update. Some changes are made to the atmosphere core, even though it is not used by E3SM, in order to maintain consistency with the framework. This update includes the following individual branches and PRs, many of which are additions to the makefiles for summit, or optional libraries: * az/azamat/mpas-cmake/mpas-tool-dir (MPAS-Dev/MPAS-Model#629) * init_atmosphere/kd_tree_ties (MPAS-Dev/MPAS-Model#630) * mark-petersen/framework/add_FillValue (MPAS-Dev/MPAS-Model#616) * mark-petersen/framework/add_lapack_option (MPAS-Dev/MPAS-Model#613) * amametjanov/framework/nullify-field-pointers (MPAS-Dev/MPAS-Model#578) * framework/makefile_e3sm (MPAS-Dev/MPAS-Model#603) * xylar/framework/make_shell_bash (MPAS-Dev/MPAS-Model#594) * registry/missing_value (MPAS-Dev/MPAS-Model#562) * pwolfram/updates_make_intel_stack (MPAS-Dev/MPAS-Model#592) * azamat/framework/pgi-cpr-omp-workaround (MPAS-Dev/MPAS-Model#449) * az/framework/e3sm-cmake-qnosmp-typo (MPAS-Dev/MPAS-Model#579) * xylar/compass/add_prerequisite_tag * atmosphere/fix_timekeeping_imports (MPAS-Dev/MPAS-Model#582) * xylar/fix_docs_ci (MPAS-Dev/MPAS-Model#575) * xylar/add_compass_docs (MPAS-Dev/MPAS-Model#472) * philipwjones/framework/summitmake (MPAS-Dev/MPAS-Model#536) * atmosphere/atm_core_cleanup (MPAS-Dev/MPAS-Model#548) * init_atmosphere/parse_geoindex (MPAS-Dev/MPAS-Model#459) * xylar/compass/add_copy_file (MPAS-Dev/MPAS-Model#467) * init_atmosphere/kd_tree (MPAS-Dev/MPAS-Model#438) * init_atmosphere/mpas_stack (MPAS-Dev/MPAS-Model#426) * operators/add_mpas_in_cell (MPAS-Dev/MPAS-Model#400) Fixes #3396 Fixes #3236 [BFB]
This commit allows missing_value to override the default value of a field if
default_value is not specified for a field in a core's Registry.xml file. If
missing_value and default_value are both present for a field, then the field
will be initialized to default_value.
Specifying missing_value for a field in the Registry.xml will still create a
missing_value NetCDF attribute if that field is written (even if default_value
is also specified).