Source code for epygram.args_catalog

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from epygram import config

[docs]def add_arg_to_parser(parser, arg): """ Wrapper to add one item of the following dictionaries to a parser. """ parser.add_argument(*arg[:-1], **arg[-1])
_defaults = {} _defaults.update(config.__dict__) """ Each argument is a list composed as follows: ['name', 'alternate_name1', 'alternate_name2', ..., dict(kw1, kw2, kw3, ...)] where the keywords 'kwi' are argparse.ArgumentParser.add_argument() optional arguments. """ #: Arguments dealing with files files_management = { 'principal_file':[ 'filename', dict(type=str, help='name of the file to be processed.')], 'file_to_refer_in_diff':[ '-d', '--diff', dict(type=str, dest='refname', help='name of the 2nd (reference) file to be processed, to which comparison is done.', required=False)], 'file_to_refer_in_diffonly':[ '-D', '--diffonly', dict(type=str, dest='Drefname', help='same as -d/--diff, but only fields difference is plot.', required=False)], 'source_file':[ '-s', '--source', dict(type=str, dest='refname', help='name of the 2nd file from which to extract the fields.', required=True)], 'replace_by_diff':[ '-d', '--diff', dict(action='store_const', const='diff', dest='replace_op', help='replaces the fields by the difference fields (filename - source).', required=False, default=False)], 'replace_by_reversediff':[ '-r', '--reversediff', dict(action='store_const', const='reversediff', dest='replace_op', help='replaces the fields by the reverse difference fields (source - filename).', required=False, default=False)], 'replace_by_addition':[ '-a', '--add', dict(action='store_const', const='add', dest='replace_op', help='replaces the fields by the addition fields (filename + source).', required=False, default=False)], } #: Arguments dealing with fields fields_management = { 'FA_field':[ '-f', '-F', '--field', dict(help="name of the field to be processed.\ To obtain the list of fields in file, use the 'fa_what' tool.", required=False, default=None)], 'FA_windfield':[ '-w', '--computewind', dict(help="to process wind module, using the following syntax:\ 'S*WIND' or 'P*VENT', 'H*VENT', 'V*VENT', 'CLSVENT.*', 'CLS*.RAF',\ * designing the level: combination of (*, ?, digits).\ Not implemented in difference mode.", required=False, default=None)], 'FA_multiple_fields':[ '-f', '-F', '--field', dict(help="name of the field to be processed.\ Regular expressions can be used, such as\ 'S00[2-6]WIND.[U-V].PHYS' to process meridian and zonal winds of levels 2 to 6,\ 'SURFALBEDO*' to process all kinds of albedo,\ 'SURF?.OF.OZONE' to process all kinds of ozone (A,B,C).\ In case this option is not used, no more than '-l' option,\ all fields present in file are processed.\ Fields not found in file are ignored.\ To obtain the list of fields in file, use the 'fa_what' tool.", required=False, default=None)], 'FA_vertical_field':[ '-F', '-f', '--field', dict(help="name of the upper-air field to be processed, with a * for level.\ To obtain the list of fields in file, use the 'fa_what' tool.", required=True, default=None)], 'DDHLFA_multiple_fields':[ '-f', '-F', '--field', dict(help="name of the field to be processed.\ Regular expressions can be used, such as\ 'F*FLUVERTDYN' or 'VKK[0-1]'.\ In case this option is not used, no more than '-l' option,\ all fields present in file are processed.\ Fields not found in file are ignored.\ To obtain the list of fields in file, use the 'ddhlfa_what' tool.", required=False, default=None)], 'DDHLFA_domain':[ '-n', '--domain_number', dict(help="number of the domain to plot. \ Multiple domains must be given within quotes, separated by comma. \ To obtain the list of domains in file, \ use the 'ddhlfa_what' tool.", required=True)], 'GRIB_field':[ '-F', '-f', '--field', dict(help="(possibly partial) handgrip of the field to be processed.\ To obtain the list of fields in file (and their handgrip), \ use EPyGrAM's 'grib_what' tool or GRIB_API's 'grib_dump'.\ If several fields match the handgrip, \ only the first one is processed. Ex: -f 'shortName:t,level:850'.", required=False, default=None)], 'list_of_fields':[ '-l', '--listoffields', dict(help="name of an external file containing the list of fields\ to be processed, with the same specifications as for -f argument.", required=False, default=None)], 'reverse_fields_selection':[ '-r', '--reverse', dict(action='store_true', help="reverse fields selection: all but those requested.", required=False, default=False)], 'sort_fields':[ '-s', '--sortfields', dict(action='store_true', help="sort fields with regards to their name and nature.", required=False, default=False)], 'GRIB_sort':[ '-s', '--sortby', dict(help="sort fields with regards to the given fid key.\ Only for *mode* == 'one+list' or 'fid_list'.", required=False, default=None)], 'GRIB_what_mode':[ '-m', '--mode', dict(help="information display mode: 'one+list' gives the \ validity/geometry of the first field in GRIB, plus \ the list of fid; 'fid_list' gives only the fid of \ each field in GRIB; 'what' gives the values of the \ keys from each GRIB message that are used to generate \ an **epygram** field from the message (slower); \ 'ls' gives the values of the 'ls' keys from each GRIB \ message; 'mars' gives the values of the 'mars' keys \ from each GRIB message.", required=False, choices=('one+list', 'fid_list', 'what', 'ls', 'mars'), default='one+list')], 'FA_set_compression':[ '-k', '--kompression', dict(help="bits number for FA gridpoint compression : KNBITS/KNBPDG.\ Defaults to "+str(_defaults['FA_default_compression']['KNBPDG'] if 'FA_default_compression' in _defaults.keys() else "(unknown)")+".", required=False, type=int, default=None)], 'netCDF_compress':[ '-c', '--compress', dict(action='store_true', help="compress fields in netCDF. Default is no compression.", required=False, default=False)], 'netCDF_set_compression_level':[ '-C', '--compressionlevel', dict(type=int, help="compression level to compress fields in netCDF. \ Ranges from 1 to 9. 1 is low-but-fast compression, 9 is high-but-slow compression. \ Default is 4.", required=False, choices=range(1, 10), default=4)], } #: Arguments dealing with output output_options = { 'output':[ '-o', '--output', dict(help="store output in file in with specified format, among ('png', pdf). \ Pdf is kind of disadvised, for it is very slow and produces much too big files...", choices=['png', 'pdf'], required=False, default=_defaults['default_graphical_output'] if 'default_graphical_output' in _defaults.keys() else False)], 'one_pdf':[ '-p', '--pdf', dict(action='store_true', help="store output (eventually multiple plots) in one .pdf file.", required=False, default=False)], 'noplot':[ '-n', '--noplot', dict(action='store_true', help="disable plot. Profile/spectrum will be computed\ and written as text output but not plotted.", required=False, default=False)], 'GeoPoints_llv':[ '--llv', dict(action='store_true', help="simplify GeoPoints format to LAT, LON, VALUE only.", required=False, default=False)], 'GeoPoints_precision':[ '-e', '--precision', dict(help="precision on values (number of decimals in scientific format).\ Default = "+str(_defaults['GeoPoints_precision'] if 'GeoPoints_precision' in _defaults.keys() else 4), required=False, default=_defaults['GeoPoints_precision'] if 'GeoPoints_precision' in _defaults.keys() else 4)], 'GeoPoints_lonlat_precision':[ '-E', '--lonlat_precision', dict(help="precision on longitudes/latitudes (number of decimals).\ Default = "+str(_defaults['GeoPoints_lonlat_precision'] if 'GeoPoints_lonlat_precision' in _defaults.keys() else 4), required=False, default=_defaults['GeoPoints_precision'] if 'GeoPoints_precision' in _defaults.keys() else 4)], 'FA_get_field_compression':[ '-c', '--compression', dict(action='store_true', help="get compression options of each field.", required=False, default=False)], } #: Miscellaneous arguments misc_options = { 'LAMzone':[ '-z', '--zone', dict(help="zone of the domain, in LAM case:\ 'C' for zone C, 'CI' for zone C+I, 'CIE' for zone C+I+E.\ Default is 'CI'.", required=False, choices=['C', 'CI', 'CIE'], default='CI')], 'array_flattening_order':[ '-o', '--order', dict(help="for LAM arrays, whether to flatten in C (row-major) or\ Fortran (column-major) order 2D arrays. Default = 'C'.", required=False, default='C')], 'operation_on_field':[ '-x', '--operation', dict(help="do the requested operation on field right after reading it. \ Syntax: '-,273.15' (e.g. for K => C). \ The operand must be among (+,-,*,/).\ For '-' operand, use short-name option -x without spacetab between option and argument.", required=False, default=None)], 'FA_log-pressure_conversion':[ '-u', '--pressure_unit_hpa', dict(action='store_true', help="converts pressure (SURFPRESSION / MSLPRESSURE) to hPa unit.", required=False, default=False)] } #: Arguments dealing with graphical options graphical_options = { 'legend':[ '-L', '--legend', dict(help="legend to be written over field plot.", required=False, default=None)], 'scientifical_unit':[ '-u', '--unit', dict(help="optional unit for labeling plot axis. Defaults to 'SI'.", required=False, default='SI')], 'vertical_logscale':[ '-s', '--logscale', dict(action='store_true', help="plots with vertical logscale.", required=False, default=False)], 'specific_map_projection':[ '-j', '--projection', dict(help="specific graphical projection of plots, among ('kav7', 'ortho', 'cyl', 'moll', 'nsperXXXX').\ Default depend on the actual projection of fields,\ or 'moll' (Mollweide projection) for Gauss geometry.\ The XXXX of 'nsperXXXX' defines the satellite height in km.\ Overwritten by 'zoom' option.", required=False, default=None)], 'graphicmode':[ '-g', '--graphicmode', dict(help="graphical mode for plots, among ('colorshades', 'contourlines', 'points').\ Default is 'colorshades'.\ There is a known bug (yet unsolved) with Arpege & contourlines.", required=False, choices=['colorshades', 'contourlines', 'points'], default='colorshades')], 'minmax':[ '-m', '--minmax', dict(help="min and max values for the plot colorbar.\ Syntax: 'min, max'. '0.0, max' also works.\ Default is the field min/max values.\ In diff mode, this is valuable for resource and reference only,\ (min, max) for difference plot should be defined with --diffminmax option.\ For negative values, use short-name option -m without spacetab between option and argument.", required=False, default=None)], 'diffminmax':[ '-M', '--diffminmax', dict(help="min and max values for the difference plot colorbar.\ Syntax: 'min, max'. '0.0, max' also works.\ Default is the difference field min/max values.\ For negative values, use short-name option -M without spacetab between option and argument.", required=False, default=None)], 'levels_number':[ '-n', '--levelsnumber', dict(help="number of levels for contours and shades.\ Default is 50.", required=False, type=int, default=50)], 'diff_levels_number':[ '-N', '--difflevelsnumber', dict(help="number of levels for difference contours and shades.\ Default is 50.", required=False, type=int, default=50)], 'colormap':[ '-c', '--colormap', dict(help="name of the **matplotlib** colormap to use.\ Default is 'jet'\ (Cf. http://matplotlib.org/examples/color/colormaps_reference.html).\ Custom colormaps can be defined (http://colormap.org or manually) and added in userconfig,\ in usercolormaps = {'my_cmap':'path_to_my_cmap'}.", required=False, default='jet')], 'diffcolormap':[ '-C', '--diffcolormap', dict(help="name of the **matplotlib** colormap to use for diff.\ Default is 'seismic'\ (Cf. http://matplotlib.org/examples/color/colormaps_reference.html).\ Custom colormaps can be defined (http://colormap.org or manually) and added in userconfig,\ in usercolormaps = {'my_cmap':'path_to_my_cmap'}.", required=False, default='seismic')], 'center_cmap_on_0':[ '-t', '--center_cmap_on_0', dict(action='store_true', help="to center the colormap on the value 0. Can be useful\ for wind plots for instance.", required=False, default=False)], 'diff_center_cmap_on_0':[ '-T', '--diffcenter_cmap_on_0', dict(action='store_false', help="NOT to center the colormap of diff plots on the value 0.\ May be useful for fluxes decumulation.", required=False, default=True)], 'gis_quality':[ '-q', '--gisquality', dict(help="quality of the GIS used to draw coastlines, rivers and countries;\ among ('c', 'l', 'i', 'h', 'f'), by increasing quality.", required=False, choices=['c', 'l', 'i', 'h', 'f'], default='i')], 'draw_rivers':[ '-r', '--drawrivers', dict(action='store_true', help="draw rivers on map. (Much more slow)", required=False, default=False)], 'french_departments':[ '--depts', dict(action='store_true', help="draw french departments on map (instead of countries boundaries).", required=False, default=False)], 'lonlat_grid_step':[ '--llgridstep', dict(help="specific step between two lon/lat gridlines, in degrees.\ Default depends on domain size.", required=False, type=float, default=None)], 'vectors_subsampling':[ '-s', '--vectors_subsampling', dict(help="Subsampling factor for plotting vectors barbs\ (-w: computewind option). Defaults to 20.", required=False, type=int, default=20)], 'points_size':[ '-p', '--pointsize', dict(help="size of points for *graphicmode* == 'points'.\ Defaults to 20.", required=False, type=int, default=20)], 'lonlat_zoom':[ '--zoom', dict(help="optional zoom on the specified region of the plot. Forces to 'cyl' projection.\ Syntax: 'lonmin=-5, lonmax=1.2, latmin=40.8, latmax=51'.\ Overwrites 'projection' option.", required=False, default=None)], 'vertical_zoom':[ '--zoom', dict(help="optional zoom (vertical reduction) on the profile plot. \ Ex: 'ymax=150, ymin=850'. The unit must be that of the \ vertical coordinate requested (hPa, m, level number).", required=False, default=None)], 'spectra_zoom':[ '--zoom', dict(help="optional zoom on the spectra plot. Ex: 'xmax=10, ymin=1.0'.", required=False, default=None)], 'emagram_like_profiles':[ '-e', '--emagramlike', dict(action='store_true', help="plots profiles in a emagram-like style (only with -P/--hybrid2pressure).\ Should not be used for other than Temperature profiles.", required=False, default=False)], 'superpose_spectra_plots':[ '-s', '--superposeplots', dict(action='store_true', help='for superposing spectra of all requested fields in one plot.', required=False, default=False)], 'spectra_slopes':[ '-k', '--kindofslopes', dict(help="optional kind of slopes to be plotted, with syntax:\ sequence of (exp offset label) between simple quotes ('), with\ slope = offset * k**exp.\ offset is optional, with default = 1.0.\ Label is optional and denotes how do the exp appears in legend.\ (by default, exp=0.5 will appear 1/2 => add a label 0.5 for it to appear unchanged.)\ If label is provided, offest must be provided as well.\ Ex: 'exp1, exp2 offset2 label2, exp3 offset3'.\ or '-3 1.0, -5./3. 1e-2 -5/3' (default).", required=False, default='-3 1.0 -3, -5./3. 1e-2 -5/3')], } #: Arguments dealing with extraction stuff extraction_options = { 'point_coordinates':[ '-c', '--coordinates', dict(help="lon/lat coordinates of the point.\ Syntax: 'lon, lat'.", required=True, default=None)], 'section_starting_point':[ '-s', '--starting_point', dict(help="lon/lat coordinate of starting point of the section.\ Syntax: 'lon, lat'.", required=True, default=None)], 'section_ending_point':[ '-e', '--ending_point', dict(help="lon/lat coordinate of ending point of the section.\ Syntax: 'lon, lat'.", required=True, default=None)], 'horizontal_interpolation':[ '-i', '--interpolation', dict(help="interpolation mode from field grid to point/section coordinates. \ Among ('nearest', 'linear', 'cubic'). Defaults to 'nearest'.", required=False, choices=['nearest', 'linear', 'cubic'], default='nearest')], 'section_transect_points_number':[ '-p', '--points_number', dict(help="number of points from starting point to ending point (included). \ Defaults to the number of points computed from the fields resolution, \ or from the resolution given via option -r.", required=False, type=int, default=None)], 'section_transect_resolution':[ '-r', '--resolution', dict(help="resolution of the section. Defaults to the fields resolution, \ or computed from the number of points given via option -N.", required=False, type=float, default=None)], 'vertical_conversion_hybrid2pressure':[ '-P', '--hybrid2pressure', dict(action='store_const', dest='Yconvert', const='hybrid2pressure', help="for model fields on HYBRID-PRESSURE LEVELS,\ compute pressure as vertical coordinate.", required=False, default=None)], 'vertical_conversion_hybrid2height':[ '-H', '--hybrid2height', dict(action='store_const', dest='Yconvert', const='hybrid2height', help="for model fields on HYBRID-PRESSURE LEVELS,\ compute height above ground as vertical coordinate.", required=False, default=None)], 'vertical_conversion_hybrid2altitude':[ '-A', '--hybrid2altitude', dict(action='store_const', dest='Yconvert', const='hybrid2altitude', help="for model fields on HYBRID-PRESSURE LEVELS,\ compute altitude as vertical coordinate.", required=False, default=None)], 'cheap_height_conversion':[ '--cheap_height', dict(action='store_true', help="for the computation of heights (-A/-H) to be done \ without taking hydrometeors into account (in R \ computation) nor NH Pressure departure \ (Non-Hydrostatic data). Faster but less true.", required=False, default=False)] } #: Arguments dealing with runtime options runtime_options = { 'verbose':[ '-v', '--verbose', dict(action='store_true', help="run verbosely. Else, only messages of level Error will be displayed.", required=False, default=False)], 'percentage':[ '-p', '--percentage', dict(action='store_true', help="display the percentage done on the run.", required=False, default=False)], } #: Arguments for domain_maker domain_maker_options = { 'mode':[ '-l', dict(dest='mode', action='store_const', help="mode: define domain by specifying a lon/lat domain that must be included inside.", const='lonlat_included', default='center_dims', required=False)], 'no_display':[ '-n', '--no_display', dict(action='store_true', help="run without displaying the domain.", required=False, default=_defaults['noninteractive_backend'] if 'noninteractive_backend' in _defaults.keys() else False)], 'maximize_CI_in_E':[ '-m', '--maximize_CI_in_E', dict(action='store_true', help="forces the C+I zone to be the greatest possible inside a given (discrete) C+I+E size. \ In other words, with a given (discrete) C+I+E size, forces the E-zone to be the smallest possible.", required=False, default=False)], }