Esempio n. 1
0
def daily_timseries( ts ):
  fig = Figure( ( 2.56, 2.56 ), 300 )
  canvas = FigureCanvas(fig)
  ax = fig.add_axes((0,0,1,1))

  ax.set_ylim( [ 0 , 500 ] )

  preferspan = ax.axhspan( SAFE[0], SAFE[1],
                           facecolor='g', alpha=0.2,
                           edgecolor = '#003333',
                           linewidth=1
                         )
  # XXX: gets a list of days.
  timestamps = glucose.get_days( ts.time )
  halfday = dates.relativedelta( hours=12 )
  soleday = dates.relativedelta( days=1 )
  xmin, xmax = ( timestamps[ 0 ], timestamps[ 1 ] + soleday )
  ax.set_xlim( [ xmin, xmax ] )
  #fig.autofmt_xdate( )
  #plot_glucose_stems( ax, ts )
  plt.setp(ax.get_xminorticklabels(), visible=False )
  plt.setp(ax.get_xmajorticklabels(), visible=False )
  plt.setp(ax.get_ymajorticklabels(), visible=False )
  plt.setp(ax.get_yminorticklabels(), visible=False )

  ax.grid(True)

  xmin, xmax = ax.get_xlim( )
  log.info( pformat( {
    'xlim': [ dates.num2date( xmin ), dates.num2date( xmax ) ],
  } ) )

  return canvas
Esempio n. 2
0
def daily_timseries(ts):
    fig = Figure((2.56, 2.56), 300)
    canvas = FigureCanvas(fig)
    ax = fig.add_axes((0, 0, 1, 1))

    ax.set_ylim([0, 500])

    preferspan = ax.axhspan(SAFE[0],
                            SAFE[1],
                            facecolor='g',
                            alpha=0.2,
                            edgecolor='#003333',
                            linewidth=1)
    # XXX: gets a list of days.
    timestamps = glucose.get_days(ts.time)
    halfday = dates.relativedelta(hours=12)
    soleday = dates.relativedelta(days=1)
    xmin, xmax = (timestamps[0], timestamps[1] + soleday)
    ax.set_xlim([xmin, xmax])
    #fig.autofmt_xdate( )
    #plot_glucose_stems( ax, ts )
    plt.setp(ax.get_xminorticklabels(), visible=False)
    plt.setp(ax.get_xmajorticklabels(), visible=False)
    plt.setp(ax.get_ymajorticklabels(), visible=False)
    plt.setp(ax.get_yminorticklabels(), visible=False)

    ax.grid(True)

    xmin, xmax = ax.get_xlim()
    log.info(pformat({
        'xlim': [dates.num2date(xmin),
                 dates.num2date(xmax)],
    }))

    return canvas
Esempio n. 3
0
def grid( data ):
  fig = Figure( ( 2.56, 2.56 ), 300 )
  canvas = FigureCanvas(fig)
  d = data.time[ 0 ]
  day = glucose.glucose_for_day( data, d )
  days = glucose.get_days( data.time )
  name = str( d )

  ax = fig.add_axes((.5,0,1,1))
  xmin, xmax = days[ 0 ], days[ -1 ]
  ax.set_xlim( [ xmin, xmax ] )
  ax.grid(True)
  safe_span(ax)
  one = ax.text( .50, .50, name,
           horizontalalignment='center',
           verticalalignment='center',
           transform = ax.transAxes )
  one.remove( )
  log.info( pformat( one ) )
  ax.text( .60, .60, name + "two",
           horizontalalignment='center',
           verticalalignment='center',
           transform = ax.transAxes )
  set_daily_locators( ax )
  config_yaxis( ax )

  return canvas
Esempio n. 4
0
def tiled_axis( ts, filename=None ):
  fig = Figure( ( 2.56 * 4, 2.56 * 4), 300 )
  canvas = FigureCanvas(fig)
  #ax = fig.add_subplot(111)

  grid = ImageGrid(fig, 111, # similar to subplot(111)
                  nrows_ncols = (3, 1),
                  axes_pad = 0.5,
                  add_all=True,
                  label_mode = "L",
                  )
  # pad half a day so that major ticks show up in the middle, not on the edges
  delta = dates.relativedelta( days=2, hours=12 )
  # XXX: gets a list of days.
  timestamps = glucose.get_days( ts.time )
  xmin, xmax = ( timestamps[  0 ] - delta,
                 timestamps[ -1 ] + delta )

  fig.autofmt_xdate( )

  def make_plot( ax, limit ):

    preferspan = ax.axhspan( SAFE[0], SAFE[1],
                             facecolor='g', alpha=0.2,
                             edgecolor = '#003333',
                             linewidth=1
                           )
  def draw_title( ax, limit ):
    ax.set_title('glucose history')

  #ax.set_ylabel('glucose mm/dL')
  return canvas
Esempio n. 5
0
def giant_timeseries( ts ):

  fig = Figure( ( 20.3, 3.5 ), 300 )
  canvas = FigureCanvas(fig)

  ax = fig.add_subplot(111)


  preferspan = ax.axhspan( SAFE[0], SAFE[1],
                           facecolor='g', alpha=0.35,
                           edgecolor = '#003333',
                           linewidth=1
                         )

  # visualize glucose using stems
  # XXX: gets a list of days.
  timestamps = glucose.get_days( ts.time )
  delta = dates.relativedelta( days=1, hours=12 )
  oneday = dates.relativedelta( days=1 )
  xmin, xmax = ( timestamps[ 0 ], timestamps[ -1 ] )
  
  
  ax.set_xlim( [ xmin, xmax ] )
  markers, stems, baselines = ax.stem( ts.time, ts.value,
           linefmt='b:' )
  plt.setp( markers, color='red', linewidth=.5,
            marker='o'
          )
  plt.setp( baselines, marker='None' ) 
  fig.autofmt_xdate( )

  ax.set_title('glucose history')
  ax.grid(True)
  ax.set_xlabel('time')

  majorLocator   = dates.DayLocator( )
  majorFormatter = dates.AutoDateFormatter( majorLocator )

  minorLocator   = dates.HourLocator( interval=6 )
  minorFormatter = dates.AutoDateFormatter( minorLocator )

  ax.xaxis.set_major_locator(majorLocator)
  ax.xaxis.set_major_formatter(majorFormatter)

  ax.xaxis.set_minor_locator(minorLocator)
  ax.xaxis.set_minor_formatter(minorFormatter)

  labels = ax.get_xminorticklabels()
  plt.setp(labels, rotation=30, fontsize='small')
  plt.setp(ax.get_xmajorticklabels(), rotation=30, fontsize='medium')


  xmin, xmax = ax.get_xlim( )
  log.info( pformat( {
    'xlim': [ dates.num2date( xmin ), dates.num2date( xmax ) ],
  } ) )

  ax.set_ylabel('glucose mm/dL')
  return canvas
Esempio n. 6
0
def giant_timeseries(ts):

    fig = Figure((20.3, 3.5), 300)
    canvas = FigureCanvas(fig)

    ax = fig.add_subplot(111)

    preferspan = ax.axhspan(SAFE[0],
                            SAFE[1],
                            facecolor='g',
                            alpha=0.35,
                            edgecolor='#003333',
                            linewidth=1)

    # visualize glucose using stems
    # XXX: gets a list of days.
    timestamps = glucose.get_days(ts.time)
    delta = dates.relativedelta(days=1, hours=12)
    oneday = dates.relativedelta(days=1)
    xmin, xmax = (timestamps[0], timestamps[-1])

    ax.set_xlim([xmin, xmax])
    markers, stems, baselines = ax.stem(ts.time, ts.value, linefmt='b:')
    plt.setp(markers, color='red', linewidth=.5, marker='o')
    plt.setp(baselines, marker='None')
    fig.autofmt_xdate()

    ax.set_title('glucose history')
    ax.grid(True)
    ax.set_xlabel('time')

    majorLocator = dates.DayLocator()
    majorFormatter = dates.AutoDateFormatter(majorLocator)

    minorLocator = dates.HourLocator(interval=6)
    minorFormatter = dates.AutoDateFormatter(minorLocator)

    ax.xaxis.set_major_locator(majorLocator)
    ax.xaxis.set_major_formatter(majorFormatter)

    ax.xaxis.set_minor_locator(minorLocator)
    ax.xaxis.set_minor_formatter(minorFormatter)

    labels = ax.get_xminorticklabels()
    plt.setp(labels, rotation=30, fontsize='small')
    plt.setp(ax.get_xmajorticklabels(), rotation=30, fontsize='medium')

    xmin, xmax = ax.get_xlim()
    log.info(pformat({
        'xlim': [dates.num2date(xmin),
                 dates.num2date(xmax)],
    }))

    ax.set_ylabel('glucose mm/dL')
    return canvas
Esempio n. 7
0
def daily_axis( ts ):
  # http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html
  fig = Figure( ( 2.56, 2.56 ), 300 )
  canvas = FigureCanvas(fig)

  ax = fig.add_subplot(111)
  safe_span(ax)
  timestamps = glucose.get_days( ts.time )
  xmin, xmax = timestamps[ 0 ], timestamps[ -1 ]
  ax.set_xlim( [ xmin, xmax ] )
  ax.set_ylim( [ ts.value.min( ) *.85 , 600 ] )
  log.info( pformat( timestamps ) )
  #fig.autofmt_xdate( )

  ax.grid(True)

  return canvas
Esempio n. 8
0
def daily_axis( ts ):
  # http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html
  fig = Figure( ( 2.56, 2.56 ), 300 )
  canvas = FigureCanvas(fig)

  ax = fig.add_subplot(111)

  preferspan = ax.axhspan( SAFE[0], SAFE[1],
                           facecolor='g', alpha=0.2,
                           edgecolor = '#003333',
                           linewidth=1
                         )
  timestamps = glucose.get_days( ts.time )
  xmin, xmax = timestamps[ 0 ], timestamps[ -1 ]
  ax.set_xlim( [ xmin, xmax ] )
  ax.set_ylim( [ ts.value.min( ) *.85 , 600 ] )
  log.info( pformat( timestamps ) )
  #fig.autofmt_xdate( )

  ax.grid(True)

  return canvas
Esempio n. 9
0
def daily_axis(ts):
    # http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/users/overview.html
    fig = Figure((2.56, 2.56), 300)
    canvas = FigureCanvas(fig)

    ax = fig.add_subplot(111)

    preferspan = ax.axhspan(SAFE[0],
                            SAFE[1],
                            facecolor='g',
                            alpha=0.2,
                            edgecolor='#003333',
                            linewidth=1)
    timestamps = glucose.get_days(ts.time)
    xmin, xmax = timestamps[0], timestamps[-1]
    ax.set_xlim([xmin, xmax])
    ax.set_ylim([ts.value.min() * .85, 600])
    log.info(pformat(timestamps))
    #fig.autofmt_xdate( )

    ax.grid(True)

    return canvas
Esempio n. 10
0
def tiled_axis( ts, filename=None ):
  fig = Figure( ( 2.56 * 4, 2.56 * 4), 300 )
  canvas = FigureCanvas(fig)
  #ax = fig.add_subplot(111)

  grid = ImageGrid(fig, 111, # similar to subplot(111)
                  nrows_ncols = (3, 1),
                  axes_pad = 0.5,
                  add_all=True,
                  label_mode = "L",
                  )
  # pad half a day so that major ticks show up in the middle, not on the edges
  delta = dates.relativedelta( days=2, hours=12 )
  # XXX: gets a list of days.
  timestamps = glucose.get_days( ts.time )
  xmin, xmax = ( timestamps[  0 ] - delta,
                 timestamps[ -1 ] + delta )

  fig.autofmt_xdate( )

  def make_plot( ax, limit ):

    preferspan = ax.axhspan( SAFE[0], SAFE[1],
                             facecolor='g', alpha=0.2,
                             edgecolor = '#003333',
                             linewidth=1
                           )
  def draw_glucose( ax, limit ):
    xmin, xmax = limit
    # visualize glucose using stems
    ax.set_xlim( [ xmin, xmax ] )
    markers, stems, baselines = ax.stem( ts.time, ts.value,
             linefmt='b:' )
    plt.setp( markers, color='red', linewidth=.5,
              marker='o'
            )
    plt.setp( baselines, marker='None' ) 

  def draw_title( ax, limit ):
    ax.set_title('glucose history')

  def get_axis( ax, limit ):
    xmin, xmax = limit
    ax.set_xlim( [ xmin, xmax ] )

    ax.grid(True)
    #ax.set_ylim( [ ts.value.min( ) *.85 , 600 ] )
    #ax.set_xlabel('time')

    majorLocator   = dates.DayLocator( )
    majorFormatter = dates.AutoDateFormatter( majorLocator )

    minorLocator   = dates.HourLocator( interval=6 )
    minorFormatter = dates.AutoDateFormatter( minorLocator )

    #ax.xaxis.set_major_locator(majorLocator)
    #ax.xaxis.set_major_formatter(majorFormatter)

    ax.xaxis.set_minor_locator(minorLocator)
    ax.xaxis.set_minor_formatter(minorFormatter)

    labels = ax.get_xminorticklabels()
    plt.setp(labels, rotation=30, fontsize='small')
    plt.setp(ax.get_xmajorticklabels(), rotation=30, fontsize='medium')

    xmin, xmax = ax.get_xlim( )
    
    log.info( pformat( {
      'xlim': [ dates.num2date( xmin ), dates.num2date( xmax ) ],
      'xticks': dates.num2date( ax.get_xticks( ) ),
    } ) )

  for i, day in enumerate(timestamps):
    ax = grid[i]
    get_axis( ax, [ day, day + delta ] )
    name = '%s-%d.png' % ( day.isoformat( ), i )
    #fig.savefig( name )
    canvas.print_figure(name)
    # fig.clf()
    #make_plot( ax, 

  #ax.set_ylabel('glucose mm/dL')
  return canvas
Esempio n. 11
0
def tiled_axis(ts, filename=None):
    fig = Figure((2.56 * 4, 2.56 * 4), 300)
    canvas = FigureCanvas(fig)
    #ax = fig.add_subplot(111)

    grid = ImageGrid(
        fig,
        111,  # similar to subplot(111)
        nrows_ncols=(3, 1),
        axes_pad=0.5,
        add_all=True,
        label_mode="L",
    )
    # pad half a day so that major ticks show up in the middle, not on the edges
    delta = dates.relativedelta(days=2, hours=12)
    # XXX: gets a list of days.
    timestamps = glucose.get_days(ts.time)
    xmin, xmax = (timestamps[0] - delta, timestamps[-1] + delta)

    fig.autofmt_xdate()

    def make_plot(ax, limit):

        preferspan = ax.axhspan(SAFE[0],
                                SAFE[1],
                                facecolor='g',
                                alpha=0.2,
                                edgecolor='#003333',
                                linewidth=1)

    def draw_glucose(ax, limit):
        xmin, xmax = limit
        # visualize glucose using stems
        ax.set_xlim([xmin, xmax])
        markers, stems, baselines = ax.stem(ts.time, ts.value, linefmt='b:')
        plt.setp(markers, color='red', linewidth=.5, marker='o')
        plt.setp(baselines, marker='None')

    def draw_title(ax, limit):
        ax.set_title('glucose history')

    def get_axis(ax, limit):
        xmin, xmax = limit
        ax.set_xlim([xmin, xmax])

        ax.grid(True)
        #ax.set_ylim( [ ts.value.min( ) *.85 , 600 ] )
        #ax.set_xlabel('time')

        majorLocator = dates.DayLocator()
        majorFormatter = dates.AutoDateFormatter(majorLocator)

        minorLocator = dates.HourLocator(interval=6)
        minorFormatter = dates.AutoDateFormatter(minorLocator)

        #ax.xaxis.set_major_locator(majorLocator)
        #ax.xaxis.set_major_formatter(majorFormatter)

        ax.xaxis.set_minor_locator(minorLocator)
        ax.xaxis.set_minor_formatter(minorFormatter)

        labels = ax.get_xminorticklabels()
        plt.setp(labels, rotation=30, fontsize='small')
        plt.setp(ax.get_xmajorticklabels(), rotation=30, fontsize='medium')

        xmin, xmax = ax.get_xlim()

        log.info(
            pformat({
                'xlim': [dates.num2date(xmin),
                         dates.num2date(xmax)],
                'xticks': dates.num2date(ax.get_xticks()),
            }))

    for i, day in enumerate(timestamps):
        ax = grid[i]
        get_axis(ax, [day, day + delta])
        name = '%s-%d.png' % (day.isoformat(), i)
        #fig.savefig( name )
        canvas.print_figure(name)
        # fig.clf()
        #make_plot( ax,

    #ax.set_ylabel('glucose mm/dL')
    return canvas
Esempio n. 12
0
def day_ticks( ):
  pass


if __name__ == '__main__':
  print "Generate a chart of a timeseries."

  parser = get_opt_parser( )
  options, args = parser.parse_args( sys.argv )
  infile, outfile = args[ 1 ], args[ 2 ]
  if infile == '-':
    infile = sys.stdin

  outfile = os.path.join(options.prefix, outfile)
  log.info( 'input: %s'  % infile )
  log.info( 'saving: %s' % outfile )
  data = get_series( infile )

  days= glucose.get_days( data.time )
  for day in days:
    records = glucose.glucose_for_day( data, day )
    n = day.strftime( '%Y-%m-%d' )
    
  canvas = y_axis_panel( )
  #canvas.print_png(outfile, transparent=True)
  #canvas.print_figure( outfile, transparent=True )
  canvas.figure.savefig( outfile, transparent=True)

#####
# EOF