示例#1
0
def convert_ta(shyft_ta):
    ta = None
    if isinstance(shyft_ta, api.TimeAxisFixedDeltaT):
        # Fixed TA
        ta = TimeAxis(Calendar.Utc, UtcTime.CreateFromUnixTime(shyft_ta.start),
                      TimeSpan.FromSeconds(shyft_ta.delta_t), shyft_ta.n)
    elif isinstance(shyft_ta, api.PointTimeaxis):
        # Point TA
        ta = create_point_ta(shyft_ta)
    elif isinstance(shyft_ta, api.TimeAxis):
        # Generic TA: either Calendar | Fixed | Point
        if shyft_ta.timeaxis_type == api.TimeAxisType.FIXED:
            ta = TimeAxis(Calendar.Utc,
                          UtcTime.CreateFromUnixTime(shyft_ta.fixed_dt.start),
                          TimeSpan.FromSeconds(shyft_ta.fixed_dt.delta_t),
                          shyft_ta.fixed_dt.n)
        elif shyft_ta.timeaxis_type == api.TimeAxisType.CALENDAR:
            cal = Calendar(shyft_ta.calendar_dt.calendar.tz_info.name)
            ta = TimeAxis(
                cal, UtcTime.CreateFromUnixTime(shyft_ta.calendar_dt.start),
                TimeSpan.FromSeconds(shyft_ta.calendar_dt.delta_t),
                shyft_ta.calendar_dt.n)
        elif shyft_ta.timeaxis_type == api.TimeAxisType.POINT:
            ta = create_point_ta(shyft_ta.point_dt)
    if ta is None:
        raise SmgDataError('Unsupported shyft time-axis: ' + str(shyft_ta))
    return ta
示例#2
0
文件: ssa_smg_db.py 项目: yisak/shyft
    def _make_ssa_ts_from_shyft_ts(name, shyft_ts):
        ''' Geturns a SSaTimeSeries from shyft_ts '''
        t = np.array([shyft_ts.time(i) for i in range(shyft_ts.size())])
        v = np.array([shyft_ts.value(i) for i in range(shyft_ts.size())])
        q = np.zeros_like(t, dtype=np.int)

        numPoints = shyft_ts.size()
        tsv = TsAsVector(numPoints, TimeSystemReference.Unix1970Utc)
        p = Period(UtcTime.CreateFromUnixTime(t[0]),
                   UtcTime.CreateFromUnixTime(t[-1] + 3600))
        tsv.SetVectors(p, t, v, q)
        tsv.Name = name
        return SsaTimeSeries(tsv)
示例#3
0
 def _make_ssa_tsps_from_shyft_ts(ts_id, shyft_ts):
     ''' returns a TimeSeriesPointSegments from shyft_ts '''
     ts_size = shyft_ts.size();
     t = np.array([shyft_ts.time(i) for i in range(ts_size)])
     v = np.array([shyft_ts.value(i) for i in range(ts_size)])
     q = np.zeros_like(t, dtype=np.int)
     tsv = TsAsVector(ts_size, TimeSystemReference.Unix1970Utc)
     p = Period(UtcTime.CreateFromUnixTime(t[0]), UtcTime.CreateFromUnixTime(t[-1] + 3600))
     tsv.SetVectors(p, t, v, q)
     ts_ps = TimeSeriesPointSegments()
     ts_ps.Identity = ts_id
     psList = List[IPointSegment]([])
     psList.Add(PointSegment(p, tsv.Points))
     ts_ps.PointSegments = psList
     return ts_ps
示例#4
0
 def _make_ssa_Period_from_shyft_period(shyft_period):
     if not shyft_period.valid():
         raise SmgDataError("shyft_period must be of type api.UtcPeriod")
     return Period(UtcTime.CreateFromUnixTime(shyft_period.start), UtcTime.CreateFromUnixTime(shyft_period.end))