You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The CDAT modules used in the codebase include cdp, cdms2, cdtime, cdutil, genutil, and MV2. We should tackle the replacement of these CDAT modules incrementally and methodically since it is a large dependency in e3sm_diags. I will take a deeper look into how we can port over to xarray/XCDAT in a way to minimize regressions in the behavior of the code.
Using VSCode's search functionality, the list below shows where the CDAT modules are referenced. Directories excluded from the search include analysis_data_preprocess, model_data_preprocess, .mypy_cache, and build.
cdp
76 results - 23 files
conda/e3sm_diags_env_dev.yml:
14 - cartopy_offlinedata
15: - cdp=1.7.0
16 - cdms2=3.1.5
conda/e3sm_diags_env.yml:
14 - cartopy_offlinedata
15: - cdp=1.7.0
16 - cdms2=3.1.5
conda/meta.yaml:
24 - python
25: - cdp >=1.7.0
26 - cdms2
docs/source/index.rst:
55 diagnostics package through a unifying framework: `Community
56: Diagnostics Package (CDP) <https://github.com/CDAT/cdp>`_.
57 - is flexible for user-specified diagnostics and configuration for
docs/source/dev_guide/adding-new-diags-sets.rst:
620 from .default_viewer import create_metadata
621: from cdp.cdp_viewer import OutputViewer
622
684
685: We use the CDP Viewer to create the webpages.
686 **This is not needed! Use whatever you want to create the webpages.**
docs/source/dev_guide/index.rst:
10 adding-new-diags-sets
11: using-cdp-output-viewer
12 releasing-e3sm-diags
docs/source/dev_guide/using-cdp-output-viewer.rst:
1: How to use the CDP Output Viewer
2 ================================
6 - The basic framework of the `ESGF Output Viewer <https://github.com/ESGF/output_viewer>`__, consisting of indices, pages, groups, rows, and columns.
7: - The process of using the `CDP Output Viewer <https://github.com/CDAT/cdp/blob/master/cdp/cdp_viewer.py>`__ (``cdp_viewer``), including explanations and examples related to the relevant functions.
8
9: - CDP Output Viewer is based on the ESGF Output Viewer
10
20
21: .. figure:: _static/cdp_example.png
22 :alt: Example of a webpage generated by the Output Viewer.
36
37: .. figure:: _static/cdp_index_page.png
38 :alt: Index page of the Output Viewer
46
47: .. figure:: _static/cdp_page.png
48 :alt: A page with two groups: ‘Results of addition’ and ‘Results of subtraction’
86
87: Using CDP Output Viewer (``cdp_viewer``)
88 ----------------------------------------
89
90: ``cdp_viewer`` is a wrapper of the Output Viewer to simplify the API for creating a working viewer.
91
92: If `cdp_viewer` is too abstract/limited, you can instead use the Output Viewer to create your own viewer.
93 Please be aware that there is no official documentation for the Output Viewer, so you will need refer to the `codebase <https://github.com/ESGF/output_viewer>`__ directly.
101
102: from cdp.cdp_viewer import OutputViewer
103
124
125: Viewer HTML generated at /Users/shaheen2/github/cdp/jupyter/index.html. Would you like to open in a browser? y/[n]: y
126
127
128: Functions of ``cdp_viewer``
129 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
130
131: The ``cdp_viewer`` five functions:
132
e3sm_diags/e3sm_diags_driver.py:
10
11: import cdp.cdp_run
12
45 """
46: When using cdp_run, parameters is a list of lists: [[Parameters], ...].
47 Make this just a list: [Parameters, ...].
324 if parameters[0].multiprocessing:
325: parameters = cdp.cdp_run.multiprocess(run_diag, parameters, context="fork")
326 elif parameters[0].distributed:
327: parameters = cdp.cdp_run.distribute(run_diag, parameters)
328 else:
329: parameters = cdp.cdp_run.serial(run_diag, parameters)
330
e3sm_diags/run.py:
83 # The select() call in get_parameters() was made for the original
84: # command-line way of using CDP.
85 # We just call it manually with the parameter object param.
e3sm_diags/parameter/core_parameter.py:
2
3: import cdp.cdp_parameter
4
5
6: class CoreParameter(cdp.cdp_parameter.CDPParameter):
7 def __init__(self):
e3sm_diags/parser/core_parser.py:
1: import cdp.cdp_parser
2
5
6: class CoreParser(cdp.cdp_parser.CDPParser):
7 def __init__(self, *args, **kwargs):
e3sm_diags/viewer/annual_cycle_zonal_mean_viewer.py:
2
3: from cdp.cdp_viewer import OutputViewer
4
e3sm_diags/viewer/area_mean_time_series_viewer.py:
2
3: from cdp.cdp_viewer import OutputViewer
4
e3sm_diags/viewer/arm_diags_viewer.py:
2
3: from cdp.cdp_viewer import OutputViewer
4
e3sm_diags/viewer/default_viewer.py:
12 import numpy
13: from cdp.cdp_viewer import OutputViewer
14
e3sm_diags/viewer/enso_diags_viewer.py:
3
4: from cdp.cdp_viewer import OutputViewer
5
e3sm_diags/viewer/mean_2d_viewer.py:
2
3: from cdp.cdp_viewer import OutputViewer
4
e3sm_diags/viewer/qbo_viewer.py:
2
3: from cdp.cdp_viewer import OutputViewer
4
e3sm_diags/viewer/streamflow_viewer.py:
2
3: from cdp.cdp_viewer import OutputViewer
4
e3sm_diags/viewer/tc_analysis_viewer.py:
2
3: from cdp.cdp_viewer import OutputViewer
4
tests/test.sh:
19 printf "==============================================\n"
20: # Integration tests must be called individually. `e3sm_diags` uses `cdp_parser.get_parameters()`, which incorrectly picks up `python -m unittest` cmd args.
21: # This results in `cdp_parser.get_parameters()` raising `error: unrecognized arguments <UNITTEST ARGS>`.
22 # Running tests using these commands do not work:
24 # - `python -m unittest discover -s tests/integration --pattern "test_*.py"`
25: # Related lines of code : https://github.com/CDAT/cdp/blob/2917603097112f7db52be0bf7a2e766e14cc2e16/cdp/cdp_parser.py#L498
26 command='python -m unittest tests/integration/'
tests/integration/e3sm_diags_run.log:
10 2021-12-10 10:30:32,869 [INFO]: run.py(_add_parent_attrs_to_children:147) >> ['test_name']
11: 2021-12-10 10:30:32,870 [WARNING]: warnings.py(_showwarnmsg:109) >> /home/ac.tvo/miniconda3/envs/e3sm_diags_env_dev/lib/python3.9/site-packages/cdp/cdp_parser.py:192: DeprecationWarning: This method will be removed in future versions. Use 'parser.read_file()' instead.
12 config.readfp(cfg_file_obj)
13
14: 2021-12-10 10:30:33,071 [WARNING]: warnings.py(_showwarnmsg:109) >> /home/ac.tvo/miniconda3/envs/e3sm_diags_env_dev/lib/python3.9/site-packages/cdp/cdp_parser.py:410: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working
15 if not isinstance(param_v, collections.Iterable):
tests/integration/all_sets_results_test/prov/environment.yml:
27 - cdms2=3.1.5=py39h6e0a748_9
28: - cdp=1.7.0=pyhd8ed1ab_0
29 - cdtime=3.1.4=py39hd7c74d3_3
cdms2
118 results - 29 files
conda/e3sm_diags_env_dev.yml:
15 - cdp=1.7.0
16: - cdms2=3.1.5
17 - cdtime=3.1.4
conda/e3sm_diags_env.yml:
15 - cdp=1.7.0
16: - cdms2=3.1.5
17 - cdtime=3.1.4
conda/meta.yaml:
25 - cdp >=1.7.0
26: - cdms2
27 - cdutil
e3sm_diags/__init__.py:
6
7: # Disable MPI in cdms2, which is not currently supported by E3SM-unified
8 os.environ["CDMS_NO_MPI"] = "True"
e3sm_diags/e3sm_diags_vars.py:
11
12: import cdms2
13
48 raise RuntimeError(msg)
49: with cdms2.open(path) as f:
50 return f.variables.keys()
e3sm_diags/derivations/acme.py:
11 if TYPE_CHECKING:
12: from cdms2.axis import FileAxis
13: from cdms2.fvariable import FileVariable
14
e3sm_diags/driver/annual_cycle_zonal_mean_driver.py:
6 import MV2
7: from cdms2 import createAxis
8
18 if TYPE_CHECKING:
19: from cdms2.axis import TransientAxis
20: from cdms2.tvariable import TransientVariable
21
e3sm_diags/driver/area_mean_time_series_driver.py:
4
5: import cdms2
6 import cdutil
60 )
61: with cdms2.open(mask_path) as f:
62 land_frac = f("LANDFRAC")
e3sm_diags/driver/arm_diags_driver.py:
4
5: import cdms2
6 import numpy as np
96 ref_file = os.path.join(ref_path, ref_file_name)
97: ref_data = cdms2.open(ref_file)
98
209 ref_file = os.path.join(ref_path, ref_file_name)
210: ref_data = cdms2.open(ref_file)
211 if var == "CLOUD":
319 )
320: ref_data = cdms2.open(ref_file)
321 vars_funcs = get_vars_funcs_for_derived_var(ref_data, var)
398 ref_file = os.path.join(ref_path, ref_file_name)
399: ref_data = cdms2.open(ref_file)
400 ref_pr = ref_data("pr") # mm/hr
e3sm_diags/driver/cosp_histogram_driver.py:
4
5: import cdms2
6
68 )
69: with cdms2.open(mask_path) as f:
70 land_frac = f("LANDFRAC")
e3sm_diags/driver/diurnal_cycle_driver.py:
4
5: import cdms2
6
40 )
41: with cdms2.open(mask_path) as f:
42 land_frac = f("LANDFRAC")
e3sm_diags/driver/enso_diags_driver.py:
6
7: import cdms2
8 import cdutil
232 )
233: with cdms2.open(mask_path) as f:
234 land_frac = f("LANDFRAC")
e3sm_diags/driver/lat_lon_driver.py:
5
6: import cdms2
7 import MV2
80 )
81: with cdms2.open(mask_path) as f:
82 land_frac = f("LANDFRAC")
100 if ref_name == "WARREN":
101: # This is cdms2 fix for bad mask, Denis' fix should fix this.
102 mv2 = MV2.masked_where(mv2 == -0.9, mv2)
104 if ref_name == "AIRS":
105: # This is cdms2 fix for bad mask, Denis' fix should fix this.
106 mv2 = MV2.masked_where(mv2 > 1e20, mv2)
107 if ref_name == "WILLMOTT" or ref_name == "CLOUDSAT":
108: # This is cdms2 fix for bad mask, Denis' fix should fix this.
109 mv2 = MV2.masked_where(mv2 == -999.0, mv2)
e3sm_diags/driver/meridional_mean_2d_driver.py:
2
3: import cdms2
4 import cdutil
20 """
21: orig_bounds = cdms2.getAutoBounds()
22: cdms2.setAutoBounds(1)
23 lev = ref.getLevel()
41 lev.setBounds(None)
42: cdms2.setAutoBounds(orig_bounds)
43
130 # in order to use regrid tool we need to have at least two latitude bands, so generate new grid first
131: lat = cdms2.createAxis([0])
132 lat.setBounds(numpy.array([-1, 1]))
133 lat.designateLatitude()
134: grid = cdms2.createRectGrid(lat, lon_out)
135
153 # latitude bands, so generate new grid first.
154: lat = cdms2.createAxis([0])
155 lat.setBounds(numpy.array([-1, 1]))
156 lat.designateLatitude()
157: grid = cdms2.createRectGrid(lat, lon_out)
158
e3sm_diags/driver/polar_driver.py:
4
5: import cdms2
6 import MV2
69 )
70: with cdms2.open(mask_path) as f:
71 land_frac = f("LANDFRAC")
89 if ref_name == "WARREN":
90: # This is cdms2 fix for bad mask, Denis' fix should fix this.
91 mv2 = MV2.masked_where(mv2 == -0.9, mv2)
93 if ref_name == "AIRS":
94: # This is cdms2 fix for bad mask, Denis' fix should fix this.
95 mv2 = MV2.masked_where(mv2 > 1e20, mv2)
96 if ref_name == "WILLMOTT" or ref_name == "CLOUDSAT":
97: # This is cdms2 fix for bad mask, Denis' fix should fix this.
98 mv2 = MV2.masked_where(mv2 == -999.0, mv2)
e3sm_diags/driver/streamflow_driver.py:
5
6: import cdms2
7 import cdutil
283 logger.info("test_array.shape={}".format(test_array.shape))
284: if type(area_upstream) == cdms2.tvariable.TransientVariable:
285 area_upstream = area_upstream.getValue()
487
488: if type(monthly) == cdms2.tvariable.TransientVariable:
489 monthly = monthly.getValue()
513
514: if type(monthly) == cdms2.tvariable.TransientVariable:
515 monthly = monthly.getValue()
e3sm_diags/driver/tc_analysis_driver.py:
7
8: import cdms2
9 import numpy as np
77 )
78: test_cyclones_hist = cdms2.open(test_cyclones_file)(
79 "density", lat=(-60, 60, "ccb"), squeeze=1
84 )
85: test_aew_hist = cdms2.open(test_aew_file)(
86 "density", lat=(0, 35, "ccb"), lon=(-180, 0, "ccb"), squeeze=1
113 )
114: ref_cyclones_hist = cdms2.open(ref_cyclones_file)("density", squeeze=1)
115 ref_aew_file = os.path.join(
118 )
119: ref_aew_hist = cdms2.open(ref_aew_file)("density", squeeze=1)
120 ref_data["metrics"] = generate_tc_metrics_from_te_stitch_file(ref_te_file)
133 )
134: ref_cyclones_hist = cdms2.open(ref_cyclones_file)(
135 "density", lat=(-60, 60, "ccb"), squeeze=1
137 ref_aew_file = os.path.join(reference_data_path, "aew_hist_ERA5_2010_2014.nc")
138: ref_aew_hist = cdms2.open(ref_aew_file)(
139 "density", lat=(0, 35, "ccb"), lon=(180, 360, "ccb"), squeeze=1
176 mask_path = os.path.join(e3sm_diags.INSTALL_PATH, "acme_ne30_ocean_land_mask.nc")
177: ocnfrac = cdms2.open(mask_path)("OCNFRAC", squeeze=1)
178
281 vars: Dict[str, Any],
282: ocnfrac: cdms2.dataset.DatasetVariable,
283 basin_info: BasinInfo,
290 :type vars: Dict[str, Any]
291: :param ocnfrac: Ocnfrac CDMS2 dataset variable
292: :type ocnfrac: cdms2.dataset.DatasetVariable
293 :param basin_info: Basin information
e3sm_diags/driver/zonal_mean_2d_driver.py:
4
5: import cdms2
6 import cdutil
21 """Creates the mean, max, min, rmse, corr in a dictionary"""
22: orig_bounds = cdms2.getAutoBounds()
23: cdms2.setAutoBounds(1)
24 lev = ref.getLevel()
42 lev.setBounds(None)
43: cdms2.setAutoBounds(orig_bounds)
44
95 )
96: with cdms2.open(mask_path) as f:
97 land_frac = f("LANDFRAC")
115 if ref_name == "WARREN":
116: # This is cdms2 fix for bad mask, Denis' fix should fix this.
117 mv2 = MV2.masked_where(mv2 == -0.9, mv2)
119 if ref_name == "AIRS":
120: # This is cdms2 fix for bad mask, Denis' fix should fix this.
121 mv2 = MV2.masked_where(mv2 > 1e20, mv2)
122 if ref_name == "WILLMOTT" or ref_name == "CLOUDSAT":
123: # This is cdms2 fix for bad mask, Denis' fix should fix this.
124 mv2 = MV2.masked_where(mv2 == -999.0, mv2)
e3sm_diags/driver/zonal_mean_xy_driver.py:
2
3: import cdms2
4 import cdutil
38 )
39: mv2_reg = cdms2.createVariable(
40 b0,
52 )
53: mv1_reg = cdms2.createVariable(
54 a0,
126 if ref_name == "WARREN":
127: # This is cdms2 fix for bad mask, Denis' fix should fix this.
128 mv2 = MV2.masked_where(mv2 == -0.9, mv2)
130 if ref_name == "AIRS":
131: # This is cdms2 fix for bad mask, Denis' fix should fix this.
132 mv2 = MV2.masked_where(mv2 > 1e20, mv2)
133 if ref_name == "WILLMOTT" or ref_name == "CLOUDSAT":
134: # This is cdms2 fix for bad mask, Denis' fix should fix this.
135 mv2 = MV2.masked_where(mv2 == -999.0, mv2)
e3sm_diags/driver/utils/climo.py:
1: import cdms2
2 import numpy as np
79
80: trans_var = cdms2.createVariable(climo)(squeeze=1)
81 # Losing the grid after a squeeze is normal, we need to set it again.
e3sm_diags/driver/utils/dataset.py:
10
11: import cdms2
12
181 file_path = self._get_timeseries_file_path(primary_var, data_path)
182: fin = cdms2.open(file_path)
183 result = fin(static_var)
231
232: with cdms2.open(filename) as f:
233 return f.getglobal(attr)
338
339: with cdms2.open(filename) as data_file:
340 for var in vars_to_get:
352
353: # Get the variables as cdms2.TransientVariables.
354: # Ex: variables is [PRECC, PRECL], where both are cdms2.TransientVariables.
355 variables = self._get_original_vars_climo(
416 Given a dictionary in the form {(vars): func}, get the vars
417: from the data_file as cdms2.TransientVariables.
418
463 if not extra_vars_only:
464: # Open the files of the variables and get the cdms2.TransientVariables.
465 # Ex: [PRECC, PRECL], where both are TransientVariables.
623 Given a dictionary in the form {(vars): func}, get the vars
624: from files in data_path as cdms2.TransientVariables.
625
683 else:
684: # with cdms2.open(fnm) as f:
685 # var_time = f(var, time=(start_time, end_time, 'ccb'))(squeeze=1)
687 # For xml files using above with statement won't work because the Dataset object returned doesn't have attribute __enter__ for content management.
688: fin = cdms2.open(fnm)
689 var_time = fin(var, time=(start_time, end_time, slice_flag))(squeeze=1)
e3sm_diags/driver/utils/general.py:
7
8: import cdms2
9 import cdutil
47 var_time[:] = 0.5 * (tbounds[:, 0] + tbounds[:, 1])
48: time2 = cdms2.createAxis(var_time)
49 time2.designateTime()
298 # Set cdms preferences - no compression, no shuffling, no complaining
299: cdms2.setNetcdfDeflateFlag(1)
300 # 1-9, min to max - Comes at heavy IO (read/write time cost)
301: cdms2.setNetcdfDeflateLevelFlag(0)
302: cdms2.setNetcdfShuffleFlag(0)
303: cdms2.setCompressionWarnings(0) # Turn off warning messages
304
314 test_pth = os.path.join(path, file_name)
315: with cdms2.open(test_pth, "w+") as file_test:
316 try:
329 # Set cdms preferences - no compression, no shuffling, no complaining
330: cdms2.setNetcdfDeflateFlag(1)
331 # 1-9, min to max - Comes at heavy IO (read/write time cost)
332: cdms2.setNetcdfDeflateLevelFlag(0)
333: cdms2.setNetcdfShuffleFlag(0)
334: cdms2.setCompressionWarnings(0) # Turn off warning messages
335
347
348: with cdms2.open(test_pth, cdms_arg) as file_test:
349 file_test.write(test)
354 ref_pth = os.path.join(pth, parameter.output_file + "_ref.nc")
355: with cdms2.open(ref_pth, cdms_arg) as file_ref:
356 file_ref.write(ref)
362 diff_pth = os.path.join(pth, parameter.output_file + "_diff.nc")
363: with cdms2.open(diff_pth, cdms_arg) as file_diff:
364 file_diff.write(diff)
tests/e3sm_diags/derivations/test_acme.py:
13 if TYPE_CHECKING:
14: from cdms2.axis import FileAxis
15
tests/e3sm_diags/drivers/test_annual_cycle_zonal_mean_driver.py:
4 import numpy as np
5: from cdms2.axis import TransientAxis
6: from cdms2.tvariable import TransientVariable
7
tests/e3sm_diags/drivers/test_tc_analysis_driver.py:
21 if TYPE_CHECKING:
22: from cdms2.dataset import DatasetVariable
23
tests/integration/e3sm_diags_run.log:
1: 2021-12-10 10:30:32,854 [WARNING]: warnings.py(_showwarnmsg:109) >> /home/ac.tvo/miniconda3/envs/e3sm_diags_env_dev/lib/python3.9/site-packages/cdms2/variable.py:74: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
2 Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
4
5: 2021-12-10 10:30:32,863 [WARNING]: warnings.py(_showwarnmsg:109) >> /home/ac.tvo/miniconda3/envs/e3sm_diags_env_dev/lib/python3.9/site-packages/cdms2/tvariable.py:331: DeprecationWarning: Non-scalar arrays for the fill value are deprecated. Use arrays with scalar values instead. The filled function still supports any array as `fill_value`.
6 self._missing = numpy.array(value).astype(self.dtype)
tests/integration/test_dataset.py:
2
3: import cdms2
4
15 def test_convert_units(self):
16: with cdms2.open(f"{TEST_DATA_PATH}/precc.nc") as precc_file:
17 var = precc_file("PRECC")
91
92: precc_file = cdms2.open(get_abs_file_path('integration_test_data/precc.nc'))
93 acme_derivations.process_derived_var('PRECT', derived_var,
105
106: precc_file = cdms2.open(get_abs_file_path('integration_test_data/precc.nc'))
107 with self.assertRaises(RuntimeError):
125 # add derived_var_dict to default_derived_vars
126: precc_file = cdms2.open(get_abs_file_path('integration_test_data/precc.nc'))
127 self.parameter.derived_variables = derived_var_dict
155 # add derived_var_dict to default_derived_vars
156: precc_file = cdms2.open(get_abs_file_path('integration_test_data/precc.nc'))
157 self.parameter.derived_variables = derived_var_dict
177
178: precc_file = cdms2.open(get_abs_file_path('integration_test_data/precc.nc'))
179 self.parameter.derived_variables = derived_var_dict
187 def test_mask_by(self):
188: with cdms2.open(get_abs_file_path('integration_test_data/precc.nc')) as precc_file:
189 prcc = precc_file('PRECC')
190: with cdms2.open(get_abs_file_path('integration_test_data/precl.nc')) as precl_file:
191 prcl = precl_file('PRECL')
tests/integration/all_sets_results_test/prov/environment.yml:
26 - cdat_info=8.2.1=pyh9f0ad1d_1
27: - cdms2=3.1.5=py39h6e0a748_9
28 - cdp=1.7.0=pyhd8ed1ab_0
tests/testing_data/create_test_data.py:
7
8: import cdms2
9
128 orig_path = os.path.join(TEMP_DIR, file_name)
129: with cdms2.open(orig_path) as orig_file:
130 if os.path.exists(f_and_v.local_uri):
132
133: with cdms2.open(f_and_v.local_uri, "w") as new_file:
134 # Copy over the attributes.
136
137: # Lat, lon, and time are considered dimensions in cdms2.
138 # Those are automatically saved.
The CDAT modules used in the codebase include cdp, cdms2, cdtime, cdutil, genutil, and MV2. We should tackle the replacement of these CDAT modules incrementally and methodically since it is a large dependency in e3sm_diags. I will take a deeper look into how we can port over to xarray/XCDAT in a way to minimize regressions in the behavior of the code.
Using VSCode's search functionality, the list below shows where the CDAT modules are referenced. Directories excluded from the search include
analysis_data_preprocess
,model_data_preprocess
,.mypy_cache
, andbuild
.cdp
cdms2
cdtime
cdutil
genutil
MV2
The text was updated successfully, but these errors were encountered: