Changeset 8147
- Timestamp:
- Mar 11, 2011, 4:02:47 PM (14 years ago)
- Location:
- trunk/anuga_core/source/anuga
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/util.py
r8124 r8147 44 44 boundary_polygon, output_centroids) 45 45 46 ##47 # @brief Replace multiple substrings in a string.48 # @param text The string to operate on.49 # @param dictionary A dict containing replacements, key->value.50 # @return The new string.51 46 def multiple_replace(text, dictionary): 52 47 """Multiple replace of words in text … … 71 66 72 67 73 ##74 # @brief Apply arbitrary expressions to the values of a dict.75 # @param expression A string expression to apply.76 # @param dictionary The dictionary to apply the expression to.77 68 def apply_expression_to_dictionary(expression, dictionary): 78 69 """Apply arbitrary expression to values of dictionary … … 119 110 120 111 121 ##122 # @brief Format a float into a string.123 # @param value Float value to format.124 # @param format The format to use (%.2f is default).125 # @return The formatted float as a string.126 112 def get_textual_float(value, format = '%.2f'): 127 113 """Get textual representation of floating point numbers … … 150 136 return format % float(value) 151 137 152 ##153 # @brief Read gauge info from a file.154 # @param filename The name of the file to read.155 # @return A (gauges, gaugelocation, elev) tuple.156 138 def get_gauges_from_file(filename): 157 139 return gauge_get_from_file(filename) 158 140 159 141 160 ##161 # @brief Check that input quantities in quantity list are legal.162 # @param quantity Quantity list to check.163 # @note Raises an exception of list is not legal.164 142 def check_list(quantity): 165 143 """ Check that input quantities in quantity list are possible … … 181 159 182 160 183 ##184 # @brief Calculate velocity bearing from North.185 # @param uh ??186 # @param vh ??187 # @return The calculated bearing.188 161 def calc_bearing(uh, vh): 189 162 """ Calculate velocity bearing from North … … 204 177 205 178 206 ##207 # @brief Create a nested sub-directory path.208 # @param root_directory The base diretory path.209 # @param directories An iterable of sub-directory names.210 # @return The final joined directory path.211 # @note If each sub-directory doesn't exist, it will be created.212 179 def add_directories(root_directory, directories): 213 180 """ … … 227 194 228 195 229 ##230 # @brief231 # @param verbose232 # @param kwargs233 # @return234 # @note TEMP235 196 def store_parameters(verbose=False,**kwargs): 236 197 """Temporary Interface to new location""" … … 245 206 246 207 247 ##248 # @brief Remove vertices that are not associated with any triangle.249 # @param verts An iterable (or array) of points.250 # @param triangles An iterable of 3 element tuples.251 # @param number_of_full_nodes ??252 # @return (verts, triangles) where 'verts' has been updated.253 208 def remove_lone_verts(verts, triangles, number_of_full_nodes=None): 254 209 """Removes vertices that are not associated with any triangles. … … 301 256 302 257 303 ##304 # @brief Compute centroid values from vertex values305 # @param x Values at vertices of triangular mesh.306 # @param triangles Nx3 integer array pointing to vertex information.307 # @return [N] array of centroid values.308 258 def get_centroid_values(x, triangles): 309 259 """Compute centroid values from vertex values … … 351 301 352 302 353 ##354 # @brief Plot time series from CSV files.355 # @param directories_dic356 # @param output_dir357 # @param base_name358 # @param plot_numbers359 # @param quantities360 # @param extra_plot_name361 # @param assess_all_csv_files362 # @param create_latex363 # @param verbose364 # @note Assumes that 'elevation' is in the CSV file(s).365 303 def csv2timeseries_graphs(directories_dic={}, 366 304 output_dir='', … … 779 717 if verbose: log.critical('Finished closing plots') 780 718 781 ##782 # @brief Return min and max of an iterable.783 # @param list The iterable to return min & max of.784 # @return (min, max) of 'list'.785 719 def get_min_max_values(list=None): 786 720 """ … … 793 727 794 728 795 ##796 # @brief Get runup around a point in a CSV file.797 # @param gauge_filename gauge file name.798 # @param sww_filename SWW file name.799 # @param runup_filename Name of file to report into.800 # @param size ??801 # @param verbose ??802 729 def get_runup_data_for_locations_from_file(gauge_filename, 803 730 sww_filename, … … 851 778 file.close() 852 779 853 ##854 # @brief ??855 # @param ??856 # @param gauge_file ??857 # @param out_name ??858 # @param quantities ??859 # @param verbose ??860 # @param use_cache ??861 780 def sww2csv_gauges(sww_file, 862 781 gauge_file, … … 949 868 output_centroids) 950 869 951 ##952 # @brief Get a wave height at a certain depth given wave height at another depth.953 # @param d1 The first depth.954 # @param d2 The second depth.955 # @param h1 Wave ampitude at d1956 # @param verbose True if this function is to be verbose.957 # @return The wave height at d2.958 870 def greens_law(d1, d2, h1, verbose=False): 959 871 """Green's Law … … 998 910 999 911 1000 ##1001 # @brief Get the square-root of a value.1002 # @param s The value to get the square-root of.1003 # @return The square-root of 's'.1004 912 def square_root(s): 1005 913 return sqrt(s) -
trunk/anuga_core/source/anuga/geospatial_data/geospatial_data.py
r8124 r8147 32 32 33 33 34 ##35 # @brief ??36 34 class Geospatial_data: 37 35 38 ##39 # @brief40 # @param data_points Mx2 iterable of tuples or array of x,y coordinates.41 # @param attributes Associated values for each data point.42 # @param geo_reference ??43 # @param default_attribute_name ??44 # @param file_name45 # @param latitudes ??46 # @param longitudes ??47 # @param points_are_lats_longs True if points are lat/long, not UTM.48 # @param max_read_lines Size of block to read, if blocking.49 # @param load_file_now True if blocking but we eant to read file now.50 # @param verbose True if this class instance is verbose.51 36 def __init__(self, 52 37 data_points=None, # this can also be a points file name … … 196 181 # print 'data as a pts NetCDF format' 197 182 198 ##199 # @brief Return length of the points set.200 183 def __len__(self): 201 184 return len(self.data_points) 202 185 203 ##204 # @brief Return a string representation of the points set.205 186 def __repr__(self): 206 187 return str(self.get_data_points(absolute=True)) 207 188 208 ##209 # @brief Check data points.210 # @param data_points Points data to check and store in instance.211 # @note Throws ValueError exception if no data.212 189 def check_data_points(self, data_points): 213 190 """Checks data points""" … … 223 200 assert self.data_points.shape[1] == 2 224 201 225 ##226 # @brief Check and assign attributes data.227 # @param attributes Dictionary or scalar to save as .attributes.228 # @note Throws exception if unable to convert dict keys to numeric.229 202 def set_attributes(self, attributes): 230 203 """Check and assign attributes dictionary""" … … 249 222 self.attributes = attributes 250 223 251 ##252 # @brief Set the georeference of geospatial data.253 # @param geo_reference The georeference data to set.254 # @note Will raise exception if param not instance of Geo_reference.255 224 def set_geo_reference(self, geo_reference): 256 225 """Set the georeference of geospatial data. … … 281 250 self.geo_reference = geo_reference 282 251 283 ##284 # @brief Set default attribute name.285 # @param default_attribute_name The default to save.286 252 def set_default_attribute_name(self, default_attribute_name): 287 253 self.default_attribute_name = default_attribute_name 288 254 289 ##290 # @brief Set the instance verbose flag.291 # @param verbose The value to save.292 # @note Will raise exception if param is not True or False.293 255 def set_verbose(self, verbose=False): 294 256 if verbose in [False, True]: … … 298 260 raise Exception(msg) 299 261 300 ##301 # @brief Clip geospatial data by a given polygon.302 # @param polygon The polygon to clip with.303 # @param closed True if points on clip boundary are not included in result.304 # @param verbose True if this function is verbose.305 262 def clip(self, polygon, closed=True, verbose=False): 306 263 """Clip geospatial data by a polygon … … 335 292 return clipped_G 336 293 337 ##338 # @brief Clip points data by polygon, return points outside polygon.339 # @param polygon The polygon to clip with.340 # @param closed True if points on clip boundary are not included in result.341 # @param verbose True if this function is verbose.342 294 def clip_outside(self, polygon, closed=True, verbose=False): 343 295 """Clip geospatial date by a polygon, keeping data OUTSIDE of polygon … … 367 319 return clipped_G 368 320 369 ##370 # @brief Get instance geo_reference data.371 321 def get_geo_reference(self): 372 322 return self.geo_reference 373 323 374 ##375 # @brief Get coordinates for all data points as an Nx2 array.376 # @param absolute If True, return UTM, else relative to xll/yll corners.377 # @param geo_reference If supplied, points are relative to it.378 # @param as_lat_long If True, return points as lat/lon.379 # @param isSouthHemisphere If True, return lat/lon points in S.Hemi.380 # @return A set of data points, in appropriate form.381 324 def get_data_points(self, 382 325 absolute=True, … … 422 365 return self.data_points 423 366 424 ##425 # @brief Get value for attribute name.426 # @param attribute_name Name to get value for.427 # @note If name passed is None, return default attribute value.428 367 def get_attributes(self, attribute_name=None): 429 368 """Return values for one named attribute. … … 448 387 return self.attributes[attribute_name] 449 388 450 ##451 # @brief Get all instance attributes.452 # @return The instance attribute dictionary, or None if no attributes.453 389 def get_all_attributes(self): 454 390 """Return values for all attributes. … … 458 394 return self.attributes 459 395 460 ##461 # @brief Override __add__() to allow addition of geospatial objects.462 # @param self This object.463 # @param other The second object.464 # @return The new geospatial object.465 396 def __add__(self, other): 466 397 """Returns the addition of 2 geospatial objects, … … 518 449 return Geospatial_data(new_points, new_attributes, new_geo_ref) 519 450 520 ##521 # @brief Override the addition case where LHS isn't geospatial object.522 # @param self This object.523 # @param other The second object.524 # @return The new geospatial object.525 451 def __radd__(self, other): 526 452 """Handle cases like None + Geospatial_data(...)""" … … 532 458 ################################################################################ 533 459 534 ##535 # @brief Import a .txt, .csv or .pts points data file.536 # @param file_name537 # @param delimiter538 # @param verbose True if this function is to be verbose.539 # @note Will throw IOError or SyntaxError if there is a problem.540 460 def import_points_file(self, file_name, delimiter=None, verbose=False): 541 461 """ load an .txt, .csv or .pts file … … 581 501 self.geo_reference = geo_reference 582 502 583 ##584 # @brief Write points data to a file (.csv or .pts).585 # @param file_name Path to file to write.586 # @param absolute ??587 # @param as_lat_long ??588 # @param isSouthHemisphere ??589 503 def export_points_file(self, file_name, absolute=True, 590 504 as_lat_long=False, isSouthHemisphere=True): … … 638 552 raise IOError(msg) 639 553 640 ##641 # @brief Get a subset of data that is referred to by 'indices'.642 # @param indices A list of indices to select data subset with.643 # @return A geospatial object containing data subset.644 554 def get_sample(self, indices): 645 555 """ Returns a object which is a subset of the original … … 667 577 return Geospatial_data(sampled_points, sampled_attributes) 668 578 669 ##670 # @brief Split one geospatial object into two.671 # @param factor Relative size to make first result object.672 # @param seed_num Random 'seed' - used only for unit test.673 # @param verbose True if this function is to be verbose.674 # @note Points in each result object are selected randomly.675 579 def split(self, factor=0.5, seed_num=None, verbose=False): 676 580 """Returns two geospatial_data object, first is the size of the 'factor' … … 766 670 return G1, G2 767 671 768 ##769 # @brief Allow iteration over this object.770 672 def __iter__(self): 771 673 """Read in the header, number_of_points and save the … … 817 719 return self 818 720 819 ##820 # @brief Read another block into the instance.821 721 def next(self): 822 722 """read a block, instanciate a new geospatial and return it""" … … 916 816 'The attribute values must be numeric.\n') 917 817 918 ##919 # @brief ??920 # @param latitudes ??921 # @param longitudes ??922 # @param geo_reference ??923 # @param data_points ??924 # @param points_are_lats_longs ??925 # @note IS THIS USED???926 818 def _set_using_lat_long(latitudes, 927 819 longitudes, … … 966 858 967 859 968 ##969 # @brief Read a .pts data file.970 # @param file_name Path to file to read.971 # @param verbose True if this function is to be verbose.972 # @return (pointlist, attributes, geo_reference)973 860 def _read_pts_file(file_name, verbose=False): 974 861 """Read .pts NetCDF file … … 1017 904 1018 905 1019 ##1020 # @brief Read a .csv data file.1021 # @param file_name Path to the .csv file to read.1022 # @param verbose True if this function is to be verbose.1023 906 def _read_csv_file(file_name, verbose=False): 1024 907 """Read .csv file … … 1050 933 1051 934 1052 ##1053 # @brief Read a .csv file header.1054 # @param file_pointer Open descriptor of the file to read.1055 # @param delimiter Header line delimiter string, split on this string.1056 # @param verbose True if this function is to be verbose.1057 # @return A tuple of (<cleaned header string>, <input file_pointer>)1058 1059 935 CSV_DELIMITER = ',' 1060 936 … … 1071 947 return header, file_pointer 1072 948 1073 ##1074 # @brief Read a .csv file, with blocking.1075 # @param file_pointer Open descriptor of the file to read.1076 # @param header List of already read .csv header fields.1077 # @param delimiter Delimiter string header was split on.1078 # @param max_read_lines The max number of lines to read before blocking.1079 # @param verbose True if this function is to be verbose.1080 # @note Will throw IndexError, SyntaxError exceptions.1081 949 def _read_csv_file_blocking(file_pointer, 1082 950 header, … … 1160 1028 1161 1029 1162 ##1163 # @brief Read a .pts file header.1164 # @param fid Handle to the open .pts file.1165 # @param verbose True if the function is to be verbose.1166 # @return (geo_reference, keys, fid.dimensions['number_of_points'])1167 # @note Will throw IOError and AttributeError exceptions.1168 1030 def _read_pts_file_header(fid, verbose=False): 1169 1031 '''Read the geo_reference and number_of_points from a .pts file''' … … 1187 1049 1188 1050 1189 ##1190 # @brief Read the body of a .pts file, with blocking.1191 # @param fid Handle to already open file.1192 # @param start_row Start row index of points to return.1193 # @param fin_row End row index of points to return.1194 # @param keys Iterable of keys to return.1195 # @return Tuple of (pointlist, attributes).1196 1051 def _read_pts_file_blocking(fid, start_row, fin_row, keys): 1197 1052 '''Read the body of a .pts file.''' … … 1206 1061 1207 1062 1208 ##1209 # @brief Write a .pts data file.1210 # @param file_name Path to the file to write.1211 # @param write_data_points Data points to write.1212 # @param write_attributes Attributes to write.1213 # @param write_geo_reference Georef to write.1214 1063 def _write_pts_file(file_name, 1215 1064 write_data_points, … … 1264 1113 1265 1114 1266 ##1267 # @brief Write a .csv data file.1268 # @param file_name Path to the file to write.1269 # @param write_data_points Data points to write.1270 # @param write_attributes Attributes to write.1271 # @param as_lat_long True if points are lat/lon, else x/y.1272 # @param delimiter The CSV delimiter to use.1273 1115 def _write_csv_file(file_name, 1274 1116 write_data_points, … … 1311 1153 1312 1154 1313 ##1314 # @brief Write a URS file.1315 # @param file_name The path of the file to write.1316 # @param points1317 # @param delimiter1318 1155 def _write_urs_file(file_name, points, delimiter=' '): 1319 1156 """Write a URS format file. … … 1335 1172 1336 1173 1337 ##1338 # @brief ??1339 # @param point_atts ??1340 # @return ??1341 1174 def _point_atts2array(point_atts): 1342 1175 point_atts['pointlist'] = num.array(point_atts['pointlist'], num.float) … … 1349 1182 1350 1183 1351 ##1352 # @brief Convert geospatial object to a points dictionary.1353 # @param geospatial_data The geospatial object to convert.1354 # @return A points dictionary.1355 1184 def geospatial_data2points_dictionary(geospatial_data): 1356 1185 """Convert geospatial data to points_dictionary""" … … 1370 1199 1371 1200 1372 ##1373 # @brief Convert a points dictionary to a geospatial object.1374 # @param points_dictionary A points dictionary to convert.1375 1201 def points_dictionary2geospatial_data(points_dictionary): 1376 1202 """Convert points_dictionary to geospatial data object""" … … 1392 1218 1393 1219 1394 ##1395 # @brief Ensure that points are in absolute coordinates.1396 # @param points A list or array of points to check, or geospatial object.1397 # @param geo_reference If supplied,1398 # @return ??1399 1220 def ensure_absolute(points, geo_reference=None): 1400 1221 """Ensure that points are in absolute coordinates. … … 1440 1261 1441 1262 1442 ##1443 # @brief1444 # @param points1445 # @param geo_reference1446 # @return A geospatial object.1447 1263 def ensure_geospatial(points, geo_reference=None): 1448 1264 """Convert various data formats to a geospatial_data instance. … … 1484 1300 1485 1301 1486 ##1487 # @brief1488 # @param data_file1489 # @param alpha_list1490 # @param mesh_file1491 # @param boundary_poly1492 # @param mesh_resolution1493 # @param north_boundary1494 # @param south_boundary1495 # @param east_boundary1496 # @param west_boundary1497 # @param plot_name1498 # @param split_factor1499 # @param seed_num1500 # @param cache1501 # @param verbose1502 1302 def find_optimal_smoothing_parameter(data_file, 1503 1303 alpha_list=None, … … 1698 1498 1699 1499 1700 ##1701 # @brief1702 # @param data_file1703 # @param alpha_list1704 # @param mesh_file1705 # @param boundary_poly1706 # @param mesh_resolution1707 # @param north_boundary1708 # @param south_boundary1709 # @param east_boundary1710 # @param west_boundary1711 # @param plot_name1712 # @param split_factor1713 # @param seed_num1714 # @param cache1715 # @param verbose1716 1500 def old_find_optimal_smoothing_parameter(data_file, 1717 1501 alpha_list=None, -
trunk/anuga_core/source/anuga/utilities/test_numerical_tools.py
r8124 r8147 467 467 # t(num.array('abc', num.float), False) 468 468 469 ##470 # @brief Test to see if ensure_numeric() behaves as we expect.471 # @note Under Numeric ensure_numeric() *always* returned a copy (bug).472 # Under numpy it copies only when it has to.473 469 def test_ensure_numeric_copy(self): 470 """Test to see if ensure_numeric() behaves as we expect. 471 472 Under Numeric ensure_numeric() *always* returned a copy (bug). 473 Under numpy it copies only when it has to. 474 """ 475 474 476 ##### 475 477 # Make 'points' a _list_ of coordinates.
Note: See TracChangeset
for help on using the changeset viewer.