Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@MiCurry
Copy link
Contributor

@MiCurry MiCurry commented May 14, 2020

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).

@MiCurry
Copy link
Contributor Author

MiCurry commented May 14, 2020

This PR closes issue #562.

As mentioned in the initial comment of this PR, if both missing_value and default_value are specified, the field will be initialized with default_value. If some other action should occur, I'm happy to update this PR.

@mgduda
Copy link
Contributor

mgduda commented May 15, 2020

@MiCurry This looks good so far. I think the same logic as you've implemented for vars is also needed for var_arrays.

@MiCurry MiCurry force-pushed the registry/missing_value branch from 7247204 to 9b6bc75 Compare May 15, 2020 17:21
@MiCurry
Copy link
Contributor Author

MiCurry commented May 15, 2020

@MiCurry This looks good so far. I think the same logic as you've implemented for vars is also needed for var_arrays.

Ah, I forgot about var_arrays. Thanks @mgduda.

I just pushed an update that contains the same changes for var_arrays. I also moved the change for vars to below the call to get_field_information. This is consistent with the var_array change and seems a bit more organized/logical.

@MiCurry
Copy link
Contributor Author

MiCurry commented May 26, 2020

All, I have updated the commit and PR message for this PR to be more explicit as to what occurs when missing_value and default_value are specified. From our telecom on 5/26 I believe this implementation is correct, but please let me know if it isn't!

@mgduda mgduda self-requested a review May 27, 2020 00:40
@mgduda
Copy link
Contributor

mgduda commented May 27, 2020

@MiCurry Is it possible that your last force-push of 6fc82f0 removed the changes for var_arrays?

@MiCurry MiCurry force-pushed the registry/missing_value branch from 6fc82f0 to e382fcb Compare May 28, 2020 21:42
@MiCurry
Copy link
Contributor Author

MiCurry commented May 28, 2020

@MiCurry Is it possible that your last force-push of 6fc82f0 removed the changes for var_arrays?

@mgduda You are correct. The last force push just re-added the var array changes!

@xylar
Copy link
Collaborator

xylar commented Jun 1, 2020

As part of testing this PR, I tried to assign a missing value to one var in a var_array:

                <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 inc/structs_and_variables.inc, only testMissingVar has the missing_value attribute. I realize this goes beyond this PR but @mgduda and @MiCurry, is that the expected behavior? Are default_value and missing_value only available at the var_array level, not at the individual var level for a var_array?

@xylar
Copy link
Collaborator

xylar commented Jun 1, 2020

Thanks for this great work, @MiCurry! I tested using a branch (which I will keep around only until this PR gets merged into ocean/develop): https://github.com/xylar/MPAS-Model/pull/new/ocean/test_missing_value

I found that everything worked as expected if I assigned a real to missing_value. But If I assigned FILLVAL, I got a compile-time error:

../inc/structs_and_variables.inc:8479:39:

       r3Ptr(1) % defaultValue = FILLVAL ! defaultValue taking specified missing_value
                                       1
Error: Symbol 'fillval' at (1) has no IMPLICIT type

This is because FILLVAL isn't getting detected and replaced with the appropriate MPAS_*_FILLVAL in default_value in the same way as it is in missing_value. See:
https://github.com/MiCurry/MPAS-Model/blob/registry/missing_value/src/tools/registry/gen_inc.c#L451-L472
To fix this, these lines:
https://github.com/MiCurry/MPAS-Model/blob/registry/missing_value/src/tools/registry/gen_inc.c#L428-L449
would need to be something like:

	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...)

@MiCurry
Copy link
Contributor Author

MiCurry commented Jun 1, 2020

I realize this goes beyond this PR but @mgduda and @MiCurry, is that the expected behavior? Are default_value and missing_value only available at the var_array level, not at the individual var level for a var_array?

That was the expected behavior of my implementation and I think the current behavior of master. default_value and missing_value are only available at the var_array level. Here is a snippet of the atmosphere's core scalar var_array (with a few members removed) from core_atmosphere/inc/structs_and_variables.inc where the defaultValue and missingValue is set for a var_array.

      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 => block

I believe r3Ptr(1) % defaultValue and r3Ptr(1) % missingValue effect all members of the array. In the code snippet above there is a single assignment for r3ptr(1) % defaultValue, but one for each member for the r3Ptr(1) % missingValue assignment. I think the assignments for missingValue are all identical statements, so even if the values assigned to them would be different, the entire array would get the last one that was executed (I think).

@MiCurry
Copy link
Contributor Author

MiCurry commented Jun 1, 2020

I found that everything worked as expected if I assigned a real to missing_value. But If I assigned FILLVAL

@xylar, ah I did not realize one could use FILLVAL to set missing_value and default_value. Thanks for pointing that out, and thanks for giving the code to fix it. I'll get to adding that!

@xylar
Copy link
Collaborator

xylar commented Jun 1, 2020

thanks for giving the code to fix it.

You're welcome, with the caveat that I didn't test that code at all so it could be completely useless.

@mgduda
Copy link
Contributor

mgduda commented Jun 1, 2020

I think the fix may be as simple as changing vararrmissingval to missing_value and similarly for the code in parse_var in the current PR:

@@ -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);
        }

@xylar
Copy link
Collaborator

xylar commented Jun 2, 2020

I think the fix may be as simple as changing vararrmissingval to missing_value and similarly for the code in parse_var in the current PR

@mgduda, ah, you're exactly right! Thanks for catching this.

My suggestion is wrong because default_value would be the expected thing coming out of get_field_information() but then it would get replaced in the new lines @MiCurry has added.

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).
@MiCurry MiCurry force-pushed the registry/missing_value branch from e382fcb to ec55a1d Compare June 2, 2020 16:06
@xylar
Copy link
Collaborator

xylar commented Jun 2, 2020

Thanks @MiCurry. I'll test this again later tonight.

@MiCurry
Copy link
Contributor Author

MiCurry commented Jun 2, 2020

Okay @mgduda, @xylar and everyone else, I have just pushed changes that changes vararrmissingval to missing_value. So now adding FILLVAL to missing_value now successfully compiles.

Copy link
Collaborator

@xylar xylar left a 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.

Copy link
Contributor

@mark-petersen mark-petersen left a 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, _, _, _ ;

@mark-petersen
Copy link
Contributor

@matthewhoffman is my ocean test sufficient for approval, or would you like to test as well?

@mark-petersen mark-petersen removed the request for review from matthewhoffman June 16, 2020 15:57
@mark-petersen
Copy link
Contributor

@MiCurry thanks for your work on this. Please merge, or I can if you prefer.

@mgduda
Copy link
Contributor

mgduda commented Jun 16, 2020

@mark-petersen I don't think @MiCurry is able to push to the develop branch, so I'll merge this today.

@mgduda mgduda merged commit 8969cb5 into MPAS-Dev:develop Jun 16, 2020
@MiCurry MiCurry deleted the registry/missing_value branch July 27, 2020 16:56
jonbob added a commit to E3SM-Project/E3SM that referenced this pull request Jul 27, 2020
#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]
jonbob added a commit to E3SM-Project/E3SM that referenced this pull request Jul 29, 2020
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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.