bin.MarsFormat
The MarsFormat executable is for converting non-MGCM data, such as that from EMARS, OpenMARS, PCM, and MarsWRF, into MGCM-like netCDF data products. The MGCM is the NASA Ames Mars Global Climate Model developed and maintained by the Mars Climate Modeling Center (MCMC). The MGCM data repository is available at data.nas.nasa.gov/mcmc.
The executable requires two arguments:
[input_file]The file to be transformed
[-gcm --gcm_name]The GCM from which the file originates
and optionally accepts:
[-rn --retain_names]Preserve original variable and dimension names
[-ba, --bin_average]Bin non-MGCM files like ‘average’ files
[-bd, --bin_diurn]Bin non-MGCM files like ‘diurn’ files
Third-party requirements:
numpy
netCDF4
sys
argparse
os
re
functools
traceback
xarray
amescap
Module Contents
Functions
|
A decorator that wraps a function with error handling |
|
Find the time dimension name in the dataset. |
|
Main processing function for MarsFormat. |
Attributes
- 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.
- get_time_dimension_name(DS, model)
Find the time dimension name in the dataset.
Updates the model object with the correct dimension name.
- Parameters:
DS (xarray.Dataset) – The xarray Dataset
model (object) – Model object with dimension information
- Returns:
The actual time dimension name found
- Return type:
str
- Raises:
KeyError – If no time dimension is found
ValueError – If the model object is not defined
TypeError – If the dataset is not an xarray Dataset
AttributeError – If the model object does not have the specified attribute
ImportError – If the xarray module cannot be imported
- main()
Main processing function for MarsFormat.
This function processes NetCDF files from various Mars General Circulation Models (GCMs) including MarsWRF, OpenMars, PCM, and EMARS, and reformats them for use in the AmesCAP framework.
- It performs the following operations:
Validates the selected GCM type and input files.
Loads NetCDF files and reads model-specific variable and
dimension mappings. - Applies model-specific post-processing, including:
Unstaggering variables (for MarsWRF and EMARS).
Creating and orienting pressure coordinates (pfull, phalf,
ak, bk). - Standardizing variable and dimension names. - Converting longitude ranges to 0-360 degrees east. - Adding scalar axes where required. - Handling vertical dimension orientation, especially for PCM files.
- Optionally performs time binning:
Daily, average (over N sols), or diurnal binning.
Ensures correct time units and bin sizes.
Preserves or corrects vertical orientation after binning.
Writes processed datasets to new NetCDF files with appropriate
naming conventions.
- Args:
None. Uses global args for configuration and file selection.
- Raises:
KeyError: If required dimensions or variables are missing in the input files. ValueError: If dimension swapping fails for PCM files. SystemExit: If no valid GCM type is specified.
- Outputs:
Writes processed NetCDF files to disk, with suffixes indicating the type of processing (e.g., _daily, _average, _diurn, _nat).
- Note:
This function assumes the presence of several helper functions and global variables, such as read_variable_dict_amescap_profile, get_time_dimension_name, reset_FV3_names, and color constants for printing.
- args
- debug
- exit_code
- parser
- path2data
- ref_press = 725