Exemple #1
0
def reformatForecast(fcstTSC):
    # converts dailies to forecast set;
    # converts irregular data with monthly 0s to standard CRT format.
    # iterate through values
    outTimes = []
    outVals = []
    firstPoint = True
    prevTime, prevVal = 0, Constants.UNDEFINED
    isIrregular = (fcstTSC.interval <= 0)
    for t,v in zip(fcstTSC.times, fcstTSC.values):
        # add end point from previous when this changes; then start with new value
        ht = HecTime()
        ht.set(t)
        prevHt = HecTime()
        prevHt.set(prevTime)
        # insert new point whenever it changes, month changes, or on the first point
        if firstPoint or v != prevVal or (ht.month() != prevHt.month() and v != 0):
            # output endtimestamp for previous value
            if not firstPoint:
                outTimes.append(prevTime)
                outVals.append(prevVal)
            if firstPoint:
                firstPoint = False
            # output start timestamp for this value
            offset = -(24*60) + 1 # default to one minute past 0000 this day.
            if isIrregular and ht.minute() != 0:
                offset = 0
            outTimes.append(t + offset)
            outVals.append(v)
        prevTime = t
        prevVal = v
    # add last value to finish out series.
    #outTimes.append(t)
    #outVals.append(v)
    # create output TSC
    fcstOutTSC = TimeSeriesContainer()
    fcstOutTSC.interval = -1
    newPathName = fcstTSC.fullName.split("/")
    if not isIrregular: 
        newPathName[5] = "IR-CENTURY"
    fcstOutTSC.fullName = "/".join(newPathName) 
    fcstOutTSC.times = outTimes
    fcstOutTSC.values = outVals
    print fcstOutTSC.fullName
    print(outVals)
    fcstOutTSC.numberValues = len(outVals)
    fcstOutTSC.startTime = outTimes[0]
    fcstOutTSC.units = fcstTSC.units
    fcstOutTSC.type = "INST-VAL"
    return fcstOutTSC
Exemple #2
0
            csvList = []

            for i in range(0, flow.numberValues):
                # print int(flow.times[i])
                time = HecTime()
                time.set(int(flow.times[i]))

                d = [
                    time.year(),
                    '%d' % (time.month(), ),
                    '%d' % (time.day(), )
                ]
                t = [
                    '%d' % (time.hour(), ),
                    '%d' % (time.minute(), ),
                    '%d' % (time.second(), )
                ]
                if (int(t[0]) > 23):
                    t[0] = '23'
                    dtStr = '-'.join(str(x) for x in d) + ' ' + ':'.join(
                        str(x) for x in t)
                    dt = datetime.datetime.strptime(dtStr, '%Y-%m-%d %H:%M:%S')
                    dt = dt + datetime.timedelta(hours=1)
                else:
                    dtStr = '-'.join(str(x) for x in d) + ' ' + ':'.join(
                        str(x) for x in t)
                    dt = datetime.datetime.strptime(dtStr, '%Y-%m-%d %H:%M:%S')

                csvList.append([
                    dt.strftime('%Y-%m-%d %H:%M:%S'),
Exemple #3
0
    if tw != None:
        st, et = tw
        print("Time window: {}".format(tw))
    else:
        raise Exception('No forecast open on Modeling tab to get a timewindow.')
    st = HecTime(st, HecTime.MINUTE_GRANULARITY)
    st.showTimeAsBeginningOfDay(True)
    # Convert start to UTC
    print('Converting time window to UTC for API request.')
    ws_tz = cavistatus.get_timezone()
    HecTime.convertTimeZone(st, ws_tz, TimeZone.getTimeZone('UTC'))    
    et = HecTime(et, HecTime.MINUTE_GRANULARITY)
    et.showTimeAsBeginningOfDay(True)
    # Convert end to UTC
    HecTime.convertTimeZone(et, ws_tz, TimeZone.getTimeZone('UTC'))    
    after = '{}-{:02d}-{:02d}T{:02d}:{:02d}:00Z'.format(st.year(), st.month(), st.day(), st.hour(), st.minute())
    before = '{}-{:02d}-{:02d}T{:02d}:{:02d}:00Z'.format(et.year(), et.month(), et.day(), et.hour(), et.minute())    
    
    # DSS filename and path
    if dssfilename is None: dssfilename = 'data.dss'
    if not dssfilename.endswith('.dss'): dssfilename += '.dss'
    if dsspath is None: dsspath = cavistatus.get_database_directory()
    dsspath = os.path.expandvars(dsspath)
    # Join the path and
    dbdss = os.path.join(dsspath, dssfilename)
    print('DSS: {}'.format(dbdss))
    
    endpoint = re.sub(r':\w+', ws_name_slug, endpoint)
else:
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
    # TESTING SECTION WHEN NOT RUNNING IN CAVI
Exemple #4
0
        else :
            csvWriter.writerow(['Location Ids', 'Hanwella'])
            csvWriter.writerow(['Time', 'Flow'])

            print flow.values[:1], flow.times[:1]
            print flow.values[-1], flow.times[-1]

            csvList = []

            for i in range(0, flow.numberValues) :
                # print int(flow.times[i])
                time = HecTime()
                time.set(int(flow.times[i]))
                
                d = [time.year(), '%d' % (time.month(),), '%d' % (time.day(),)]
                t = ['%d' % (time.hour(),), '%d' % (time.minute(),), '%d' % (time.second(),)]
                if(int(t[0]) > 23) :
                    t[0] = '23'
                    dtStr = '-'.join(str(x) for x in d) + ' ' + ':'.join(str(x) for x in t)
                    dt = datetime.datetime.strptime(dtStr, '%Y-%m-%d %H:%M:%S')
                    dt = dt + datetime.timedelta(hours=1)
                else :
                    dtStr = '-'.join(str(x) for x in d) + ' ' + ':'.join(str(x) for x in t)
                    dt = datetime.datetime.strptime(dtStr, '%Y-%m-%d %H:%M:%S')

                csvList.append([dt.strftime('%Y-%m-%d %H:%M:%S'), "%.2f" % flow.values[i]])
                
            print csvList[:3], "...", csvList[-3:]
            csvWriter.writerows(csvList)

    except Exception, e :