Ignore:
Timestamp:
Apr 17, 2007, 5:07:33 PM (18 years ago)
Author:
duncan
Message:

small modifications to geo-reffing

File:
1 edited

Legend:

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

    r4382 r4387  
    7272from anuga.coordinate_transforms.redfearn import redfearn, \
    7373     convert_from_latlon_to_utm
    74 from anuga.coordinate_transforms.geo_reference import Geo_reference
     74from anuga.coordinate_transforms.geo_reference import Geo_reference, \
     75     write_NetCDF_georeference
    7576from anuga.geospatial_data.geospatial_data import Geospatial_data,\
    7677     ensure_absolute
     
    26452646    outfile = NetCDFFile(swwname, 'w')
    26462647
    2647     #Create new file
    2648     outfile.institution = 'Geoscience Australia'
    2649     outfile.description = 'Converted from Ferret files: %s, %s, %s, %s'\
    2650                           %(basename_in + '_ha.nc',
    2651                             basename_in + '_ua.nc',
    2652                             basename_in + '_va.nc',
    2653                             basename_in + '_e.nc')
    2654 
    2655 
    2656     #For sww compatibility
    2657     outfile.smoothing = 'Yes'
    2658     outfile.order = 1
    2659 
    2660     #Start time in seconds since the epoch (midnight 1/1/1970)
    2661     outfile.starttime = starttime = times[0]
    2662     times = times - starttime  #Store relative times
    2663 
    2664     # dimension definitions
    2665     outfile.createDimension('number_of_volumes', number_of_volumes)
    2666 
    2667     outfile.createDimension('number_of_vertices', 3)
    2668     outfile.createDimension('number_of_points', number_of_points)
    2669 
    2670 
    2671     #outfile.createDimension('number_of_timesteps', len(times))
    2672     outfile.createDimension('number_of_timesteps', len(times))
    2673 
    2674     # variable definitions
    2675     outfile.createVariable('x', precision, ('number_of_points',))
    2676     outfile.createVariable('y', precision, ('number_of_points',))
    2677     outfile.createVariable('elevation', precision, ('number_of_points',))
    2678 
    2679     #FIXME: Backwards compatibility
    2680     outfile.createVariable('z', precision, ('number_of_points',))
    2681     #################################
    2682 
    2683     outfile.createVariable('volumes', Int, ('number_of_volumes',
    2684                                             'number_of_vertices'))
    2685 
    2686     outfile.createVariable('time', precision,
    2687                            ('number_of_timesteps',))
    2688 
    2689     outfile.createVariable('stage', precision,
    2690                            ('number_of_timesteps',
    2691                             'number_of_points'))
    2692 
    2693     outfile.createVariable('xmomentum', precision,
    2694                            ('number_of_timesteps',
    2695                             'number_of_points'))
    2696 
    2697     outfile.createVariable('ymomentum', precision,
    2698                            ('number_of_timesteps',
    2699                             'number_of_points'))
    2700 
     2648    description = 'Converted from Ferret files: %s, %s, %s, %s'\
     2649                  %(basename_in + '_ha.nc',
     2650                    basename_in + '_ua.nc',
     2651                    basename_in + '_va.nc',
     2652                    basename_in + '_e.nc')
     2653    write_sww_header(outfile, times, number_of_volumes,
     2654                     number_of_points, description=description)
     2655#     #Create new file
     2656#     outfile.institution = 'Geoscience Australia'
     2657#     outfile.description = 'Converted from Ferret files: %s, %s, %s, %s'\
     2658#                           %(basename_in + '_ha.nc',
     2659#                             basename_in + '_ua.nc',
     2660#                             basename_in + '_va.nc',
     2661#                             basename_in + '_e.nc')
     2662
     2663
     2664#     #For sww compatibility
     2665#     outfile.smoothing = 'Yes'
     2666#     outfile.order = 1
     2667
     2668#     #Start time in seconds since the epoch (midnight 1/1/1970)
     2669#     outfile.starttime = starttime = times[0]
     2670#     times = times - starttime  #Store relative times
     2671
     2672#     # dimension definitions
     2673#     outfile.createDimension('number_of_volumes', number_of_volumes)
     2674
     2675#     outfile.createDimension('number_of_vertices', 3)
     2676#     outfile.createDimension('number_of_points', number_of_points)
     2677
     2678
     2679#     #outfile.createDimension('number_of_timesteps', len(times))
     2680#     outfile.createDimension('number_of_timesteps', len(times))
     2681
     2682#     # variable definitions
     2683#     outfile.createVariable('x', precision, ('number_of_points',))
     2684#     outfile.createVariable('y', precision, ('number_of_points',))
     2685#     outfile.createVariable('elevation', precision, ('number_of_points',))
     2686
     2687#     #FIXME: Backwards compatibility
     2688#     outfile.createVariable('z', precision, ('number_of_points',))
     2689#     #################################
     2690
     2691#     outfile.createVariable('volumes', Int, ('number_of_volumes',
     2692#                                             'number_of_vertices'))
     2693
     2694#     outfile.createVariable('time', precision,
     2695#                            ('number_of_timesteps',))
     2696
     2697#     outfile.createVariable('stage', precision,
     2698#                            ('number_of_timesteps',
     2699#                             'number_of_points'))
     2700
     2701#     outfile.createVariable('xmomentum', precision,
     2702#                            ('number_of_timesteps',
     2703#                             'number_of_points'))
     2704
     2705#     outfile.createVariable('ymomentum', precision,
     2706#                            ('number_of_timesteps',
     2707#                             'number_of_points'))
     2708
     2709#     outfile.variables['time'][:] = times   #Store time relative
    27012710
    27022711    #Store
     
    27412750    volumes = array(volumes)
    27422751
    2743     if origin == None:
    2744         zone = refzone
    2745         xllcorner = min(x)
    2746         yllcorner = min(y)
    2747     else:
    2748         zone = origin[0]
    2749         xllcorner = origin[1]
    2750         yllcorner = origin[2]
    2751 
    2752 
    2753     outfile.xllcorner = xllcorner
    2754     outfile.yllcorner = yllcorner
    2755     outfile.zone = zone
     2752    if origin is None:
     2753        origin = Geo_reference(refzone,min(x),min(y))
     2754    geo_ref = write_NetCDF_georeference(origin, outfile)
     2755   
     2756#     if origin == None:
     2757#         zone = refzone
     2758#         xllcorner = min(x)
     2759#         yllcorner = min(y)
     2760#     else:
     2761#         zone = origin[0]
     2762#         xllcorner = origin[1]
     2763#         yllcorner = origin[2]
     2764
     2765
     2766#     outfile.xllcorner = xllcorner
     2767#     outfile.yllcorner = yllcorner
     2768#     outfile.zone = zone
    27562769
    27572770
     
    27672780    from Numeric import resize
    27682781    z = resize(z,outfile.variables['z'][:].shape)
    2769     outfile.variables['x'][:] = x - xllcorner
    2770     outfile.variables['y'][:] = y - yllcorner
     2782    outfile.variables['x'][:] = x - geo_ref.get_xllcorner()
     2783    outfile.variables['y'][:] = y - geo_ref.get_yllcorner()
    27712784    outfile.variables['z'][:] = z             #FIXME HACK for bacwards compat.
    27722785    outfile.variables['elevation'][:] = z
    2773     outfile.variables['time'][:] = times   #Store time relative
    27742786    outfile.variables['volumes'][:] = volumes.astype(Int32) #For Opteron 64
    27752787
     
    28082820        print '  Reference:'
    28092821        print '    Lower left corner: [%f, %f]'\
    2810               %(xllcorner, yllcorner)
     2822              %(geo_ref.get_xllcorner(), geo_ref.get_yllcorner())
    28112823        print '    Start time: %f' %starttime
    28122824        print '  Extent:'
     
    45734585    return mux_times_start_i, mux_times_fin_i
    45744586
    4575 def write_sww_header(outfile, times, number_of_volumes, number_of_points ):
     4587def write_sww_header(outfile, times, number_of_volumes, number_of_points, description='Converted from XXX'):
    45764588    """
    45774589    outfile - the name of the file that will be written
     
    45794591    number_of_volumes - the number of triangles
    45804592    """
     4593    times = ensure_numeric(times)
     4594   
    45814595    number_of_times = len(times)
    45824596   
    45834597    outfile.institution = 'Geoscience Australia'
    45844598    outfile.description = 'Converted from XXX'
    4585 
    45864599
    45874600    #For sww compatibility
     
    45944607    else:
    45954608        outfile.starttime = starttime = times[0]
    4596 
     4609    times = times - starttime  #Store relative times
    45974610
    45984611    # dimension definitions
    45994612    outfile.createDimension('number_of_volumes', number_of_volumes)
    4600 
    46014613    outfile.createDimension('number_of_vertices', 3)
    46024614    outfile.createDimension('number_of_points', number_of_points)
     
    46304642                            'number_of_points'))
    46314643   
    4632     outfile.variables['time'][:] = times   
     4644    outfile.variables['time'][:] = times    #Store time relative
    46334645
    46344646
     
    46394651    volumes = array(volumes)
    46404652
    4641     if origin is not None:
    4642         if isinstance(origin, Geo_reference):
    4643             geo_ref = origin
    4644         else:
    4645             geo_ref = apply(Geo_reference,origin)
    4646     else:
    4647         geo_ref = Geo_reference(zone,min(points_utm[:,0]),min(points_utm[:,1]))
    4648     #geo_ref = Geo_reference(zone,0,0)
    4649     geo_ref.write_NetCDF(outfile)
     4653    if origin is None:
     4654        origin = Geo_reference(zone,min(points_utm[:,0]),min(points_utm[:,1]))
     4655    geo_ref = write_NetCDF_georeference(origin, outfile)
     4656   
     4657#     if origin is not None:
     4658#         if isinstance(origin, Geo_reference):
     4659#             geo_ref = origin
     4660#         else:
     4661#             geo_ref = apply(Geo_reference,origin)
     4662#     else:
     4663#         geo_ref = Geo_reference(zone,min(points_utm[:,0]),min(points_utm[:,1]))
     4664#     #geo_ref = Geo_reference(zone,0,0)
     4665#     geo_ref.write_NetCDF(outfile)
     4666   
    46504667
    46514668    # This will put the geo ref in the middle
Note: See TracChangeset for help on using the changeset viewer.