bin.MarsInterp

The MarsInterp executable is for interpolating files to pressure or altitude coordinates. Options include interpolation to standard pressure (pstd), standard altitude (zstd), altitude above ground level (zagl), or a custom vertical grid.

The executable requires:

  • [input_file] The file to be transformed

and optionally accepts:

  • [-t --interp_type] Type of interpolation to perform (altitude, pressure, etc.)

  • [-v --vertical_grid] Specific vertical grid to interpolate to

  • [-incl --include] Variables to include in the new interpolated file

  • [-ext --extension] Custom extension for the new file

  • [-print --print_grid] Print the vertical grid to the screen

Third-party Requirements:

  • numpy

  • netCDF4

  • argparse

  • os

  • time

  • matplotlib

  • re

  • functools

  • traceback

  • sys

  • amescap

Module Contents

Functions

debug_wrapper(func)

A decorator that wraps a function with error handling

main()

Main function for performing vertical interpolation on Mars

Attributes

Cp

M_co2

R

args

debug

exit_code

filepath

fill_value

g

parser

rgas

debug_wrapper(func)

A decorator that wraps a function with error handling based on the –debug flag. If the –debug flag is set, it prints the full traceback of any exception that occurs. Otherwise, it prints a simplified error message.

Parameters:

func (function) – The function to wrap.

Returns:

The wrapped function.

Return type:

function

Raises:
  • Exception – If an error occurs during the function call.

  • TypeError – If the function is not callable.

  • ValueError – If the function is not found.

  • NameError – If the function is not defined.

  • AttributeError – If the function does not have the specified attribute.

  • ImportError – If the function cannot be imported.

  • RuntimeError – If the function cannot be run.

  • KeyError – If the function does not have the specified key.

  • IndexError – If the function does not have the specified index.

  • IOError – If the function cannot be opened.

  • OSError – If the function cannot be accessed.

  • EOFError – If the function cannot be read.

  • MemoryError – If the function cannot be allocated.

  • OverflowError – If the function cannot be overflowed.

  • ZeroDivisionError – If the function cannot be divided by zero.

  • StopIteration – If the function cannot be stopped.

  • KeyboardInterrupt – If the function cannot be interrupted.

  • SystemExit – If the function cannot be exited.

  • AssertionError – If the function cannot be asserted.

main()

Main function for performing vertical interpolation on Mars atmospheric model NetCDF files.

This function processes one or more input NetCDF files, interpolating variables from their native vertical coordinate (e.g., model pressure levels) to a user-specified standard vertical grid (pressure, altitude, or altitude above ground level). The interpolation type and grid can be customized via command-line arguments.

Workflow:

1. Parses command-line arguments for input files, interpolation type, custom vertical grid, and other options. 2. Loads standard vertical grid definitions (pressure, altitude, or altitude above ground level) or uses a custom grid. 3. Optionally prints the vertical grid and exits if requested. 4. For each input file:

  • Checks file existence.

  • Loads necessary variables (e.g., pk, bk, ps, temperature).

  • Computes the 3D vertical coordinate field for interpolation.

  • Creates a new NetCDF output file with updated vertical dimension.

  • Interpolates selected variables to the new vertical grid.

  • Copies or interpolates other variables as appropriate.

5. Handles both regular and diurnal-cycle files, as well as FV3-tiled and lat/lon grids.

Command-line arguments (via args):
  • input_file: List of input NetCDF files to process.

  • interp_type: Type of vertical interpolation (‘pstd’, ‘zstd’, or ‘zagl’).

  • vertical_grid: Custom vertical grid definition (optional).

  • print_grid: If True, prints the vertical grid and exits.

  • extension: Optional string to append to output filenames.

  • include: List of variable names to include in interpolation.

  • debug: Enable debug output.

Notes:
  • Requires several helper functions and classes (e.g., section_content_amescap_profile, find_fixedfile, Dataset, Ncdf, vinterp).

  • Handles both FV3-tiled and regular lat/lon NetCDF files.

  • Exits with an error message if required files or variables are missing.

Cp = 735.0
M_co2 = 0.044
R = 8.314
args
debug
exit_code
filepath
fill_value = 0.0
g = 3.72
parser
rgas = 189.0