Changes between Version 8 and Version 9 of ClassGeospatial_data


Ignore:
Timestamp:
Mar 2, 2009, 11:10:14 AM (16 years ago)
Author:
rwilson
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ClassGeospatial_data

    v8 v9  
    3434== Class Methods ==
    3535
    36 || '''__init__(data_points=None, attributes=None, geo_reference=None, default_attribute=None, file_name=None, latitudes=None, longitudes=None, points_are_lats_longs=False, max_read_lines=None, load_file_now=True, verbose=False)''' || Constructor.     ||
    37 || '''!BearingTo(self, P)''' || Returns the bearing in degrees from `self` to point `P`. ||
    38 || '''name''' ||  ||
    39 || '''name''' ||  ||
    40 || '''name''' ||  ||
    41 || '''name''' ||  ||
    42 || '''name''' ||  ||
    43 || '''name''' ||  ||
    44 || '''name''' ||  ||
     36|| '''_ _init_ _(data_points=None, attributes=None, geo_reference=None, default_attribute=None, file_name=None, latitudes=None, longitudes=None, points_are_lats_longs=False, max_read_lines=None, load_file_now=True, verbose=False)''' || '''data_points''' is either a 2-dimensional (Mx2) set of points or a filename (ending in .pts, .csv or .txt) of a file containing the point data.  '''attributes''' contains the attribute value to be stored at each data point and must be either a list or vector array (length M, assumed attribute 'elevation') or a dictionary with multiple attribute name keys and value lists. '''geo_reference''' is the Geo_reference reference defining the origin of the points in this object. '''default_attribute_name''' is the name of the attribute considered to be default in the get_attribute() method. '''file_name''' is the name of a NetCDF (or .txt) file to load points data from. '''latitudes''' and '''longitudes''' are lists/vectors defining points as lats/longs rather then the '''data_points''' parameter. '''points_are_lats_longs''' is a boolean which is True if the points data are actually lats/longs and not UTM coordinates.  '''max_read_lines''' sets the number of lines to read in a 'block' if blocking data from a file.  '''load_file_now''' is True if the file data is to be automatically loaded into memory (used if blocking). '''verbose''' is True if this class is to be verbose.  ||
     37|| '''_ _len_ _()''' || Returns the length of the '''data_points''' attribute. ||
     38|| '''_ _repr_ _()''' || Returns a string representation of '''get_data_points(absolute=True)'''. ||
     39|| '''check_data_points(data_points)''' || Populate the '''data_points''' attribute dataset. ||
     40|| '''set_attributes(attributes)''' || Assign attributes data to this instance. '''attributes''' is either list/array of attributes values (default name '''elevation''') or a dictionary of attribute name:values pairs. ||
     41|| '''set_geo-reference()''' || Set or change the Geo_reference reference for this instance.  If changing, ensure that absolute coordinate values are unchanged. ||
     42|| '''set_default_attribute(default_attribute_name)''' || Set the instance default attribute name (used in get_attribute()). ||
     43|| '''set_verbose(verbose=False)''' || Set the verbose attribute for this instance. ||
     44|| '''clip(polygon, closed=True, verbose=False)''' || Clip the instance points set by a given polygon. '''polygon''' is either a list or array of points (Nx2) or a Geospatial_data instance. '''closed''' is True if any points `on` the bounding polygon are to be considered `inside` the polygon. '''verbose''' - not sure why this is here - class has a '''verbose''' attribute.  Method returns the point set inside the clipping polygon. ||
     45|| '''clip_outside(polygon, closed=True, verbose=False)''' || Clip the instance points set by a given polygon. '''polygon''' is either a list or array of points (Nx2) or a Geospatial_data instance. '''closed''' is True if any points `on` the bounding polygon are to be considered `inside` the polygon. '''verbose''' - not sure why this is here - class has a '''verbose''' attribute.  Method returns the point set outside the clipping polygon. ||
     46|| '''get_geo_reference()''' || Return the Geo_reference reference assigned to this instance. ||
     47|| '''get_data_points(absolute=True, geo_reference=None, as_lat_long=False, isSouthHemisphere=True''' || Get coordinates of the points dataset in this instance. Id '''absolute''' is True return absolute UTM coordinates, else return coordinates relative to the associated Geo_reference origin. If '''geo_reference''' is supplied return coordinates relative to that origin. If '''as_lat_long''' is True return coordinates as lat/long points.  If '''isSouthHemisphere''' is True return any lat/long coordinates as for the southern hemisphere, else the northern. ||
     48|| '''get_attributes(attribute_name=None)''' || Return the attribute values for one attribute. If '''attribute_name''' is None return the values for the default attribute.||
     49|| '''get_all_attributes()''' || Return '''all''' attributes as a (possibly empty) dictionary or None (if no attributes). ||
     50|| '''_ _add_ _(other)''' || Method to allow addition of two Geo_reference instances.  In this case, 'add' means concatenate the point datasets and attributes.  Throws an exception if the attributes aren't the same in both instances.  Returns a new instance of Geo_reference which is '''absolute'''. ||
     51|| '''_ _radd_ _(other)''' || Method to allow addition of two Geo_reference instances.  In this case, 'add' means concatenate the point datasets and attributes.  Throws an exception if the attributes aren't the same in both instances.  Returns a new instance of Geo_reference which is '''absolute'''. ||
     52|| '''import_points_file(file_name, delimiter=None, verbose=False)''' || Import a .txt, .csv or .pts file into this instance from '''file_name'''.  Also reads attributes and geo_reference data from the input file. '''delimiter''' is unused. '''verbose''' is superfluous. ||
     53|| '''export_points_file(file_name, absolute=True, as_lat_long=False, isSouthHemisphere=True)''' || Write Geo_reference instance data to a .pts, .csv or .txt file. '''file_name''' is the path to the file to write. If '''absolute''' is True then the point coordinates in the instance are converted to absolute form and then written out. If '''absolute''' is False the Geo_reference point coordinates remain unchanged and written out (note, they may be relative or absolute).  If '''is_lat_long''' is True then points are written out as lat/long coordinates, southern hemisphere form if '''isSouthHemisphere''' is True, northern if False. ||
     54|| '''get_sample(indices)''' || Get a new Geo_reference instance containing a sample of points in this instance. '''indices''' contains the ordinals of the points to be placed in the new instance.  Attributes of the sampled points are copied to the new instance. ||
     55|| '''split(factor=0.5, seed_num=None, verbose=False)''' || Split this instance into two new instances containing a random selection of points. '''factor''' is the fraction of the input instance to be copied into the first split instance. '''seed_num''' is the random seed to use (testing only). If '''verbose''' is True then this method is to be verbose. ||
     56|| '''_ _iter()_ _()''' || Allow iteration of the instance over input blocks.  This function sets up ready for the next() method.  This measn that the '''blocking_georef''', '''blocking_keys''' and '''number_of_points''' are read from the file if it is a .pts file, or the '''header''' and '''file_pointer''' are read from the assumed .csv file.  In the .pts case we also initialize variables used for PTS blocking. ||
     57|| '''next()''' || Read another block of data into memory. Return an instance of a new Geospatial_data object containing the data block read. ||
     58
     59== Module Methods ==
     60
     61|| '''_set_using_lat_long(latitudes, longitudes, geo_reference, data_points, points_are_lats_longs)''' || Set the points data with lat/long values.  If '''geo_reference''' is supplied will always throw exception? ||
     62|| '''_read_pts_file(file_name, verbose=False)''' || Read a NetCDF .pts file and return (dict_points, dict_attributes, geo_reference). ||
     63|| '''_read_csv_file(file_name, verbose=False)''' || Read a .csv file and return (dict_points, dict_attributes, geo_reference). ||
     64|| '''_read_csv_file_header(file_pointer, delimiter=CSV_DELIMITER, verbose=False)''' || Read the header form an already open CSV text file.  Returns the `cleaned` header and '''file_pointer''' (the open file handle). ||
     65|| '''_read_csv_file_blocking(file_pointer, header, delimiter=CSV_DELIMITER, max_read_lines=MAX_READ_LINES, verbose=False)''' || Read a .csv file with blocking semantics - will raise StopIteration if no more data. Otherwise return (points, dict_attributes, geo_ref, file_pointer). ||
     66|| '''_read_pts_file_header(fid, verbose=False)''' || Read .pts file header information from open file '''fid'''.  Returns (geo_ref, attribute_keys, number_of_points). ||
     67|| '''_read_pts_file_blocking(fid, start_row, fin_row, keys)''' || Read the body of a .pts file, with blocking semantics. Returns (point_list, attributes) where '''point_list''' is the points subset defined by ['''start_row''':'''fin_row'''] and '''attributes''' is the attributes from the same subset. ||
     68|| '''_write_pts_file(file_name, write_data_points, write_attributes=None, write_geo_reference=None''' || Write a .pts data file to a file '''file_name'''.  '''write_data_points''' holds the points data to write.  '''write_attributes''' contains the attributes to write. '''write_geo_reference''' is the Geo_reference data to write. ||
     69|| '''_write_csv_file(file_name, write_data_points, write_attributes=None, as_lat_long=False, delimiter=',')''' || Write paoint and attributes data to a .csv file '''file_name'''.  If '''as_lat_long''' is True write coordinates out as lat/long. ||
     70|| '''_write_urs_file(file_name, points, delimiter=' ')''' || Write points data to a URS file '''file_name'''.  '''points''' data is in lat/long form. ||
     71|| '''_point_atts2array(point_atts)''' || Convert a dictionary of points data into a dictionary of num.array data.  Input dictionary has keys 'pointlist' of points data and key 'attributelist' which is a dictionary of attributes data. Changes '''point_atts''' in-place. ||
     72|| '''geospatial_data2points_dictionary(geospatial_data)''' || Convert a geospatial object to a dictionary of points. Dictionary is left with keys 'pointlist' which contains a list/array of points, 'attributelist' which is a dictionary of key:value pairs and 'geo_reference' which is the geo_reference object.  ||
     73|| '''points_dictionary2geospatial_data(geospatial_data)''' || Convert a dictionary of points to a Geo_spatial object. Inverse of geospatial_data2points_dictionary() above. ||
     74|| '''ensure_absolute(points, geo_reference=None)''' || Ensure that a set of points are in absolute coordinates. If '''geo_reference''' is specified, assume the points are relative to it. ||
     75|| '''ensure_geospatial(points, geo_reference=None)''' || Convert a set of points to a Geospatial_data instance.  '''geo_reference''' may be either a Geo_reference object or a 3-tuple of (zone, easting, northing). ||
     76|| '''find_optimal_smoothing_parameter(data_file, alpha_list=None, mesh_file=None, boundary_poly=None, mesh_resolution=100000, north_boundary=None, south_boundary=None, east_boundary=None, west_boundary=None, plot_name='all_alphas', split_factor=0.1, seed_num=False, cache=False, verbose=False)''' || Using a sample of points from '''data_file''' and a selection of alpha values from '''alpha_list''' returns the alpha value that has the smallest covariance between the predicted value and removed values. ||
     77|| '''find_optimal_smoothing_parameter()''' || Obsolete version of the above function. ||
    4578
    4679== Notes ==
     
    4881This class is defined in the 'old' way.  Will need to be changed for python 2.6/3.x.
    4982
    50 '''Way too overloaded''' in the constructor.  For instance, data_points are `either` a 2-dimensional array of points `or` a filename of input data.  Yet there is also a file_name parameter for a filename!?  Maybe better not to fill with data in the constructor but call one of a selection of 'file_with_data' routines later.
     83'''Way too overloaded in the constructor.'''  For instance, data_points are `either` a 2-dimensional array of points `or` a filename of input data.  Yet there is another '''file_name''' parameter!?  Maybe better not to fill with data in the constructor but call one of a selection of 'fill_with_data' routines later.
    5184
    52 Not sure that building in blocking to this class is the correct approach.  Perhaps better to override file semantics to provide blocking and then get this class to contain a reference to a file-like object to get data from.  See above point, also.
     85Not sure that building blocking into this class is the correct approach.  Probably better to override file semantics to provide blocking and then get this class to contain a reference to a file-like object to get data from.  See above point.
     86
     87Overloaded way too much in some methods.  For instance, get_data_points() should be broken up into a simple method and attributes that control UTM/lat/long coordinates, southern/northern hemisphere, etc.
     88
     89Return values overloaded too much.  For instance, get_all_attributes() should '''always''' return an empty dictionary if no attributes, not "either an empty dictionary or None".
    5390
    5491-----