3838from pathlib import Path
3939
4040import cftime
41+ import iris
4142import numpy as np
4243import pandas as pd
43- import xarray as xr
4444from attrs import frozen
4545from typing_extensions import TypeAlias
4646
5151 infer_time_start_time_end_for_filename ,
5252)
5353from input4mips_validation .serialisation import converter_json
54+ from input4mips_validation .xarray_helpers .iris import ds_from_iris_cubes
55+ from input4mips_validation .xarray_helpers .variables import (
56+ XRVariableHelper ,
57+ XRVariableProcessorLike ,
58+ )
5459
5560DATA_REFERENCE_SYNTAX_FILENAME : str = "input4MIPs_DRS.json"
5661"""Default name of the file in which the data reference syntax is saved"""
@@ -539,6 +544,7 @@ def validate_file_written_according_to_drs(
539544 file : Path ,
540545 frequency_metadata_keys : FrequencyMetadataKeys = FrequencyMetadataKeys (),
541546 time_dimension : str = "time" ,
547+ xr_variable_processor : XRVariableProcessorLike = XRVariableHelper (),
542548 ) -> None :
543549 """
544550 Validate that a file is correctly written in the DRS
@@ -554,6 +560,9 @@ def validate_file_written_according_to_drs(
554560 time_dimension
555561 The time dimension of the data
556562
563+ xr_variable_processor
564+ Helper to use for processing the variables in xarray objects.
565+
557566 Raises
558567 ------
559568 ValueError
@@ -570,7 +579,12 @@ def validate_file_written_according_to_drs(
570579 file .name
571580 )
572581
573- ds = xr .open_dataset (file , use_cftime = True )
582+ ds = ds_from_iris_cubes (
583+ iris .load (file ),
584+ xr_variable_processor = xr_variable_processor ,
585+ raw_file = file ,
586+ time_dimension = time_dimension ,
587+ )
574588 comparison_metadata = {
575589 k : apply_known_replacements (v )
576590 for k , v in ds .attrs .items ()
0 commit comments