Ignore:
Timestamp:
Mar 28, 2006, 2:36:03 PM (18 years ago)
Author:
steve
Message:

Updated merimbula viewer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • production/merimbula_2005/prepare.py

    r2225 r2622  
    11
    22
    3 def prepare_timeboundary(filename):
    4     """Converting tide time series to NetCDF tms file.
     3def prepare_wind_stress(filename):
     4    """Converting wind timeseries to NetCDF tms file.
    55    This is a 'throw-away' code taylor made for files like
    66    'Benchmark_2_input.txt' from the LWRU2 benchmark
    77    """
    88
    9     print 'Preparing time boundary from %s' %filename
     9    print 'Preparing wind timeseries %s' %filename
    1010    from Numeric import array, zeros, Float, asarray
    1111
     
    1313
    1414    #Skip first line
    15     line = fid.readline()
     15    #line = fid.readline()
    1616
    1717    #Read remaining lines
     
    2222    N = len(lines)
    2323    T = zeros(N, Float)  #Time
    24     Q = zeros(N, Float)  #Values
     24    S = zeros(N, Float)  #Speed
     25    B = zeros(N, Float)  #Bearing
    2526
    2627    Told = 0.0
    2728    Sold = ' '
    2829    Lold = ' '
     30
    2931    for i, line in enumerate(lines):
    3032        fields = line.split()
     
    4648        T[i] = T[i] - Tstart
    4749        #this is specific to this data set. deals with daylight saving
    48         if i>3270:
    49             T[i] = T[i]+3600
    50 
     50#        if i>3270:
     51#            T[i] = T[i]+3600
     52#
    5153        if T[i]<Told :
    5254            print Lold
     
    5860            print i, T[i]-Told
    5961
    60         Q[i] = float(fields[2])
     62        S[i] = float(fields[2])
     63        B[i] = float(fields[3])
    6164
    6265        Told = T[i]
     
    6568
    6669
     70    #print T
     71    #Create tms file
     72    from Scientific.IO.NetCDF import NetCDFFile
     73
     74    outfile = filename[:-4] + '.tms'
     75    print 'Writing to', outfile
     76    fid = NetCDFFile(outfile, 'w')
     77
     78    fid.institution = 'Australian National University'
     79    fid.description = 'Input wind for Merimbula'
     80    fid.starttime = 0.0
     81    fid.createDimension('number_of_timesteps', len(T))
     82    fid.createVariable('time', Float, ('number_of_timesteps',))
     83    fid.variables['time'][:] = T
     84
     85    fid.createVariable('speed', Float, ('number_of_timesteps',))
     86    fid.variables['speed'][:] = S[:]
     87
     88    fid.createVariable('bearing', Float, ('number_of_timesteps',))
     89    fid.variables['bearing'][:] = B[:]
     90
     91
     92    fid.close()
     93
     94
     95def prepare_timeboundary(filename):
     96    """Converting tide time series to NetCDF tms file.
     97    This is a 'throw-away' code taylor made for files like
     98    'Benchmark_2_input.txt' from the LWRU2 benchmark
     99    """
     100
     101    print 'Preparing time boundary from %s' %filename
     102    from Numeric import array, zeros, Float, asarray
     103
     104    fid = open(filename)
     105
     106    #Skip first line
     107    line = fid.readline()
     108
     109    #Read remaining lines
     110    lines = fid.readlines()
     111    fid.close()
     112
     113
     114    N = len(lines)
     115    T = zeros(N, Float)  #Time
     116    Q = zeros(N, Float)  #Values
     117
     118    Told = 0.0
     119    Sold = ' '
     120    Lold = ' '
     121    for i, line in enumerate(lines):
     122        fields = line.split()
     123
     124        #print fields
     125
     126        l_time = (fields[0]+' '+fields[1])[0:-1]
     127        from time import strptime, mktime
     128
     129        s_time = strptime(l_time,'%d/%m/%y  %H:%M:%S')
     130
     131        #print s_time
     132
     133        T[i] = float(mktime(s_time))
     134
     135        if i==0:
     136            Tstart = T[0]
     137
     138        T[i] = T[i] - Tstart
     139        #this is specific to this data set. deals with daylight saving
     140        if i>3270:
     141            T[i] = T[i]+3600
     142
     143        if T[i]<Told :
     144            print Lold
     145            print l_time
     146            print Sold
     147            print s_time
     148            print Told
     149            print T[i]
     150            print i, T[i]-Told
     151
     152        Q[i] = float(fields[2])
     153
     154        Told = T[i]
     155        Sold = s_time
     156        Lold = l_time
     157
     158
     159    #print T
    67160    #Create tms file
    68161    from Scientific.IO.NetCDF import NetCDFFile
     
    90183    fid.close()
    91184
    92 
    93185#-------------------------------------------------------------
    94186if __name__ == "__main__":
     
    96188    print 'Prepare Open sea boundary condition from ',project.original_boundary_filename
    97189    prepare_timeboundary(project.original_boundary_filename )
     190
     191
     192    print 'Prepare wind from ',project.original_wind_filename
     193    prepare_wind_stress(project.original_wind_filename )
    98194
    99195    #Preparing points
Note: See TracChangeset for help on using the changeset viewer.