# http://pyrocko.org - GPLv3 # # The Pyrocko Developers, 21st Century # ---|P------/S----------~Lg----------
# This file is part of GmtPy (http://emolch.github.io/gmtpy/) # See there for copying and licensing information.
'isolatin1+': 'iso-8859-1', 'standard+': 'ascii', 'isolatin1': 'iso-8859-1', 'standard': 'ascii'}
except GMTInstallationProblem: return False
raise ExternalProgramMissing('GMT is not installed or cannot be found')
prog, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except OSError: return False
width=None, height=None, size=None):
fmt_arg = '-svg' tmp_filename = tmp_filename_base oversample = 1.0 else:
scale_args = ['-scale-to', '%i' % int(round(size*oversample))] scale_args = ['-scale-to-x', '%i' % int(round(width*oversample))] scale_args = ['-scale-to-y', '%i' % int(round(height*oversample))] else:
['pdftocairo'] + scale_args + [fmt_arg, in_filename, tmp_filename_base]) except OSError as e: raise GmtPyError( 'Cannot start `pdftocairo`, is it installed? (%s)' % str(e))
'convert', tmp_filename, '-resize', '%i%%' % int(round(100.0/oversample)), out_filename]) except OSError as e: raise GmtPyError( 'Cannot start `convert`, is it installed? (%s)' % str(e))
else: else: try: subprocess.check_call( ['convert', tmp_filename, out_filename]) except Exception as e: raise GmtPyError( 'Cannot start `convert`, is it installed? (%s)' % str(e))
except Exception: raise
finally:
raise GmtPyError('Cannot find bbox')
'%.3f' % float(x) for x in bbox)).encode('ascii') else: int(math.floor(bbox[0])), int(math.floor(bbox[1])), int(math.ceil(bbox[2])), int(math.ceil(bbox[3])))).encode('ascii')
s = args[0] return pat.sub(repl, s)
else:
'''This function should be used for debugging output only - it could be insecure.'''
if re.search(r'[^a-zA-Z0-9._/=-]', s): return "'" + s.replace("'", "'\\''") + "'" else: return s
'''This function should be used for debugging output only - it could be insecure.'''
return ' '.join([escape_shell_arg(x) for x in args])
# units in points 'i': 72., 'c': 72./2.54, 'm': 72.*100./2.54, 'p': 1.}
# some awsome colors 'butter1': (252, 233, 79), 'butter2': (237, 212, 0), 'butter3': (196, 160, 0), 'chameleon1': (138, 226, 52), 'chameleon2': (115, 210, 22), 'chameleon3': (78, 154, 6), 'orange1': (252, 175, 62), 'orange2': (245, 121, 0), 'orange3': (206, 92, 0), 'skyblue1': (114, 159, 207), 'skyblue2': (52, 101, 164), 'skyblue3': (32, 74, 135), 'plum1': (173, 127, 168), 'plum2': (117, 80, 123), 'plum3': (92, 53, 102), 'chocolate1': (233, 185, 110), 'chocolate2': (193, 125, 17), 'chocolate3': (143, 89, 2), 'scarletred1': (239, 41, 41), 'scarletred2': (204, 0, 0), 'scarletred3': (164, 0, 0), 'aluminium1': (238, 238, 236), 'aluminium2': (211, 215, 207), 'aluminium3': (186, 189, 182), 'aluminium4': (136, 138, 133), 'aluminium5': (85, 87, 83), 'aluminium6': (46, 52, 54) }
'scarletred2', 'skyblue3', 'chameleon3', 'orange2', 'plum2', 'chocolate2', 'butter2')]
'''Generate a string for GMT option arguments expecting a color.
If ``x`` is None, a random color is returned. If it is an integer, the corresponding ``gmtpy.graph_colors[x]`` or black returned. If it is a string and the corresponding ``gmtpy.tango_colors[x]`` exists, this is returned, or the string is passed through. If ``x`` is a tuple, it is transformed into the string form which GMT expects. '''
return '%i/%i/%i' % tuple(random.randint(0, 255) for _ in 'rgb')
if 0 <= x < len(graph_colors): return '%i/%i/%i' % graph_colors[x] else: return '0/0/0'
else: return x
return tuple([random.randint(0, 255) for _x in 'rgb'])
if 0 <= x < len(graph_colors): return graph_colors[x] else: return (0, 0, 0)
# Set fixed installation(s) to use... # (use this, if you want to use different GMT versions simultaneously.)
# _gmt_installations['4.2.1'] = {'home': '/sw/etch-ia32/gmt-4.2.1', # 'bin': '/sw/etch-ia32/gmt-4.2.1/bin'} # _gmt_installations['4.3.0'] = {'home': '/sw/etch-ia32/gmt-4.3.0', # 'bin': '/sw/etch-ia32/gmt-4.3.0/bin'} # _gmt_installations['4.3.1'] = {'home': '/sw/share/gmt', # 'bin': '/sw/bin' }
# ... or let GmtPy autodetect GMT via $PATH and $GMTHOME
# To have consistent defaults, they are hardcoded here and should not be # changed.
# # GMT-SYSTEM 4.2.1 Defaults file # #-------- Plot Media Parameters ------------- PAGE_COLOR = 255/255/255 PAGE_ORIENTATION = portrait PAPER_MEDIA = a4+ #-------- Basemap Annotation Parameters ------ ANNOT_MIN_ANGLE = 20 ANNOT_MIN_SPACING = 0 ANNOT_FONT_PRIMARY = Helvetica ANNOT_FONT_SIZE = 12p ANNOT_OFFSET_PRIMARY = 0.075i ANNOT_FONT_SECONDARY = Helvetica ANNOT_FONT_SIZE_SECONDARY = 16p ANNOT_OFFSET_SECONDARY = 0.075i DEGREE_SYMBOL = ring HEADER_FONT = Helvetica HEADER_FONT_SIZE = 36p HEADER_OFFSET = 0.1875i LABEL_FONT = Helvetica LABEL_FONT_SIZE = 14p LABEL_OFFSET = 0.1125i OBLIQUE_ANNOTATION = 1 PLOT_CLOCK_FORMAT = hh:mm:ss PLOT_DATE_FORMAT = yyyy-mm-dd PLOT_DEGREE_FORMAT = +ddd:mm:ss Y_AXIS_TYPE = hor_text #-------- Basemap Layout Parameters --------- BASEMAP_AXES = WESN BASEMAP_FRAME_RGB = 0/0/0 BASEMAP_TYPE = plain FRAME_PEN = 1.25p FRAME_WIDTH = 0.075i GRID_CROSS_SIZE_PRIMARY = 0i GRID_CROSS_SIZE_SECONDARY = 0i GRID_PEN_PRIMARY = 0.25p GRID_PEN_SECONDARY = 0.5p MAP_SCALE_HEIGHT = 0.075i TICK_LENGTH = 0.075i POLAR_CAP = 85/90 TICK_PEN = 0.5p X_AXIS_LENGTH = 9i Y_AXIS_LENGTH = 6i X_ORIGIN = 1i Y_ORIGIN = 1i UNIX_TIME = FALSE UNIX_TIME_POS = -0.75i/-0.75i #-------- Color System Parameters ----------- COLOR_BACKGROUND = 0/0/0 COLOR_FOREGROUND = 255/255/255 COLOR_NAN = 128/128/128 COLOR_IMAGE = adobe COLOR_MODEL = rgb HSV_MIN_SATURATION = 1 HSV_MAX_SATURATION = 0.1 HSV_MIN_VALUE = 0.3 HSV_MAX_VALUE = 1 #-------- PostScript Parameters ------------- CHAR_ENCODING = ISOLatin1+ DOTS_PR_INCH = 300 N_COPIES = 1 PS_COLOR = rgb PS_IMAGE_COMPRESS = none PS_IMAGE_FORMAT = ascii PS_LINE_CAP = round PS_LINE_JOIN = miter PS_MITER_LIMIT = 35 PS_VERBOSE = FALSE GLOBAL_X_SCALE = 1 GLOBAL_Y_SCALE = 1 #-------- I/O Format Parameters ------------- D_FORMAT = %lg FIELD_DELIMITER = tab GRIDFILE_SHORTHAND = FALSE GRID_FORMAT = nf INPUT_CLOCK_FORMAT = hh:mm:ss INPUT_DATE_FORMAT = yyyy-mm-dd IO_HEADER = FALSE N_HEADER_RECS = 1 OUTPUT_CLOCK_FORMAT = hh:mm:ss OUTPUT_DATE_FORMAT = yyyy-mm-dd OUTPUT_DEGREE_FORMAT = +D XY_TOGGLE = FALSE #-------- Projection Parameters ------------- ELLIPSOID = WGS-84 MAP_SCALE_FACTOR = default MEASURE_UNIT = inch #-------- Calendar/Time Parameters ---------- TIME_FORMAT_PRIMARY = full TIME_FORMAT_SECONDARY = full TIME_EPOCH = 2000-01-01T00:00:00 TIME_IS_INTERVAL = OFF TIME_INTERVAL_FRACTION = 0.5 TIME_LANGUAGE = us TIME_SYSTEM = other TIME_UNIT = d TIME_WEEK_START = Sunday Y2K_OFFSET_YEAR = 1950 #-------- Miscellaneous Parameters ---------- HISTORY = TRUE INTERPOLANT = akima LINE_STEP = 0.01i VECTOR_SHAPE = 0 VERBOSE = FALSE'''
# # GMT-SYSTEM 4.3.0 Defaults file # #-------- Plot Media Parameters ------------- PAGE_COLOR = 255/255/255 PAGE_ORIENTATION = portrait PAPER_MEDIA = a4+ #-------- Basemap Annotation Parameters ------ ANNOT_MIN_ANGLE = 20 ANNOT_MIN_SPACING = 0 ANNOT_FONT_PRIMARY = Helvetica ANNOT_FONT_SIZE_PRIMARY = 12p ANNOT_OFFSET_PRIMARY = 0.075i ANNOT_FONT_SECONDARY = Helvetica ANNOT_FONT_SIZE_SECONDARY = 16p ANNOT_OFFSET_SECONDARY = 0.075i DEGREE_SYMBOL = ring HEADER_FONT = Helvetica HEADER_FONT_SIZE = 36p HEADER_OFFSET = 0.1875i LABEL_FONT = Helvetica LABEL_FONT_SIZE = 14p LABEL_OFFSET = 0.1125i OBLIQUE_ANNOTATION = 1 PLOT_CLOCK_FORMAT = hh:mm:ss PLOT_DATE_FORMAT = yyyy-mm-dd PLOT_DEGREE_FORMAT = +ddd:mm:ss Y_AXIS_TYPE = hor_text #-------- Basemap Layout Parameters --------- BASEMAP_AXES = WESN BASEMAP_FRAME_RGB = 0/0/0 BASEMAP_TYPE = plain FRAME_PEN = 1.25p FRAME_WIDTH = 0.075i GRID_CROSS_SIZE_PRIMARY = 0i GRID_PEN_PRIMARY = 0.25p GRID_CROSS_SIZE_SECONDARY = 0i GRID_PEN_SECONDARY = 0.5p MAP_SCALE_HEIGHT = 0.075i POLAR_CAP = 85/90 TICK_LENGTH = 0.075i TICK_PEN = 0.5p X_AXIS_LENGTH = 9i Y_AXIS_LENGTH = 6i X_ORIGIN = 1i Y_ORIGIN = 1i UNIX_TIME = FALSE UNIX_TIME_POS = BL/-0.75i/-0.75i UNIX_TIME_FORMAT = %Y %b %d %H:%M:%S #-------- Color System Parameters ----------- COLOR_BACKGROUND = 0/0/0 COLOR_FOREGROUND = 255/255/255 COLOR_NAN = 128/128/128 COLOR_IMAGE = adobe COLOR_MODEL = rgb HSV_MIN_SATURATION = 1 HSV_MAX_SATURATION = 0.1 HSV_MIN_VALUE = 0.3 HSV_MAX_VALUE = 1 #-------- PostScript Parameters ------------- CHAR_ENCODING = ISOLatin1+ DOTS_PR_INCH = 300 N_COPIES = 1 PS_COLOR = rgb PS_IMAGE_COMPRESS = none PS_IMAGE_FORMAT = ascii PS_LINE_CAP = round PS_LINE_JOIN = miter PS_MITER_LIMIT = 35 PS_VERBOSE = FALSE GLOBAL_X_SCALE = 1 GLOBAL_Y_SCALE = 1 #-------- I/O Format Parameters ------------- D_FORMAT = %lg FIELD_DELIMITER = tab GRIDFILE_SHORTHAND = FALSE GRID_FORMAT = nf INPUT_CLOCK_FORMAT = hh:mm:ss INPUT_DATE_FORMAT = yyyy-mm-dd IO_HEADER = FALSE N_HEADER_RECS = 1 OUTPUT_CLOCK_FORMAT = hh:mm:ss OUTPUT_DATE_FORMAT = yyyy-mm-dd OUTPUT_DEGREE_FORMAT = +D XY_TOGGLE = FALSE #-------- Projection Parameters ------------- ELLIPSOID = WGS-84 MAP_SCALE_FACTOR = default MEASURE_UNIT = inch #-------- Calendar/Time Parameters ---------- TIME_FORMAT_PRIMARY = full TIME_FORMAT_SECONDARY = full TIME_EPOCH = 2000-01-01T00:00:00 TIME_IS_INTERVAL = OFF TIME_INTERVAL_FRACTION = 0.5 TIME_LANGUAGE = us TIME_UNIT = d TIME_WEEK_START = Sunday Y2K_OFFSET_YEAR = 1950 #-------- Miscellaneous Parameters ---------- HISTORY = TRUE INTERPOLANT = akima LINE_STEP = 0.01i VECTOR_SHAPE = 0 VERBOSE = FALSE'''
# # GMT-SYSTEM 4.3.1 Defaults file # #-------- Plot Media Parameters ------------- PAGE_COLOR = 255/255/255 PAGE_ORIENTATION = portrait PAPER_MEDIA = a4+ #-------- Basemap Annotation Parameters ------ ANNOT_MIN_ANGLE = 20 ANNOT_MIN_SPACING = 0 ANNOT_FONT_PRIMARY = Helvetica ANNOT_FONT_SIZE_PRIMARY = 12p ANNOT_OFFSET_PRIMARY = 0.075i ANNOT_FONT_SECONDARY = Helvetica ANNOT_FONT_SIZE_SECONDARY = 16p ANNOT_OFFSET_SECONDARY = 0.075i DEGREE_SYMBOL = ring HEADER_FONT = Helvetica HEADER_FONT_SIZE = 36p HEADER_OFFSET = 0.1875i LABEL_FONT = Helvetica LABEL_FONT_SIZE = 14p LABEL_OFFSET = 0.1125i OBLIQUE_ANNOTATION = 1 PLOT_CLOCK_FORMAT = hh:mm:ss PLOT_DATE_FORMAT = yyyy-mm-dd PLOT_DEGREE_FORMAT = +ddd:mm:ss Y_AXIS_TYPE = hor_text #-------- Basemap Layout Parameters --------- BASEMAP_AXES = WESN BASEMAP_FRAME_RGB = 0/0/0 BASEMAP_TYPE = plain FRAME_PEN = 1.25p FRAME_WIDTH = 0.075i GRID_CROSS_SIZE_PRIMARY = 0i GRID_PEN_PRIMARY = 0.25p GRID_CROSS_SIZE_SECONDARY = 0i GRID_PEN_SECONDARY = 0.5p MAP_SCALE_HEIGHT = 0.075i POLAR_CAP = 85/90 TICK_LENGTH = 0.075i TICK_PEN = 0.5p X_AXIS_LENGTH = 9i Y_AXIS_LENGTH = 6i X_ORIGIN = 1i Y_ORIGIN = 1i UNIX_TIME = FALSE UNIX_TIME_POS = BL/-0.75i/-0.75i UNIX_TIME_FORMAT = %Y %b %d %H:%M:%S #-------- Color System Parameters ----------- COLOR_BACKGROUND = 0/0/0 COLOR_FOREGROUND = 255/255/255 COLOR_NAN = 128/128/128 COLOR_IMAGE = adobe COLOR_MODEL = rgb HSV_MIN_SATURATION = 1 HSV_MAX_SATURATION = 0.1 HSV_MIN_VALUE = 0.3 HSV_MAX_VALUE = 1 #-------- PostScript Parameters ------------- CHAR_ENCODING = ISOLatin1+ DOTS_PR_INCH = 300 N_COPIES = 1 PS_COLOR = rgb PS_IMAGE_COMPRESS = none PS_IMAGE_FORMAT = ascii PS_LINE_CAP = round PS_LINE_JOIN = miter PS_MITER_LIMIT = 35 PS_VERBOSE = FALSE GLOBAL_X_SCALE = 1 GLOBAL_Y_SCALE = 1 #-------- I/O Format Parameters ------------- D_FORMAT = %lg FIELD_DELIMITER = tab GRIDFILE_SHORTHAND = FALSE GRID_FORMAT = nf INPUT_CLOCK_FORMAT = hh:mm:ss INPUT_DATE_FORMAT = yyyy-mm-dd IO_HEADER = FALSE N_HEADER_RECS = 1 OUTPUT_CLOCK_FORMAT = hh:mm:ss OUTPUT_DATE_FORMAT = yyyy-mm-dd OUTPUT_DEGREE_FORMAT = +D XY_TOGGLE = FALSE #-------- Projection Parameters ------------- ELLIPSOID = WGS-84 MAP_SCALE_FACTOR = default MEASURE_UNIT = inch #-------- Calendar/Time Parameters ---------- TIME_FORMAT_PRIMARY = full TIME_FORMAT_SECONDARY = full TIME_EPOCH = 2000-01-01T00:00:00 TIME_IS_INTERVAL = OFF TIME_INTERVAL_FRACTION = 0.5 TIME_LANGUAGE = us TIME_UNIT = d TIME_WEEK_START = Sunday Y2K_OFFSET_YEAR = 1950 #-------- Miscellaneous Parameters ---------- HISTORY = TRUE INTERPOLANT = akima LINE_STEP = 0.01i VECTOR_SHAPE = 0 VERBOSE = FALSE'''
# # GMT-SYSTEM 4.4.0 [64-bit] Defaults file # #-------- Plot Media Parameters ------------- PAGE_COLOR = 255/255/255 PAGE_ORIENTATION = portrait PAPER_MEDIA = a4+ #-------- Basemap Annotation Parameters ------ ANNOT_MIN_ANGLE = 20 ANNOT_MIN_SPACING = 0 ANNOT_FONT_PRIMARY = Helvetica ANNOT_FONT_SIZE_PRIMARY = 14p ANNOT_OFFSET_PRIMARY = 0.075i ANNOT_FONT_SECONDARY = Helvetica ANNOT_FONT_SIZE_SECONDARY = 16p ANNOT_OFFSET_SECONDARY = 0.075i DEGREE_SYMBOL = ring HEADER_FONT = Helvetica HEADER_FONT_SIZE = 36p HEADER_OFFSET = 0.1875i LABEL_FONT = Helvetica LABEL_FONT_SIZE = 14p LABEL_OFFSET = 0.1125i OBLIQUE_ANNOTATION = 1 PLOT_CLOCK_FORMAT = hh:mm:ss PLOT_DATE_FORMAT = yyyy-mm-dd PLOT_DEGREE_FORMAT = +ddd:mm:ss Y_AXIS_TYPE = hor_text #-------- Basemap Layout Parameters --------- BASEMAP_AXES = WESN BASEMAP_FRAME_RGB = 0/0/0 BASEMAP_TYPE = plain FRAME_PEN = 1.25p FRAME_WIDTH = 0.075i GRID_CROSS_SIZE_PRIMARY = 0i GRID_PEN_PRIMARY = 0.25p GRID_CROSS_SIZE_SECONDARY = 0i GRID_PEN_SECONDARY = 0.5p MAP_SCALE_HEIGHT = 0.075i POLAR_CAP = 85/90 TICK_LENGTH = 0.075i TICK_PEN = 0.5p X_AXIS_LENGTH = 9i Y_AXIS_LENGTH = 6i X_ORIGIN = 1i Y_ORIGIN = 1i UNIX_TIME = FALSE UNIX_TIME_POS = BL/-0.75i/-0.75i UNIX_TIME_FORMAT = %Y %b %d %H:%M:%S #-------- Color System Parameters ----------- COLOR_BACKGROUND = 0/0/0 COLOR_FOREGROUND = 255/255/255 COLOR_NAN = 128/128/128 COLOR_IMAGE = adobe COLOR_MODEL = rgb HSV_MIN_SATURATION = 1 HSV_MAX_SATURATION = 0.1 HSV_MIN_VALUE = 0.3 HSV_MAX_VALUE = 1 #-------- PostScript Parameters ------------- CHAR_ENCODING = ISOLatin1+ DOTS_PR_INCH = 300 N_COPIES = 1 PS_COLOR = rgb PS_IMAGE_COMPRESS = lzw PS_IMAGE_FORMAT = ascii PS_LINE_CAP = round PS_LINE_JOIN = miter PS_MITER_LIMIT = 35 PS_VERBOSE = FALSE GLOBAL_X_SCALE = 1 GLOBAL_Y_SCALE = 1 #-------- I/O Format Parameters ------------- D_FORMAT = %lg FIELD_DELIMITER = tab GRIDFILE_SHORTHAND = FALSE GRID_FORMAT = nf INPUT_CLOCK_FORMAT = hh:mm:ss INPUT_DATE_FORMAT = yyyy-mm-dd IO_HEADER = FALSE N_HEADER_RECS = 1 OUTPUT_CLOCK_FORMAT = hh:mm:ss OUTPUT_DATE_FORMAT = yyyy-mm-dd OUTPUT_DEGREE_FORMAT = +D XY_TOGGLE = FALSE #-------- Projection Parameters ------------- ELLIPSOID = WGS-84 MAP_SCALE_FACTOR = default MEASURE_UNIT = inch #-------- Calendar/Time Parameters ---------- TIME_FORMAT_PRIMARY = full TIME_FORMAT_SECONDARY = full TIME_EPOCH = 2000-01-01T00:00:00 TIME_IS_INTERVAL = OFF TIME_INTERVAL_FRACTION = 0.5 TIME_LANGUAGE = us TIME_UNIT = d TIME_WEEK_START = Sunday Y2K_OFFSET_YEAR = 1950 #-------- Miscellaneous Parameters ---------- HISTORY = TRUE INTERPOLANT = akima LINE_STEP = 0.01i VECTOR_SHAPE = 0 VERBOSE = FALSE '''
# # GMT-SYSTEM 4.5.2 [64-bit] Defaults file # #-------- Plot Media Parameters ------------- PAGE_COLOR = white PAGE_ORIENTATION = portrait PAPER_MEDIA = a4+ #-------- Basemap Annotation Parameters ------ ANNOT_MIN_ANGLE = 20 ANNOT_MIN_SPACING = 0 ANNOT_FONT_PRIMARY = Helvetica ANNOT_FONT_SIZE_PRIMARY = 14p ANNOT_OFFSET_PRIMARY = 0.075i ANNOT_FONT_SECONDARY = Helvetica ANNOT_FONT_SIZE_SECONDARY = 16p ANNOT_OFFSET_SECONDARY = 0.075i DEGREE_SYMBOL = ring HEADER_FONT = Helvetica HEADER_FONT_SIZE = 36p HEADER_OFFSET = 0.1875i LABEL_FONT = Helvetica LABEL_FONT_SIZE = 14p LABEL_OFFSET = 0.1125i OBLIQUE_ANNOTATION = 1 PLOT_CLOCK_FORMAT = hh:mm:ss PLOT_DATE_FORMAT = yyyy-mm-dd PLOT_DEGREE_FORMAT = +ddd:mm:ss Y_AXIS_TYPE = hor_text #-------- Basemap Layout Parameters --------- BASEMAP_AXES = WESN BASEMAP_FRAME_RGB = black BASEMAP_TYPE = plain FRAME_PEN = 1.25p FRAME_WIDTH = 0.075i GRID_CROSS_SIZE_PRIMARY = 0i GRID_PEN_PRIMARY = 0.25p GRID_CROSS_SIZE_SECONDARY = 0i GRID_PEN_SECONDARY = 0.5p MAP_SCALE_HEIGHT = 0.075i POLAR_CAP = 85/90 TICK_LENGTH = 0.075i TICK_PEN = 0.5p X_AXIS_LENGTH = 9i Y_AXIS_LENGTH = 6i X_ORIGIN = 1i Y_ORIGIN = 1i UNIX_TIME = FALSE UNIX_TIME_POS = BL/-0.75i/-0.75i UNIX_TIME_FORMAT = %Y %b %d %H:%M:%S #-------- Color System Parameters ----------- COLOR_BACKGROUND = black COLOR_FOREGROUND = white COLOR_NAN = 128 COLOR_IMAGE = adobe COLOR_MODEL = rgb HSV_MIN_SATURATION = 1 HSV_MAX_SATURATION = 0.1 HSV_MIN_VALUE = 0.3 HSV_MAX_VALUE = 1 #-------- PostScript Parameters ------------- CHAR_ENCODING = ISOLatin1+ DOTS_PR_INCH = 300 GLOBAL_X_SCALE = 1 GLOBAL_Y_SCALE = 1 N_COPIES = 1 PS_COLOR = rgb PS_IMAGE_COMPRESS = lzw PS_IMAGE_FORMAT = ascii PS_LINE_CAP = round PS_LINE_JOIN = miter PS_MITER_LIMIT = 35 PS_VERBOSE = FALSE TRANSPARENCY = 0 #-------- I/O Format Parameters ------------- D_FORMAT = %.12lg FIELD_DELIMITER = tab GRIDFILE_FORMAT = nf GRIDFILE_SHORTHAND = FALSE INPUT_CLOCK_FORMAT = hh:mm:ss INPUT_DATE_FORMAT = yyyy-mm-dd IO_HEADER = FALSE N_HEADER_RECS = 1 NAN_RECORDS = pass OUTPUT_CLOCK_FORMAT = hh:mm:ss OUTPUT_DATE_FORMAT = yyyy-mm-dd OUTPUT_DEGREE_FORMAT = D XY_TOGGLE = FALSE #-------- Projection Parameters ------------- ELLIPSOID = WGS-84 MAP_SCALE_FACTOR = default MEASURE_UNIT = inch #-------- Calendar/Time Parameters ---------- TIME_FORMAT_PRIMARY = full TIME_FORMAT_SECONDARY = full TIME_EPOCH = 2000-01-01T00:00:00 TIME_IS_INTERVAL = OFF TIME_INTERVAL_FRACTION = 0.5 TIME_LANGUAGE = us TIME_UNIT = d TIME_WEEK_START = Sunday Y2K_OFFSET_YEAR = 1950 #-------- Miscellaneous Parameters ---------- HISTORY = TRUE INTERPOLANT = akima LINE_STEP = 0.01i VECTOR_SHAPE = 0 VERBOSE = FALSE '''
# # GMT-SYSTEM 4.5.3 (CVS Jun 18 2010 10:56:07) [64-bit] Defaults file # #-------- Plot Media Parameters ------------- PAGE_COLOR = white PAGE_ORIENTATION = portrait PAPER_MEDIA = a4+ #-------- Basemap Annotation Parameters ------ ANNOT_MIN_ANGLE = 20 ANNOT_MIN_SPACING = 0 ANNOT_FONT_PRIMARY = Helvetica ANNOT_FONT_SIZE_PRIMARY = 14p ANNOT_OFFSET_PRIMARY = 0.075i ANNOT_FONT_SECONDARY = Helvetica ANNOT_FONT_SIZE_SECONDARY = 16p ANNOT_OFFSET_SECONDARY = 0.075i DEGREE_SYMBOL = ring HEADER_FONT = Helvetica HEADER_FONT_SIZE = 36p HEADER_OFFSET = 0.1875i LABEL_FONT = Helvetica LABEL_FONT_SIZE = 14p LABEL_OFFSET = 0.1125i OBLIQUE_ANNOTATION = 1 PLOT_CLOCK_FORMAT = hh:mm:ss PLOT_DATE_FORMAT = yyyy-mm-dd PLOT_DEGREE_FORMAT = +ddd:mm:ss Y_AXIS_TYPE = hor_text #-------- Basemap Layout Parameters --------- BASEMAP_AXES = WESN BASEMAP_FRAME_RGB = black BASEMAP_TYPE = plain FRAME_PEN = 1.25p FRAME_WIDTH = 0.075i GRID_CROSS_SIZE_PRIMARY = 0i GRID_PEN_PRIMARY = 0.25p GRID_CROSS_SIZE_SECONDARY = 0i GRID_PEN_SECONDARY = 0.5p MAP_SCALE_HEIGHT = 0.075i POLAR_CAP = 85/90 TICK_LENGTH = 0.075i TICK_PEN = 0.5p X_AXIS_LENGTH = 9i Y_AXIS_LENGTH = 6i X_ORIGIN = 1i Y_ORIGIN = 1i UNIX_TIME = FALSE UNIX_TIME_POS = BL/-0.75i/-0.75i UNIX_TIME_FORMAT = %Y %b %d %H:%M:%S #-------- Color System Parameters ----------- COLOR_BACKGROUND = black COLOR_FOREGROUND = white COLOR_NAN = 128 COLOR_IMAGE = adobe COLOR_MODEL = rgb HSV_MIN_SATURATION = 1 HSV_MAX_SATURATION = 0.1 HSV_MIN_VALUE = 0.3 HSV_MAX_VALUE = 1 #-------- PostScript Parameters ------------- CHAR_ENCODING = ISOLatin1+ DOTS_PR_INCH = 300 GLOBAL_X_SCALE = 1 GLOBAL_Y_SCALE = 1 N_COPIES = 1 PS_COLOR = rgb PS_IMAGE_COMPRESS = lzw PS_IMAGE_FORMAT = ascii PS_LINE_CAP = round PS_LINE_JOIN = miter PS_MITER_LIMIT = 35 PS_VERBOSE = FALSE TRANSPARENCY = 0 #-------- I/O Format Parameters ------------- D_FORMAT = %.12lg FIELD_DELIMITER = tab GRIDFILE_FORMAT = nf GRIDFILE_SHORTHAND = FALSE INPUT_CLOCK_FORMAT = hh:mm:ss INPUT_DATE_FORMAT = yyyy-mm-dd IO_HEADER = FALSE N_HEADER_RECS = 1 NAN_RECORDS = pass OUTPUT_CLOCK_FORMAT = hh:mm:ss OUTPUT_DATE_FORMAT = yyyy-mm-dd OUTPUT_DEGREE_FORMAT = D XY_TOGGLE = FALSE #-------- Projection Parameters ------------- ELLIPSOID = WGS-84 MAP_SCALE_FACTOR = default MEASURE_UNIT = inch #-------- Calendar/Time Parameters ---------- TIME_FORMAT_PRIMARY = full TIME_FORMAT_SECONDARY = full TIME_EPOCH = 2000-01-01T00:00:00 TIME_IS_INTERVAL = OFF TIME_INTERVAL_FRACTION = 0.5 TIME_LANGUAGE = us TIME_UNIT = d TIME_WEEK_START = Sunday Y2K_OFFSET_YEAR = 1950 #-------- Miscellaneous Parameters ---------- HISTORY = TRUE INTERPOLANT = akima LINE_STEP = 0.01i VECTOR_SHAPE = 0 VERBOSE = FALSE '''
# # GMT 5.1.2 Defaults file # vim:sw=8:ts=8:sts=8 # $Revision: 13836 $ # $LastChangedDate: 2014-12-20 03:45:42 -1000 (Sat, 20 Dec 2014) $ # # COLOR Parameters # COLOR_BACKGROUND = black COLOR_FOREGROUND = white COLOR_NAN = 127.5 COLOR_MODEL = none COLOR_HSV_MIN_S = 1 COLOR_HSV_MAX_S = 0.1 COLOR_HSV_MIN_V = 0.3 COLOR_HSV_MAX_V = 1 # # DIR Parameters # DIR_DATA = DIR_DCW = DIR_GSHHG = # # FONT Parameters # FONT_ANNOT_PRIMARY = 14p,Helvetica,black FONT_ANNOT_SECONDARY = 16p,Helvetica,black FONT_LABEL = 14p,Helvetica,black FONT_LOGO = 8p,Helvetica,black FONT_TITLE = 24p,Helvetica,black # # FORMAT Parameters # FORMAT_CLOCK_IN = hh:mm:ss FORMAT_CLOCK_OUT = hh:mm:ss FORMAT_CLOCK_MAP = hh:mm:ss FORMAT_DATE_IN = yyyy-mm-dd FORMAT_DATE_OUT = yyyy-mm-dd FORMAT_DATE_MAP = yyyy-mm-dd FORMAT_GEO_OUT = D FORMAT_GEO_MAP = ddd:mm:ss FORMAT_FLOAT_OUT = %.12g FORMAT_FLOAT_MAP = %.12g FORMAT_TIME_PRIMARY_MAP = full FORMAT_TIME_SECONDARY_MAP = full FORMAT_TIME_STAMP = %Y %b %d %H:%M:%S # # GMT Miscellaneous Parameters # GMT_COMPATIBILITY = 4 GMT_CUSTOM_LIBS = GMT_EXTRAPOLATE_VAL = NaN GMT_FFT = auto GMT_HISTORY = true GMT_INTERPOLANT = akima GMT_TRIANGULATE = Shewchuk GMT_VERBOSE = compat GMT_LANGUAGE = us # # I/O Parameters # IO_COL_SEPARATOR = tab IO_GRIDFILE_FORMAT = nf IO_GRIDFILE_SHORTHAND = false IO_HEADER = false IO_N_HEADER_RECS = 0 IO_NAN_RECORDS = pass IO_NC4_CHUNK_SIZE = auto IO_NC4_DEFLATION_LEVEL = 3 IO_LONLAT_TOGGLE = false IO_SEGMENT_MARKER = > # # MAP Parameters # MAP_ANNOT_MIN_ANGLE = 20 MAP_ANNOT_MIN_SPACING = 0p MAP_ANNOT_OBLIQUE = 1 MAP_ANNOT_OFFSET_PRIMARY = 0.075i MAP_ANNOT_OFFSET_SECONDARY = 0.075i MAP_ANNOT_ORTHO = we MAP_DEFAULT_PEN = default,black MAP_DEGREE_SYMBOL = ring MAP_FRAME_AXES = WESNZ MAP_FRAME_PEN = thicker,black MAP_FRAME_TYPE = fancy MAP_FRAME_WIDTH = 5p MAP_GRID_CROSS_SIZE_PRIMARY = 0p MAP_GRID_CROSS_SIZE_SECONDARY = 0p MAP_GRID_PEN_PRIMARY = default,black MAP_GRID_PEN_SECONDARY = thinner,black MAP_LABEL_OFFSET = 0.1944i MAP_LINE_STEP = 0.75p MAP_LOGO = false MAP_LOGO_POS = BL/-54p/-54p MAP_ORIGIN_X = 1i MAP_ORIGIN_Y = 1i MAP_POLAR_CAP = 85/90 MAP_SCALE_HEIGHT = 5p MAP_TICK_LENGTH_PRIMARY = 5p/2.5p MAP_TICK_LENGTH_SECONDARY = 15p/3.75p MAP_TICK_PEN_PRIMARY = thinner,black MAP_TICK_PEN_SECONDARY = thinner,black MAP_TITLE_OFFSET = 14p MAP_VECTOR_SHAPE = 0 # # Projection Parameters # PROJ_AUX_LATITUDE = authalic PROJ_ELLIPSOID = WGS-84 PROJ_LENGTH_UNIT = cm PROJ_MEAN_RADIUS = authalic PROJ_SCALE_FACTOR = default # # PostScript Parameters # PS_CHAR_ENCODING = ISOLatin1+ PS_COLOR_MODEL = rgb PS_COMMENTS = false PS_IMAGE_COMPRESS = deflate,5 PS_LINE_CAP = butt PS_LINE_JOIN = miter PS_MITER_LIMIT = 35 PS_MEDIA = a4 PS_PAGE_COLOR = white PS_PAGE_ORIENTATION = portrait PS_SCALE_X = 1 PS_SCALE_Y = 1 PS_TRANSPARENCY = Normal # # Calendar/Time Parameters # TIME_EPOCH = 1970-01-01T00:00:00 TIME_IS_INTERVAL = off TIME_INTERVAL_FRACTION = 0.5 TIME_UNIT = s TIME_WEEK_START = Monday TIME_Y2K_OFFSET_YEAR = 1950 '''
args = [gmtdefaultsbinary]
environ = os.environ.copy() environ['GMTHOME'] = gmthomedir or ''
p = subprocess.Popen( args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=environ)
(stdout, stderr) = p.communicate() m = re.search(br'(\d+(\.\d+)*)', stderr) \ or re.search(br'# GMT (\d+(\.\d+)*)', stdout)
if not m: raise GMTInstallationProblem( "Can't extract version number from output of %s" % gmtdefaultsbinary)
return str(m.group(1).decode('ascii'))
# GMT 4.x: ['GMT'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdout, stderr) = p.communicate()
m = re.search(br'Version\s+(\d+(\.\d+)*)', stderr, re.M) if not m: raise GMTInstallationProblem( "Can't version number from output of GMT")
version = str(m.group(1).decode('ascii')) if version[0] != '5':
m = re.search(br'^\s+executables\s+(.+)$', stderr, re.M) if not m: raise GMTInstallationProblem( "Can't extract executables dir from output of GMT")
gmtbin = str(m.group(1).decode('ascii'))
m = re.search(br'^\s+shared data\s+(.+)$', stderr, re.M) if not m: raise GMTInstallationProblem( "Can't extract shared dir from output of GMT")
gmtshare = str(m.group(1).decode('ascii')) if not gmtshare.endswith('/share'): raise GMTInstallationProblem( "Can't determine GMTHOME from output of GMT")
gmthome = gmtshare[:-6]
installations[version] = { 'home': gmthome, 'bin': gmtbin}
['gmt', '--version']).strip().decode('ascii')).split('_')[0] ['gmt', '--show-bindir']).strip().decode('ascii')) 'bin': gmtbin}
except (OSError, subprocess.CalledProcessError) as e: errmesses.append(('gmt', str(e)))
s = [] for (progname, errmess) in errmesses: s.append('Cannot start "%s" executable: %s' % (progname, errmess))
raise GMTInstallationProblem(', '.join(s))
return version
return avails[max(0, iavail-1)]
'''Get default GMT configuration dict for given version.'''
# if not version in _gmt_defaults_by_version: # raise GMTError('No GMT defaults for version %s found' % version)
d1 = gmt_default_config(v1) d2 = gmt_default_config(v2) for k in d1: if k not in d2: print('%s not in %s' % (k, v2)) else: if d1[k] != d2[k]: print('%s %s = %s' % (v1, k, d1[k])) print('%s %s = %s' % (v2, k, d2[k]))
for k in d2: if k not in d1: print('%s not in %s' % (k, v1))
# diff_defaults('4.5.2', '4.5.3')
logging.error(('Directory does not exist: %s\n' 'Check your GMT installation.') % d)
gmtdefaults = pjoin(bin_dir, 'gmtdefaults')
versionfound = get_gmt_version(gmtdefaults, home_dir)
if versionfound != version: raise GMTInstallationProblem(( 'Expected GMT version %s but found version %s.\n' '(Looking at output of %s)') % ( version, versionfound, gmtdefaults))
logging.warn('GMT version %s not installed, taking version %s instead' % (version, newest_installed_gmt_version()))
version = 'newest'
# store defaults as dicts into the gmt installations dicts
A1 1684 2380 A2 1190 1684 A3 842 1190 A4 595 842 A5 421 595 A6 297 421 A7 210 297 A8 148 210 A9 105 148 A10 74 105 B0 2836 4008 B1 2004 2836 B2 1418 2004 B3 1002 1418 B4 709 1002 B5 501 709 archA 648 864 archB 864 1296 archC 1296 1728 archD 1728 2592 archE 2592 3456 flsa 612 936 halfletter 396 612 note 540 720 letter 612 792 legal 612 1008 11x17 792 1224 ledger 1224 792'''
for k in ['MEASURE_UNIT', 'PROJ_LENGTH_UNIT']: if k in gmt_config: return gmt_config[k]
raise GmtPyError('cannot get measure unit / proj length unit from config')
raise GmtPyError('cannot get paper media from config')
raise GmtPyError('cannot get paper orientation from config')
leftmargin, topmargin, rightmargin, bottommargin = margins portrait = page_orientation(gmt_config).lower() == 'portrait'
paper_size = get_paper_size(paper_media(gmt_config)) if not portrait: paper_size = paper_size[1], paper_size[0]
xoffset = (paper_size[0] - (width + leftmargin + rightmargin)) / \ 2.0 + leftmargin yoffset = (paper_size[1] - (height + topmargin + bottommargin)) / \ 2.0 + bottommargin
if portrait: bb1 = int((xoffset - leftmargin)) bb2 = int((yoffset - bottommargin)) bb3 = bb1 + int((width+leftmargin+rightmargin)) bb4 = bb2 + int((height+topmargin+bottommargin)) else: bb1 = int((yoffset - topmargin)) bb2 = int((xoffset - leftmargin)) bb3 = bb1 + int((height+topmargin+bottommargin)) bb4 = bb2 + int((width+leftmargin+rightmargin))
return xoffset, yoffset, (bb1, bb2, bb3, bb4)
'''Get the built-in gmtdefaults.'''
if version not in _gmt_installations: logging.warn('GMT version %s not installed, taking version %s instead' % (version, newest_installed_gmt_version())) version = 'newest'
if version == 'newest': version = newest_installed_gmt_version()
return _gmt_defaults_by_version[version]
'''Write COARDS compliant netcdf (grd) file.'''
else:
else:
arr *= var.scale_factor
arr += var.add_offset
'''Read COARDS compliant netcdf (grd) file.'''
num.array([asorted.size])))
num.array([asorted.size]))) asorted[indis[:-1]], (bsum[indis[1:]] - bsum[indis[:-1]]) / (indis[1:]-indis[:-1]))
return nxs, nys, 0 # exact match elif nxs >= xs.size*critical_fraction and nys >= xs.size*critical_fraction: # possibly randomly sampled nxs = int(math.sqrt(xs.size)) nys = nxs return nxs, nys, 2 else: return nxs, nys, 1
'''Grid tabular XYZ data by binning.
This function does some extra work to guess the size of the grid. This should work fine if the input values are already defined on an rectilinear grid, even if data points are missing or duplicated. This routine also tries to detect a random distribution of input data and in that case creates a grid of size sqrt(N) x sqrt(N).
The points do not have to be given in any particular order. Grid nodes without data are assigned the NaN value. If multiple data points map to the same grid node, their average is assigned to the grid node. '''
else: xf = num.linspace(xs[0], xs[-1], nx) yf = num.linspace(ys[0], ys[-1], ny) zf = griddata_regular(x, y, z, xf, yf)
'''Abstract base class providing template interpolation, accessible as attributes.
Classes deriving from this one, have to implement a :py:meth:`get_params` method, which is called to get a dict to do ordinary ``"%(key)x"``-substitutions. The deriving class must also provide a dict with the templates.'''
# hand through templates dict
return template_name in self.templates
return iter(self.templates)
del(self.templates[template_name])
raise AttributeError(template_names)
'''Round ``x`` to nice value.'''
x = -x sign = -1 x *= 10.0 exp /= 10.0
'''Tunable 1D autoscaling based on data range.
Instances of this class may be used to determine nice minima, maxima and increments for ax annotations, as well as suitable common exponents for notation.
The autoscaling process is guided by the following public attributes:
.. py:attribute:: approx_ticks
Approximate number of increment steps (tickmarks) to generate.
.. py:attribute:: mode
Mode of operation: one of ``'auto'``, ``'min-max'``, ``'0-max'``, ``'min-0'``, ``'symmetric'`` or ``'off'``.
================ ================================================== mode description ================ ================================================== ``'auto'``: Look at data range and choose one of the choices below. ``'min-max'``: Output range is selected to include data range. ``'0-max'``: Output range shall start at zero and end at data max. ``'min-0'``: Output range shall start at data min and end at zero. ``'symmetric'``: Output range shall by symmetric by zero. ``'off'``: Similar to ``'min-max'``, but snap and space are disabled, such that the output range always exactly matches the data range. ================ ==================================================
.. py:attribute:: exp
If defined, override automatically determined exponent for notation by the given value.
.. py:attribute:: snap
If set to True, snap output range to multiples of increment. This parameter has no effect, if mode is set to ``'off'``.
.. py:attribute:: inc
If defined, override automatically determined tick increment by the given value.
.. py:attribute:: space
Add some padding to the range. The value given, is the fraction by which the output range is increased on each side. If mode is ``'0-max'`` or ``'min-0'``, the end at zero is kept fixed at zero. This parameter has no effect if mode is set to ``'off'``.
.. py:attribute:: exp_factor
Exponent of notation is chosen to be a multiple of this value.
.. py:attribute:: no_exp_interval:
Range of exponent, for which no exponential notation is allowed.
'''
self, approx_ticks=7.0, mode='auto', exp=None, snap=False, inc=None, space=0.0, exp_factor=3, no_exp_interval=(-3, 5)):
'''Create new AutoScaler instance.
The parameters are described in the AutoScaler documentation. '''
'''Get nice minimum, maximum and increment for given data range.
Returns ``(minimum, maximum, increment)`` or ``(maximum, minimum, -increment)``, depending on whether data_range is ``(data_min, data_max)`` or ``(data_max, data_min)``. If ``override_mode`` is defined, the mode attribute is temporarily overridden by the given value. '''
a = override_mode
else: ma = 1.0 else: mi = -1.0
mi -= 1.0 ma += 1.0
# make nice tick increment else: else: inc = nice_value((ma-mi)*10.)
inc = 1.0
# snap min and max to ticks if this is wanted
return ma, mi, -inc else:
'''Get nice exponent for notation of ``x``.
For ax annotations, give tick increment as ``x``.'''
return self.exp
return 0
'''Guess mode of operation, based on data range.
Used to map ``'auto'`` mode to ``'0-max'``, ``'min-0'``, ``'min-max'`` or ``'symmetric'``.'''
else: a = 'min-max' if data_max > data_min/2.: a = 'min-0' else: a = 'min-max' (abs(data_max)+abs(data_min))) < 0.5: else: a = 'min-max'
'''Ax description with autoscaling capabilities.
The ax is described by the :py:class:`AutoScaler` public attributes, plus the following additional attributes (with default values given in paranthesis):
.. py:attribute:: label
Ax label (without unit).
.. py:attribute:: unit
Physical unit of the data attached to this ax.
.. py:attribute:: scaled_unit
(see below)
.. py:attribute:: scaled_unit_factor
Scaled physical unit and factor between unit and scaled_unit so that
unit = scaled_unit_factor x scaled_unit.
(E.g. if unit is 'm' and data is in the range of nanometers, you may want to set the scaled_unit to 'nm' and the scaled_unit_factor to 1e9.)
.. py:attribute:: limits
If defined, fix range of ax to limits=(min,max).
.. py:attribute:: masking
If true and if there is a limit on the ax, while calculating ranges, the data points are masked such that data points outside of this axes limits are not used to determine the range of another dependant ax.
'''
scaled_unit='', limits=None, masking=True, **kwargs):
'''Get label string including the unit and multiplier.'''
else:
override_scaled_unit_factor=None):
'''Get minimum, maximum, increment and label string for ax display.'
Returns minimum, maximum, increment and label string including unit and multiplier for given data range.
If ``ax_projection`` is True, values suitable to be displayed on the ax are returned, e.g. min, max and inc are returned in scaled units. Otherwise the values are returned in the original units, without any scaling applied. '''
sf = override_scaled_unit_factor
else: else:
'''2D/3D autoscaling and ax annotation facility.
Instances of this class provide automatic determination of plot ranges, tick increments and scaled annotations, as well as label/unit handling. It can in particular be used to automatically generate the -R and -B option arguments, which are required for most GMT commands.
It extends the functionality of the :py:class:`Ax` and :py:class:`AutoScaler` classes at the level, where it can not be handled anymore by looking at a single dimension of the dataset's data, e.g.:
* The ability to impose a fixed aspect ratio between two axes.
* Recalculation of data range on non-limited axes, when there are limits imposed on other axes.
'''
percent_interval=None, copy_from=None):
from scipy.stats import scoreatpercentile as scap
R='-R%(xmin)g/%(xmax)g/%(ymin)g/%(ymax)g', B='-B%(xinc)g:%(xlabel)s:/%(yinc)g:%(ylabel)s:WSen', T='-T%(zmin)g/%(zmax)g/%(zinc)g')
else: maxdim = len(axes) else:
# sophisticated data-range calculation ax_limits = list(ax.limits) if ax_limits[0] is None: ax_limits[0] = -num.inf if ax_limits[1] is None: ax_limits[1] = num.inf in_range = num.logical_and( in_range, num.logical_and(ax_limits[0] <= x, x <= ax_limits[1]))
xmasked = num.where(in_range, x, num.NaN) if percent_interval is None: range_this = ( num.nanmin(xmasked), num.nanmax(xmasked)) else: xmasked_finite = num.compress( num.isfinite(xmasked), xmasked) range_this = ( scap(xmasked_finite, (100.-percent_interval)/2.), scap(xmasked_finite, 100.-(100.-percent_interval)/2.)) else: else: xmasked_finite = num.compress( num.isfinite(xmasked), xmasked) range_this = ( scap(xmasked_finite, (100.-percent_interval)/2.), scap(xmasked_finite, 100.-(100.-percent_interval)/2.)) else:
if ax.limits[0] is not None: range_this = ax.limits[0], max(ax.limits[0], range_this[1])
if ax.limits[1] is not None: range_this = min(ax.limits[1], range_this[0]), ax.limits[1]
else: range_this = ax.limits
else:
num.isfinite(data_ranges[i][0]) and num.isfinite(data_ranges[i][1])):
data_ranges[i] = (0., 1.)
'''Get dict with output parameters.
For each data dimension, ax minimum, maximum, increment and a label string (including unit and exponential factor) are determined. E.g. in for the first dimension the output dict will contain the keys ``'xmin'``, ``'xmax'``, ``'xinc'``, and ``'xlabel'``.
Normally, values corresponding to the scaling of the raw data are produced, but if ``ax_projection`` is ``True``, values which are suitable to be printed on the axes are returned. This means that in the latter case, the :py:attr:`Ax.scaled_unit` and :py:attr:`Ax.scaled_unit_factor` attributes as set on the axes are respected and that a common 10^x factor is factored out and put to the label string. '''
self.data_ranges[0], ax_projection) self.data_ranges[1], ax_projection) self.data_ranges[2], ax_projection)
# enforce certain aspect, if needed xwid = xma-xmi ywid = yma-ymi if ywid < xwid*self.aspect: ymi -= (xwid*self.aspect - ywid)*0.5 yma += (xwid*self.aspect - ywid)*0.5 ymi, yma, yinc, ylabel = self.axes[1].make_params( (ymi, yma), ax_projection, override_mode='off', override_scaled_unit_factor=1.)
elif xwid < ywid/self.aspect: xmi -= (ywid/self.aspect - xwid)*0.5 xma += (ywid/self.aspect - xwid)*0.5 xmi, xma, xinc, xlabel = self.axes[0].make_params( (xmi, xma), ax_projection, override_mode='off', override_scaled_unit_factor=1.)
ymin=ymi, ymax=yma, yinc=yinc, ylabel=ylabel)
'''Sizing policy implementing a minimal size, plus a desire to grow.'''
else: else:
else:
'''Base class of the gmtpy layout system.
The Widget class provides the basic functionality for the nesting and placing of elements on the output page, and maintains the sizing policies of each element. Each of the layouts defined in gmtpy is itself a Widget.
Sizing of the widget is controlled by :py:meth:`get_min_size` and :py:meth:`get_grow` which should be overloaded in derived classes. The basic behaviour of a Widget instance is to have a vertical and a horizontal minimum size which default to zero, as well as a vertical and a horizontal desire to grow, represented by floats, which default to 1.0. Additionally an aspect ratio constraint may be imposed on the Widget.
After layouting, the widget provides its width, height, x-offset and y-offset in various ways. Via the Guru interface (see :py:class:`Guru` class), templates for the -X, -Y and -J option arguments used by GMT arguments are provided. The defaults are suitable for plotting of linear (-JX) plots. Other projections can be selected by giving an appropriate 'J' template, or by manual construction of the -J option, e.g. by utilizing the :py:meth:`width` and :py:meth:`height` methods. The :py:meth:`bbox` method can be used to create a PostScript bounding box from the widgets border, e.g. for use in the :py:meth:`save` method of :py:class:`GMT` instances.
The convention is, that all sizes are given in PostScript points. Conversion factors are provided as constants :py:const:`inch` and :py:const:`cm` in the gmtpy module. '''
'''Create new widget.'''
X='-Xa%(xoffset)gp', Y='-Ya%(yoffset)gp', J='-JX%(width)gp/%(height)gp')
else:
else:
'''Set the parent widget.
This method should not be called directly. The :py:meth:`set_widget` methods are responsible for calling this. '''
'''Get the widgets parent widget.'''
return self.parent
'''Get the root widget in the layout hierarchy.'''
if self.parent is not None: return self.get_parent() else: return self
'''Set the horizontal sizing policy of the Widget.
:param minimal: new minimal width of the widget :param grow: new horizontal grow disire of the widget '''
return self.horizontal.get_minimal(), self.horizontal.get_grow()
'''Set the horizontal sizing policy of the Widget.
:param minimal: new minimal height of the widget :param grow: new vertical grow disire of the widget '''
return self.vertical.get_minimal(), self.vertical.get_grow()
'''Set aspect constraint on the widget.
The aspect is given as height divided by width. '''
'''Shortcut to set sizing and aspect constraints in a single method call.'''
mh, gh = self.get_horizontal() mv, gv = self.get_vertical() return (mh, mv), (gh, gv), self.aspect
'''Get legal size for widget.
Returns: (new_size, new_offset)
Given a box as ``size`` and ``offset``, return ``new_size`` and ``new_offset``, such that the widget's sizing and aspect constraints are fullfilled. The returned box is centered on the given input box. '''
oh += (sh-sv/self.aspect)/2. sh = sv/self.aspect ov += (sv-sh*self.aspect)/2. sv = sh*self.aspect
'''Get minimum size of widget.
Used by the layout managers. Should be overloaded in derived classes. '''
elif mh == 0.0: return mv/self.aspect, mv
'''Get widget's desire to grow.
Used by the layout managers. Should be overloaded in derived classes. '''
'''Set the widget's current size.
Should not be called directly. It is the layout manager's responsibility to call this. '''
def __str__(self):
def indent(ind, str): return ('\n'+ind).join(str.splitlines()) size, offset = self.get_size() s = "%s (%g x %g) (%g, %g)\n" % ((self.__class__,) + size + offset) children = self.get_children() if children: s += '\n'.join([' ' + indent(' ', str(c)) for c in children]) return s
def indent(ind, str): return ('\n'+ind).join(str.splitlines()) mins, grows, aspect = self.get_policy() s = "%s: minimum=(%s, %s), grow=(%s, %s), aspect=%s\n" % ( (self.__class__,) + mins+grows+(aspect,))
children = self.get_children() if children: s += '\n'.join([' ' + indent( ' ', c.policies_debug_str()) for c in children]) return s
'''Get coordinates of the corners of the widget.
Returns list with coordinate tuples.
If ``descend`` is True, the returned list will contain corner coordinates of all sub-widgets. '''
self.do_layout() (sh, sv), (oh, ov) = self.get_size() corners = [(oh, ov), (oh+sh, ov), (oh+sh, ov+sv), (oh, ov+sv)] if descend: for child in self.get_children(): corners.extend(child.get_corners(descend=True)) return corners
'''Get sizes of this widget and all it's children.
Returns a list with size tuples. '''
'''Triggers layouting of the widget hierarchy, if needed.'''
sh = 15.*cm sv = 15.*cm*gv/gh * 1./golden_ratio
'''Get sub-widgets contained in this widget.
Returns a list of widgets. '''
'''Get current size and position of the widget.
Triggers layouting and returns ``((width, height), (xoffset, yoffset))`` '''
self.vertical.get_value()), self.offset
'''Get current size and position of the widget.
Triggers layouting and returns dict with keys ``'xoffset'``, ``'yoffset'``, ``'width'`` and ``'height'``. '''
width_m=w/_units['m'])
'''Get current width of the widget.
Triggers layouting and returns width.'''
'''Get current height of the widget.
Triggers layouting and return height.'''
'''Get PostScript bounding box for this widget.
Triggers layouting and returns values suitable to create PS bounding box, representing the widgets current size and position. '''
self.offset[1]+self.height())
'''Set dirty flag on top level widget in the hierarchy.
Called by various methods, to indicate, that the widget hierarchy needs new layouting. '''
'''A layout manager which centers its single child widget.
The child widget may be oversized. '''
vertical=GumSpring(grow=1.), parent=self)
shc = sh svc = sv
'''Set the child widget, which shall be centered.'''
widget = Widget()
return self.content
return [self.content]
'''A layout manager containing a center widget sorrounded by four margin widgets.
::
+---------------------------+ | top | +---------------------------+ | | | | | left | center | right | | | | | +---------------------------+ | bottom | +---------------------------+
This layout manager does a little bit of extra effort to maintain the aspect constraint of the center widget, if this is set. It does so, by allowing for a bit more flexibility in the sizing of the margins. Two shortcut methods are provided to set the margin sizes in one shot: :py:meth:`set_fixed_margins` and :py:meth:`set_min_margins`. The first sets the margins to fixed sizes, while the second gives them a minimal size and a (neglectably) small desire to grow. Using the latter may be useful when setting an aspect constraint on the center widget, because this way the maximum size of the center widget may be controlled without creating empty spaces between the widgets. '''
horizontal=GumSpring(grow=0.15, minimal=mw), parent=self) horizontal=GumSpring(grow=0.15, minimal=mw), parent=self) vertical=GumSpring(grow=0.15, minimal=mw/golden_ratio), parent=self) vertical=GumSpring(grow=0.15, minimal=mw/golden_ratio), parent=self) horizontal=GumSpring(grow=0.7), vertical=GumSpring(grow=0.7), parent=self)
'''Give margins fixed size constraints.'''
'''Give margins a minimal size and the possibility to grow.
The desire to grow is set to a very small number.'''
self.left, self.right, self.top, self.bottom, self.center)] self.left, self.right, self.top, self.bottom, self.center)]
# prevent widgets from collapsing
self.right.get_grow()[0] + self.center.get_grow()[0]) * ghs self.bottom.get_grow()[1] + self.center.get_grow()[1]) * gvs
self.left, self.right, self.top, self.bottom, self.center)] self.left, self.right, self.top, self.bottom, self.center)]
raise GmtPyError("Container not wide enough for contents " "(FrameLayout, available: %g cm, needed: %g cm)" % (sh/cm, (sl[0]+sr[0]+sc[0])/cm)) raise GmtPyError("Container not high enough for contents " "(FrameLayout, available: %g cm, needed: %g cm)" % (sv/cm, (st[1]+sb[1]+sc[1])/cm))
(gl[0], gr[0], gc[0]), ah) (gt[1], gb[1], gc[1]), av)
slh, srh, sch = distribute( (sl[0], sr[0], scv/self.center.aspect), (gl[0], gr[0], 0.0), ahm)
sch*self.center.aspect), (gt[1], gb[1], 0.0), avm)
'''Set one of the sub-widgets.
``which`` should be one of ``'left'``, ``'right'``, ``'top'``, ``'bottom'`` or ``'center'``. '''
widget = Widget()
else: raise GmtPyError('No such sub-widget: %s' % which)
'''Get one of the sub-widgets.
``which`` should be one of ``'left'``, ``'right'``, ``'top'``, ``'bottom'`` or ``'center'``. '''
else: raise GmtPyError('No such sub-widget: %s' % which)
'''A layout manager which arranges its sub-widgets in a grid.
The grid spacing is flexible and based on the sizing policies of the contained sub-widgets. If an equidistant grid is needed, the sizing policies of the sub-widgets have to be set equally.
The height of each row and the width of each column is derived from the sizing policy of the largest sub-widget in the row or column in question. The algorithm is not very sophisticated, so conflicting sizing policies might not be resolved optimally. '''
'''Create new grid layout with ``nx`` columns and ``ny`` rows.'''
[[w.get_min_size()[0] for w in row] for row in self.grid], dtype=num.float) [[w.get_min_size()[1] for w in row] for row in self.grid], dtype=num.float)
[[w.get_grow()[0] for w in row] for row in self.grid], dtype=num.float) [[w.get_grow()[1] for w in row] for row in self.grid], dtype=num.float)
else: gh = 1.0 else: gv = 1.0
# available additional space
else: av = sv ah = sh
raise GmtPyError("Container not wide enough for contents " "(GridLayout, available: %g cm, needed: %g cm)" % (sh/cm, (num.sum(esh.max(0)))/cm)) raise GmtPyError("Container not high enough for contents " "(GridLayout, available: %g cm, needed: %g cm)" % (sv/cm, (num.sum(esv.max(1)))/cm))
# distribute additional space on rows and columns # according to grow weights and minimal sizes
# resize child widgets
'''Set one of the sub-widgets.
Sets the sub-widget in column ``ix`` and row ``iy``. The indices are counted from zero. '''
widget = Widget()
'''Get one of the sub-widgets.
Gets the sub-widget from column ``ix`` and row ``iy``. The indices are counted from zero.'''
return self.grid[iy][ix]
else: gmt.psbasemap('-G0', finish=True, *args, **kwargs) l, b, r, t = gmt.bbox()
text, font=0, font_size=12., angle=0, gmtversion='newest', **kwargs):
else: row = [0, 0, font_size, 0, font, 'BL', text] farg = []
in_rows=[row], finish=True, R=(0, 1, 0, 1), J='x10p', N=True, *farg, **kwargs)
['gs', '-q', '-dNOPAUSE', '-dBATCH', '-r720', '-sDEVICE=bbox', fn], stderr=subprocess.PIPE).communicate()
'''Utility class to turn tables into lines.'''
self.encoding)
self.encoding)
'''File-like object to buffer data.'''
raise ValueError('Cannot read from closed LineStreamChopper.')
pass
0: 'Helvetica', 1: 'Helvetica-Bold', }
'''A thin wrapper to GMT command execution.
A dict ``config`` may be given to override some of the default GMT parameters. The ``version`` argument may be used to select a specific GMT version, which should be used with this GMT instance. The selected version of GMT has to be installed on the system, must be supported by gmtpy and gmtpy must know where to find it.
Each instance of this class is used for the task of producing one PS or PDF output file.
Output of a series of GMT commands is accumulated in memory and can then be saved as PS or PDF file using the :py:meth:`save` method.
GMT commands are accessed as method calls to instances of this class. See the :py:meth:`__getattr__` method for details on how the method's arguments are translated into options and arguments for the GMT command.
Associated with each instance of this class, a temporary directory is created, where temporary files may be created, and which is automatically deleted, when the object is destroyed. The :py:meth:`tempfilename` method may be used to get a random filename in the instance's temporary directory.
Any .gmtdefaults files are ignored. The GMT class uses a fixed set of defaults, which may be altered via an argument to the constructor. If possible, GMT is run in 'isolation mode', which was introduced with GMT version 4.2.2, by setting `GMT_TMPDIR` to the instance's temporary directory. With earlier versions of GMT, problems may arise with parallel execution of more than one GMT instance.
Each instance of the GMT class may pick a specific version of GMT which shall be used, so that, if multiple versions of GMT are installed on the system, different versions of GMT can be used simultaneously such that backward compatibility of the scripts can be maintained.
'''
self, config=None, kontinue=None, version='newest', config_papersize=None, eps_mode=False):
int(config_papersize[0]), int(config_papersize[1]))
else: self.gmt_config['PAPER_MEDIA'] = config_papersize
self.load_unfinished(kontinue) self.needstart = False else:
# GMT isolation mode: works only properly with GMT version >= 4.2.2
return self.installation['version']
return self.gmt_config[key]
return 0
else: default_unit = measure_unit(self.gmt_config).lower()[0] return float(string)/_units[default_unit]
else: return self.to_points(self.gmt_config['LABEL_FONT_SIZE'])
if self.is_gmt5(): return font_tab_rev(self.gmt_config['FONT_LABEL'].split(',')[1]) else: return self.gmt_config['LABEL_FONT']
('#\n# GMT %s Defaults file\n' % self.installation['version']).encode('ascii'))
'''Execute arbitrary GMT command.
See docstring in __getattr__ for details. '''
# check for mutual exclusiveness on input and output possibilities [x for x in [ in_stream, in_filename, in_string, in_columns, in_rows] if x is not None])) if x is not None]))
gmt_config_filename = self.gmt_config_filename if config_override: gmt_config = self.gmt_config.copy() gmt_config.update(config_override) gmt_config_override_filename = pjoin( self.tempdir, 'gmtdefaults_override') self.gen_gmt_config_file( gmt_config_override_filename, gmt_config) gmt_config_filename = gmt_config_override_filename
else: # gmt5 needs override variables as --VAR=value
'PS_CHAR_ENCODING', gmt_config.get('CHAR_ENCODING', 'ISOLatin1+'))
in_rows=in_rows, encoding=encoding))
# convert option arguments to strings raise GmtPyError('Found illegal keyword argument "%s" ' 'while preparing options for command "%s"' % (k, command))
else:
# if not redirecting to an external sink, handle -K -O else:
else:
# run the command else: args = [pjoin(self.installation['bin'], command)]
raise OSError('No such file: %s' % args[0]) # does not seem to work with GMT 5 (and should not be necessary args.append('+'+gmt_config_filename)
stdout=subprocess.PIPE, bufsize=bs, env=self.environ) out_stream.write(p.stdout.read(bs)) else: break
self.keep_temp_dir = True raise GMTError('Command %s returned an error. ' 'While executing command:\n%s' % (command, escape_shell_args(args)))
'''Maps to call self._gmtcommand(command, \\*addargs, \\*\\*kwargs).
Execute arbitrary GMT command.
Run a GMT command and by default append its postscript output to the output file maintained by the GMT instance on which this method is called.
Except for a few keyword arguments listed below, any ``kwargs`` and ``addargs`` are converted into command line options and arguments and passed to the GMT command. Numbers in keyword arguments are converted into strings. E.g. ``S=10`` is translated into ``'-S10'``. Tuples of numbers or strings are converted into strings where the elements of the tuples are separated by slashes '/'. E.g. ``R=(10, 10, 20, 20)`` is translated into ``'-R10/10/20/20'``. Options with a boolean argument are only appended to the GMT command, if their values are True.
If no output redirection is in effect, the -K and -O options are handled by gmtpy and thus should not be specified. Use ``out_discard=True`` if you don't want -K or -O beeing added, but are not interested in the output.
The standard input of the GMT process is fed by data selected with one of the following ``in_*`` keyword arguments:
=============== ======================================================= ``in_stream`` Data is read from an open file like object. ``in_filename`` Data is read from the given file. ``in_string`` String content is dumped to the process. ``in_columns`` A 2D nested iterable whose elements can be accessed as ``in_columns[icolumn][irow]`` is converted into an ascii table, which is fed to the process. ``in_rows`` A 2D nested iterable whos elements can be accessed as ``in_rows[irow][icolumn]`` is converted into an ascii table, which is fed to the process. =============== =======================================================
The standard output of the GMT process may be redirected by one of the following options:
================= ===================================================== ``out_stream`` Output is fed to an open file like object. ``out_filename`` Output is dumped to the given file. ``out_discard`` If True, output is dumped to :file:`/dev/null`. ================= =====================================================
Additional keyword arguments:
===================== ================================================= ``config`` Dict with GMT defaults which override the currently active set of defaults exclusively during this call. ``finish`` If True, the postscript file, which is maintained by the GMT instance is finished, and no further plotting is allowed. ``suppress_defaults`` Suppress appending of the ``'+gmtdefaults'`` option to the command. ===================== =================================================
'''
'''Get filename for temporary file in the private temp directory.
If no ``name`` argument is given, a random name is picked. If ``name`` is given, returns a path ending in that ``name``.'''
[random.choice('abcdefghijklmnopqrstuvwxyz') for i in range(10)])
'''Create and open a file in the private temp directory.'''
fn = self.tempfilename(name) f = open(fn, 'wb') return f, fn
width=None, height=None, size=None, crop_eps_mode=False, psconvert=False):
''' Finish and save figure as PDF, PS or PPM file.
If filename ends with ``'.pdf'`` a PDF file is created by piping the GMT output through :program:`gmtpy-epstopdf`.
If filename ends with ``'.png'`` a PNG file is created by running :program:`gmtpy-epstopdf`, :program:`pdftocairo` and :program:`convert`. ``resolution`` specifies the resolution in DPI for raster file formats. Rasterization is done at a higher resolution if ``oversample`` is set to a value higher than one. The output image size can also be controlled by setting ``width``, ``height`` or ``size`` instead of ``resolution``. When ``size`` is given, the image is scaled so that ``max(width, height) == size``.
The bounding box is set according to the values given in ``bbox``. '''
else: out = sys.stdout
out.write(replace_bbox(bbox, self.output.getvalue())) else:
not self.is_gmt5() and filename.endswith('.eps')):
else:
[pjoin(self.installation['bin'], 'gmt'), 'psconvert', '-Te', '-F%s' % tempfn + '.eps', tempfn, ] + addarg)
else: shutil.move(tempfn, tempfn + '.eps')
gmt_bin = pjoin(self.installation['bin'], 'gmt') subprocess.call([gmt_bin, 'psconvert', tempfn, '-Tf', '-F' + filename]) else: '--outfile=' + filename, tempfn + '.eps']) else: 'gmtpy-epstopdf', '--res=%i' % (resolution * oversample), '--outfile=' + tempfn + '.pdf', tempfn + '.eps'])
tempfn + '.pdf', filename, resolution=resolution, oversample=oversample, size=size, width=width, height=height)
return get_bbox(self.output.getvalue())
'''Get the command log.'''
return self.command_log
def __str__(self): s = '' for com in self.command_log: s += com[0] + "\n " + "\n ".join(com[1:]) + "\n\n" return s
'''Try to get paper size of output postscript file in points.'''
pm = pm[:-1]
else: return get_paper_size(pm)[1], get_paper_size(pm)[0]
w *= _units[uw] h *= _units[uh] else: return h, w
return None, None
'''Get a default layout for the output page.
One of three different layouts is choosen, depending on the `PAPER_MEDIA` setting in the GMT configuration dict.
If `PAPER_MEDIA` ends with a ``'+'`` (EPS output is selected), a :py:class:`FrameLayout` is centered on the page, whose size is controlled by its center widget's size plus the margins of the :py:class:`FrameLayout`.
If `PAPER_MEDIA` indicates, that a custom page size is wanted by starting with ``'Custom_'``, a :py:class:`FrameLayout` is used to fill the complete page. The center widget's size is then controlled by the page's size minus the margins of the :py:class:`FrameLayout`.
In any other case, two FrameLayouts are nested, such that the outer layout attaches a 1 cm (printer) margin around the complete page, and the inner FrameLayout's center widget takes up as much space as possible under the constraint, that an aspect ratio of 1/golden_ratio is preserved.
In any case, a reference to the innermost :py:class:`FrameLayout` instance is returned. The top-level layout can be accessed by calling :py:meth:`Widget.get_parent` on the returned layout. '''
raise GmtPyError("Can't determine page size for layout")
palette_layout = GridLayout(3, 1) spacer = palette_layout.get_widget(1, 0) palette_widget = palette_layout.get_widget(2, 0) spacer.set_horizontal(0.5*cm) palette_widget.set_horizontal(0.5*cm)
inner.set_widget('center', palette_layout) widget = palette_layout else: aspect=1./golden_ratio) mw, mw, mw/golden_ratio, mw/golden_ratio)
mw, mw, mw/golden_ratio, mw/golden_ratio) layout.set_widget('center', palette_layout) else:
inner.set_widget('center', palette_layout) widget = palette_layout else:
'''Use psxy to draw layout; for debugging'''
# corners = layout.get_corners(descend=True) num.zeros(nrects), rects_hei, rects_wid)
# points = num.array(corners, dtype=num.float)
C='ocean', T='%g/%g/%g' % (-nrects, nrects, 1), Z=True, out_filename=cptfile, suppress_defaults=True)
in_columns=prects, C=cptfile, W='1p', S='J', R=(bb[0], bb[2], bb[1], bb[3]), *layout.XYJ())
'space', 'mode', 'approx_ticks', 'limits', 'masking', 'inc', 'snap'):
contour=False, method='surface', zscaler=None, **extra): self.data = data self.cpt = cpt self.tension = tension self.size = size self.contour = contour self.method = method self.zscaler = zscaler self.extra = extra
self, data, size=9, justify='MC', fontno=0, offset=(0, 0), color='black'):
height=15.*cm / golden_ratio, margins=(2.*cm, 2.*cm, 2.*cm, 2.*cm), with_palette=False, palette_offset=0.5*cm, palette_width=None, palette_height=None, zlabeloffset=2*cm, draw_layout=False)
dpd = DensityPlotDef(data, **kwargs) self.density_plot_defs.append(dpd)
self.data_x.append(data) self.symbols_x.append(symbol)
self.data_y.append(data) self.symbols_y.append(symbol)
self.config.update(kwargs)
gmtconfig.update(self.gmtconfig)
version=self.gmtversion, config=gmtconfig, config_papersize='Custom_%ix%i' % (w, h))
widget = layout.get_widget().get_widget(0, 0) spacer = layout.get_widget().get_widget(1, 0) spacer.set_horizontal(conf['palette_offset']) palette_widget = layout.get_widget().get_widget(2, 0) if conf['palette_width'] is not None: palette_widget.set_horizontal(conf['palette_width']) if conf['palette_height'] is not None: palette_widget.set_vertical(conf['palette_height']) widget.set_vertical(h-margins[2]-margins[3]-0.03*cm) return gmt, layout, widget, palette_widget else:
ndims = 3
if dsd.zscaler is None: data_all.append(dsd.data) else: data_all.append(dsd.data[:2])
R = scaler.R() # par = scaler.get_params() rxyj = R + widget.XYJ() innerticks = False for dpd in self.density_plot_defs:
fn_cpt = gmt.tempfilename() + '.cpt'
if dpd.zscaler is not None: s = dpd.zscaler else: s = scaler
gmt.makecpt(C=dpd.cpt, out_filename=fn_cpt, *s.T())
fn_grid = gmt.tempfilename()
fn_mean = gmt.tempfilename()
if dpd.method in ('surface', 'triangulate'): gmt.blockmean(in_columns=dpd.data, I='%i+/%i+' % dpd.size, # noqa out_filename=fn_mean, *R)
if dpd.method == 'surface': gmt.surface( in_filename=fn_mean, T=dpd.tension, G=fn_grid, I='%i+/%i+' % dpd.size, # noqa out_discard=True, *R)
if dpd.method == 'triangulate': gmt.triangulate( in_filename=fn_mean, G=fn_grid, I='%i+/%i+' % dpd.size, # noqa out_discard=True, V=True, *R)
if gmt.is_gmt5(): gmt.grdimage(fn_grid, C=fn_cpt, E='i', n='l', *rxyj)
else: gmt.grdimage(fn_grid, C=fn_cpt, E='i', S='l', *rxyj)
if dpd.contour: gmt.grdcontour(fn_grid, C=fn_cpt, W='0.5p,black', *rxyj) innerticks = '0.5p,black'
os.remove(fn_grid) os.remove(fn_mean)
if dpd.method == 'fillcontour': extra = dict(C=fn_cpt) extra.update(dpd.extra) gmt.pscontour(in_columns=dpd.data, I=True, *rxyj, **extra) # noqa
if dpd.method == 'contour': extra = dict(W='0.5p,black', C=fn_cpt) extra.update(dpd.extra) gmt.pscontour(in_columns=dpd.data, *rxyj, **extra)
return fn_cpt, innerticks
gmt.psxy(in_columns=dat, *(sym.split() + scaler_x.R() + widget.JXY()))
gmt.psxy(in_columns=dat, *(sym.split() + scaler_y.R() + widget.JXY()))
in_rows=[(x, y, text)], F='+f%gp,%s,%s+a%g+j%s' % ( size, fontno, color, angle, justify), D='%gp/%gp' % td.offset, *rxyj) else: gmt.pstext( in_rows=[(x, y, size, angle, fontno, justify, text)], D='%gp/%gp' % td.offset, *rxyj)
aspect = aspect_for_projection( gmt.installation['version'], *(widget.J() + scaler.R()))
widget.set_aspect(aspect)
gmt.draw_layout(layout) cptfile, innerticks = self.draw_density(gmt, widget, scaler)
nice_palette(gmt, palette_widget, scaler, cptfile, innerticks=innerticks, zlabeloffset=conf['zlabeloffset'])
self.set_defaults(xmode='min-max')
widget['J'] = '-JX%(width)gpl/%(height)gp' scaler['B'] = '-B2:%(xlabel)s:/%(yinc)g:%(ylabel)s:WSen'
self.set_defaults(ymode='min-max')
widget['J'] = '-JX%(width)gp/%(height)gpl' scaler['B'] = '-B%(xinc)g:%(xlabel)s:/2:%(ylabel)s:WSen'
self.set_defaults(mode='min-max')
widget['J'] = '-JX%(width)gpl/%(height)gpl' scaler['B'] = '-B2:%(xlabel)s:/2:%(ylabel)s:WSen'
Simple.__init__(self, *args, **kwargs) self.fixate_widget_aspect = True
self.set_defaults( height=15.*cm, width=15.*cm, xmode='off', xlimits=(0., 360.), xinc=45.)
widget['J'] = '-JPa%(width)gp'
scaler['B'] = '-B%(xinc)g:%(xlabel)s:/%(yinc)g:%(ylabel)s:N'
Simple.__init__(self, *args, **kwargs) self.fixate_widget_aspect = True
self.set_defaults(xmode='min-max', ymode='min-max')
par = scaler.get_params() lon0 = (par['xmin'] + par['xmax'])/2. lat0 = (par['ymin'] + par['ymax'])/2. sll = '%g/%g' % (lon0, lat0) widget['J'] = '-JM' + sll + '/%(width)gp' scaler['B'] = \ '-B%(xinc)gg%(xinc)g:%(xlabel)s:/%(yinc)gg%(yinc)g:%(ylabel)s:WSen'
innerticks=True):
par = scaleguru.get_params() par_ax = scaleguru.get_params(ax_projection=True) nz_palette = int(widget.height()/inch * 300) px = num.zeros(nz_palette*2) px[1::2] += 1 pz = num.linspace(par['zmin'], par['zmax'], nz_palette).repeat(2) pdz = pz[2]-pz[0] palgrdfile = gmt.tempfilename() pal_r = (0, 1, par['zmin'], par['zmax']) pal_ax_r = (0, 1, par_ax['zmin'], par_ax['zmax']) gmt.xyz2grd( G=palgrdfile, R=pal_r, I=(1, pdz), in_columns=(px, pz, pz), # noqa out_discard=True)
gmt.grdimage(palgrdfile, R=pal_r, C=cptfile, *widget.JXY()) if isinstance(innerticks, str): tickpen = innerticks gmt.grdcontour(palgrdfile, W=tickpen, R=pal_r, C=cptfile, *widget.JXY())
negpalwid = '%gp' % -widget.width() if not isinstance(innerticks, str) and innerticks: ticklen = negpalwid else: ticklen = '0p'
TICK_LENGTH_PARAM = 'MAP_TICK_LENGTH' if gmt.is_gmt5() else 'TICK_LENGTH' gmt.psbasemap( R=pal_ax_r, B='4::/%(zinc)g::nsw' % par_ax, config={TICK_LENGTH_PARAM: ticklen}, *widget.JXY())
if innerticks: gmt.psbasemap( R=pal_ax_r, B='4::/%(zinc)g::E' % par_ax, config={TICK_LENGTH_PARAM: '0p'}, *widget.JXY()) else: gmt.psbasemap(R=pal_ax_r, B='4::/%(zinc)g::E' % par_ax, *widget.JXY())
if par_ax['zlabel']: label_font = gmt.label_font() label_font_size = gmt.label_font_size() label_offset = zlabeloffset gmt.pstext( R=(0, 1, 0, 2), D="%gp/0p" % label_offset, N=True, in_rows=[(1, 1, label_font_size, -90, label_font, 'CB', par_ax['zlabel'])], *widget.JXY()) |