<s> """<STR_LIT>""" <EOL> import matplotlib . pyplot as plt <EOL> from netCDF4 import num2date <EOL> from . . exceptions import _deprecated_alias <EOL> from . . config import get_field_colormap , get_field_limits <EOL> from . . core import transforms as _transforms <EOL> radar_coords_to_cart = _deprecated_alias ( <EOL> _transforms . antenna_to_cartesian , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> sweep_coords_to_cart = _deprecated_alias ( <EOL> _transforms . antenna_vectors_to_cartesian , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> def parse_ax ( ax ) : <EOL> """<STR_LIT>""" <EOL> if ax is None : <EOL> ax = plt . gca ( ) <EOL> return ax <EOL> def parse_ax_fig ( ax , fig ) : <EOL> """<STR_LIT>""" <EOL> if ax is None : <EOL> ax = plt . gca ( ) <EOL> if fig is None : <EOL> fig = plt . gcf ( ) <EOL> return ax , fig <EOL> def parse_norm_vmin_vmax ( norm , container , field , vmin , vmax ) : <EOL> """<STR_LIT>""" <EOL> if norm is None : <EOL> vmin , vmax = parse_vmin_vmax ( container , field , vmin , vmax ) <EOL> else : <EOL> vmin = None <EOL> vmax = None <EOL> return norm , vmin , vmax <EOL> def parse_cmap ( cmap , field = None ) : <EOL> """<STR_LIT>""" <EOL> if cmap is None : <EOL> cmap = get_field_colormap ( field ) <EOL> return cmap <EOL> def parse_vmin_vmax ( container , field , vmin , vmax ) : <EOL> """<STR_LIT>""" <EOL> field_dict = container . fields [ field ] <EOL> field_default_vmin , field_default_vmax = get_field_limits ( field ) <EOL> if vmin is None : <EOL> if '<STR_LIT>' in field_dict : <EOL> vmin = field_dict [ '<STR_LIT>' ] <EOL> else : <EOL> vmin = field_default_vmin <EOL> if vmax is None : <EOL> if '<STR_LIT>' in field_dict : <EOL> vmax = field_dict [ '<STR_LIT>' ] <EOL> else : <EOL> vmax = field_default_vmax <EOL> return vmin , vmax <EOL> def parse_lon_lat ( grid , lon , lat ) : <EOL> """<STR_LIT>""" <EOL> if lat is None : <EOL> lat = grid . origin_latitude [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] <EOL> if lon is None : <EOL> lon = grid . origin_longitude [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] <EOL> return lon , lat <EOL> def generate_colorbar_label ( standard_name , units ) : <EOL> """<STR_LIT>""" <EOL> return standard_name . replace ( '<STR_LIT:_>' , '<STR_LIT:U+0020>' ) + '<STR_LIT>' + units + '<STR_LIT:)>' <EOL> def generate_field_name ( container , field ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in container . fields [ field ] : <EOL> field_name = container . fields [ field ] [ '<STR_LIT>' ] <EOL> elif '<STR_LIT>' in container . fields [ field ] : <EOL> field_name = container . fields [ field ] [ '<STR_LIT>' ] <EOL> else : <EOL> field_name = str ( field ) <EOL> field_name = field_name . replace ( '<STR_LIT:_>' , '<STR_LIT:U+0020>' ) <EOL> field_name = field_name [ <NUM_LIT:0> ] . upper ( ) + field_name [ <NUM_LIT:1> : ] <EOL> return field_name <EOL> def generate_radar_name ( radar ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in radar . metadata : <EOL> return radar . metadata [ '<STR_LIT>' ] <EOL> else : <EOL> return '<STR_LIT>' <EOL> def generate_grid_name ( grid ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in grid . metadata : <EOL> return grid . metadata [ '<STR_LIT>' ] <EOL> else : <EOL> return '<STR_LIT>' <EOL> def generate_radar_time_begin ( radar ) : <EOL> """<STR_LIT>""" <EOL> times = radar . time [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] <EOL> units = radar . time [ '<STR_LIT>' ] <EOL> calendar = radar . time [ '<STR_LIT>' ] <EOL> return num2date ( times , units , calendar ) <EOL> def generate_grid_time_begin ( grid ) : <EOL> """<STR_LIT>""" <EOL> times = grid . time [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] <EOL> units = grid . time [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in grid . time : <EOL> calendar = grid . time [ '<STR_LIT>' ] <EOL> else : <EOL> calendar = '<STR_LIT>' <EOL> return num2date ( times , units , calendar ) <EOL> def generate_filename ( radar , field , sweep , ext = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> name_s = generate_radar_name ( radar ) . replace ( '<STR_LIT:U+0020>' , '<STR_LIT:_>' ) <EOL> field_s = field . replace ( '<STR_LIT:U+0020>' , '<STR_LIT:_>' ) <EOL> time_s = generate_radar_time_begin ( radar ) . strftime ( '<STR_LIT>' ) <EOL> sweep_s = str ( sweep ) . zfill ( <NUM_LIT:2> ) <EOL> return '<STR_LIT>' % ( name_s , field_s , sweep_s , time_s , ext ) <EOL> def generate_grid_filename ( grid , field , level , ext = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> name_s = generate_grid_name ( grid ) . replace ( '<STR_LIT:U+0020>' , '<STR_LIT:_>' ) <EOL> field_s = field . replace ( '<STR_LIT:U+0020>' , '<STR_LIT:_>' ) <EOL> time_s = generate_grid_time_begin ( grid ) . strftime ( '<STR_LIT>' ) <EOL> level_s = str ( level ) . zfill ( <NUM_LIT:2> ) <EOL> return '<STR_LIT>' % ( name_s , field_s , level_s , time_s , ext ) <EOL> def generate_title ( radar , field , sweep ) : <EOL> """<STR_LIT>""" <EOL> time_str = generate_radar_time_begin ( radar ) . isoformat ( ) + '<STR_LIT>' <EOL> fixed_angle = radar . fixed_angle [ '<STR_LIT:data>' ] [ sweep ] <EOL> l1 = "<STR_LIT>" % ( generate_radar_name ( radar ) , fixed_angle , <EOL> time_str ) <EOL> field_name = generate_field_name ( radar , field ) <EOL> return l1 + '<STR_LIT:\n>' + field_name <EOL> def generate_grid_title ( grid , field , level ) : <EOL> """<STR_LIT>""" <EOL> time_str = generate_grid_time_begin ( grid ) . isoformat ( ) + '<STR_LIT>' <EOL> height = grid . z [ '<STR_LIT:data>' ] [ level ] / <NUM_LIT> <EOL> l1 = "<STR_LIT>" % ( generate_grid_name ( grid ) , height , <EOL> time_str ) <EOL> field_name = generate_field_name ( grid , field ) <EOL> return l1 + '<STR_LIT:\n>' + field_name <EOL> def generate_longitudinal_level_title ( grid , field , level ) : <EOL> """<STR_LIT>""" <EOL> time_str = generate_grid_time_begin ( grid ) . isoformat ( ) + '<STR_LIT>' <EOL> disp = grid . x [ '<STR_LIT:data>' ] [ level ] / <NUM_LIT> <EOL> if disp >= <NUM_LIT:0> : <EOL> direction = "<STR_LIT>" <EOL> else : <EOL> direction = "<STR_LIT>" <EOL> disp = - disp <EOL> l1 = "<STR_LIT>" % ( generate_grid_name ( grid ) , disp , <EOL> direction , time_str ) <EOL> field_name = generate_field_name ( grid , field ) <EOL> return l1 + '<STR_LIT:\n>' + field_name <EOL> def generate_latitudinal_level_title ( grid , field , level ) : <EOL> """<STR_LIT>""" <EOL> time_str = generate_grid_time_begin ( grid ) . isoformat ( ) + '<STR_LIT>' <EOL> disp = grid . y [ '<STR_LIT:data>' ] [ level ] / <NUM_LIT> <EOL> if disp >= <NUM_LIT:0> : <EOL> direction = "<STR_LIT>" <EOL> else : <EOL> direction = "<STR_LIT>" <EOL> disp = - disp <EOL> l1 = "<STR_LIT>" % ( generate_grid_name ( grid ) , disp , <EOL> direction , time_str ) <EOL> field_name = generate_field_name ( grid , field ) <EOL> return l1 + '<STR_LIT:\n>' + field_name <EOL> def generate_vpt_title ( radar , field ) : <EOL> """<STR_LIT>""" <EOL> time_str = generate_radar_time_begin ( radar ) . isoformat ( ) + '<STR_LIT>' <EOL> l1 = "<STR_LIT>" % ( generate_radar_name ( radar ) , time_str ) <EOL> field_name = generate_field_name ( radar , field ) <EOL> return l1 + '<STR_LIT:\n>' + field_name <EOL> def generate_ray_title ( radar , field , ray ) : <EOL> """<STR_LIT>""" <EOL> time_str = generate_radar_time_begin ( radar ) . isoformat ( ) + '<STR_LIT>' <EOL> l1 = "<STR_LIT>" % ( generate_radar_name ( radar ) , time_str ) <EOL> azim = radar . azimuth [ '<STR_LIT:data>' ] [ ray ] <EOL> elev = radar . elevation [ '<STR_LIT:data>' ] [ ray ] <EOL> l2 = "<STR_LIT>" % ( ray , azim , elev ) <EOL> field_name = generate_field_name ( radar , field ) <EOL> return l1 + '<STR_LIT:\n>' + l2 + '<STR_LIT:\n>' + field_name <EOL> def generate_az_rhi_title ( radar , field , azimuth ) : <EOL> """<STR_LIT>""" <EOL> time_str = generate_radar_time_begin ( radar ) . isoformat ( ) + '<STR_LIT>' <EOL> l1 = "<STR_LIT>" % ( generate_radar_name ( radar ) , time_str ) <EOL> l2 = "<STR_LIT>" % azimuth <EOL> field_name = generate_field_name ( radar , field ) <EOL> return l1 + '<STR_LIT:\n>' + l2 + '<STR_LIT:\n>' + field_name <EOL> def set_limits ( xlim = None , ylim = None , ax = None ) : <EOL> """<STR_LIT>""" <EOL> if ax is None : <EOL> ax = plt . gca ( ) <EOL> if ylim is not None : <EOL> ax . set_ylim ( ylim ) <EOL> if xlim is not None : <EOL> ax . set_xlim ( xlim ) </s>
