GCEL / ILAMB

(This is the GCEL development fork of ILAMB - it is not intended to replace the ornl bitbucket site which should be referred to first.)
2 stars 1 forks source link

Date at the top of HTML output is incorrect #9

Closed dvalters closed 5 years ago

dvalters commented 6 years ago

At the very top of the model output page, the date range is wrong.

screenshot from 2018-06-22 16-11-57

Date is presumably(?) calculated from the netCDF variable attributes, but this doesn't seem to work. I.e. if the date is 2001-01-01 it still calculates from 1850.

variables:
    int time(time) ;
        time:units = "days since 2001-01-01 00:00:00" ;

But other instances of dates are correctly calculated - e.g. from the timeseries output. So it is only the HTML headers that are affected:

jules_amazon_spaceint

dvalters commented 5 years ago

This is partly due to the way it calculates the header information. If there are no time_bounds defined in the netcdf file, it defaults to 1850. For example:

Confrontation.py l.118

        y0 = None; yf = None
        with Dataset(self.source) as dataset:
            if dataset.dimensions.has_key("data"):
                #self.hasSites = True
                if "site_name" in dataset.ncattrs():
                    self.lbls = dataset.site_name.split(",")
                else:
                    self.lbls = ["site%d" % s for s in range(len(dataset.dimensions["data"]))]
            if dataset.dimensions.has_key("time"):
                t = dataset.variables["time"]
                if "bounds" in t.ncattrs():
                    t  = dataset.variables[t.bounds][...]
                    y0 = int(t[ 0,0]/365.+1850.)
                    yf = int(t[-1,1]/365.+1850.)-1
                else:
                    y0 = int(round(t[ 0]/365.)+1850.)
                    yf = int(round(t[-1]/365.)+1850.)-1

The HTML is rendered in:

Post.py l.846

class HtmlLayout():

    def __init__(self,pages,cname,years=None):

        self.pages = pages
        self.cname = cname.replace("/"," / ")
        if years is not None:
            try:
                self.cname += " / %d-%d" % (years)

So you must have a bounds attribute to your time variable for this to work.