コード例 #1
0
def transfer(infile, outfile, select, window, transform, interval, unique=0):
    f = opendss(infile)
    g = findpath(f, select)
    select = select.upper()
    if not outfile:
        raise "Output file name is None"

    if not g or len(g) == 0:
        raise "No matches for selection [%s] found in file %s" % (select,
                                                                  infile)

    if (unique and len(g) > 1):
        raise "Selection not unique and the unique flag is set true for selection [%s] in file %s" % (
            select, infile)

    for ref in g:
        if window:
            r = DataReference.create(ref, window)
            if not r:
                print "No data in window for reference: %s" % ref
                continue
        else:
            r = DataReference.create(ref)

        d = r.getData()

        if not d or len(d) == 0:
            raise "Data retrieval failed for %s " % ref2
        if transform:
            transform = transform.lower()
            if transform == "period_max":
                d = per_max(d, interval.toString())
            elif transform == "period_min":
                d = per_min(d, interval.toString())
            elif transform == "period_ave":
                d = per_avg(d, interval.toString())
            elif transform == "tidal_ave":
                d = tidal_avg(d)
            elif transform == "godin":
                d = godin(d)
            else:
                raise "Transform %s not recognized" % transform

        p = Pathname.createPathname(d.getName())
        if transform:
            old_c = p.getPart(Pathname.C_PART)
            new_c = old_c + "_" + transform.upper()
            p.setPart(Pathname.C_PART, new_c)
        path = p.toString()
        writedss(outfile, path, d)
        del d
        del r

    #
    return
コード例 #2
0
ファイル: transfer.py プロジェクト: CalSimCalLite/CalLiteGUI
def transfer(infile,outfile,select,window,transform,interval,unique=0):
    f=opendss(infile)
    g=findpath(f,select)
    select=select.upper()
    if not outfile:
        raise "Output file name is None"
    
    if not g or len(g) == 0:
        raise "No matches for selection [%s] found in file %s" % (select,infile)

    if (unique and len(g) > 1):
        raise "Selection not unique and the unique flag is set true for selection [%s] in file %s" % (select,infile)
    
    for ref in g:
        if window:
            r = DataReference.create(ref,window)
            if not r:
                print "No data in window for reference: %s" % ref
                continue
        else:
            r=DataReference.create(ref)
        
        d = r.getData()

        if not d or len(d)==0:
            raise "Data retrieval failed for %s " % ref2
        if transform:
            transform=transform.lower()
            if transform == "period_max":
                d=per_max(d,interval.toString())
            elif transform == "period_min":
                d=per_min(d,interval.toString())
            elif transform == "period_ave":
                d=per_avg(d,interval.toString())
            elif transform == "tidal_ave":
                d=tidal_avg(d)
            elif transform == "godin":
                d=godin(d)
            else:
                raise "Transform %s not recognized" %transform
        
        p=Pathname.createPathname(d.getName())
        if transform:
            old_c=p.getPart(Pathname.C_PART)
            new_c=old_c+"_"+transform.upper()
            p.setPart(Pathname.C_PART,new_c)
        path=p.toString()
        writedss(outfile,path,d)
        del d
        del r

    #
    return
コード例 #3
0
ファイル: dicu_calc.py プロジェクト: CalSimCalLite/CalLiteGUI
def do_sum(cpart,dicufile):
    g=opendss(dicufile)
    g=findparts(g,c=cpart)
    ts=None
    for ref in g:
        if ts==None:
            ts=ref.data
        else:
            ts+=ref.data
    path=Pathname.createPathname(ts.name)
    path=set_part(path,'ALL',Pathname.B_PART)
    ts.name=str(path)
    return ts
コード例 #4
0
def do_sum(cpart, dicufile):
    g = opendss(dicufile)
    g = findparts(g, c=cpart)
    ts = None
    for ref in g:
        if ts == None:
            ts = ref.data
        else:
            ts += ref.data
    path = Pathname.createPathname(ts.name)
    path = set_part(path, 'ALL', Pathname.B_PART)
    ts.name = str(path)
    return ts
コード例 #5
0
def make_dss_path(pathname, a_part='', b_part='', f_part=''):
    """
    make_dss_path(pathname, a_part='', b_part='', f_part='')
    Adds additional A, B and F part text to an input pathname, and
    checks for max length of each part and the pathname. Returns
    a either a pathname object or string which is the new pathname,
    depending on the type of the input pathname.
    """
    pnp = string.split(str(pathname), '/')
    pnp[1] += a_part
    pnp[2] += b_part
    pnp[6] += f_part
    pnp[4] = '' # remove D part for now
    # strictly trim to 32 chars each part
    for ndx in range(1, 7):
        if len(pnp[ndx]) > 32: pnp[ndx] = pnp[ndx][:32]
    pn = string.join(pnp, '/')
    if len(pn) > 80: pn = pn[:80]
    if isinstance(pathname, Pathname): return Pathname.createPathname(pn)
    else: return pn
コード例 #6
0
def set_part(pathname, new_part, new_part_id=Pathname.B_PART):
    p=Pathname.createPathname(pathname)
    p.setPart(new_part_id, new_part)
    return p.toString()
コード例 #7
0
def read_dss_txt(file,dssts=True,flag=False):
    """
    read_dss_txt(file, dssts=True,flag=False): reads from a ascii file in dssts or dssits format
    and writes out the data to the appropriate dss file and pathnames.
    If dssts == True then dssts format is assumed in the file else dssits format is assumed
    For more info  look up doc on read_dssts(file) and read_dssits(file)
    If flag == True then it expects a flag value in the ascii file as well
    The flag values in the ascii file are represented as
    flag_type|user_name
    where flag_type is one of UNSCREENED,QUESTIONABLE,MISSING,REJECT,OK
    & user_name is one of the authorized users/agency.
    e.g. MISSING|nsandhu or REJECT|kate
    """
    import string
    tf = TimeFactory.getInstance()
    f = open(file)
    line = f.readline()[:-1]
    dssfile = line
    while line :
        try :
            line = string.upper(f.readline()[:-1])
            if line == "FINISH": break;
            path = Pathname.createPathname(string.upper(line))
        except :
            print 'Incorrect format for path: ', line
            break
        try :
            line = f.readline()[:-1]
            units = string.upper(line)
        except :
            print 'Incorrect format for units: ', line
            break
        try :
            line = f.readline()[:-1]
            type = string.upper(line)
        except :
            print 'Incorrect format for type: ', line
            break
        if dssts:
            try :
                line = f.readline()[:-1]
                stime = tf.createTime(line)
            except :
                print 'Incorrect format for time: ', line
                break
        #
        line = string.upper(f.readline()[:-1])
        xvals = []
        yvals = []
    if flag:
        flags = []
    else:
        flags = None
        while line != "END" :
            if dssts:
                try:
                    if flag:
                        vals = string.split(line)
                        if len(vals) != 2: raise "No flags in file %s @ line: %s"%(file,line)
                        yvals.append(float(vals[0]))
                        flags.append(make_flag_value(vals[1]))
                    else:   # no flags
                        yvals.append(float(line))
                except:
                    yvals.append(Constants.MISSING_VALUE);
                    if flag: flags.append(make_flag_value('MISSING|null'))
            else :
                try :
                    line = string.strip(line)
                    tmstr = line[0:14]
                    tm = tf.createTime(tmstr)
                    try :
                        if flag:
                            vals = string.split(line[14:])
                            if len(vals) != 2: raise "No flags in file %s @ line: %s"%(file,line)
                            val = float(vals[0])
                            flag_val = vals[1]
                        else:   # no flag
                            val = float(line[14:])
                    except :
                        val = Constants.MISSING_VALUE
                    xvals.append(tm)
                    yvals.append(val)
                    flags.append(make_flag_value(flag_val))
                except Exception, exc:
                    print exc
                    print "Error reading line: ", line
            line = string.upper(f.readline()[:-1])
            # create appropriate time series object
            if len(yvals) == 0 : continue
            #print yvals, flags
        if ( dssts ):
            attr = DataSetAttr(DataType.REGULAR_TIME_SERIES,"TIME",units,"",type)
            ts = RegularTimeSeries("",repr(stime),path.getPart(Pathname.E_PART),
                                   yvals, flags, attr)
        else :
            attr = DataSetAttr(DataType.IRREGULAR_TIME_SERIES,"TIME",units,"",type)
            ts = IrregularTimeSeries("",xvals, yvals, flags, attr)