Skip to content

Commit

Permalink
CDAT Migration: Prepare branch for merge to main (#885)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvothecoder authored Nov 5, 2024
1 parent 43d2df7 commit 3406bf2
Show file tree
Hide file tree
Showing 42 changed files with 198 additions and 6,390 deletions.
131 changes: 67 additions & 64 deletions auxiliary_tools/aerosol_budget.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# NOTE: This module uses the deprecated e3sm_diags.driver.utils.dataset.Dataset
# class, which was replaced by e3sm_diags.driver.utils.dataset_xr.Dataset.
import e3sm_diags
from e3sm_diags.driver import utils
import cdms2
Expand All @@ -12,11 +14,12 @@


def global_integral(var, area_m2):
""" Compute global integral of 2 dimentional properties"""
return numpy.sum(numpy.sum(abs(var)*area_m2,axis = 0), axis=0)
"""Compute global integral of 2 dimentional properties"""
return numpy.sum(numpy.sum(abs(var) * area_m2, axis=0), axis=0)


def calc_column_integral(data, aerosol, season):
""" Calculate column integrated mass """
"""Calculate column integrated mass"""

# take aerosol and change it to the appropriate string
# ncl -> SEASALT, dst -> DUST, rest1 -> REST1
Expand All @@ -32,129 +35,129 @@ def calc_column_integral(data, aerosol, season):
burden = data.get_climo_variable(f"ABURDEN{aerosol_name}", season)
except RuntimeError:
# if not, use the Mass_ terms and integrate over the column
mass = data.get_climo_variable(f'Mass_{aerosol}', season)
mass = data.get_climo_variable(f"Mass_{aerosol}", season)
hyai, hybi, ps = data.get_extra_variables_only(
f'Mass_{aerosol}', season, extra_vars=["hyai", "hybi", "PS"]
f"Mass_{aerosol}", season, extra_vars=["hyai", "hybi", "PS"]
)

p0 = 100000.0 # Pa
ps = ps # Pa
pressure_levs = cdutil.vertical.reconstructPressureFromHybrid(ps, hyai, hybi, p0)
ps = ps # Pa
pressure_levs = cdutil.vertical.reconstructPressureFromHybrid(
ps, hyai, hybi, p0
)

#(72,lat,lon)
delta_p = numpy.diff(pressure_levs,axis = 0)
mass_3d = mass*delta_p/9.8 #mass density * mass air kg/m2
burden = numpy.nansum(mass_3d,axis = 0) #kg/m2
# (72,lat,lon)
delta_p = numpy.diff(pressure_levs, axis=0)
mass_3d = mass * delta_p / 9.8 # mass density * mass air kg/m2
burden = numpy.nansum(mass_3d, axis=0) # kg/m2
return burden



def generate_metrics_dic(data, aerosol, season):
metrics_dict = {}
wetdep = data.get_climo_variable(f'{aerosol}_SFWET', season)
drydep = data.get_climo_variable(f'{aerosol}_DDF', season)
srfemis = data.get_climo_variable(f'SF{aerosol}', season)
area = data.get_extra_variables_only(
f'{aerosol}_DDF', season, extra_vars=["area"]
)
wetdep = data.get_climo_variable(f"{aerosol}_SFWET", season)
drydep = data.get_climo_variable(f"{aerosol}_DDF", season)
srfemis = data.get_climo_variable(f"SF{aerosol}", season)
area = data.get_extra_variables_only(f"{aerosol}_DDF", season, extra_vars=["area"])
area_m2 = area * REARTH**2

burden = calc_column_integral(data, aerosol, season)
burden_total= global_integral(burden, area_m2)*1e-9 # kg to Tg
print(f'{aerosol} Burden (Tg): ',f'{burden_total:.3f}')
sink = global_integral((drydep-wetdep),area_m2)*UNITS_CONV
drydep = global_integral(drydep,area_m2)*UNITS_CONV
wetdep = global_integral(wetdep,area_m2)*UNITS_CONV
srfemis = global_integral(srfemis,area_m2)*UNITS_CONV
print(f'{aerosol} Sink (Tg/year): ',f'{sink:.3f}')
print(f'{aerosol} Lifetime (days): ',f'{burden_total/sink*365:.3f}')
burden_total = global_integral(burden, area_m2) * 1e-9 # kg to Tg
print(f"{aerosol} Burden (Tg): ", f"{burden_total:.3f}")
sink = global_integral((drydep - wetdep), area_m2) * UNITS_CONV
drydep = global_integral(drydep, area_m2) * UNITS_CONV
wetdep = global_integral(wetdep, area_m2) * UNITS_CONV
srfemis = global_integral(srfemis, area_m2) * UNITS_CONV
print(f"{aerosol} Sink (Tg/year): ", f"{sink:.3f}")
print(f"{aerosol} Lifetime (days): ", f"{burden_total/sink*365:.3f}")
metrics_dict = {
"Surface Emission (Tg/yr)": f'{srfemis:.3f}',
"Sink (Tg/yr)": f'{sink:.3f}',
"Dry Deposition (Tg/yr)": f'{drydep:.3f}',
"Wet Deposition (Tg/yr)": f'{wetdep:.3f}',
"Burden (Tg)": f'{burden_total:.3f}',
"Lifetime (Days)": f'{burden_total/sink*365:.3f}',
"Surface Emission (Tg/yr)": f"{srfemis:.3f}",
"Sink (Tg/yr)": f"{sink:.3f}",
"Dry Deposition (Tg/yr)": f"{drydep:.3f}",
"Wet Deposition (Tg/yr)": f"{wetdep:.3f}",
"Burden (Tg)": f"{burden_total:.3f}",
"Lifetime (Days)": f"{burden_total/sink*365:.3f}",
}
return metrics_dict


param = CoreParameter()
param.test_name = 'v2.LR.historical_0101'
param.test_name = 'F2010.PD.NGD_v3atm.0096484.compy'
param.test_data_path = '/Users/zhang40/Documents/ACME_simulations/'
param.test_data_path = '/compyfs/mahf708/E3SMv3_dev/F2010.PD.NGD_v3atm.0096484.compy/post/atm/180x360_aave/clim/10yr'
param.test_name = "v2.LR.historical_0101"
param.test_name = "F2010.PD.NGD_v3atm.0096484.compy"
param.test_data_path = "/Users/zhang40/Documents/ACME_simulations/"
param.test_data_path = "/compyfs/mahf708/E3SMv3_dev/F2010.PD.NGD_v3atm.0096484.compy/post/atm/180x360_aave/clim/10yr"
test_data = utils.dataset.Dataset(param, test=True)

#rearth = 6.37122e6 #km
#UNITS_CONV = 86400.0*365.0*1e-9 # kg/s to Tg/yr
REARTH = 6.37122e6 #km
UNITS_CONV = 86400.0*365.0*1e-9 # kg/s to Tg/yr
# rearth = 6.37122e6 #km
# UNITS_CONV = 86400.0*365.0*1e-9 # kg/s to Tg/yr
REARTH = 6.37122e6 # km
UNITS_CONV = 86400.0 * 365.0 * 1e-9 # kg/s to Tg/yr
# TODO:
# Convert so4 unit to TgS
#mwso4 = 115.0
#mws = 32.066
#UNITS_CONV_S = UNITS_CONV/mwso4*mws # kg/s to TgS/yr
# mwso4 = 115.0
# mws = 32.066
# UNITS_CONV_S = UNITS_CONV/mwso4*mws # kg/s to TgS/yr


species = ["bc", "dst", "mom", "ncl","pom","so4","soa"]
SPECIES_NAMES = {"bc": "Black Carbon",
species = ["bc", "dst", "mom", "ncl", "pom", "so4", "soa"]
SPECIES_NAMES = {
"bc": "Black Carbon",
"dst": "Dust",
"mom": "Marine Organic Matter",
"ncl": "Sea Salt",
"pom": "Primary Organic Matter",
"so4": "Sulfate",
"soa": "Secondary Organic Aerosol"}
"soa": "Secondary Organic Aerosol",
}
MISSING_VALUE = 999.999
metrics_dict = {}
metrics_dict_ref = {}

seasons = ["ANN"]

ref_data_path = os.path.join(
e3sm_diags.INSTALL_PATH,
"control_runs",
"aerosol_global_metrics_benchmarks.json",
)
e3sm_diags.INSTALL_PATH,
"control_runs",
"aerosol_global_metrics_benchmarks.json",
)

with open(ref_data_path, 'r') as myfile:
ref_file=myfile.read()
with open(ref_data_path, "r") as myfile:
ref_file = myfile.read()

metrics_ref = json.loads(ref_file)

for season in seasons:
for aerosol in species:
print(f'Aerosol species: {aerosol}')
print(f"Aerosol species: {aerosol}")
metrics_dict[aerosol] = generate_metrics_dic(test_data, aerosol, season)
metrics_dict_ref[aerosol] = metrics_ref[aerosol]
#metrics_dict_ref[aerosol] = {
# metrics_dict_ref[aerosol] = {
# "Surface Emission (Tg/yr)": f'{MISSING_VALUE:.3f}',
# "Sink (Tg/yr)": f'{MISSING_VALUE:.3f}',
# "Dry Deposition (Tg/yr)": f'{MISSING_VALUE:.3f}',
# "Wet Deposition (Tg/yr)": f'{MISSING_VALUE:.3f}',
# "Burden (Tg)": f'{MISSING_VALUE:.3f}',
# "Lifetime (Days)": f'{MISSING_VALUE:.3f}',
# }
with open(f'aerosol_table_{season}.csv', "w") as table_csv:

with open(f"aerosol_table_{season}.csv", "w") as table_csv:
writer = csv.writer(
table_csv,
delimiter=",",
quotechar="'",
quoting=csv.QUOTE_MINIMAL,
lineterminator='\n',
lineterminator="\n",
)
#writer.writerow([" ", "test","ref",])
# writer.writerow([" ", "test","ref",])
for key, values in metrics_dict.items():
writer.writerow([SPECIES_NAMES[key]])
print('key',key, values)
print("key", key, values)
for value in values:
print(value)
line = []
line.append(value)
line.append(values[value])
line.append(metrics_dict_ref[key][value])
print(line, 'line')
print(line, "line")
writer.writerows([line])
writer.writerows([""])




Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# NOTE: This module uses the deprecated e3sm_diags.driver.utils.dataset.Dataset
# class, which was replaced by e3sm_diags.driver.utils.dataset_xr.Dataset.
from __future__ import annotations

import glob
Expand Down
4 changes: 1 addition & 3 deletions conda-env/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ dependencies:
- beautifulsoup4
- cartopy >=0.17.0
- cartopy_offlinedata
- cdms2 3.1.5
- cdutil 8.2.1
- cf-units
- dask
- esmpy >=8.4.0
- genutil 8.2.1
- lxml
- mache >=0.15.0
- matplotlib-base
Expand Down
59 changes: 0 additions & 59 deletions conda-env/dev-nompi.yml

This file was deleted.

4 changes: 1 addition & 3 deletions conda-env/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ dependencies:
- beautifulsoup4
- cartopy >=0.17.0
- cartopy_offlinedata
- cdms2 3.1.5
- cdutil 8.2.1
- cf-units
- dask
- esmpy >=8.4.0
- genutil 8.2.1
- lxml
- mache >=0.15.0
- matplotlib-base
Expand Down
17 changes: 6 additions & 11 deletions docs/source/available-parameters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,19 @@ functionality of the diagnostics.
See `default_regions.py
<https://github.com/E3SM-Project/e3sm_diags/blob/master/e3sm_diags/derivations/default_regions.py>`__
for a list of possible regions. Ex: ``regions=["global", "TROPICS"]``.
- **regrid_method**: What regird method of the regrid tool to use.
- **regrid_method**: What grid method of the regrid tool to use.
Possible values are ``'linear'`` or ``'conservative'``. Default is ``'conservative'``.
Read the CDMS documentation for more information.
Read the xCDAT documentation on `regridding`_ for more information.
- **regrid_tool**: The regrid tool to use. Default is ``'esmf'``.
Read the xCDAT documentation on `regridding`_ for more information.
- **seasons**: A list of season to use. Default is annual and all seasons: ``['ANN', 'DJF', 'MAM', 'JJA', 'SON']``.
- **sets**: A list of the sets to be run. Default is all sets:
``['zonal_mean_xy', 'zonal_mean_2d', 'meridional_mean_2d', 'lat_lon', 'polar', 'area_mean_time_series', 'cosp_histogram', 'enso_diags', 'qbo', 'streamflow','diurnal_cycle']``.
- **variables**: What variable(s) to use for this run. Ex: ``variables=["T", "PRECT"]``.

.. _regridding: https://xcdat.readthedocs.io/en/latest/getting-started-guide/faqs.html#regridding


Parameters for plotting
~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -267,12 +271,3 @@ Other parameters
- **selectors**: Default is ``['sets', 'seasons']``. See :ref:`Using the selectors parameter <selector-ex>`.
- **viewer_descr**: Used to specify values in the viewer. Default ``{}``.
- **fail_on_incomplete**: Exit status will reflect failure if any parameter fails to complete. Default is ``False`` (e.g., a failing parameter will not create a failing exit code).

Deprecated parameters
~~~~~~~~~~~~~~~~~~~~~
- **canvas_size_h**: Height of the image in pixels and only used by
vcs. Is ``1628`` by default.
- **canvas_size_w**: Width of the image in pixels and only used by
vcs. Is ``1212`` by default.
- **logo**: ``True`` (default value) to show the UV-CDAT logo on
the vcs backend, ``False`` to not. Just keep it on please.
Loading

0 comments on commit 3406bf2

Please sign in to comment.