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

Add global metadata attributes to model output files #15

Open
aidanheerdegen opened this issue Sep 17, 2024 · 0 comments
Open

Add global metadata attributes to model output files #15

aidanheerdegen opened this issue Sep 17, 2024 · 0 comments

Comments

@aidanheerdegen
Copy link
Member

aidanheerdegen commented Sep 17, 2024

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:

payu-org/payu#510

I think it should be straightforward to add

netCDF:

!-----------------------------------------------------------------
! global attributes
!-----------------------------------------------------------------
! ... the user should change these to something useful ...
!-----------------------------------------------------------------
#ifdef CCSMCOUPLED
call check(nf90_put_att(ncid,nf90_global,'title',runid), &
'in global attribute title')
#else
title = 'sea ice model output for CICE'
call check(nf90_put_att(ncid,nf90_global,'title',title), &
'global attribute title')
#endif
title = 'Diagnostic and Prognostic Variables'
call check(nf90_put_att(ncid,nf90_global,'contents',title), &
'global attribute contents')
title = 'Los Alamos Sea Ice Model (CICE) Version 5'
call check(nf90_put_att(ncid,nf90_global,'source',title), &
'global attribute source')
#ifdef AusCOM
write(title,'(a,i3,a)') 'This Year Has ',int(dayyr),' days'
#else
if (use_leap_years) then
write(title,'(a,i3,a)') 'This year has ',int(dayyr),' days'
else
write(title,'(a,i3,a)') 'All years have exactly ',int(dayyr),' days'
endif
#endif
call check(nf90_put_att(ncid,nf90_global,'comment',title), &
'global attribute comment')
write(title,'(a,i8.8)') 'File written on model date ',idate
call check(nf90_put_att(ncid,nf90_global,'comment2',title), &
'global attribute date1')
write(title,'(a,i6)') 'seconds elapsed into model date: ',sec
call check(nf90_put_att(ncid,nf90_global,'comment3',title), &
'global attribute date2')
title = 'CF-1.0'
call check(nf90_put_att(ncid,nf90_global,'conventions',title), &
'global attribute conventions')
call date_and_time(date=current_date, time=current_time)
write(start_time,1000) current_date(1:4), current_date(5:6), &
current_date(7:8), current_time(1:2), &
current_time(3:4), current_time(5:8)
1000 format('This dataset was created on ', &
a,'-',a,'-',a,' at ',a,':',a,':',a)
call check(nf90_put_att(ncid,nf90_global,'history',start_time), &
'global attribute history')
call check(nf90_put_att(ncid,nf90_global,'io_flavor','io_netcdf'), &
'global attribute io_flavor')

pio:

!-----------------------------------------------------------------
! global attributes
!-----------------------------------------------------------------
! ... the user should change these to something useful ...
!-----------------------------------------------------------------
#ifdef CCSMCOUPLED
status = pio_put_att(File,pio_global,'title',runid)
#else
title = 'sea ice model output for CICE'
status = pio_put_att(File,pio_global,'title',trim(title))
#endif
title = 'Diagnostic and Prognostic Variables'
status = pio_put_att(File,pio_global,'contents',trim(title))
title = 'Los Alamos Sea Ice Model (CICE) Version 5'
status = pio_put_att(File,pio_global,'source',trim(title))
select case (histfreq(ns))
case ("y", "Y")
write(time_period_freq,'(a,i0)') 'year_',histfreq_n(ns)
case ("m", "M")
write(time_period_freq,'(a,i0)') 'month_',histfreq_n(ns)
case ("d", "D")
write(time_period_freq,'(a,i0)') 'day_',histfreq_n(ns)
case ("h", "H")
write(time_period_freq,'(a,i0)') 'hour_',histfreq_n(ns)
case ("1")
write(time_period_freq,'(a,i0)') 'step_',histfreq_n(ns)
end select
status = pio_put_att(File,pio_global,'time_period_freq',trim(time_period_freq))
if (use_leap_years) then
write(title,'(a,i3,a)') 'This year has ',int(dayyr),' days'
else
write(title,'(a,i3,a)') 'All years have exactly ',int(dayyr),' days'
endif
status = pio_put_att(File,pio_global,'comment',trim(title))
write(title,'(a,i8.8)') 'File written on model date ',idate
status = pio_put_att(File,pio_global,'comment2',trim(title))
write(title,'(a,i6)') 'seconds elapsed into model date: ',sec
status = pio_put_att(File,pio_global,'comment3',trim(title))
title = 'CF-1.0'
status = &
pio_put_att(File,pio_global,'conventions',trim(title))
call date_and_time(date=current_date, time=current_time)
write(start_time,1000) current_date(1:4), current_date(5:6), &
current_date(7:8), current_time(1:2), &
current_time(3:4)
1000 format('This dataset was created on ', &
a,'-',a,'-',a,' at ',a,':',a)
status = pio_put_att(File,pio_global,'history',trim(start_time))
status = pio_put_att(File,pio_global,'io_flavor','io_pio')

@aidanheerdegen aidanheerdegen moved this to New Issues 🌅 in Model Release Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New Issues 🌅
Development

No branches or pull requests

1 participant