4 Replies Latest reply on Jul 13, 2018 12:02 PM by Jiaqi

    How to get values from PIPoint.Summaries in Matlab


      Dear all,

      I'm trying to use Matlab to download time-averaged data from PI server and found PIPoint.Summaries may do the job for me.

      Below is the very simple testing example.

      import OSIsoft.AF.*
      import OSIsoft.AF.Asset.*;
      import OSIsoft.AF.Time.*;
      import OSIsoft.AF.Data.*;
      import OSIsoft.AF.PI.*;
      piservers = OSIsoft.AF.PI.PIServers;
      pisrv = piservers.DefaultPIServer;
      point = PIPoint.FindPIPoint(pisrv,'sinusoid'); % 
      timerg = AFTimeRange('*-1d','*');
      inter = AFTimeSpan(0,0,0,1);    % 1hr interval
      summarizedVals = point.Summaries(timerg, inter, AFSummaryTypes.Average, AFCalculationBasis.TimeWeighted, AFTimestampCalculation.Auto);


      The summarizedVals returns a dictionary object: 1x1 Dictionary<OSIsoft*AF*Data*AFSummaryTypes,OSIsoft*AF*Asset*AFValues>

      I'm not familiar with .NET syntax. I tried to use summarizedVals.TryGetValue, but I don't know what shall be the (TKey, Tvalue) in the method TryGetValue(TKey, TValue). I would like to have an array (length of 24, that is 1d with 1h interval) with values and times, but don't know how to realize that.


      My question is: how can I retrieve values from summarizedVals and store them in an array in Matlab? Thank you.


      Kind regards,


        • Re: How to get values from PIPoint.Summaries in Matlab

          In Python I was able to retrieve the summaries(Average)

          Could you try

          for s in summarizedVals: #should be just Average summary type as specified
              vals = s.Value
              for v in vals:
                  print ("{}".format(v.Value))

          The values you are looking for are v.Value and you can put them into a Matlab array.

          Also I had to modify the AFTimespan constructor to have 0,0,0,1.0 (int,int,int,double)

          1 of 1 people found this helpful
            • Re: How to get values from PIPoint.Summaries in Matlab


              Thanks. With the Item method, I can retrieve AFValues now.

              AFSumTypes = bitor(AFSummaryTypes.Average, AFSummaryTypes.Minimum);

              AFSumTypes = bitor(AFSumTypes, AFSummaryTypes.Maximum);

              summarizedVals = point.Summaries(timerg, inter, AFSumTypes,...

                  AFCalculationBasis.TimeWeighted, AFTimestampCalculation.Auto);

              values = summarizedVals.Item(AFSummaryTypes.Average);


              Following your explanation, I further wrote a function to retrieve multiple summaries.

              Multiple AF values are stored in a structure. Maybe there are more efficient ways, but it works fine by far.

              [AFVals, valKey] = GetKeyAFValues(summarizedVals);


              function [AFVals, valKey] = GetKeyAFValues(DictionaryObj)

                  key_enum = DictionaryObj.GetEnumerator;

                  len = DictionaryObj.Keys.Count;

                  valKey = cell(1, len);

                  AFVals = struct;

                  cnt = 1;

                  stat = 1;

                  while stat

                      stat = key_enum.MoveNext;

                      if stat

                          key_val = key_enum.Current;

                          if ~isempty(key_val.Value)

                              valKey{1,cnt} = char(key_val.Key);

                              AFVals.(char(key_val.Key)) = key_val.Value;

                              cnt = cnt+1;