Changeset 4387
- Timestamp:
- Apr 17, 2007, 5:07:33 PM (18 years ago)
- Location:
- anuga_core/source/anuga
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/coordinate_transforms/geo_reference.py
r4180 r4387 16 16 TITLE = '#geo reference' + "\n" #this title is referred to in the .xya format 17 17 18 DEFAULT_PROJECTION = 'UTM' 19 DEFAULT_DATUM = 'wgs84' 20 DEFAULT_UNITS = 'm' 21 DEFAULT_FALSE_EASTING = 500000 22 DEFAULT_FALSE_NORTHING = 10000000 #Default for southern hemisphere 23 18 24 class Geo_reference: 19 25 """ … … 24 30 xllcorner = 0.0, 25 31 yllcorner = 0.0, 26 datum = 'wgs84', 27 projection = 'UTM', units = 'm', 28 false_easting = 500000, 29 false_northing = 10000000, #Default for southern hemisphere 32 datum = DEFAULT_DATUM, 33 projection = DEFAULT_PROJECTION, 34 units = DEFAULT_UNITS, 35 false_easting = DEFAULT_FALSE_EASTING, 36 false_northing = DEFAULT_FALSE_NORTHING, 30 37 NetCDFObject=None, 31 38 ASCIIFile=None, … … 39 46 it can't unread it, so this info has to be passed. 40 47 If you know of a way to unread this info, then tell us. 41 """ 48 49 Note, the text file only saves a sub set of the info the 50 points file does. Currently the info not written in text 51 must be the default info, since ANUGA assumes it isn't 52 changing. 53 """ 42 54 43 55 self.false_easting = false_easting … … 82 94 self.zone = infile.zone[0] 83 95 96 self.false_easting = infile.false_easting[0] 97 self.false_northing = infile.false_northing[0] 98 99 self.datum = infile.datum 100 self.projection = infile.projection 101 self.units = infile.units 102 84 103 # Fix some assertion failures 85 104 if type(self.zone) == ArrayType and self.zone.shape == (): … … 95 114 type(self.yllcorner) == types.IntType) 96 115 assert (type(self.zone) == types.IntType) 97 98 #FIXME (Ole) Read in the rest... 116 117 assert (self.false_easting == DEFAULT_FALSE_EASTING) 118 assert (self.false_northing == DEFAULT_FALSE_NORTHING) 119 120 assert(self.datum == DEFAULT_DATUM) 121 assert(self.projection == DEFAULT_PROJECTION) 122 assert (self.units == DEFAULT_UNITS) 99 123 100 124 … … 132 156 assert (type(self.zone) == types.IntType) 133 157 134 #false_easting = infile.false_easting[0]135 #false_northing = infile.false_northing[0]136 158 137 159 def change_points_geo_ref(self, points, … … 267 289 cmp = 1 268 290 return cmp 269 291 292 def write_NetCDF_georeference(origin, outfile): 293 """ 294 Write georeferrence info to a netcdf file, usually sww. 295 296 The origin can be a georef instance or parrameters for a geo_ref instance 297 298 outfile is the name of the file to be written to. 299 """ 300 if isinstance(origin, Geo_reference): 301 geo_ref = origin 302 else: 303 geo_ref = apply(Geo_reference,origin) 304 geo_ref.write_NetCDF(outfile) 305 return geo_ref 306 270 307 #----------------------------------------------------------------------- 271 308 -
anuga_core/source/anuga/shallow_water/data_manager.py
r4382 r4387 72 72 from anuga.coordinate_transforms.redfearn import redfearn, \ 73 73 convert_from_latlon_to_utm 74 from anuga.coordinate_transforms.geo_reference import Geo_reference 74 from anuga.coordinate_transforms.geo_reference import Geo_reference, \ 75 write_NetCDF_georeference 75 76 from anuga.geospatial_data.geospatial_data import Geospatial_data,\ 76 77 ensure_absolute … … 2645 2646 outfile = NetCDFFile(swwname, 'w') 2646 2647 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 2701 2710 2702 2711 #Store … … 2741 2750 volumes = array(volumes) 2742 2751 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 2756 2769 2757 2770 … … 2767 2780 from Numeric import resize 2768 2781 z = resize(z,outfile.variables['z'][:].shape) 2769 outfile.variables['x'][:] = x - xllcorner2770 outfile.variables['y'][:] = y - yllcorner2782 outfile.variables['x'][:] = x - geo_ref.get_xllcorner() 2783 outfile.variables['y'][:] = y - geo_ref.get_yllcorner() 2771 2784 outfile.variables['z'][:] = z #FIXME HACK for bacwards compat. 2772 2785 outfile.variables['elevation'][:] = z 2773 outfile.variables['time'][:] = times #Store time relative2774 2786 outfile.variables['volumes'][:] = volumes.astype(Int32) #For Opteron 64 2775 2787 … … 2808 2820 print ' Reference:' 2809 2821 print ' Lower left corner: [%f, %f]'\ 2810 %( xllcorner, yllcorner)2822 %(geo_ref.get_xllcorner(), geo_ref.get_yllcorner()) 2811 2823 print ' Start time: %f' %starttime 2812 2824 print ' Extent:' … … 4573 4585 return mux_times_start_i, mux_times_fin_i 4574 4586 4575 def write_sww_header(outfile, times, number_of_volumes, number_of_points 4587 def write_sww_header(outfile, times, number_of_volumes, number_of_points, description='Converted from XXX'): 4576 4588 """ 4577 4589 outfile - the name of the file that will be written … … 4579 4591 number_of_volumes - the number of triangles 4580 4592 """ 4593 times = ensure_numeric(times) 4594 4581 4595 number_of_times = len(times) 4582 4596 4583 4597 outfile.institution = 'Geoscience Australia' 4584 4598 outfile.description = 'Converted from XXX' 4585 4586 4599 4587 4600 #For sww compatibility … … 4594 4607 else: 4595 4608 outfile.starttime = starttime = times[0] 4596 4609 times = times - starttime #Store relative times 4597 4610 4598 4611 # dimension definitions 4599 4612 outfile.createDimension('number_of_volumes', number_of_volumes) 4600 4601 4613 outfile.createDimension('number_of_vertices', 3) 4602 4614 outfile.createDimension('number_of_points', number_of_points) … … 4630 4642 'number_of_points')) 4631 4643 4632 outfile.variables['time'][:] = times 4644 outfile.variables['time'][:] = times #Store time relative 4633 4645 4634 4646 … … 4639 4651 volumes = array(volumes) 4640 4652 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 4650 4667 4651 4668 # This will put the geo ref in the middle -
anuga_core/source/anuga/shallow_water/test_data_manager.py
r4382 r4387 5724 5724 times = fid.variables['time'][:] 5725 5725 5726 times_actual = [ 200,300,400,500]5726 times_actual = [0,100,200,300] 5727 5727 5728 5728 assert allclose(ensure_numeric(times), … … 5974 5974 #------------------------------------------------------------- 5975 5975 if __name__ == "__main__": 5976 #suite = unittest.makeSuite(Test_Data_Manager,'test_urs2sww ')5976 #suite = unittest.makeSuite(Test_Data_Manager,'test_urs2sww_origin') 5977 5977 #suite = unittest.makeSuite(Test_Data_Manager,'cache_test_URS_points_needed_and_urs_ungridded2sww') 5978 5978 #suite = unittest.makeSuite(Test_Data_Manager,'test_urs_ungridded_hole')
Note: See TracChangeset
for help on using the changeset viewer.