11import json
22import logging
33import os
4- from typing import Any , Dict , KeysView , List , Literal , Optional , Tuple , TypedDict
4+ from typing import Any , KeysView , Literal , TypedDict
55
66import cmor
77import numpy as np
@@ -32,7 +32,7 @@ def __init__(
3232 self ,
3333 name : str ,
3434 units : str ,
35- raw_variables : List [str ],
35+ raw_variables : list [str ],
3636 table : str ,
3737 ):
3838 # The CMIP variable name.
@@ -79,11 +79,11 @@ def __init__(
7979 name : str ,
8080 units : str ,
8181 table : str ,
82- raw_variables : List [str ],
83- unit_conversion : Optional [ str ] = None ,
84- formula : Optional [ str ] = None ,
85- positive : Optional [ Literal ["up" , "down" ]] = None ,
86- levels : Optional [ Levels ] = None ,
82+ raw_variables : list [str ],
83+ unit_conversion : str | None = None ,
84+ formula : str | None = None ,
85+ positive : Literal ["up" , "down" ] | None = None ,
86+ levels : Levels | None = None ,
8787 ):
8888 super ().__init__ (name , units , raw_variables , table )
8989
@@ -135,7 +135,7 @@ def __init__(
135135 self .levels = levels
136136
137137 # Output data for CMORizing.
138- self .output_data : Optional [ np .ndarray ] = None
138+ self .output_data : np .ndarray | None = None
139139
140140 def __eq__ (self , other ):
141141 if isinstance (self , other .__class__ ):
@@ -155,7 +155,7 @@ def __eq__(self, other):
155155 def __str__ (self ):
156156 return yaml .dump (self .__dict__ , default_flow_style = False , sort_keys = False )
157157
158- def to_dict (self ) -> Dict [str , Any ]:
158+ def to_dict (self ) -> dict [str , Any ]:
159159 """
160160 Return __dict__ with additional entries to support existing e3sm_to_cmip
161161 functions.
@@ -166,7 +166,7 @@ def to_dict(self) -> Dict[str, Any]:
166166
167167 Returns
168168 -------
169- Dict [str, Any]
169+ dict [str, Any]
170170 __dict__ with additional entries.
171171 """
172172 # TODO: Remove this method e3sm_to_cmip functions parse VarHandler
@@ -175,7 +175,7 @@ def to_dict(self) -> Dict[str, Any]:
175175
176176 def cmorize (
177177 self ,
178- vars_to_filepaths : Dict [str , List [str ]],
178+ vars_to_filepaths : dict [str , list [str ]],
179179 tables_path : str ,
180180 metadata_path : str ,
181181 cmor_log_dir : str ,
@@ -185,7 +185,7 @@ def cmorize(
185185
186186 Parameters
187187 ----------
188- vars_to_filepaths : Dict [str, List [str]]
188+ vars_to_filepaths : dict [str, list [str]]
189189 A dictionary mapping E3SM raw variables to a list of filepath(s).
190190 tables_path : str
191191 The path to directory containing CMOR Tables directory.
@@ -272,13 +272,13 @@ def cmorize(
272272 return is_cmor_successful
273273
274274 def _all_vars_have_filepaths (
275- self , vars_to_filespaths : Dict [str , List [str ]]
275+ self , vars_to_filespaths : dict [str , list [str ]]
276276 ) -> bool :
277277 """Checks if all raw variables have filepaths found.
278278
279279 Parameters
280280 ----------
281- vars_to_filespaths : Dict [str, List [str]]
281+ vars_to_filespaths : dict [str, list [str]]
282282 A dictionary of raw variables to filepaths.
283283
284284 Returns
@@ -347,13 +347,13 @@ def _get_var_time_dim(self, table_path: str) -> str | None:
347347 return None
348348
349349 def _get_mfdataset (
350- self , vars_to_filepaths : Dict [str , List [str ]], index : int , time_dim : str | None
350+ self , vars_to_filepaths : dict [str , list [str ]], index : int , time_dim : str | None
351351 ) -> xr .Dataset :
352352 """Get the xr.Dataset using the filepaths for all raw variables.
353353
354354 Parameters
355355 ----------
356- vars_to_filepaths : Dict [str, List [str]]
356+ vars_to_filepaths : dict [str, list [str]]
357357 A dictionary mapping E3SM raw variables to a list of filepath(s).
358358 index : int
359359 The index representing the time range for the file.
@@ -374,7 +374,7 @@ def _get_mfdataset(
374374 """
375375 # Sort the input filepath names for each variable to ensure time axis data
376376 # is aligned and in order across variables.
377- sorted_v_to_fp : Dict [str , List [str ]] = {
377+ sorted_v_to_fp : dict [str , list [str ]] = {
378378 var : sorted (vars_to_filepaths [var ]) for var in vars_to_filepaths
379379 }
380380
@@ -442,7 +442,7 @@ def _get_time_bnds_key(self, data_vars: KeysView[Any]) -> str:
442442
443443 def _get_cmor_axis_ids_and_ips_id (
444444 self , ds : xr .Dataset , time_dim : str | None
445- ) -> Tuple [ Dict [str , int ], int | None ]:
445+ ) -> tuple [ dict [str , int ], int | None ]:
446446 """Create the CMOR axes objects, which are set globally in the CMOR module.
447447
448448 The CMOR ids for "time" and "lev" should be the starting elements of the
@@ -462,7 +462,7 @@ def _get_cmor_axis_ids_and_ips_id(
462462
463463 Returns
464464 -------
465- Tuple[Dict [str, int], int | None]
465+ tuple[dict [str, int], int | None]
466466 A tuple with the first element being a dictionary (value is the
467467 CMOR axis and key is the ID of the CMOR axis), and the second
468468 element being the CMOR zfactor ID for ips if the dataset and handler
@@ -471,7 +471,7 @@ def _get_cmor_axis_ids_and_ips_id(
471471 Example:
472472 ({"time": 0, "lev": 1, "lat": 2, "lon": 3}, 4)
473473 """
474- axis_id_map : Dict [str , int ] = {}
474+ axis_id_map : dict [str , int ] = {}
475475 cmor_ips_id = None
476476
477477 if time_dim is not None :
@@ -540,7 +540,7 @@ def _has_hybrid_sigma_levels(self, ds: xr.Dataset):
540540 return set (hybrid_sigma_levels ).issubset (ds .data_vars )
541541
542542 def _set_cmor_zfactor_for_hybrid_levels (
543- self , ds : xr .Dataset , cmor_axis_id_map : Dict [str , cmor .axis ]
543+ self , ds : xr .Dataset , cmor_axis_id_map : dict [str , cmor .axis ]
544544 ):
545545 lev_id = cmor_axis_id_map ["lev" ]
546546 lev_name = self .levels ["name" ] # type: ignore
@@ -580,13 +580,13 @@ def _set_cmor_zfactor_for_hybrid_levels(
580580 )
581581
582582 def _set_and_get_cmor_zfactor_ips_id (
583- self , cmor_axis_id_map : Dict [str , cmor .axis ]
583+ self , cmor_axis_id_map : dict [str , cmor .axis ]
584584 ) -> int :
585585 """Creates ips as a cmor.zfactor and returns its global CMOR id.
586586
587587 Parameters
588588 ----------
589- cmor_axis_id_map : Dict [str, cmor.axis]
589+ cmor_axis_id_map : dict [str, cmor.axis]
590590 A dictionary mapping the name of a CMOR axis set globally to its CMOR axis
591591 ID.
592592
0 commit comments