コード例 #1
0
ファイル: Write.py プロジェクト: yosukefk/pseudonetcdf
def write_wind(sdate, stime, time_step, vals, lstagger=None):
    """
    Takes an iterable and some defining information
    and creates a CAMx read wind file

    sdate - integer start date
    stime - float start time
    time_step - float increment between times

    vals - array axes time,uv,xy,z
    """
    wind_string = ""
    edate, etime = timeadd((sdate, stime), (0, vals.shape[0] * time_step))

    for i, (d, t) in enumerate(
            timerange((sdate, stime), (edate, etime), time_step)):
        if lstagger is not None:
            wind_string += writeline((t, d, lstagger), "fii")
        else:
            wind_string += writeline((t, d), "fi")

        for k in range(vals.shape[-1]):
            for uv in range(2):
                wind_string += writeline(vals[i, uv, ..., k],
                                         "f" * vals.shape[-2])
        wind_string += writeline((0, ), "i")
    return wind_string
コード例 #2
0
ファイル: Write.py プロジェクト: wongmengya/pseudonetcdf
def write_point(start_date, start_time, time_step, hdr, vals):
    # Internalize header
    hdr = [h for h in hdr]
    species = hdr[-4]
    nstk = hdr[-3][1]
    timeprops = hdr.pop()

    # initialize hdr_fmts with species count
    hdr_fmts = ["10i60i3ifif", "ffiffffiiiiifff",
                "iiii", "10i" * len(species), "ii", "ffffff" * nstk]

    # initialize output variable
    pt_string = ''

    # Change name and note
    hdr[0] = list(hdr[0][0]) + list(hdr[0][1]) + list(hdr[0][2:])

    # Reducing stk props
    stkprops = hdr[-1]
    hdr[-1] = []
    for stk in stkprops:
        hdr[-1].extend(stk)
    stk_time_prop_fmt = "iiiff" * nstk

    stk_time_props = []
    for time in timeprops:
        stk_time_props.append([])
        for stk in time:
            stk_time_props[-1].extend(stk)

    # Change species names to array of characters
    hdr[-3] = reduce(operator.concat, [Asc2Int(s) for s in hdr[-3]])

    # for each item in the header, write it to output
    for i, (h, f) in enumerate(zip(hdr, hdr_fmts)):
        pt_string += writeline(h, f, False)

    # create value format
    valfmt = 'i10i' + ('f' * nstk)

    # Get end date
    (end_date, end_time) = timeadd(
        (start_date, start_time), (0, time_step * vals.shape[0]))

    # Write out values
    for ti, (d, t) in enumerate(timerange((start_date, start_time),
                                          (end_date, end_time),
                                          time_step)):
        ed, et = timeadd((d, t), (0, time_step))
        pt_string += writeline((d, t, ed, et), 'ifif', False)
        pt_string += writeline((1, nstk), 'ii', False)
        pt_string += writeline(stk_time_props[ti], stk_time_prop_fmt, False)
        for si, spc in enumerate(species):
            # Dummy variable,spc characters and values flattened
            temp = [1]
            temp.extend(Asc2Int(spc))
            temp.extend(vals[ti, si, ...])
            pt_string += writeline(temp, valfmt, False)

    return pt_string
コード例 #3
0
ファイル: Write.py プロジェクト: yosukefk/pseudonetcdf
def write_hgtprss(sdate, stime, time_step, vals):
    """
    Takes an iterable and some defining information
    and creates a CAMx read wind file

    sdate - integer start date
    stime - float start time
    time_step - float increment between times

    vals - array axes time,uv,xy,z
    """
    hp_string = ""
    edate, etime = timeadd((sdate, stime), (0, vals.shape[0] * time_step))

    tind = (2400, 24)[int(time_step % 2)]
    tenum = enumerate(
        timerange((sdate, stime), timeadd((edate, etime), (0, 0)), time_step,
                  tind))
    for i, (d, t) in tenum:
        for k in range(vals.shape[-1]):
            for hp in range(2):
                hpvals = [t, d]
                hpvals.extend(vals[i, hp, ..., k])
                hp_string += writeline(hpvals, "fi" + "f" * vals.shape[-2])
    return hp_string
コード例 #4
0
ファイル: Write.py プロジェクト: tatawang/pseudonetcdf
def write_wind(sdate,stime,time_step,vals,lstagger=None):
    """
    Takes an iterable and some defining information
    and creates a CAMx read wind file
    
    sdate - integer start date
    stime - float start time
    time_step - float increment between times
    
    vals - array axes time,uv,xy,z
    """
    wind_string=""    
    edate,etime=timeadd((sdate,stime),(0,vals.shape[0]*time_step))
    
    for i,(d,t) in enumerate(timerange((sdate,stime),(edate,etime),time_step)):
        if lstagger!=None:
            wind_string+=writeline((t,d,lstagger),"fii")
        else:
            wind_string+=writeline((t,d),"fi")
            
        for k in range(vals.shape[-1]):
            for uv in range(2):
                wind_string+=writeline(vals[i,uv,...,k],"f"*vals.shape[-2])
        wind_string+=writeline((0,),"i")
    return wind_string
コード例 #5
0
ファイル: Write.py プロジェクト: tatawang/pseudonetcdf
def write_point(start_date,start_time,time_step,hdr,vals):
    #Internalize header
    hdr=[h for h in hdr]
    species=hdr[-4]
    nstk=hdr[-3][1]
    timeprops=hdr.pop()
    
    #initialize hdr_fmts with species count
    hdr_fmts=["10i60i3ifif","ffiffffiiiiifff","iiii","10i"*len(species),"ii","ffffff"*nstk]
    
    #initialize output variable
    pt_string=''
    
    #Change name and note
    hdr[0]=list(hdr[0][0])+list(hdr[0][1])+list(hdr[0][2:])
    
    #Reducing stk props
    stkprops=hdr[-1]
    hdr[-1]=[]
    for stk in stkprops:
        hdr[-1].extend(stk)
    stk_time_prop_fmt="iiiff"*nstk
    
    stk_time_props=[]
    for time in timeprops:
        stk_time_props.append([])
        for stk in time:
            stk_time_props[-1].extend(stk)
            
    #Change species names to array of characters
    hdr[-3]=reduce(operator.concat,[Asc2Int(s) for s in hdr[-3]])
    
    #for each item in the header, write it to output
    for i,(h,f) in enumerate(zip(hdr,hdr_fmts)):
        pt_string+=writeline(h,f,False)

    #create value format
    valfmt='i10i'+('f'*nstk)
    
    #Get end date
    (end_date,end_time)=timeadd((start_date,start_time),(0,time_step*vals.shape[0]))
    
    #Write out values
    for ti,(d,t) in enumerate(timerange((start_date,start_time),(end_date,end_time),time_step)):
        ed,et=timeadd((d,t),(0,time_step))
        pt_string+=writeline((d,t,ed,et),'ifif',False)
        pt_string+=writeline((1,nstk),'ii',False)
        pt_string+=writeline(stk_time_props[ti],stk_time_prop_fmt,False)
        for si,spc in enumerate(species):
            #Dummy variable,spc characters and values flattened
            temp=[1]
            temp.extend(Asc2Int(spc))
            temp.extend(vals[ti,si,...])
            pt_string+=writeline(temp,valfmt,False)
    
    return pt_string
コード例 #6
0
ファイル: Read.py プロジェクト: tatawang/pseudonetcdf
    def __gettimeprops(self):
        self.stk_time_props=[]
        for ti,(d,t) in enumerate(timerange((self.start_date,self.start_time),(self.end_date,self.end_time),self.time_step,(2400,24)[int(self.time_step % 2)])):
            tmpprop=zeros((len(self.stk_time_prop_fmt)),'f')
            tmpprop[...]=self.seekandread(d,t,1,True,self.stk_time_prop_fmt)
            tmpprop=tmpprop.reshape(self.nstk,5)
            for i in range(tmpprop.shape[0]):
                if tmpprop[i,-2]==array_nan:
                    tmpprop[i,-2]=float('-nan')

            self.stk_time_props.append(tmpprop.tolist())
コード例 #7
0
ファイル: Write.py プロジェクト: tatawang/pseudonetcdf
def write_emissions(start_date, start_time, time_step, hdr, vals):
    #initialize hdr_fmts with species count
    hdr_fmts = ["10i60i3ifif", "ffiffffiiiiifff", "iiii", "10i" * len(hdr[-1])]

    #initialize output variable
    emis_string = ''

    #Internalize header
    hdr = [h for h in hdr]
    species = hdr[-1]

    #Check start_date and start_time
    if tuple(hdr[0][4:6]) != (start_date, start_time):
        print("Header doesn't match start date/time", file=sys.stderr)

    #Change name and note
    hdr[0] = list(hdr[0][0]) + list(hdr[0][1]) + list(hdr[0][2:])

    #Change species names to array of characters
    hdr[-1] = reduce(operator.concat, [Asc2Int(s) for s in hdr[-1]])

    #for each item in the header, write it to output
    for h, f in zip(hdr, hdr_fmts):
        emis_string += writeline(h, f)

    #create value format
    cells = vals.shape[2] * vals.shape[3]
    valfmt = 'i10i' + ('f' * cells)

    #Get end date
    (end_date, end_time) = timeadd((start_date, start_time),
                                   (0, time_step * vals.shape[0]))

    if tuple(hdr[0][6:]) != (end_date, end_time):
        print("Header doesn't match end date/time", file=sys.stderr)

    #Write out values
    for ti, (d, t) in enumerate(
            timerange((start_date, start_time), (end_date, end_time),
                      time_step)):
        ed, et = timeadd((d, t), (0, time_step))
        emis_string += writeline((d, t, ed, et), 'ifif')
        for si, spc in enumerate(species):
            for k in range(vals.shape[-1]):
                #Dummy variable,spc characters and values flattened
                temp = [1]
                temp.extend(Asc2Int(spc))
                spcvals = vals[ti, si, ..., ..., k]
                spcvals = spcvals.transpose().ravel()
                temp.extend(spcvals)
                emis_string += writeline(temp, valfmt)

    return emis_string
コード例 #8
0
ファイル: Write.py プロジェクト: tatawang/pseudonetcdf
def write_emissions(start_date,start_time,time_step,hdr,vals):
    #initialize hdr_fmts with species count
    hdr_fmts=["10i60i3ifif","ffiffffiiiiifff","iiii","10i"*len(hdr[-1])]
    
    #initialize output variable
    emis_string=''
    
    #Internalize header
    hdr=[h for h in hdr]
    species=hdr[-1]
    
    #Check start_date and start_time
    if tuple(hdr[0][4:6])!=(start_date,start_time):
        print("Header doesn't match start date/time", file = sys.stderr)
       
    #Change name and note
    hdr[0]=list(hdr[0][0])+list(hdr[0][1])+list(hdr[0][2:])
    
    #Change species names to array of characters
    hdr[-1]=reduce(operator.concat,[Asc2Int(s) for s in hdr[-1]])
    
    #for each item in the header, write it to output
    for h,f in zip(hdr,hdr_fmts):
        emis_string+=writeline(h,f)

    #create value format
    cells=vals.shape[2]*vals.shape[3]
    valfmt='i10i'+('f'*cells)
    
    #Get end date
    (end_date,end_time)=timeadd((start_date,start_time),(0,time_step*vals.shape[0]))
    
    if tuple(hdr[0][6:])!=(end_date,end_time):
        print("Header doesn't match end date/time", file = sys.stderr)
    
    #Write out values
    for ti,(d,t) in enumerate(timerange((start_date,start_time),(end_date,end_time),time_step)):
        ed,et=timeadd((d,t),(0,time_step))
        emis_string+=writeline((d,t,ed,et),'ifif')
        for si,spc in enumerate(species):
            for k in range(vals.shape[-1]):
                #Dummy variable,spc characters and values flattened
                temp=[1]
                temp.extend(Asc2Int(spc))
                spcvals=vals[ti,si,...,...,k]
                spcvals=spcvals.transpose().ravel()
                temp.extend(spcvals)
                emis_string+=writeline(temp,valfmt)
    
    return emis_string        
コード例 #9
0
ファイル: Read.py プロジェクト: tatawang/pseudonetcdf
    def __gettimeprops(self):
        self.stk_time_props = []
        for ti, (d, t) in enumerate(
                timerange((self.start_date, self.start_time),
                          (self.end_date, self.end_time), self.time_step,
                          (2400, 24)[int(self.time_step % 2)])):
            tmpprop = zeros((len(self.stk_time_prop_fmt)), 'f')
            tmpprop[...] = self.seekandread(d, t, 1, True,
                                            self.stk_time_prop_fmt)
            tmpprop = tmpprop.reshape(self.nstk, 5)
            for i in range(tmpprop.shape[0]):
                if tmpprop[i, -2] == array_nan:
                    tmpprop[i, -2] = float('-nan')

            self.stk_time_props.append(tmpprop.tolist())
コード例 #10
0
ファイル: Write.py プロジェクト: tatawang/pseudonetcdf
def write_hgtprss(sdate,stime,time_step,vals):
    """
    Takes an iterable and some defining information
    and creates a CAMx read wind file
    
    sdate - integer start date
    stime - float start time
    time_step - float increment between times
    
    vals - array axes time,uv,xy,z
    """
    hp_string=""    
    edate,etime=timeadd((sdate,stime),(0,vals.shape[0]*time_step))
    
    for i,(d,t) in enumerate(timerange((sdate,stime),timeadd((edate,etime),(0,0)),time_step,(2400,24)[int(time_step % 2)])):
        for k in range(vals.shape[-1]):
            for hp in range(2):
                hpvals=[t,d]
                hpvals.extend(vals[i,hp,...,k])
                hp_string+=writeline(hpvals,"fi"+"f"*vals.shape[-2])
    return hp_string
コード例 #11
0
ファイル: Memmap.py プロジェクト: tatawang/pseudonetcdf
 def timerange(self):
     return timerange((self.start_date, self.start_time + self.time_step),
                      timeadd((self.end_date, self.end_time),
                              (0, self.time_step)), self.time_step)
コード例 #12
0
ファイル: Read.py プロジェクト: yosukefk/pseudonetcdf
 def keys(self):
     for d, t in timerange((self.start_date, self.start_time),
                           timeadd((self.end_date, self.end_time),
                                   (0, self.time_step)), self.time_step):
         for k in range(1, self.nlayers + 1):
             yield d, t, k
コード例 #13
0
ファイル: Read.py プロジェクト: tatawang/pseudonetcdf
 def timerange(self):
     return timerange((self.start_date,self.start_time),timeadd((self.end_date,self.end_time),(0,self.time_step),(2400,24)[int(self.time_step % 2)]),self.time_step,(2400,24)[int(self.time_step % 2)])
コード例 #14
0
ファイル: Read.py プロジェクト: tatawang/pseudonetcdf
 def keys(self):
     for d,t in timerange((self.start_date,self.start_time),timeadd((self.end_date,self.end_time),(0,self.time_step)),self.time_step):
         for k in range(1,self.nlayers+1):
             yield d,t,k
コード例 #15
0
ファイル: Read.py プロジェクト: tatawang/pseudonetcdf
 def timerange(self):
     return timerange((self.start_date,self.start_time),(self.end_date,self.end_time),self.time_step,eod=24)
コード例 #16
0
 def timerange(self):
     t1 = (self.start_date, self.start_time)
     tind = (2400, 24)[int(self.time_step % 2)]
     t2 = timeadd((self.end_date, self.end_time), (0, self.time_step), tind)
     return timerange(t1, t2, self.time_step, tind)
コード例 #17
0
 def timerange(self):
     return timerange(
         (self.start_date, self.start_time),
         timeadd((self.end_date, self.end_time), (0, self.time_step),
                 (2400, 24)[int(self.time_step % 2)]), self.time_step,
         (2400, 24)[int(self.time_step % 2)])
コード例 #18
0
ファイル: Memmap.py プロジェクト: tatawang/pseudonetcdf
 def timerange(self):
     return timerange((self.start_date,self.start_time+self.time_step),timeadd((self.end_date,self.end_time),(0,self.time_step)),self.time_step)
コード例 #19
0
ファイル: Read.py プロジェクト: tatawang/pseudonetcdf
 def timerange(self):
     return timerange((self.start_date, self.start_time),
                      (self.end_date, self.end_time),
                      self.time_step,
                      eod=24)
コード例 #20
0
 def timerange(self):
     t1 = (self.start_date, self.start_time + self.time_step)
     t2 = timeadd((self.end_date, self.end_time), (0, self.time_step))
     return timerange(t1, t2, self.time_step)