Skip to content

#886 apply cell measures jared#955

Closed
Jared Drayton (mo-jareddrayton) wants to merge 9 commits into
mainfrom
886_apply_cell_measures_jared
Closed

#886 apply cell measures jared#955
Jared Drayton (mo-jareddrayton) wants to merge 9 commits into
mainfrom
886_apply_cell_measures_jared

Conversation

@mo-jareddrayton

@mo-jareddrayton Jared Drayton (mo-jareddrayton) commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

NOT FOR MERGING. JUST FOR DEMONSTRATION

Having spent a bit of time looking at this I personally would avoid adding this functionality to new_variable.py / Variable.process()

If you look at what is going on in Variable.process, it is all focussed on manipulating data and metadata in the iris cubes.

self.logger.debug('Processing the data ...')
self._remove_units_from_input_variables_as_necessary()
self._remove_forecast_period()
self._ensure_masked_arrays()
self._apply_removal()
self._apply_mask()
self._apply_expression()
self._remove_alevhalf_bounds()
if self._force_coordinate_rotation:
self._rotated_coords()
self._validate_cube()
if self._time_coord:
self._update_time_units()
if hasattr(self.model_to_mip_mapping, 'valid_min'):
self._apply_valid_min_correction()

Whereas this change is about managing the state of the cmor singleton. So although the example I provide adds a bit more complexity to requested_variables.py I think it makes far more sense to keep it in this module. Especially as there is already a precedent for this with setting frequency. Doing this also avoids the circular import and cuts down the overall complexity.

saver.cmor.set_frequency(frequency)

I'm also quite baffled by this code in general and will need to spend some more time figuring out what is actually going on here.

        if saver.varid is None:
            from mip_convert.save import create_cmor_variable  # deferred to avoid circular import
            cmor_variable = create_cmor_variable(self)
            saver._getVarId(cmor_variable)
            saver.cmor.apply_cell_measures(*cell_measures_config, saver.varid)

@mo-gill

Ed (mo-gill) commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

I'm also quite baffled by this code in general and will need to spend some more time figuring out what is actually going on here.

If it's any help (i do agree on face value that change looks confusing), those changes were made after this commit: 22530bb , at which point i was encountering this error:

---------------------------------------------------------------------------- Captured stdout call ----------------------------------------------------------------------------
Unable to produce MIP requested variable "uas_tavg-h10m-hxy-u" for "CMIP7_atmos": 'NoneType' object cannot be interpreted as an integer
'NoneType' object cannot be interpreted as an integer
Traceback (most recent call last):
  File "CDDS/mip_convert/mip_convert/request.py", line 124, in convert
    produce_mip_requested_variable(variable_name, stream_id, substream, mip_table, user_config,
  File "CDDS/mip_convert/mip_convert/requested_variables.py", line 129, in produce_mip_requested_variable
    saver.cmor.apply_cell_measures(
  File "CDDS/mip_convert/mip_convert/save/cmor/cmor_wrapper.py", line 140, in apply_cell_measures
    retval = cmor.cmor.set_variable_attribute(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/site-packages/cmor/pywrapper.py", line 1060, in set_variable_attribute
    return _cmor.set_variable_attribute(var_id, name, data_type, value)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object cannot be interpreted as an integer

There's a comment i added about this on the original issue which hopefully explains it a bit:
#892 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants