Changeset 4387 for anuga_core/source/anuga/shallow_water/data_manager.py
- Timestamp:
- Apr 17, 2007, 5:07:33 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note: See TracChangeset
for help on using the changeset viewer.