aisdb.webdata.shore_dist module
This module calculates distances from the shore, coast, and the nearest port for given coordinates using raster files from NASA and Global Fishing Watch. These calculations are valuable for various analyses, including environmental impact studies, navigation safety assessments, and maritime activities monitoring.
To use this module, the necessary raster files must be first manually downloaded and placed in the specified data_dir due to the requirement of a (free) login for accessing Global Fishing Watch rasters. This pre-step ensures that the module operates smoothly without needing interactive authentication during runtime.
You can download the required raster data from the following sources:
- For distance from the coast calculations:
https://oceancolor.gsfc.nasa.gov/docs/distfromcoast/GMT_intermediate_coast_distance_01d.zip
- For distance from shore and port calculations (Global Fishing Watch):
- Distance from the shore:
https://globalfishingwatch.org/data-download/datasets/public-distance-from-shore-v1
- Distance from the nearest port:
https://globalfishingwatch.org/data-download/datasets/public-distance-from-port-v1
After downloading, please extract the zip files and place the resulting geotiff files into the data_dir you specified. This setup enables the module to directly access and utilize these raster files for distance calculations. This documentation and the accompanying module aim to facilitate easy and efficient access to marine geographical data for research and operational purposes.
- class aisdb.webdata.shore_dist.CoastDist(data_dir, tif_filename='GMT_intermediate_coast_distance_01d.tif')[source]
Bases:
RasterFile
- data_url = 'http://bigdata5.research.cs.dal.ca/raster-coast.7z'
- get_distance(tracks)[source]
This method calculates the distance of each track in the given track list from the nearest coast. It checks if the ‘imgpath’ attribute exists in the class object calling the method. Then, it calls the ‘merge_tracks’ method, passing the tracks list and specifying the new track key as ‘km_from_coast’. The ‘merge_tracks’ method merges all the tracks into a single track object and adds the new track key with the calculated distance.
- Parameters:
tracks – A list of track objects
- Returns:
A merged track object with a new track key ‘km_from_coast’
- Example:
>>> y1, x1 = 48.271185186388735, -61.10595523571155 >>> # Creating a sample track >>> tracks_short = [dict( ... lon=np.array([x1]), lat=np.array([y1]), ... time=[0], dynamic={'time'}, )]
>>> with CoastDist(data_dir="./testdata/") as cdist: >>> # Getting distance from the nearest coast for each point in the track >>> for track in cdist.get_distance(tracks_short): >>> assert 'km_from_coast' in track.keys() >>> assert 'km_from_coast' in track['dynamic'] >>> print(track['km_from_coast'])
- class aisdb.webdata.shore_dist.PortDist(data_dir, tif_filename='distance-from-port-v20201104.tiff')[source]
Bases:
RasterFile
- data_url = 'http://bigdata5.research.cs.dal.ca/raster-ports.7z'
- get_distance(tracks)[source]
This method calculates the distance of each track in the given track list from the nearest port. It first checks if the ‘imgpath’ attribute exists in the class object calling the method. Then, it calls the ‘merge_tracks’ method, passing the tracks list and specifying the new track key as ‘km_from_port’. The ‘merge_tracks’ method merges all the tracks into a single track object and adds the new track key with the calculated distance.
- Parameters:
tracks – A list of track objects
- Returns:
A merged track object with a new track key ‘km_from_port’
- Example:
>>> y1, x1 = 48.271185186388735, -61.10595523571155 >>> # Creating a sample track >>> tracks_short = [dict( ... lon=np.array([x1]), lat=np.array([y1]), ... time=[0], dynamic={'time'}, )]
>>> with PortDist(data_dir="./testdata/") as pdist: >>> # Getting distance from the nearest port for each point in the track >>> for track in pdist.get_distance(tracks_short): >>> assert 'km_from_port' in track.keys() >>> assert 'km_from_port' in track['dynamic'] >>> print(track['km_from_port'])
- class aisdb.webdata.shore_dist.ShoreDist(data_dir, tif_filename='distance-from-shore.tif')[source]
Bases:
RasterFile
- data_url = 'http://bigdata5.research.cs.dal.ca/raster-shore.7z'
- get_distance(tracks)[source]
This method calculates the distance of each track in the given tracks list from the shore. It first checks if the ‘imgpath’ attribute exists in the class object calling the method. Then, it calls the ‘merge_tracks’ method, passing the tracks list and specifying the new track key as ‘km_from_shore’. The ‘merge_tracks’ method merges all the tracks into a single track object and adds the new track key with the calculated distance.
- Parameters:
tracks – A list of track objects
- Returns:
A merged track object with a new track key ‘km_from_shore’
- Example:
>>> y1, x1 = 48.271185186388735, -61.10595523571155 >>> # creating a sample track >>> tracks_short = [ dict( ... lon=np.array([x1]), lat=np.array([y1]), ... time=[0], dynamic={'time'}, ) ]
>>> with ShoreDist(data_dir="./testdata/") as sdist: >>> # getting distance from shore for each point in the track >>> for track in sdist.get_distance(tracks_short): >>> assert 'km_from_shore' in track.keys() >>> assert 'km_from_shore' in track['dynamic'] >>> print(track['km_from_shore'])
- aisdb.webdata.shore_dist.download_unzip(data_url, data_dir, bytesize=0, timeout=(10, 30))[source]
Download and unzip a file from a given URL to a specified directory.
- Parameters:
data_url – The URL of the file to download.
data_dir – The directory in which to store the downloaded file.
bytesize – The expected size of the file in bytes (optional, default=0).
timeout – The timeout values for the connection and response in seconds (optional, default=(10, 30)).