示例#1
0
def _orderValuesAsTimes(a, b):
    """Orders two values in ascending value, parsing the supplied strings as times.
    @param a: first value
    @param b: second value
    @return tuple containing the supplied values in the appropriate order, or None if they values
        cannot be parsed
    """
    try:
        aCt = date_util.iso2comptime(a)
        bCt = date_util.iso2comptime(b)
        return (a, b) if aCt.compare(bCt) <= 0 else (b, a)
    except ValueError:
        return None
示例#2
0
def formatObs(layerInfo, keywordData):
    field = layerInfo.layerName
    try:
        fieldcaption = keywordData["title"]
    except KeyError:
        fieldcaption = field
    period = keywordData["period"]
    time = date_util.iso2comptime(layerInfo.params["TIME"])
    today = datetime.today().strftime("%d %B, %Y")

    if period == "10":
        minYear = time.year - (time.year % 10) + 1
        maxYear = minYear + 9
    elif period == "30":
        minYear = time.year - ((time.year - 1900) % 30) + 1
        maxYear = minYear + 29

    caption = """Observed %s, %s %s-%s mean.
Climatic Research Unit Climatology (New et al., 1999).
Figure obtained from www.ipcc-data.org. %s.""" % (
        fieldcaption,
        months[time.month - 1],
        minYear,
        maxYear,
        today,
    )

    return caption
示例#3
0
def formatSim(layerInfo, keywordData):
    field = layerInfo.layerName
    time = date_util.iso2comptime(layerInfo.params["TIME"])
    fieldcaption = keywordData["varcaption"]
    institute = keywordData["caption"]
    model = keywordData["model"]
    projection = keywordData["short"]
    ref = keywordData["ref"]
    today = datetime.today().strftime("%d %B, %Y")
    period = int(keywordData["period"])

    # This algorithm is copied from the ddc javascript where it seems to work for AR4
    # there is a workaround for TAR that would need putting here too if we use formatProj
    # for the TAR data.
    dy = period / 2
    minYear = time.year - dy + 1
    maxYear = time.year - dy + period

    caption = """%s, %s %s-%s mean.
Simulated by the %s; 
Scenario %s (%s); Model %s (IPCC 2007).
Figure obtained from www.ipcc-data.org. %s.""" % (
        fieldcaption,
        months[time.month - 1],
        minYear,
        maxYear,
        institute,
        projection,
        ref,
        model,
        today,
    )

    return caption
示例#4
0
 def applyFormat(self, name, dimensionValues):
     """Applies a dimension format to a list of values, returning the list formatted values or
     None if no formatting is possible.
     @param name: name of dimension
     @param dimensionValues: list of dimension values
     @return list of formatted values or None if there is no applicable format
     """
     log.debug('Formatting %s in format "%s"' % (name, self.formatString))
     if (name == 'time') and (self.formatString):
         displayValues = []
         for val in dimensionValues:
             comptime = date_util.iso2comptime(val)
             displayValues.append(comptime.format(self.formatString))
     else:
         displayValues = None
     return displayValues