Skip to content

Commit e31e578

Browse files
committed
Merge remote-tracking branch 'origin/devel' into devel
2 parents ffd9094 + 75a8264 commit e31e578

File tree

3 files changed

+80
-7
lines changed

3 files changed

+80
-7
lines changed

bin/MarsInterp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ def wrapper(*args, **kwargs):
141141
f"(zstd), or altitude above ground level (zagl).\nWorks on "
142142
f"'daily', 'average', and 'diurn' files.\n"
143143
f"{Green}Example:\n"
144-
f"> MarsInterp 01336.atmos_average.nc\n"
145144
f"> MarsInterp 01336.atmos_average.nc -t pstd\n"
145+
f"> MarsInterp 01336.atmos_average.nc -t pstd -v pstd_default\n"
146146
f"{Nclr}\n\n"
147147
)
148148
)
@@ -300,7 +300,7 @@ def main():
300300
# Load all of the netcdf files
301301
file_list = file_list = [f.name for f in args.input_file]
302302
interp_type = args.interp_type # e.g. pstd
303-
custom_level = args.vertical_grid # e.g. p44
303+
custom_level = args.vertical_grid # e.g. pstd_default
304304
grid_out = args.print_grid
305305

306306
# Create a namespace with numpy available
@@ -322,7 +322,7 @@ def main():
322322
if custom_level:
323323
lev_in = eval(f"np.array({custom_level})", namespace)
324324
else:
325-
lev_in = np.array(namespace['pstd_default'])
325+
lev_in = eval("np.array(pstd_default)", namespace)
326326

327327
# =========================== zstd ===========================
328328
elif interp_type == "zstd":

bin/MarsVars.py

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,18 @@ def wrapper(*args, **kwargs):
254254
['Vg_sed', 'w'],
255255
['pfull', 'pstd', 'zstd', 'zagl']
256256
],
257+
'dustref_per_pa': [
258+
"Dust opacity per Pascal [dustref/delp]",
259+
'op/Pa',
260+
['dustref', 'delp'],
261+
['pfull']
262+
],
263+
'dustref_per_km': [
264+
"Dust opacity per kilometer [dustref/delz]",
265+
'op/km',
266+
['dustref', 'delz'],
267+
['pfull']
268+
],
257269
'wdir': [
258270
"Wind direction",
259271
'degree',
@@ -1173,6 +1185,59 @@ def compute_w_net(Vg, wvar):
11731185
return w_net
11741186

11751187

1188+
1189+
# =====================================================================
1190+
def compute_dustref_per_pa(dustref, delp):
1191+
"""
1192+
Computes visible dust opacity per Pascal from dustref and delp.
1193+
dustref is visible dust opacity per level (model layer).
1194+
1195+
opacity per Pa = opacity per layer / layer thickness in Pa::
1196+
1197+
dustref_per_pa = dustref/delp
1198+
1199+
[Courtney Batterson, 2025]
1200+
1201+
:param dustref: Visible dust opacity [op/model layer]
1202+
:type dustref: array [time, lev, lat, lon]
1203+
:param delp: Layer thickness [Pa]
1204+
:type delp: array [time, lev, lat, lon]
1205+
:return: `dustref_per_pa` Visible dust opacity [op/Pa]
1206+
:rtype: array [time, lev, lat, lon]
1207+
:raises ValueError: If the input dimensions are not compatible
1208+
:raises TypeError: If the input types are not compatible
1209+
:raises Exception: If any other error occurs
1210+
"""
1211+
1212+
dustref_per_pa = dustref/delp
1213+
return dustref_per_pa
1214+
1215+
# =====================================================================
1216+
def compute_dustref_per_z(dustref, delz):
1217+
"""
1218+
Computes visible dust opacity per kilometer from dustref and delz.
1219+
dustref is visible dust opacity per level (model layer).
1220+
1221+
opacity per km = opacity per layer / layer thickness in m * 1000::
1222+
1223+
dustref_per_z = dustref/delz*1000
1224+
1225+
[Courtney Batterson, 2025]
1226+
1227+
:param dustref: Visible dust opacity [op/model layer]
1228+
:type dustref: array [time, lev, lat, lon]
1229+
:param delz: Layer thickness [m]
1230+
:type delz: array [time, lev, lat, lon]
1231+
:return: `dustref_per_z` Visible dust opacity [op/km]
1232+
:rtype: array [time, lev, lat, lon]
1233+
:raises ValueError: If the input dimensions are not compatible
1234+
:raises TypeError: If the input types are not compatible
1235+
:raises Exception: If any other error occurs
1236+
"""
1237+
1238+
dustref_per_z = dustref/delz*1000
1239+
return dustref_per_z
1240+
11761241
# =====================================================================
11771242
def compute_theta(p_3D, ps, T, f_type):
11781243
"""
@@ -1906,9 +1971,9 @@ def process_add_variables(file_name, add_list, master_list, debug=False):
19061971
f"file:{Nclr}")
19071972
for var, actual_var in already_in_file:
19081973
if var == actual_var:
1909-
print(f"{Yellow} - {var}{Nclr}")
1974+
print(f"{Yellow} - {var}{Nclr}")
19101975
else:
1911-
print(f"{Yellow} - {var} (as '{actual_var}'){Nclr}")
1976+
print(f"{Yellow} - {var} (as '{actual_var}'){Nclr}")
19121977
return
19131978

19141979

@@ -2101,6 +2166,16 @@ def add_with_dependencies(var):
21012166
wvar = f.variables["w"][:]
21022167
OUT = compute_w_net(Vg, wvar)
21032168

2169+
if var == "dustref_per_pa":
2170+
dustref = f.variables["dustref"][:]
2171+
delp = f.variables["delp"][:]
2172+
OUT = compute_dustref_per_pa(dustref, delp)
2173+
2174+
if var == "dustref_per_z":
2175+
dustref = f.variables["dustref"][:]
2176+
delz = f.variables["delz"][:]
2177+
OUT = compute_dustref_per_z(dustref, delz)
2178+
21042179
if var == "pfull3D":
21052180
OUT = p_3D
21062181

docs/source/description.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,6 @@ Open ``~/.amesgcm_profile`` with any text editor to see customizable grid defini
300300
1.0e-02, 5.0e-03, 3.0e-03, 5.0e-04, 3.0e-04, 1.0e-04, 5.0e-05,
301301
3.0e-05, 1.0e-05]
302302
303-
phalf_mb=[50]
304-
305303
Use your custom grid with the ``[-v --vertical_grid]`` argument:
306304
307305
.. code-block:: bash

0 commit comments

Comments
 (0)