VSCRIPT FAQ

This is a FAQ for vscript. These are frequently asked questions and is a document that is living. Please feel free to contribute questions and answers to this list.

Note: Anything with >>> at the beginning of the line is to be entered on the vscript prompt.

Note: Anything with ... at the beginning of the line is a command that has not be completed yet.

  1. How can I open a dss file?
    Enter on the prompt the following :-
    >>> g=opendss('file.dss') # for local access
    >>> g=opendss('/xyz/data/file.dss','iep'); # for remote access on iep
    	
  2. How do I display a dss file ?
    First open the dss file ( as explained in 1 ). Then
    >>> GroupFrame(g);
    	
  3. I want to keep only pathnames which have the word flow in them ?
    >>> g = opendss('file.dss')
    >>> g.filterBy('flow') 
    	
  4. I want to see all the data in two files...
    >>> g1 = opendss('file1.dss')
    >>> g2 = opendss('file2.dss')
    >>> g3 = g1 + g2
    >>> GroupFrame(g3)
    	
  5. I want to find out the number of data sets in a dss file...
    >>> g = opendss('file.dss')
    >>> len(g)
    	
  6. I want to keep only pathnames in which the b part has 'xyz' in it
    >>> g = opendss('file.dss')
    >>> g.filterBy(1,PathPartPredicate('xyz',Pathname.B_PART))
    	
    1. I want to create a new group that contains only pathnames in which the b part has 'xyz' in it
      >>> g2 = find(g,'xyz','b')
      	    
    2. I want to create a new group that contains only pathnames in which the bpart DOES NOT have 'xyz'
      >>> g2 = find(g,'xyz','b',0)
      	    
  7. I want to reject only pathnames in which the c part starts with 'jk'...
    >>> g = opendss('file.dss')
    >>> g.filterBy(0,PathPartPredicate('^jk',Pathname.C_PART))
    	

    Note: The 0 in the first argument means reject matching

    1. Again if we want to create a new group from the existing group that contains only the pathnames having jk as the starting words in the c part we can do
      >>> g = opendss('file.dss')
      >>> g2 = find(g,'^jk','c')
      	
    2. or to reject them do
      >>> g2 = find(g,'^jk','c',0)
      	
  8. I want to keep only pathnames in which the b part is exactly 'xyz'
    >>> g = opendss('file.dss')
    >>> g.filterBy(1,PathPartPredicate('^xyz$',Pathname.B_PART))
          

    again to create a new group with such a filter do

    >>> g2 = find(g,'^xyz$', 'b')
          
  9. I want to keep pathnames that have 'xy' or 'zz' in the b part ...
    >>> g = opendss('file.dss')
    >>> g.filterBy(1,PathPartPredicate('xy|zz', Pathname.B_PART))
          
  10. I want to sort a group by the c part in deceasing order
    >>> g = opendss('file.dss')
    >>> sort(g,"C",0)
          

    or in the increasing order as

    >>> sort(g,'C',1)
          
  11. I want to sort a group by first the b part in increasing order then the c part in decreasing order only if the b part is the same We have a stable sort programmed in vista so its just a matter of doing the sort in the appropriate order
    >>> g = opendss('file.dss')
    >>> sort(g,"B",1)
    >>> sort(g,"C",0)
          
  12. I want to make a group out of the first 10 pathnames...
    >>> g = opendss('file.dss')
    >>> refs = Group.createGroup('first 10 paths',g[0:10])
          
  13. I want the last 10 pathnames
    >>> g = opendss('file.dss')
    >>> refs = Group.createGroup(last 10 paths',g[-10:])
          
  14. I want to get the data from a pathname in a dss file Let's say that the pathname has a c part of 'FLOW' and a b part of 'XYZ' then
    >>> g = opendss('file.dss')
    >>> g.filterBy(1,PathPartPredicate('^FLOW$',Pathname.C_PART))
    >>> g.filterBy(1,PathPartPredicate('^XYZ$',Pathname.B_PART))
          

    or in a much easier way to do the same thing but generating a new group containing the filtered pathnames one can do

    >>> g2 = find(g,'^FLOW$','c')
    >>> g2 = find(g2,'^XYZ$','b')
          

    or in on step as

    >>> g2 = find (find(g,'^FLOW$','c'), '^XYZ$', 'b')
          
  15. How do I display a dss pathname?
    First open the dss file
    >>> g = opendss('file.dss')
          

    Now get the first reference in this file and plot it

    >>> ref1 = g[0]
    >>> plot(ref1)
          

    Now get the first reference in this file and tabulate it

    >>> ref1 = g[0]
    >>> tabulate(ref1)
          
  16. How do I display more than one dss pathnames together
    First open the dss file
    >>> g = opendss('file.dss')
          

    Now get the first reference in this file and plot it

    >>> ref1 = g[0]
    >>> ref2 = g[1]
    >>> ref3 = g[2]
    >>> plot(ref1,ref2,ref3)
          

    Now get the first reference in this file and tabulate it

    >>> tabulate(ref1,ref2,ref3)
          
  17. I only want pathnames that have a certain time window.
    >>> tw = timewindow('01JAN1990 0000 - 01JAN1992 0000')
    >>> mylist = []
    >>> for ref in g:
    ...  ref2 = DataReference.create(ref,tw)
    ...  if ref2: mylist.append(ref2)
    ... 
    >>> g = Group.createGroup('time windowed', mylist)
    >>> GroupFrame(g)
          
  18. I want to export a few data sets to text files...
    >>> ref = g[0]
    >>> writeascii('junk.txt',ref.getData())
          

    if you want the flags as well

    >>> writeascii('junk.txt',ref.getData(),1)
          
  19. how can i read from a text file a time series and then save it to a dss file
    >>> import vutils
          

    for regular time series

    >>> vutils.read_dssts('test.dssts')
          

    or for irregular time series

    >>> vutils.read_dssits('test.dssits')
          
  20. I want to plot two time series versus each other. (Scatter plot)
    >>> refx = g[0]
    >>> refy = g[1]
    >>> scatterplot(refx,refy)
          
  21. I want to write out a few of the data referenes to a filename...
    >>> reflist = g[0:5]
    >>> for ref in reflist:
    ...  writedss('xyz.dss', ref.getPathname().toString(), ref.getData())
          
  22. how do i do a period average/min/max?
    >>> ref = g[0]
    >>> ref_pa = per_avg(ref)
    >>> ds1 = ref.getData()
    >>> ds1_pa = vutils.per_avg(ds1_pa)
    >>> ds1_pa = vutils.per_max(ds1_pa)
    >>> ds1_pa = vutils.per_min(ds1_pa)
          
  23. how do i do a moving average?
    >>> ref = g[0]
    >>> ref_ma = vutils.mov_avg(ref)
          
    1. how do i do a tidal average
      >>> ref_tidal_avg = vutils.tidal_avg(ref)
      	  
  24. how can i do math operations on a time series
    >>> ref1, ref2 = g[0], g[5]
    >>> ds1 = ref1.getData()
    >>> ds2 = ref2.getData()
    >>> ds12_add = ds1+ds2
    >>> ds12_div = ds1/ds2
    >>> ds1_add = ds1+5.3
    >>> dsc = 2*ds1-5.3*ds2+4.5
          
  25. what else can i do with a time series
    >>> ds = ref.getData()
    >>> print ds.getTimeWindow()
    >>> print ds[0], ds[5]
    >>> print ds[0:5]
    >>> print ds[-10:]
    >>> for e in ds: print e
          
  26. how can i do a first difference on a time series
    >>> ds_1stdiff = ds1 - (ds1 << 1) 
  27. how can i save a time series generated from math operations
    >>> writedss('junk.dss','/MY COMP/DATA/FLOW//15min/mathops/',2*ds1-5.4*ds2)
          
  28. how can i create my own time series and save/load it later
    >>> x = range(50)
    >>> y = map(Math.sin,x)
    >>> rts = RegularTimeSeries('/MY RTS/MY DATA/MY TYPE//5MIN/MYSOURCE','01jan1977 0100', '5min',y)
          
  29. how can i retrieve data for a few pathnames from a huge dss file sitting over the network without having to download it all
    >>> g=opendss('/export/home/www/htdocs/dss/db/hydro.dss','iep.water.ca.gov')
    >>> g2 = find(g,'flow')
    >>> for ref in g2:
    ...  writedss(ref.getFilename(), ref.getPathname().toString(),ref.getData())
          
  30. how can i set / retrieve flags

    Here's an example of setting missing value -901.0 and -902.0 to have missing value flags

    >>> ds = ref.getData()
    >>> dsi = ds.getIterator()
    >>> uId = DSSUtil.getUserId()
    >>> while not dsi.atEnd():
    ...  e = dsi.getElement()
    ...  if e.y == -901.0 or e.y == -902.0: 
    ...   FlagUtils.setQualityFlag(e,FlagUtils.REJECT_FLAG,uId)
    ...   dsi.putElement(e)
    ...  dsi.advance()
          
  31. how can i set flags for data outside a certain range
    This has already been done in vutils
    >>> import vutils
    >>> vutils.checkRange(ref, 0.0, 5000.0)
          
  32. how can i clear flags?

    do just as in FAQ 26 and replace the reject flag setting with this line

    ...   FlagUtils.clearAllFlags(e,0)
          
  33. how about generating customized plots and in a batch mode
    Use VPlotter
  34. how can i do time manipulation
    1. creating a time object
      >>> tm = time('01jan1990 0100')
      	  
    2. creating a time with an increment or decrement
      >>> tm1 = tm + '1hour'
      >>> tm2 = tm - '1day'
      	  
    3. difference between 2 times in minutes
      >>> diff = tm2 - tm1
      	  
    4. creating a time interval
      >>> ti = timeinterval('1hour')
      	  
    5. creating a time from addition/subtraction from a time
      >>> tm2 = tm + ti
      >>> tm3 = tm - ti
      	  
    6. creating a time interval from another interval
      >>> ti = timeinterval('1hour')
      >>> ti2 = 2*ti + ti
      >>> ti3 = timeinterval('1day')
      >>> ti4 = ti3+ti2
      >>> ti5 = ti3+ti
      >>> print ti5/ti
      >>> print (tm-tm2)/ti
      	  
  35. how can i learn more about specific objects being used
    Look at the conceptual faq.
  36. I can't find the answer to my question...
    1. Read the documentation
    2. Using the mailing list to post your question to other users
    3. talk to me.

[ Back | Home ]


Copyright © 2000. California Department of Water Resources. All rights reserved.
Webmaster: Tawnly Pranger
The URL is http://modeling.water.ca.gov/delta/models
Last modified: June 13, 2000.

Disclaimer
Comments or Questions
Webmaster email to htdelmod@water.ca.gov