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.
- 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
- How do I display a dss file ?
First open the dss file ( as explained in 1 ). Then
>>> GroupFrame(g);
- I want to keep only pathnames which have the word flow in them ?
>>> g = opendss('file.dss')
>>> g.filterBy('flow')
- I want to see all the data in two files...
>>> g1 = opendss('file1.dss')
>>> g2 = opendss('file2.dss')
>>> g3 = g1 + g2
>>> GroupFrame(g3)
- I want to find out the number of data sets in a dss file...
>>> g = opendss('file.dss')
>>> len(g)
- 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))
- 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')
- 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)
- 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
- 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')
- or to reject them do
>>> g2 = find(g,'^jk','c',0)
- 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')
- 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))
- 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)
- 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)
- 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])
- I want the last 10 pathnames
>>> g = opendss('file.dss')
>>> refs = Group.createGroup(last 10 paths',g[-10:])
- 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')
- 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)
- 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)
- 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)
- 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)
- 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')
- I want to plot two time series versus each other. (Scatter plot)
>>> refx = g[0]
>>> refy = g[1]
>>> scatterplot(refx,refy)
- 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())
- 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)
- how do i do a moving average?
>>> ref = g[0]
>>> ref_ma = vutils.mov_avg(ref)
- how do i do a tidal average
>>> ref_tidal_avg = vutils.tidal_avg(ref)
- 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
- 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
- how can i do a first difference on a time series
>>> ds_1stdiff = ds1 - (ds1 << 1)
- 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)
- 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)
- 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())
- 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()
- 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)
- how can i clear flags?
do just as in FAQ 26 and replace the reject flag setting with this line
... FlagUtils.clearAllFlags(e,0)
- how about generating customized plots and in a batch mode
Use VPlotter
- how can i do time manipulation
- creating a time object
>>> tm = time('01jan1990 0100')
- creating a time with an increment or decrement
>>> tm1 = tm + '1hour'
>>> tm2 = tm - '1day'
- difference between 2 times in minutes
>>> diff = tm2 - tm1
- creating a time interval
>>> ti = timeinterval('1hour')
- creating a time from addition/subtraction from a time
>>> tm2 = tm + ti
>>> tm3 = tm - ti
- 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
- how can i learn more about specific objects being used
Look at the conceptual faq.
- I can't find the answer to my question...
- Read the documentation
- Using the mailing list to post your question
to other users
- talk to me.