mom-ocean / MOM6

Modular Ocean Model
Other
185 stars 232 forks source link

Add global metadata attributes to diagnostic output files #1640

Open aidanheerdegen opened 2 months ago

aidanheerdegen commented 2 months ago

ACCESS-NRI would like the capability to embed global metadata attributes into diagnostic ouput files.

Specifically we want to add unique tracking IDs to model diagnostic (and tracer) outputs to create a full experiment provenance chain that would enable users to discover experiment metadata.

Ideally there would be a config file where any global attribute could be set. A fallback option would be dedicated namelist options for setting specific global metadata attributes.

For background see this related issue for the tool we're using to run our models:

https://github.com/payu-org/payu/issues/510

From the docs it appears quite straightforward:

For MOM6 Global attributes can be written by calling register_global_attribute. Scalar and 1d real and integers (32 and 64 bit) and scalar string values are supported

call register_global_attribute(fileobj, "global_attribute_name", value)

Is it already possible? If not has anyone done anything of this nature before so there is a design pattern we could follow?

marshallward commented 2 months ago

I don't know of any canonical way to add model-specific metadata to netCDF output. AFAIK anyone doing this would apply to their own model-specific output, rather than modifications to output from MOM6.

We have the write_metadata_axis/field/global functions, handled by the write_metadata interface, which append the usual netCDF metadata content to the data records. That seems like it may provide the low-level functionality you need.

I think the current write_metadata_axis/field can only write specific content, such as longname, units, etc. But it could be generalized to support other metadata. write_metadata_global is more general-purpose and might already meet your needs.

You would also need some way to pass your information from (say) driver/coupler to MOM. At the moment, I'm not sure there is an established "MOM API" function to do that. If not, then it could also be provided. (The MOM_infra_file object may be able to do this. If not, then this is where I would add it.)

Note that these functions all pass through FMS, and their main purpose was to ensure that output works smoothly with FMS. The FMS developers are currently working on a redesign of the diag manager, so you might want to see how that is going.