Code Monkey home page Code Monkey logo

Comments (5)

AdamTheisen avatar AdamTheisen commented on May 31, 2024

@ajsockol can you post the code used to create the first plot?

from act.

ajsockol avatar ajsockol commented on May 31, 2024
# Import necessary standard libraries
from os import environ
import datetime as dt
import astral, act, pathlib
from dqlib.io.data import read_arm_data_act
from dqlib.utils.utils import DatastreamParser, string_dates
from dqlib.io.image import save_plot

def plot_module(run_parameters, ds_object, days=0):

    #Get all the file parameters and metadata needed for processing

    #Get AMC Data
    filename = run_parameters['filename']
    params = DatastreamParser(filename)
    date = params.date
    datastream = params.datastream_standard
    site = params.site
    platform = params.datastream_class
    facility = params.facility
    level = params.level
    data_path = run_parameters['base_data_path']

    #Sets default x-range to one day
    xrng = [(dt.datetime.strptime(date,'%Y%m%d') -
         dt.timedelta(days=days)),
        (dt.datetime.strptime(date,'%Y%m%d') +
         dt.timedelta(days=1))]

    #If keyword day is > 0, then weekly plots are made
    if days > 0:
        sdate, edate = tuple(string_dates(xrng, format='full'))
        ds_object = read_arm_data_act(
            datastream, startdate=sdate, enddate=edate,
            basepath=data_path)
        plotname = 'SRG_weekly'
    else:
        plotname = 'SRG_daily'

    # ----------------------------------
    # Plot data
    # ----------------------------------

    #Make SRG Plots

    #Create figure and set size by multiplying figheight
    #by the number of figures to plot from subplot_shape
    figwidth = 10  # width of figure in pixels. 9 = 900 pixels
    figheight = 3  # height of figure in pixels. 3 = 300 pixels
    subplot_shape = (3, ) #Number of plots in figure

    #Use ACT time series display
    display = act.plotting.TimeSeriesDisplay(
        {datastream:ds_object}, subplot_shape=subplot_shape,
        figsize=(figwidth, subplot_shape[0]*figheight))
    display.fig.tight_layout()
    display.fig.subplots_adjust(left=0.1,right=0.85,bottom=0.08,
        top=0.95,hspace=0.3)

    var_names = ['battery_voltage_min','panel_temperature','siphon_rain_gauge_adc']
    subplot_titles = ['Minimum Battery Voltage','Panel Temperature',
        'Instantaneous Precipitation Amount of Siphon Gauge']
    subplot_indices = [0,1,2]

    for ii, var in enumerate(var_names):
        subplot_index = subplot_indices[ii]
        display.plot(var, subplot_index=(subplot_index, ), label=var)
        leg2 = display.axes[subplot_index].legend(loc='center left', bbox_to_anchor=(0.99, 0.5),prop={'size':8},
        frameon=False, markerscale=0, handlelength=0)
    for line, text in zip(leg2.get_lines(), leg2.get_texts()):
        text.set_color(line.get_color())
    display.axes[subplot_index].autoscale(tight=False,axis='y')
    display.axes[subplot_index].set_xlim(xrng)
    if days > 0:
        display.axes[subplot_index].set_title(datastream + ' ' + subplot_titles[subplot_index] + ' from ' + sdate + ' to ' + date)
    else:
        display.axes[subplot_index].set_title(datastream + ' ' + subplot_titles[subplot_index] + ' on ' + date)

    try:
        display.day_night_background(datastream, subplot_index=(subplot_index, ))
    except (AttributeError, ValueError, astral.AstralError):
        pass

    #Create and save plots as png files
    imagename = '.'.join([datastream,plotname,date,'png'])
    imagename = pathlib.Path(environ['DQPLOT_DATA'], site, site+platform,
        date, imagename)
    save_plot(display.fig, imagename=imagename, run_parameters=run_parameters)

from act.

AdamTheisen avatar AdamTheisen commented on May 31, 2024

@ajsockol I think I figured it out. The data are first plotting for 1-2 days, so the x-format is based on those 2 days. You then adjust the xrng after the plotting and don't adjust the format. 2 options

  1. add the following
    myFmt = common.get_date_format(days)
    display.axes[subplot_index].xaxis.set_major_formatter(myFmt)

  2. Pass your xrng to the plot call using time_rng that was added at some point.

    display.plot('battery_voltage_min', time_rng=xrng)

Option number 2 is much simpler it looks like.

from act.

AdamTheisen avatar AdamTheisen commented on May 31, 2024

option_2

from act.

ajsockol avatar ajsockol commented on May 31, 2024

@AdamTheisen Thanks! I think I fixed it. All good now. We can probably close this Issue out.

from act.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.