Skip to content
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

[PI] Ensure flags are correctly loaded/saved to/from NetCDF #3474

Closed
5 tasks done
lbdreyer opened this issue Oct 21, 2019 · 3 comments
Closed
5 tasks done

[PI] Ensure flags are correctly loaded/saved to/from NetCDF #3474

lbdreyer opened this issue Oct 21, 2019 · 3 comments

Comments

@lbdreyer
Copy link
Member

lbdreyer commented Oct 21, 2019

Part of #3358

According to CF, flags contain flag_values, flag_masks and flag_meanings attributes.

This ticket is to check whether flags require any special handling to ensure that they are correctly loaded/saved.

Additional, 2019-12-12
(from @pp-mo)
Following the "CF-metadata" email list, it seems to me that some of the expected forms and vocabulary usages for flags still rather fluid + changing,
That is, maybe despite statements already accepted in the cf 1.7 document
See cf-convention/cf-conventions#216 in particular,
which is also the issue referenced by this comment from @stephenworsley below


Acceptance Criteria

@alastair-gemmell
Copy link
Contributor

This ticket is best tackled after #3473

@stephenworsley
Copy link
Contributor

stephenworsley commented Dec 5, 2019

The convention with status_flags is to be unitless. An example of a status flag being described within CF conventions is given here: cf-convention/cf-conventions#216

variables:

    float sea_water_practical_salinity(time, z);
        sea_water_practical_salinity:units = "1";
        sea_water_practical_salinity:long_name = "Salinity";
        sea_water_practical_salinity:standard_name = "sea_water_practical_salinity";
        sea_water_practical_salinity:ancillary_variables = "sea_water_practical_salinity_qc_agg sea_water_practical_salinity_qc_flat_line_test";

    int sea_water_practical_salinity_qc_agg(time, z);
        sea_water_practical_salinity_qc_agg:long_name = "Salinity QARTOD Aggregate Flag";
        sea_water_practical_salinity_qc_agg:standard_name = "status_flag qartod_aggregate_quality_flag";
        sea_water_practical_salinity_qc_agg:missing_value = 2;
        sea_water_practical_salinity_qc_agg:flag_meanings = "PASS NOT_EVALUATED SUSPECT FAIL MISSING";
        sea_water_practical_salinity_qc_agg:flag_values = 1, 2, 3, 4, 9;

    int sea_water_practical_salinity_qc_flat_line_test(time, z);
        sea_water_practical_salinity_qc_flat_line_test:long_name = "Salinity QARTOD Flat Line Test Flag";
        sea_water_practical_salinity_qc_flat_line_test:standard_name = "status_flag qartod_flat_line_test_quality_flag";
        sea_water_practical_salinity_qc_flat_line_test:missing_value = 2;
        sea_water_practical_salinity_qc_flat_line_test:flag_meanings = "PASS NOT_EVALUATED SUSPECT FAIL MISSING";
        sea_water_practical_salinity_qc_flat_line_test:flag_values = 1, 2, 3, 4, 9;

When such a file is loaded by Iris, the current behaviour is to assign the unit to be "1" (In fact, this is the behaviour when using iris to directly instatiate an AncillaryVariable without specifying the unit). As such, a round trip (loading then saving) would result in a unit being assigned to the status_flag against current convention.
It seems as though the unit convention of status_flags in CF conventions is described by the standard name modifier. See #3408 for a discussion on handling of standard name modifiers.
Also, see #3394 with respect to saving without a unit.

Additional 2019-12-12
(@pp-mo)
Caution: the content of cf-convention/cf-conventions#216 has changed again since this was written. The ways in which such status flags + related info are stored and indicated are still evolving ...

@stephenworsley
Copy link
Contributor

stephenworsley commented Dec 5, 2019

In order to preserve unitless cf variables, it may be worthwhile changing the general behaviour defined here:

attr_units = getattr(cf_var, CF_ATTR_UNITS, cf_units._UNIT_DIMENSIONLESS)
if not attr_units:
attr_units = '1'

Changing cf_units._UNIT_DIMENSIONLESS to "no_unit" or cf_units._NO_UNIT_STRING, combined with fixing #3394, ought to make round tripping consistent.


As an alternative to the general approach above, flag variables could be given special treatment, similar to that in the following line:

if np.issubdtype(cf_var.dtype, np.str_):
attr_units = cf_units._NO_UNIT_STRING

The cases in which units would be set to "no_unit" could be decided by some combination of standard name, standard name modifier, and presence of flag values and meanings in the variable.

@stephenworsley stephenworsley modified the milestones: v3.0.0, v3.1.0 Dec 20, 2019
@abooton abooton changed the title Ensure flags are correctly loaded/saved to/from NetCDF PI-3358: Ensure flags are correctly loaded/saved to/from NetCDF May 14, 2020
@abooton abooton changed the title PI-3358: Ensure flags are correctly loaded/saved to/from NetCDF [PI] Ensure flags are correctly loaded/saved to/from NetCDF Jun 10, 2020
@abooton abooton linked a pull request Jun 10, 2020 that will close this issue
@pp-mo pp-mo closed this as completed Aug 21, 2020
abooton pushed a commit that referenced this issue Aug 21, 2020
Addresses issues associated with #3473, #3474 and #3358, loading/saving of ancillary variables to/from netcdf, including quality flags.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants