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

A request to check the 'required_global_attributes' from the table before 'cmor.write' #26

Closed
ehogan opened this issue May 22, 2015 · 1 comment
Assignees

Comments

@ehogan
Copy link
Contributor

ehogan commented May 22, 2015

Would it be possible to check for the presence of the required global attributes from the table (i.e., run cmor_has_required_global_attributes) after cmor.dataset / cmor_set_cur_dataset_attribute (perhaps when running cmor.load_table, assuming cmor.dataset has been previously run?) rather than waiting until cmor.write (as shown in the example below), so that any errors can be caught sooner?

The output when I run cmor_example.py (see below) is:

No module named cdms2
Running cmor.setup
Running cmor.dataset
Running cmor.load_table
Running cmor.axis
Running cmor.variable
Running cmor.write

C Traceback:
In function: cmor_has_required_global_attributes


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!                                                                                                                                              !
! Error: Required global attribute parent_experiment_rip is missing please check call(s) to cmor_dataset and/or cmor_set_cur_dataset_attribute !
!                                                                                                                                              !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Note that the example, which is based on 'Sample Program 1' from the CMOR Users Guide, doesn't work as-is, since parent_experiment_rip is not defined in cmor.dataset (but exists in the required_global_attributes in the table).

Contents of cmor_example.py:

#! /usr/bin/env python
import cmor

def main():
    """
    'Sample Program 1' from the CMOR Users Guide.

    ``CMIP5_Amon`` table from https://github.com/PCMDI/
    cmip5-cmor-tables/blob/master/Tables/CMIP5_Amon.

    Some minor edits were made:

      * ``inpath`` was removed from ``cmor.setup``.
      * ``source``, ``model_id`` and ``forcing`` in ``cmor.dataset``
        were updated.

    This sample program doesn't work as the ``CMIP5_Amon`` table has
    ``parent_experiment_rip`` in the ``required_global_attributes``.
    """
    print 'Running cmor.setup'
    cmor.setup(netcdf_file_action=cmor.CMOR_REPLACE)

    print 'Running cmor.dataset'
    cmor.dataset(
        experiment_id='historical', institution='ukmo', source='HadCM3 (2010)',
        calendar='360_day', contact='Tim Lincecum, timmy@sfgiants.com',
        model_id='HadCM3', forcing='N/A', institute_id='pcmdi',
        parent_experiment_id='N/A', branch_time=0.)

    print 'Running cmor.load_table'
    table = 'CMIP5_Amon'
    cmor.load_table(table)

    print 'Running cmor.axis'
    itime = cmor.axis(table_entry='time',
                      units='days since 2000-01-01 00:00:00', coord_vals=[15,],
                      cell_bounds=[0, 30])
    ilat = cmor.axis(table_entry='latitude', units='degrees_north',
                     coord_vals=[0], cell_bounds=[-1, 1])
    ilon = cmor.axis(table_entry='longitude', units='degrees_east',
                     coord_vals=[90], cell_bounds=[89, 91])
    axis_ids = [itime, ilat, ilon]

    print 'Running cmor.variable'
    varid = cmor.variable('ts', 'K', axis_ids)

    print 'Running cmor.write'
    cmor.write(varid, [273])

    print 'Running cmor.close'
    path = cmor.close(varid, file_name=True)
    print path
    cmor.close()

if __name__ == '__main__':
    main()
@doutriaux1
Copy link
Collaborator

@ehogan I don't think we can because some project have required attributes that will not be set by cmor.dataset and require to be set via set_cur_dataset. So we have to wait until we actually try to write to the file to be sure all defintiions are done. does that make sense? Feel free to re-open

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

2 participants