Changeset 7317 for anuga_core/source/anuga/geospatial_data
- Timestamp:
- Jul 22, 2009, 9:22:11 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/geospatial_data/geospatial_data.py
r7276 r7317 26 26 from anuga.config import netcdf_mode_r, netcdf_mode_w, netcdf_mode_a 27 27 from anuga.config import netcdf_float 28 import anuga.utilities.log as log 28 29 29 30 … … 170 171 if verbose is True: 171 172 if file_name is not None: 172 print 'Loading Geospatial data from file: %s' % file_name 173 log.critical('Loading Geospatial data from file: %s' 174 % file_name) 173 175 174 176 self.import_points_file(file_name, verbose=verbose) … … 181 183 if verbose is True: 182 184 if file_name is not None: 183 print 'Geospatial data created from file: %s' % file_name 185 log.critical('Geospatial data created from file: %s' 186 % file_name) 184 187 if load_file_now is False: 185 print 'Data will be loaded blockwise on demand'188 log.critical('Data will be loaded blockwise on demand') 186 189 187 190 if file_name.endswith('csv') or file_name.endswith('txt'): … … 437 440 438 441 if self.verbose is True: 439 print 'Using attribute %s' %attribute_name440 print 'Available attributes: %s' %(self.attributes.keys())442 log.critical('Using attribute %s' % attribute_name) 443 log.critical('Available attributes: %s' % (self.attributes.keys())) 441 444 442 445 msg = 'Attribute name %s does not exist in data set' % attribute_name … … 696 699 697 700 # Find unique random numbers 698 if verbose: print "make unique random number list and get indices" 701 if verbose: log.critical("make unique random number list " 702 "and get indices") 699 703 700 704 total = num.array(range(self_size), num.int) #array default# 701 705 total_list = total.tolist() 702 706 703 if verbose: print "total list len", len(total_list)707 if verbose: log.critical("total list len=%d" % len(total_list)) 704 708 705 709 # There will be repeated random numbers however will not be a … … 708 712 # still basically random 709 713 ## create list of non-unquie random numbers 710 if verbose: print "create random numbers list %s long" %new_size 714 if verbose: log.critical("create random numbers list %s long" 715 % str(new_size)) 711 716 712 717 # Set seed if provided, mainly important for unit test! … … 717 722 seed() 718 723 719 #if verbose: print "seed:", get_seed()720 721 724 random_num = randint(0, self_size-1, (int(new_size),)) 722 725 random_num = random_num.tolist() … … 726 729 random_num.reverse() 727 730 728 if verbose: print "make random number list and get indices"731 if verbose: log.critical("make random number list and get indices") 729 732 730 733 j = 0 … … 740 743 # prints progress 741 744 if verbose and round(random_num_len/10*k) == j: 742 print '(%s/%s)' % (j, random_num_len)745 log.critical('(%s/%s)' % (j, random_num_len)) 743 746 k += 1 744 747 … … 755 758 756 759 # Get new samples 757 if verbose: print "get values of indices for random list"760 if verbose: log.critical("get values of indices for random list") 758 761 G1 = self.get_sample(random_list) 759 if verbose: print "get values of indices for opposite of random list" 762 if verbose: log.critical("get values of indices for " 763 "opposite of random list") 760 764 G2 = self.get_sample(remainder_list) 761 765 … … 800 804 801 805 if self.verbose is True: 802 print('Reading %d points (in ~%d blocks) from file %s. '803 % (self.number_of_points, self.number_of_blocks,804 self.file_name)),805 print('Each block consists of %d data points'806 % self.max_read_lines)806 log.critical('Reading %d points (in ~%d blocks) from file %s. ' 807 % (self.number_of_points, self.number_of_blocks, 808 self.file_name)) 809 log.critical('Each block consists of %d data points' 810 % self.max_read_lines) 807 811 else: 808 812 # Assume the file is a csv file … … 837 841 if (self.show_verbose >= self.start_row 838 842 and self.show_verbose < fin_row): 839 print('Reading block %d (points %d to %d) out of %d'840 % (self.block_number, self.start_row,841 fin_row, self.number_of_blocks))843 log.critical('Reading block %d (points %d to %d) out of %d' 844 % (self.block_number, self.start_row, 845 fin_row, self.number_of_blocks)) 842 846 843 847 self.show_verbose += max(self.max_read_lines, … … 976 980 """ 977 981 978 if verbose: print 'Reading ', file_name982 if verbose: log.critical('Reading %s' % file_name) 979 983 980 984 # See if the file is there. Throw a QUIET IO error if it isn't … … 988 992 keys = fid.variables.keys() 989 993 990 if verbose: print 'Got %d variables: %s' % (len(keys), keys)994 if verbose: log.critical('Got %d variables: %s' % (len(keys), keys)) 991 995 992 996 try: … … 999 1003 attributes = {} 1000 1004 for key in keys: 1001 if verbose: print "reading attribute '%s'" % key1005 if verbose: log.critical("reading attribute '%s'" % key) 1002 1006 1003 1007 attributes[key] = num.array(fid.variables[key]) … … 1173 1177 raise IOError, msg 1174 1178 1175 if verbose: print 'Got %d variables: %s' % (len(keys), keys)1179 if verbose: log.critical('Got %d variables: %s' % (len(keys), keys)) 1176 1180 1177 1181 try: … … 1562 1566 1563 1567 if mesh_file is None: 1564 if verbose: print "building mesh"1568 if verbose: log.critical("building mesh") 1565 1569 mesh_file = 'temp.msh' 1566 1570 … … 1597 1601 1598 1602 # split topo data 1599 if verbose: print 'Reading elevation file: %s' % data_file1603 if verbose: log.critical('Reading elevation file: %s' % data_file) 1600 1604 G = Geospatial_data(file_name = data_file) 1601 if verbose: print 'Start split'1605 if verbose: log.critical('Start split') 1602 1606 G_small, G_other = G.split(split_factor, seed_num, verbose=verbose) 1603 if verbose: print 'Finish split'1607 if verbose: log.critical('Finish split') 1604 1608 points = G_small.get_data_points() 1605 1609 1606 if verbose: print "Number of points in sample to compare: ", len(points) 1610 if verbose: log.critical("Number of points in sample to compare: %d" 1611 % len(points)) 1607 1612 1608 1613 if alpha_list == None: … … 1628 1633 normal_cov = num.array(num.zeros([len(alphas), 2]), dtype=num.float) 1629 1634 1630 if verbose: print 'Setup computational domains with different alphas' 1635 if verbose: log.critical('Setup computational domains with ' 1636 'different alphas') 1631 1637 1632 1638 for i, alpha in enumerate(alphas): 1633 1639 # add G_other data to domains with different alphas 1634 1640 if verbose: 1635 print '\nCalculating domain and mesh for Alpha =', alpha, '\n' 1641 log.critical('Calculating domain and mesh for Alpha=%s' 1642 % str(alpha)) 1636 1643 domain = Domain(mesh_file, use_cache=cache, verbose=verbose) 1637 if verbose: print domain.statistics()1644 if verbose: log.critical(domain.statistics()) 1638 1645 domain.set_quantity(attribute_smoothed, 1639 1646 geospatial_data=G_other, … … 1647 1654 # returns the predicted elevation of the points that were "split" out 1648 1655 # of the original data set for one particular alpha 1649 if verbose: print 'Get predicted elevation for location to be compared' 1656 if verbose: log.critical('Get predicted elevation for location ' 1657 'to be compared') 1650 1658 elevation_predicted = \ 1651 1659 domain.quantities[attribute_smoothed].\ … … 1660 1668 1661 1669 if verbose: 1662 print 'Covariance for alpha ', normal_cov[i][0], '= ', \1663 normal_cov[i][1]1664 print '-------------------------------------------- \n'1670 log.critical('Covariance for alpha %s=%s' 1671 % (normal_cov[i][0], normal_cov[i][1])) 1672 log.critical('--------------------------------------------') 1665 1673 1666 1674 normal_cov0 = normal_cov[:,0] … … 1678 1686 1679 1687 if verbose: 1680 print 'Final results:'1688 log.critical('Final results:') 1681 1689 for i, alpha in enumerate(alphas): 1682 print('covariance for alpha %s = %s '1683 % (normal_cov[i][0], normal_cov[i][1]))1684 print ('\nOptimal alpha is: %s '1685 % normal_cov_new[(num.argmin(normal_cov_new, axis=0))[1], 0])1690 log.critical('covariance for alpha %s = %s ' 1691 % (normal_cov[i][0], normal_cov[i][1])) 1692 log.critical('Optimal alpha is: %s ' 1693 % normal_cov_new[(num.argmin(normal_cov_new, axis=0))[1], 0]) 1686 1694 1687 1695 # covariance and optimal alpha … … 1802 1810 # split topo data 1803 1811 G = Geospatial_data(file_name=data_file) 1804 if verbose: print 'start split'1812 if verbose: log.critical('start split') 1805 1813 G_small, G_other = G.split(split_factor, seed_num, verbose=verbose) 1806 if verbose: print 'finish split'1814 if verbose: log.critical('finish split') 1807 1815 points = G_small.get_data_points() 1808 1816 1809 if verbose: print "Number of points in sample to compare: ", len(points) 1817 if verbose: log.critical("Number of points in sample to compare: %d" 1818 % len(points)) 1810 1819 1811 1820 if alpha_list == None: … … 1818 1827 domains = {} 1819 1828 1820 if verbose: print 'Setup computational domains with different alphas' 1829 if verbose: log.critical('Setup computational domains with ' 1830 'different alphas') 1821 1831 1822 1832 for alpha in alphas: 1823 1833 # add G_other data to domains with different alphas 1824 1834 if verbose: 1825 print '\nCalculating domain and mesh for Alpha =', alpha, '\n' 1835 log.critical('Calculating domain and mesh for Alpha = %s' % 1836 str(alpha)) 1826 1837 domain = Domain(mesh_file, use_cache=cache, verbose=verbose) 1827 if verbose: print domain.statistics()1838 if verbose: log.critical(domain.statistics()) 1828 1839 domain.set_quantity(attribute_smoothed, 1829 1840 geospatial_data=G_other, … … 1849 1860 1850 1861 if verbose: 1851 print 'Determine difference between predicted results and actual data' 1862 log.critical('Determine difference between predicted results ' 1863 'and actual data') 1852 1864 1853 1865 for i, alpha in enumerate(domains): … … 1867 1879 ele_cov = cov(elevation_sample - elevation_predicted) 1868 1880 normal_cov[i,:] = [alpha,ele_cov / sample_cov] 1869 print 'memory usage during compare', mem_usage() 1870 if verbose: print 'cov', normal_cov[i][0], '= ', normal_cov[i][1] 1881 log.critical('memory usage during compare: %s' % str(mem_usage())) 1882 if verbose: log.critical('cov %s = %s' 1883 % (normal_cov[i][0], normal_cov[i][1])) 1871 1884 1872 1885 normal_cov0 = normal_cov[:,0]
Note: See TracChangeset
for help on using the changeset viewer.