def readTracks(trackFile):
    """
    Read a track file and create a `GeoPandas.GeoDataFrame` from the data, with
    separate polyline features for each unique track in the file. Also adds a
    nominal intensity category based on the central pressure value.
    
    :param str trackFile: Path to a TCRM-format track file
    
    :returns: `GeoPandas.GeoDataFrame` of tracks
    """

    LOGGER.debug(f"Loading track data from {trackFile}")
    tracks = track.ncReadTrackData(trackFile)
    trackgdf = []
    for t in tracks:
        segments = []
        for n in range(len(t.data) - 1):
            segment = LineString([[t.Longitude[n], t.Latitude[n]],
                                  [t.Longitude[n + 1], t.Latitude[n + 1]]])
            segments.append(segment)
        gdf = gpd.GeoDataFrame.from_records(t.data[:-1])
        gdf['geometry'] = segments
        gdf['category'] = pd.cut(gdf['CentralPressure'],
                                 bins=[0, 930, 955, 970, 985, 990, 1020],
                                 labels=[5, 4, 3, 2, 1, 0])
        trackgdf.append(gdf)
    trackgdf = pd.concat(trackgdf)
    return trackgdf
示例#2
0
def parseTracks(configFile,
                trackFile,
                source,
                delta,
                outputFile=None,
                interpolation_type=None):
    """
    Load a track dataset, then interpolate to some time delta (given in
    hours). Events with only a single record are not altered.

    :type  configFile: string
    :param configFile: Configuration file containing settings that
                       describe the data source.

    :type  trackFile: string
    :param trackFile: Path to the input data source.

    :type  source: string
    :param source: Name of the data source. `configFile` must have a
                   corresponding section which contains options that
                   describe the data format.

    :type  delta: float
    :param delta: Time difference to interpolate the dataset to. Must be
                  positive.

    :type  outputFile: string
    :param outputFile: Path to the destination of output, if it is to
                       be saved.

    :type  results: `list` of :class:`Track` objects containing the
                    interpolated track data

    """
    LOG.info("Interpolating tracks from {0}".format(trackFile))
    if delta < 0.0:
        raise ValueError("Time step for interpolation must be positive")

    if trackFile.endswith("nc"):
        from Utilities.track import ncReadTrackData
        tracks = ncReadTrackData(trackFile)
    else:
        tracks = loadTrackFile(configFile, trackFile, source)

    results = []

    for track in tracks:
        if len(track.data) == 1:
            results.append(track)
        else:
            newtrack = interpolate(track, delta, interpolation_type)
            results.append(newtrack)

    if outputFile:
        # Save data to file:
        ncSaveTracks(outputFile, results)

    return results
示例#3
0
def loadTracks(trackfile):
    """
    Read tracks from a track .nc file and return a list of :class:`Track`
    objects.

    This calls the function `ncReadTrackData` to parse the track .nc file.

    :type  trackfile: str
    :param trackfile: the track data filename.
    """
    tracks = ncReadTrackData(trackfile)
    return tracks
示例#4
0
    if args.source:
        source = args.source
    else:
        source = config.get('DataProcess', 'Source')

    output_path = dirname(realpath(track_file))
    filename, ext = splitext(track_file)
    pt_output_file = filename + '_pt.shp'
    line_output_file = filename + '_line.shp'
    dissolve_output_file = filename + '_dissolve.shp'

    if track_file.endswith(".nc"):

        from Utilities.track import ncReadTrackData
        tracks = ncReadTrackData(track_file)
        netcdf_format = True

    elif track_file.endswith(".csv"):
        tracks = loadTrackFile(config_file,
                               track_file,
                               source,
                               calculateWindSpeed=True)
        netcdf_format = False

    else:
        raise ValueError("format of {} is not recognizable".format(track_file))

    tracks2point(tracks, pt_output_file, netcdf_format=netcdf_format)
    tracks2line(tracks, line_output_file, netcdf_format=netcdf_format)
    tracks2line(tracks,