Changeset 5347


Ignore:
Timestamp:
May 21, 2008, 9:52:16 AM (16 years ago)
Author:
jakeman
Message:

added sts format to datamanager and mux2sts

Location:
anuga_core/source/anuga/shallow_water
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/shallow_water/data_manager.py

    r5336 r5347  
    26972697    latitudes = file_h.variables[dim_h_latitude]
    26982698    longitudes = file_h.variables[dim_h_longitude]
    2699    
     2699
     2700    kmin, kmax, lmin, lmax = _get_min_max_indexes(latitudes[:],
     2701                                                  longitudes[:],
     2702                                                  minlat, maxlat,
     2703                                                  minlon, maxlon)
    27002704    # get dimensions for file_e
    27012705    for dimension in file_e.dimensions.keys():
     
    39123916    latitudes = ensure_numeric(latitudes)
    39133917    longitudes = ensure_numeric(longitudes)
    3914    
     3918
    39153919    assert allclose(sort(longitudes), longitudes)
     3920
     3921    print latitudes[0],longitudes[0]
     3922    print len(latitudes),len(longitudes)
     3923    print latitudes[len(latitudes)-1],longitudes[len(longitudes)-1]
    39163924   
    39173925    lat_ascending = True
     
    48164824    # Do some conversions while writing the sww file
    48174825
    4818    
     4826    ##################################
     4827    # READ MUX2 FILES line of points #
     4828    ##################################
     4829
     4830WAVEHEIGHT_MUX2_LABEL = '_waveheight-z-mux2'
     4831EAST_VELOCITY_MUX2_LABEL =  '_velocity-e-mux2'
     4832NORTH_VELOCITY_MUX2_LABEL =  '_velocity-n-mux2'   
     4833
     4834def read_mux2_py(filenames,weights=None):
     4835
     4836    from Numeric import ones,Float,compress,zeros,arange
     4837    from urs_ext import read_mux2
     4838
     4839    if weights is None:
     4840        weights=ones(len(filenames),Float)/len(filenames) #default 1/numSrc
     4841
     4842    file_params=-1*ones(3,Float)#[nsta,dt,nt]
     4843    write=1 #write txt files to current directory as well
     4844    data=read_mux2(1,filenames,weights,file_params,write)
     4845
     4846    msg='File parameter values were not read in correctly from c file'
     4847    assert len(compress(file_params>0,file_params))!=0,msg
     4848    msg='The number of stations specifed in the c array and in the file are inconsitent'
     4849    assert file_params[0]==data.shape[0],msg
     4850   
     4851    nsta=int(file_params[0])
     4852    msg='Must have at least one station'
     4853    assert nsta>0,msg
     4854    dt=file_params[1]
     4855    msg='Must have a postive timestep'
     4856    assert dt>0,msg
     4857    nt=int(file_params[2])
     4858    msg='Must have at least one gauge value'
     4859    assert nt>0,msg
     4860   
     4861    OFFSET=5 #number of site parameters p passed back with data
     4862    #p=[geolat,geolon,depth,start_tstep,finish_tstep]
     4863
     4864    times=dt*arange(1,(data.shape[1]-OFFSET)+1)
     4865    latitudes=zeros(data.shape[0],Float)
     4866    longitudes=zeros(data.shape[0],Float)
     4867    elevation=zeros(data.shape[0],Float)
     4868    stage=zeros((data.shape[0],data.shape[1]-OFFSET),Float)
     4869    for i in range(0,data.shape[0]):
     4870        latitudes[i]=data[i][data.shape[1]-OFFSET]
     4871        longitudes[i]=data[i][data.shape[1]-OFFSET+1]
     4872        elevation[i]=-data[i][data.shape[1]-OFFSET+2]
     4873        stage[i]=data[i][:-OFFSET]
     4874
     4875    return times, latitudes, longitudes, elevation, stage
     4876
    48194877def mux2sww_time(mux_times, mint, maxt):
    48204878    """
     
    48344892
    48354893    return mux_times_start_i, mux_times_fin_i
     4894
     4895
     4896def urs2sts(basename_in, basename_out = None, verbose = False, origin = None,
     4897            mean_stage=0.0,zscale=1.0,
     4898            minlat = None, maxlat = None,
     4899            minlon = None, maxlon = None):
     4900    """Convert URS mux2 format for wave propagation to sts format
     4901
     4902    Specify only basename_in and read files of the form
     4903    out_waveheight-z-mux2
     4904
     4905    Also convert latitude and longitude to UTM. All coordinates are
     4906    assumed to be given in the GDA94 datum
     4907
     4908    origin is a 3-tuple with geo referenced
     4909    UTM coordinates (zone, easting, northing)
     4910    """
     4911    import os
     4912    from Scientific.IO.NetCDF import NetCDFFile
     4913    from Numeric import Float, Int, Int32, searchsorted, zeros, array
     4914    from Numeric import allclose, around
     4915
     4916    precision = Float
     4917
     4918    msg = 'Must use latitudes and longitudes for minlat, maxlon etc'
     4919
     4920    if minlat != None:
     4921        assert -90 < minlat < 90 , msg
     4922    if maxlat != None:
     4923        assert -90 < maxlat < 90 , msg
     4924        if minlat != None:
     4925            assert maxlat > minlat
     4926    if minlon != None:
     4927        assert -180 < minlon < 180 , msg
     4928    if maxlon != None:
     4929        assert -180 < maxlon < 180 , msg
     4930        if minlon != None:
     4931            assert maxlon > minlon
     4932
     4933    if basename_out is None:
     4934        stsname = basename_in + '.sts'
     4935    else:
     4936        stsname = basename_out + '.sts'
     4937
     4938    files_in = [basename_in + WAVEHEIGHT_MUX2_LABEL,
     4939                basename_in + EAST_VELOCITY_MUX2_LABEL,
     4940                basename_in + NORTH_VELOCITY_MUX2_LABEL]
     4941    quantities = ['HA','UA','VA']
     4942
     4943    #need to do this for velocity-e-mux2 and velocity-n-mux2 files as well
     4944    #for now set x_momentum and y_moentum quantities to zero
     4945    if (verbose): print 'reading mux2 file'
     4946    mux={}
     4947    for quantity, file in map(None, quantities, files_in):
     4948        times_urs, latitudes_urs, longitudes_urs, elevation, mux[quantity] = read_mux2_py([file])
     4949        if quantity!=quantities[0]:
     4950            msg='%s, %s and %s have inconsitent gauge data'%(files_in[0],files_in[1],files_in[2])
     4951            assert allclose(times_urs,times_urs_old),msg
     4952            assert allclose(latitudes_urs,latitudes_urs_old),msg
     4953            assert allclose(longitudes_urs,longitudes_urs_old),msg
     4954            assert allclose(elevation,elevation_old),msg
     4955        times_urs_old=times_urs
     4956        latitudes_urs_old=latitudes_urs
     4957        longitudes_urs_old=longitudes_urs
     4958        elevation_old=elevation
     4959       
     4960    if (minlat is not None) and (minlon is not None) and (maxlat is not None) and (maxlon is not None):
     4961        latitudes = compress((latitudes_urs>=minlat)&(latitudes_urs<=maxlat)&(longitudes_urs>=minlon)&(longitudes_urs<=maxlon),latitudes_urs)
     4962        longitudes = compress((latitudes_urs>=minlat)&(latitudes_urs<=maxlat)&(longitudes_urs>=minlon)&(longitudes_urs<=maxlon),longitudes_urs)
     4963        times = compress((latitudes_urs>=minlat)&(latitudes_urs<=maxlat)&(longitudes_urs>=minlon)&(longitudes_urs<=maxlon),times_urs)
     4964    else:
     4965        latitudes=latitudes_urs
     4966        longitudes=longitudes_urs
     4967        times=times_urs
     4968
     4969    number_of_points = latitudes.shape[0]
     4970    number_of_times = times.shape[0]
     4971    number_of_latitudes = latitudes.shape[0]
     4972    number_of_longitudes = longitudes.shape[0]
     4973
     4974    # NetCDF file definition
     4975    outfile = NetCDFFile(stsname, 'w')
     4976
     4977    description = 'Converted from URS mux2 files: %s'\
     4978                  %(basename_in)
     4979   
     4980    # Create new file
     4981    starttime = times[0]
     4982    sts = Write_sts()
     4983    sts.store_header(outfile, times,number_of_points, description=description,
     4984                     verbose=verbose,sts_precision=Float)
     4985   
     4986    # Store
     4987    from anuga.coordinate_transforms.redfearn import redfearn
     4988    x = zeros(number_of_points, Float)  #Easting
     4989    y = zeros(number_of_points, Float)  #Northing
     4990
     4991    # Check zone boundaries
     4992    refzone, _, _ = redfearn(latitudes[0],longitudes[0]) 
     4993
     4994    for i in range(number_of_points):
     4995        zone, easting, northing = redfearn(latitudes[i],longitudes[i])
     4996        x[i] = easting
     4997        y[i] = northing
     4998        #print zone,easting,northing
     4999
     5000    if origin is None:
     5001        origin = Geo_reference(refzone,min(x),min(y))
     5002    geo_ref = write_NetCDF_georeference(origin, outfile)
     5003
     5004    z = elevation
     5005   
     5006    #print geo_ref.get_xllcorner()
     5007    #print geo_ref.get_yllcorner()
     5008
     5009    z = resize(z,outfile.variables['z'][:].shape)
     5010    outfile.variables['x'][:] = x - geo_ref.get_xllcorner()
     5011    outfile.variables['y'][:] = y - geo_ref.get_yllcorner()
     5012    outfile.variables['z'][:] = z             #FIXME HACK for bacwards compat.
     5013    outfile.variables['elevation'][:] = z
     5014
     5015    stage = outfile.variables['stage']
     5016    xmomentum = outfile.variables['xmomentum']
     5017    ymomentum =outfile.variables['ymomentum']
     5018
     5019    if verbose: print 'Converting quantities'
     5020    for j in range(len(times)):
     5021        for i in range(number_of_points):
     5022            w = zscale*mux['HA'][i,j] + mean_stage
     5023            h=w-elevation[i]
     5024            stage[j,i] = w
     5025            #delete following two lines once velcotu files are read in.
     5026            xmomentum[j,i] = mux['UA'][i,j]*h
     5027            ymomentum[j,i] = mux['VA'][i,j]*h
     5028
     5029    outfile.close()
    48365030
    48375031
     
    52265420           
    52275421            i +=1
     5422
     5423class Write_sts:
     5424
     5425    sts_quantities = ['stage','xmomentum','ymomentum']
     5426
     5427
     5428    RANGE = '_range'
     5429    EXTREMA = ':extrema'
     5430   
     5431    def __init__(self):
     5432        pass
     5433
     5434    def store_header(self,
     5435                     outfile,
     5436                     times,
     5437                     number_of_points,
     5438                     description='Converted from URS mux2 format',
     5439                     sts_precision=Float32,
     5440                     verbose=False):
     5441        """
     5442        outfile - the name of the file that will be written
     5443        times - A list of the time slice times OR a start time
     5444        Note, if a list is given the info will be made relative.
     5445        number_of_points - the number of urs gauges sites
     5446        """
     5447
     5448        outfile.institution = 'Geoscience Australia'
     5449        outfile.description = description
     5450       
     5451        try:
     5452            revision_number = get_revision_number()
     5453        except:
     5454            revision_number = None
     5455        # Allow None to be stored as a string               
     5456        outfile.revision_number = str(revision_number)
     5457       
     5458        # times - A list or array of the time slice times OR a start time
     5459        # Start time in seconds since the epoch (midnight 1/1/1970)
     5460
     5461        # This is being used to seperate one number from a list.
     5462        # what it is actually doing is sorting lists from numeric arrays.
     5463        if type(times) is list or type(times) is ArrayType: 
     5464            number_of_times = len(times)
     5465            times = ensure_numeric(times) 
     5466            if number_of_times == 0:
     5467                starttime = 0
     5468            else:
     5469                starttime = times[0]
     5470                times = times - starttime  #Store relative times
     5471        else:
     5472            number_of_times = 0
     5473            starttime = times
     5474
     5475        outfile.starttime = starttime
     5476
     5477        # Dimension definitions
     5478        outfile.createDimension('number_of_points', number_of_points)
     5479        outfile.createDimension('number_of_timesteps', number_of_times)
     5480        outfile.createDimension('numbers_in_range', 2)
     5481
     5482        # Variable definitions
     5483        outfile.createVariable('x', sts_precision, ('number_of_points',))
     5484        outfile.createVariable('y', sts_precision, ('number_of_points',))
     5485        outfile.createVariable('elevation', sts_precision,('number_of_points',))
     5486
     5487        q = 'elevation'
     5488        outfile.createVariable(q+Write_sts.RANGE, sts_precision,
     5489                               ('numbers_in_range',))
     5490
     5491        # Initialise ranges with small and large sentinels.
     5492        # If this was in pure Python we could have used None sensibly
     5493        outfile.variables[q+Write_sts.RANGE][0] = max_float  # Min
     5494        outfile.variables[q+Write_sts.RANGE][1] = -max_float # Max
     5495
     5496        outfile.createVariable('z', sts_precision, ('number_of_points',))
     5497        # Doing sts_precision instead of Float gives cast errors.
     5498        outfile.createVariable('time', Float, ('number_of_timesteps',))
     5499
     5500        for q in Write_sts.sts_quantities:
     5501            outfile.createVariable(q, sts_precision,
     5502                                   ('number_of_timesteps',
     5503                                    'number_of_points'))
     5504            outfile.createVariable(q+Write_sts.RANGE, sts_precision,
     5505                                   ('numbers_in_range',))
     5506            # Initialise ranges with small and large sentinels.
     5507            # If this was in pure Python we could have used None sensibly
     5508            outfile.variables[q+Write_sts.RANGE][0] = max_float  # Min
     5509            outfile.variables[q+Write_sts.RANGE][1] = -max_float # Max
     5510
     5511        if type(times) is list or type(times) is ArrayType: 
     5512            outfile.variables['time'][:] = times    #Store time relative
     5513
     5514        if verbose:
     5515            print '------------------------------------------------'
     5516            print 'Statistics:'
     5517            print '    t in [%f, %f], len(t) == %d'\
     5518                  %(min(times.flat), max(times.flat), len(times.flat))
     5519
     5520    def store_points(self,
     5521                     outfile,
     5522                     points_utm,
     5523                     elevation, zone=None, new_origin=None,
     5524                     points_georeference=None, verbose=False):
     5525
     5526        """
     5527        points_utm - currently a list or array of the points in UTM.
     5528        points_georeference - the georeference of the points_utm
     5529
     5530        How about passing new_origin and current_origin.
     5531        If you get both, do a convertion from the old to the new.
     5532       
     5533        If you only get new_origin, the points are absolute,
     5534        convert to relative
     5535       
     5536        if you only get the current_origin the points are relative, store
     5537        as relative.
     5538       
     5539        if you get no georefs create a new georef based on the minimums of
     5540        points_utm.  (Another option would be to default to absolute)
     5541       
     5542        Yes, and this is done in another part of the code.
     5543        Probably geospatial.
     5544       
     5545        If you don't supply either geo_refs, then supply a zone. If not
     5546        the default zone will be used.
     5547
     5548        precondition:
     5549             header has been called.
     5550        """
     5551
     5552        number_of_points = len(points_utm)
     5553        points_utm = array(points_utm)
     5554
     5555        # given the two geo_refs and the points, do the stuff
     5556        # described in the method header
     5557        points_georeference = ensure_geo_reference(points_georeference)
     5558        new_origin = ensure_geo_reference(new_origin)
     5559       
     5560        if new_origin is None and points_georeference is not None:
     5561            points = points_utm
     5562            geo_ref = points_georeference
     5563        else:
     5564            if new_origin is None:
     5565                new_origin = Geo_reference(zone,min(points_utm[:,0]),
     5566                                           min(points_utm[:,1]))
     5567            points = new_origin.change_points_geo_ref(points_utm,
     5568                                                      points_georeference)
     5569            geo_ref = new_origin
     5570
     5571        # At this stage I need a georef and points
     5572        # the points are relative to the georef
     5573        geo_ref.write_NetCDF(outfile)
     5574
     5575        x =  points[:,0]
     5576        y =  points[:,1]
     5577        z = outfile.variables['z'][:]
     5578   
     5579        if verbose:
     5580            print '------------------------------------------------'
     5581            print 'More Statistics:'
     5582            print '  Extent (/lon):'
     5583            print '    x in [%f, %f], len(lat) == %d'\
     5584                  %(min(x), max(x),
     5585                    len(x))
     5586            print '    y in [%f, %f], len(lon) == %d'\
     5587                  %(min(y), max(y),
     5588                    len(y))
     5589            print '    z in [%f, %f], len(z) == %d'\
     5590                  %(min(elevation), max(elevation),
     5591                    len(elevation))
     5592            print 'geo_ref: ',geo_ref
     5593            print '------------------------------------------------'
     5594           
     5595        #z = resize(bath_grid,outfile.variables['z'][:].shape)
     5596        #print "points[:,0]", points[:,0]
     5597        outfile.variables['x'][:] = points[:,0] #- geo_ref.get_xllcorner()
     5598        outfile.variables['y'][:] = points[:,1] #- geo_ref.get_yllcorner()
     5599        outfile.variables['z'][:] = elevation
     5600        outfile.variables['elevation'][:] = elevation  #FIXME HACK4
     5601
     5602        q = 'elevation'
     5603        # This updates the _range values
     5604        outfile.variables[q+Write_sts.RANGE][0] = min(elevation)
     5605        outfile.variables[q+Write_sts.RANGE][1] = max(elevation)
     5606
     5607    def store_quantities(self, outfile, sts_precision=Float32,
     5608                         slice_index=None, time=None,
     5609                         verbose=False, **quant):
     5610       
     5611        """
     5612        Write the quantity info.
     5613
     5614        **quant is extra keyword arguments passed in. These must be
     5615          the sts quantities, currently; stage.
     5616       
     5617        if the time array is already been built, use the slice_index
     5618        to specify the index.
     5619       
     5620        Otherwise, use time to increase the time dimension
     5621
     5622        Maybe make this general, but the viewer assumes these quantities,
     5623        so maybe we don't want it general - unless the viewer is general
     5624       
     5625        precondition:
     5626            triangulation and
     5627            header have been called.
     5628        """
     5629        if time is not None:
     5630            file_time = outfile.variables['time']
     5631            slice_index = len(file_time)
     5632            file_time[slice_index] = time   
     5633
     5634        # Write the conserved quantities from Domain.
     5635        # Typically stage,  xmomentum, ymomentum
     5636        # other quantities will be ignored, silently.
     5637        # Also write the ranges: stage_range
     5638        for q in Write_sts.sts_quantities:
     5639            if not quant.has_key(q):
     5640                msg = 'STS file can not write quantity %s' %q
     5641                raise NewQuantity, msg
     5642            else:
     5643                q_values = quant[q]
     5644                outfile.variables[q][slice_index] = \
     5645                                q_values.astype(sts_precision)
     5646
     5647                # This updates the _range values
     5648                q_range = outfile.variables[q+Write_sts.RANGE][:]
     5649                q_values_min = min(q_values)
     5650                if q_values_min < q_range[0]:
     5651                    outfile.variables[q+Write_sts.RANGE][0] = q_values_min
     5652                q_values_max = max(q_values)
     5653                if q_values_max > q_range[1]:
     5654                    outfile.variables[q+Write_sts.RANGE][1] = q_values_max
     5655
     5656
    52285657   
    52295658class Urs_points:
  • anuga_core/source/anuga/shallow_water/test_data_manager.py

    r5308 r5347  
    59775977        os.remove(sww_file)
    59785978       
     5979
     5980    def write_mux2(self,lat_long_points, time_step_count, time_step,
     5981                  depth=None, ha=None, ua=None, va=None
     5982                  ):
     5983        """
     5984        This will write 3 non-gridded mux files, for testing.
     5985        If no quantities are passed in,
     5986        na and va quantities will be the Easting values.
     5987        Depth and ua will be the Northing value.
     5988        """
     5989        #print "lat_long_points", lat_long_points
     5990        #print "time_step_count",time_step_count
     5991        #print "time_step",
     5992
     5993        #irrelevant header information
     5994        ig=ilon=ilat=0
     5995        mcolat=mcolon=centerlat=centerlon=offset=az=baz=id=0.0
     5996
     5997        points_num = len(lat_long_points)
     5998        latlondeps = []
     5999        quantities = ['HA','UA','VA']
     6000
     6001        mux_names = [WAVEHEIGHT_MUX2_LABEL,
     6002                     EAST_VELOCITY_MUX2_LABEL,
     6003                     NORTH_VELOCITY_MUX2_LABEL]
     6004        quantities_init = [[],[],[]]
     6005        # urs binary is latitude fastest
     6006        for point in lat_long_points:
     6007            lat = point[0]
     6008            lon = point[1]
     6009            _ , e, n = redfearn(lat, lon)
     6010            if depth is None:
     6011                this_depth = n
     6012            else:
     6013                this_depth = depth
     6014            if ha is None:
     6015                this_ha = e
     6016            else:
     6017                this_ha = ha
     6018            if ua is None:
     6019                this_ua = n
     6020            else:
     6021                this_ua = ua
     6022            if va is None:
     6023                this_va = e   
     6024            else:
     6025                this_va = va         
     6026            latlondeps.append([lat, lon, this_depth])
     6027            quantities_init[0].append(this_ha) # HA
     6028            quantities_init[1].append(this_ua) # UA
     6029            quantities_init[2].append(this_va) # VA
     6030
     6031        file_handle, base_name = tempfile.mkstemp("")
     6032        os.close(file_handle)
     6033        os.remove(base_name)
     6034
     6035        files = []       
     6036        for i,q in enumerate(quantities):
     6037            quantities_init[i] = ensure_numeric(quantities_init[i])
     6038            #print "HA_init", HA_init
     6039            q_time = zeros((time_step_count, points_num), Float)
     6040            for time in range(time_step_count):
     6041                q_time[time,:] = quantities_init[i] #* time * 4
     6042
     6043            #Write C files
     6044            columns = 3 # long, lat , depth
     6045            file = base_name + mux_names[i]
     6046            #print "base_name file",file
     6047            f = open(file, 'wb')
     6048            files.append(file)
     6049
     6050            f.write(pack('i',points_num))
     6051            #write mux 2 header
     6052            for latlondep in latlondeps:
     6053                f.write(pack('f',latlondep[0]))
     6054                f.write(pack('f',latlondep[1]))
     6055                f.write(pack('f',mcolat))
     6056                f.write(pack('f',mcolon))
     6057                f.write(pack('i',ig))
     6058                f.write(pack('i',ilon))
     6059                f.write(pack('i',ilat))
     6060                f.write(pack('f',latlondep[2]))
     6061                f.write(pack('f',centerlat))
     6062                f.write(pack('f',centerlon))
     6063                f.write(pack('f',offset))
     6064                f.write(pack('f',az))
     6065                f.write(pack('f',baz))
     6066                f.write(pack('f',time_step))
     6067                f.write(pack('i',time_step_count))
     6068                for j in range(4): # identifier
     6069                    f.write(pack('f',id))   
     6070
     6071            first_tstep=1
     6072            last_tstep=time_step_count
     6073            for latlondep in latlondeps:
     6074                f.write(pack('i',first_tstep))
     6075            for latlondep in latlondeps:
     6076                f.write(pack('i',last_tstep))
     6077
     6078            # Write quantity info
     6079
     6080            for time in  range(time_step_count):
     6081                #first timestep always assumed to be zero
     6082                f.write(pack('f',0.0))
     6083                for point_i in range(points_num):
     6084                    f.write(pack('f',q_time[time,point_i]))
     6085
     6086            f.close()
     6087        return base_name, files
     6088
     6089    def test_read_mux2_py(self):
     6090        from Numeric import ones,Float
     6091        tide = 1
     6092        time_step_count = 3
     6093        time_step = 2
     6094        lat_long_points =[(-21.5,114.5),(-21,114.5),(-21.5,115), (-21.,115.)]
     6095        depth=20
     6096        ha=2
     6097        ua=5
     6098        va=-10 #-ve added to take into account mux file format where south
     6099               # is positive.
     6100        base_name, files = self.write_mux2(lat_long_points,
     6101                                     time_step_count, time_step,
     6102                                     depth=depth,
     6103                                     ha=ha,
     6104                                     ua=ua,
     6105                                     va=va)
     6106
     6107        weights=ones(1,Float)
     6108        #ensure that files are indeed mux2 files
     6109        times, latitudes, longitudes, elevation, stage=read_mux2_py([files[0]],weights)
     6110        self.delete_mux(files)
     6111
     6112        msg='time array has incorrect length'
     6113        assert times.shape[0]==time_step_count,msg
     6114        msg = 'time array is incorrect'
     6115        assert allclose(times,time_step*arange(1,time_step_count+1)),msg
     6116        msg='Incorrect gauge positions returned'
     6117        for i,point in enumerate(lat_long_points):
     6118            assert allclose(latitudes[i],point[0]) and allclose(longitudes[i],point[1]),msg
     6119        msg='Incorrect gauge depths returned'
     6120        assert allclose(elevation,-depth*ones(len(lat_long_points),Float)),msg
     6121        msg='incorrect gauge time series returned'
     6122        assert allclose(stage,ha*ones((len(lat_long_points),time_step_count),Float))
     6123
     6124    def test_urs2sts(self):
     6125        from Numeric import ones,Float
     6126        tide = 1
     6127        time_step_count = 3
     6128        time_step = 2
     6129        lat_long = [[-21.5,114.5],[-21,114.5],[-21,115]]
     6130        depth=20
     6131        ha=2
     6132        ua=5
     6133        va=-10 #-ve added to take into account mux file format where south
     6134               # is positive.
     6135        base_name, files = self.write_mux2(lat_long,
     6136                                     time_step_count, time_step,
     6137                                     depth=depth,
     6138                                     ha=ha,
     6139                                     ua=ua,
     6140                                     va=va)
     6141
     6142        urs2sts(base_name,mean_stage=tide,verbose=False)
     6143
     6144        # now I want to check the sts file ...
     6145        sts_file = base_name + '.sts'
     6146
     6147        #Let's interigate the sww file
     6148        # Note, the sww info is not gridded.  It is point data.
     6149        fid = NetCDFFile(sts_file)
     6150
     6151        # Make x and y absolute
     6152        x = fid.variables['x'][:]
     6153        y = fid.variables['y'][:]
     6154
     6155        geo_reference = Geo_reference(NetCDFObject=fid)
     6156        points = geo_reference.get_absolute(map(None, x, y))
     6157        points = ensure_numeric(points)
     6158
     6159        x = points[:,0]
     6160        y = points[:,1]
     6161
     6162        #Check that first coordinate is correctly represented       
     6163        #Work out the UTM coordinates for first point
     6164        zone, e, n = redfearn(lat_long[0][0], lat_long[0][1])
     6165        assert allclose([x[0],y[0]], [e,n])
     6166
     6167        #Check the time vector
     6168        times = fid.variables['time'][:]
     6169
     6170        times_actual = []
     6171        for i in range(time_step_count):
     6172            times_actual.append(time_step * i)
     6173
     6174        assert allclose(ensure_numeric(times),
     6175                        ensure_numeric(times_actual))
     6176
     6177        #Check first value
     6178        stage = fid.variables['stage'][:]
     6179        xmomentum = fid.variables['xmomentum'][:]
     6180        ymomentum = fid.variables['ymomentum'][:]
     6181        elevation = fid.variables['elevation'][:]
     6182        assert allclose(stage[0,0], ha+tide)  #Meters
     6183
     6184
     6185        #Check the momentums - ua
     6186        #momentum = velocity*(stage-elevation)
     6187        # elevation = - depth
     6188        #momentum = velocity_ua *(stage+depth)
     6189
     6190        answer_x = ua*(ha+tide+depth)
     6191        actual_x = xmomentum[0,0]
     6192        #print "answer_x",answer_x
     6193        #print "actual_x",actual_x
     6194        assert allclose(answer_x, actual_x)  #Meters
     6195
     6196        #Check the momentums - va
     6197        #momentum = velocity*(stage-elevation)
     6198        # elevation = - depth
     6199        #momentum = velocity_va *(stage+depth)
     6200
     6201        answer_y = va*(ha+tide+depth)
     6202        actual_y = ymomentum[0,0]
     6203        #print "answer_y",answer_y
     6204        #print "actual_y",actual_y
     6205        assert allclose(answer_y, actual_y)  #Meters
     6206
     6207        # check the stage values, first time step.
     6208        assert allclose(stage[0], ha +tide)  #Meters
     6209        # check the elevation values.
     6210        # -ve since urs measures depth, sww meshers height,
     6211        # these arrays are equal since the northing values were used as
     6212        # the elevation
     6213        assert allclose(-elevation, depth)  #Meters
     6214
     6215        fid.close()
     6216        self.delete_mux(files)
     6217        os.remove(sts_file)
     6218
    59796219    def test_lon_lat2grid(self):
    59806220        lonlatdep = [
     
    75557795
    75567796
    7557 
    75587797       
    75597798        domain.set_quantity('elevation', 0.0)
     
    75757814                          interpolation_points=I,
    75767815                          verbose=False)
    7577 
    75787816        for t in range(t_end+1):
    75797817            for i in range(3):
Note: See TracChangeset for help on using the changeset viewer.