def download_features(group_names, dry_run=True): for group_name in group_names: feature_defns = FEATURE_DEFN_GROUPS[group_name] if isinstance(feature_defns, Feature): feature = feature_defns level = list(feature._levels)[0] downloader = Downloader.from_config(('shapefiles', 'gshhs', feature._scale, level)) format_dict = {'config': config, 'scale': feature._scale, 'level': level} if dry_run: print('URL: {}'.format(downloader.url(format_dict))) else: downloader.path(format_dict) geoms = list(feature.geometries()) print('Feature {} length: {}'.format(feature, len(geoms))) else: for category, name, scales in feature_defns: if not isinstance(scales, tuple): scales = (scales,) for scale in scales: downloader = Downloader.from_config(('shapefiles', 'natural_earth', scale, category, name)) feature = NaturalEarthFeature(category, name, scale) format_dict = {'config': config, 'category': category, 'name': name, 'resolution': scale} if dry_run: print('URL: {}'.format(downloader.url(format_dict))) else: downloader.path(format_dict) geoms = list(feature.geometries()) print('Feature {}, {}, {} length: {}' ''.format(category, name, scale, len(geoms)))
def __init__(self, url_template=_NE_URL_TEMPLATE, target_path_template=None, pre_downloaded_path_template='', ): # adds some NE defaults to the __init__ of a Downloader Downloader.__init__(self, url_template, target_path_template, pre_downloaded_path_template)
def __init__( self, url_template=_NE_URL_TEMPLATE, target_path_template=None, pre_downloaded_path_template='', ): # adds some NE defaults to the __init__ of a Downloader Downloader.__init__(self, url_template, target_path_template, pre_downloaded_path_template)
def __init__( self, target_path_template, pre_downloaded_path_template='', ): # adds some SRTM defaults to the __init__ of a Downloader # namely, the URL is determined on the fly using the # ``SRTMDownloader._SRTM_LOOKUP_MASK`` array Downloader.__init__(self, None, target_path_template, pre_downloaded_path_template)
def __init__(self, target_path_template, pre_downloaded_path_template='', ): # adds some SRTM3 defaults to the __init__ of a Downloader # namely, the URl is determined on the fly using the # ``SRTM3Downloader._SRTM3_LOOKUP_URL`` dictionary Downloader.__init__(self, None, target_path_template, pre_downloaded_path_template)
def __init__(self, target_path_template, pre_downloaded_path_template=""): # adds some SRTM defaults to the __init__ of a Downloader # namely, the URL is determined on the fly using the # ``SRTMDownloader._SRTM_LOOKUP_MASK`` array Downloader.__init__(self, None, target_path_template, pre_downloaded_path_template) warnings.warn( "SRTM requires an account set up and log in to access." "use of this class is likely to fail with" " HTTP 401 errors." )
def __init__( self, target_path_template, pre_downloaded_path_template='', ): # adds some SRTM3 defaults to the __init__ of a Downloader # namely, the URl is determined on the fly using the # ``SRTM3Downloader._SRTM3_LOOKUP_URL`` dictionary Downloader.__init__(self, None, target_path_template, pre_downloaded_path_template)
def __init__(self, target_path_template, pre_downloaded_path_template='', ): # adds some SRTM defaults to the __init__ of a Downloader # namely, the URL is determined on the fly using the # ``SRTMDownloader._SRTM_LOOKUP_MASK`` array Downloader.__init__(self, None, target_path_template, pre_downloaded_path_template)
def __init__(self, target_path_template, pre_downloaded_path_template='', ): # adds some SRTM defaults to the __init__ of a Downloader # namely, the URL is determined on the fly using the # ``SRTMDownloader._SRTM_LOOKUP_MASK`` array Downloader.__init__(self, None, target_path_template, pre_downloaded_path_template) warnings.warn('SRTM requires an account set up and log in to access.' 'use of this class is likely to fail with' ' HTTP 401 errors.')
def srtm_fname(self, lon, lat): """ Return the filename for the given lon/lat SRTM tile (downloading if necessary), or None if no such tile exists (i.e. the tile would be entirely over water, or out of latitude range). """ if int(lon) != lon or int(lat) != lat: raise ValueError('Integer longitude/latitude values required.') x = '%s%03d' % ('E' if lon >= 0 else 'W', abs(int(lon))) y = '%s%02d' % ('N' if lat >= 0 else 'S', abs(int(lat))) srtm_downloader = Downloader.from_config( ('SRTM', f'SRTM{self._resolution}')) params = { 'config': config, 'resolution': self._resolution, 'x': x, 'y': y } # If the URL doesn't exist then we are over sea/north/south of the # limits of the SRTM data and we return None. if srtm_downloader.url(params) is None: return None else: return self.downloader.path(params)
def natural_earth(resolution="110m", category="physical", name="coastline"): """ Returns the path to the requested natural earth shapefile, downloading and unziping if necessary. To identify valid components for this function, either browse NaturalEarthData.com, or if you know what you are looking for, go to https://github.com/nvkelso/natural-earth-vector/tree/master/zips to see the actual files which will be downloaded. .. note:: Some of the Natural Earth shapefiles have special features which are described in the name. For example, the 110m resolution "admin_0_countries" data also has a sibling shapefile called "admin_0_countries_lakes" which excludes lakes in the country outlines. For details of what is available refer to the Natural Earth website, and look at the "download" link target to identify appropriate names. """ # get hold of the Downloader (typically a NEShpDownloader instance) # which we can then simply call its path method to get the appropriate # shapefile (it will download if necessary) ne_downloader = Downloader.from_config(("shapefiles", "natural_earth", resolution, category, name)) format_dict = {"config": config, "category": category, "name": name, "resolution": resolution} return ne_downloader.path(format_dict)
def __init__(self, downloader=None, max_nx=3, max_ny=3): """ Parameters ========== downloader : :class:`cartopy.io.Downloader` instance or None The downloader to use for the SRTM3 dataset. If None, the downloader will be taken using :class:`cartopy.io.Downloader.from_config` with ('SRTM', 'SRTM3') as the target. max_nx : int The maximum number of x tiles to be combined when producing a wider composite for this RasterSource. max_ny : int The maximum number of y tiles to be combined when producing a taller composite for this RasterSource. """ #: The CRS of the underlying SRTM3 data. self.crs = ccrs.PlateCarree() #: The cartopy Downloader which can handle SRTM3 data. Normally, this #: will be a :class:`SRTM3Downloader` instance. self.downloader = downloader if self.downloader is None: self.downloader = Downloader.from_config(('SRTM', 'SRTM3')) #: A tuple of (max_x_tiles, max_y_tiles). self._max_tiles = (max_nx, max_ny)
def natural_earth(resolution='110m', category='physical', name='coastline'): """ Return the path to the requested natural earth shapefile, downloading and unzipping if necessary. To identify valid components for this function, either browse NaturalEarthData.com, or if you know what you are looking for, go to https://github.com/nvkelso/natural-earth-vector/tree/master/zips to see the actual files which will be downloaded. Note ---- Some of the Natural Earth shapefiles have special features which are described in the name. For example, the 110m resolution "admin_0_countries" data also has a sibling shapefile called "admin_0_countries_lakes" which excludes lakes in the country outlines. For details of what is available refer to the Natural Earth website, and look at the "download" link target to identify appropriate names. """ # get hold of the Downloader (typically a NEShpDownloader instance) # which we can then simply call its path method to get the appropriate # shapefile (it will download if necessary) ne_downloader = Downloader.from_config( ('shapefiles', 'natural_earth', resolution, category, name)) format_dict = { 'config': config, 'category': category, 'name': name, 'resolution': resolution } return ne_downloader.path(format_dict)
def grab_ne(category, feature, res): """Download the correct Natural Earth feature using Cartopy.""" download = Downloader.from_config(('shapefiles', 'natural_earth')) download.path({ 'category': category, 'name': feature, 'resolution': res, 'config': config })
def gshhs(scale="c", level=1): """ Returns the path to the requested GSHHS shapefile, downloading and unziping if necessary. """ # Get hold of the Downloader (typically a GSHHSShpDownloader instance) # and call its path method to get the appropriate shapefile (it will # download it if necessary). gshhs_downloader = Downloader.from_config(("shapefiles", "gshhs", scale, level)) format_dict = {"config": config, "scale": scale, "level": level} return gshhs_downloader.path(format_dict)
def download_features(group_names, dry_run=True): for group_name in group_names: feature_defns = FEATURE_DEFN_GROUPS[group_name] if isinstance(feature_defns, Feature): feature = feature_defns level = list(feature._levels)[0] downloader = Downloader.from_config( ("shapefiles", "gshhs", feature._scale, level) ) format_dict = {"config": config, "scale": feature._scale, "level": level} if dry_run: print("URL: {}".format(downloader.url(format_dict))) else: downloader.path(format_dict) geoms = list(feature.geometries()) print("Feature {} length: {}".format(feature, len(geoms))) else: for category, name, scales in feature_defns: if not isinstance(scales, tuple): scales = (scales,) for scale in scales: downloader = Downloader.from_config( ("shapefiles", "natural_earth", scale, category, name) ) feature = NaturalEarthFeature(category, name, scale) format_dict = { "config": config, "category": category, "name": name, "resolution": scale, } if dry_run: print("URL: {}".format(downloader.url(format_dict))) else: downloader.path(format_dict) geoms = list(feature.geometries()) print( "Feature {}, {}, {} length: {}" "".format(category, name, scale, len(geoms)) )
def gshhs(scale='c', level=1): """ Returns the path to the requested GSHHS shapefile, downloading and unziping if necessary. """ # Get hold of the Downloader (typically a GSHHSShpDownloader instance) # and call its path method to get the appropriate shapefile (it will # download it if necessary). gshhs_downloader = Downloader.from_config(('shapefiles', 'gshhs', scale, level)) format_dict = {'config': config, 'scale': scale, 'level': level} return gshhs_downloader.path(format_dict)
def gshhs(scale='c', level=1): """ Return the path to the requested GSHHS shapefile, downloading and unzipping if necessary. """ # Get hold of the Downloader (typically a GSHHSShpDownloader instance) # and call its path method to get the appropriate shapefile (it will # download it if necessary). gshhs_downloader = Downloader.from_config( ('shapefiles', 'gshhs', scale, level)) format_dict = {'config': config, 'scale': scale, 'level': level} return gshhs_downloader.path(format_dict)
def natural_earth(resolution='110m', category='physical', name='coastline'): """ Returns the path to the requested natural earth shapefile, downloading and unziping if necessary. """ # get hold of the Downloader (typically a NEShpDownloader instance) # which we can then simply call its path method to get the appropriate # shapefile (it will download if necessary) ne_downloader = Downloader.from_config(('shapefiles', 'natural_earth', resolution, category, name)) format_dict = {'config': config, 'category': category, 'name': name, 'resolution': resolution} return ne_downloader.path(format_dict)
def SRTM3_retrieve(lon, lat): """ Return the path of a .hgt file for the given SRTM location. If no such .hgt file exists (because it is over the ocean) None will be returned. """ x = '%s%03d' % ('E' if lon > 0 else 'W', abs(int(lon))) y = '%s%02d' % ('N' if lat > 0 else 'S', abs(int(lat))) srtm_downloader = Downloader.from_config(('SRTM', 'SRTM3')) params = {'config': config, 'x': x, 'y': y} if srtm_downloader.url(params) is None: return None else: return srtm_downloader.path({'config': config, 'x': x, 'y': y})
def natural_earth(resolution='110m', category='physical', name='coastline'): """ Returns the path to the requested natural earth shapefile, downloading and unziping if necessary. """ # get hold of the Downloader (typically a NEShpDownloader instance) # which we can then simply call its path method to get the appropriate # shapefile (it will download if necessary) ne_downloader = Downloader.from_config( ('shapefiles', 'natural_earth', resolution, category, name)) format_dict = { 'config': config, 'category': category, 'name': name, 'resolution': resolution } return ne_downloader.path(format_dict)
def __init__(self, resolution, downloader, max_nx, max_ny): """ Parameters ---------- resolution The resolution of SRTM to download, in integer arc-seconds. Data is available at resolutions of 3 and 1 arc-seconds. downloader: :class:`cartopy.io.Downloader` instance or None The downloader to use for the SRTM dataset. If None, the downloader will be taken using :class:`cartopy.io.Downloader.from_config` with ('SRTM', 'SRTM{resolution}') as the target. max_nx The maximum number of x tiles to be combined when producing a wider composite for this RasterSource. max_ny The maximum number of y tiles to be combined when producing a taller composite for this RasterSource. """ if resolution == 3: self._shape = (1201, 1201) elif resolution == 1: self._shape = (3601, 3601) else: raise ValueError( f'Resolution is an unexpected value ({resolution}).') self._resolution = resolution #: The CRS of the underlying SRTM data. self.crs = ccrs.PlateCarree() #: The Cartopy Downloader which can handle SRTM data. Normally, this #: will be a :class:`SRTMDownloader` instance. self.downloader = downloader if self.downloader is None: self.downloader = Downloader.from_config( ('SRTM', f'SRTM{resolution}')) #: A tuple of (max_x_tiles, max_y_tiles). self._max_tiles = (max_nx, max_ny)
def __init__(self, resolution, downloader, max_nx, max_ny): """ Parameters ========== resolution : int The resolution of SRTM to download, in arc-seconds. Data is available at resolutions of 3 and 1 arc-seconds. downloader : :class:`cartopy.io.Downloader` instance or None The downloader to use for the SRTM dataset. If None, the downloader will be taken using :class:`cartopy.io.Downloader.from_config` with ('SRTM', 'SRTM{resolution}') as the target. max_nx : int The maximum number of x tiles to be combined when producing a wider composite for this RasterSource. max_ny : int The maximum number of y tiles to be combined when producing a taller composite for this RasterSource. """ if resolution == 3: self._shape = (1201, 1201) elif resolution == 1: self._shape = (3601, 3601) else: raise ValueError( 'Resolution is an unexpected value ({}).'.format(resolution)) self._resolution = resolution #: The CRS of the underlying SRTM data. self.crs = ccrs.PlateCarree() #: The Cartopy Downloader which can handle SRTM data. Normally, this #: will be a :class:`SRTMDownloader` instance. self.downloader = downloader if self.downloader is None: self.downloader = Downloader.from_config( ('SRTM', 'SRTM' + str(resolution))) #: A tuple of (max_x_tiles, max_y_tiles). self._max_tiles = (max_nx, max_ny)
def srtm_fname(self, lon, lat): """ Return the filename for the given lon/lat SRTM tile (downloading if necessary), or None if no such tile exists (i.e. the tile would be entirely over water, or out of latitude range). """ if int(lon) != lon or int(lat) != lat: raise ValueError('Integer longitude/latitude values required.') x = '%s%03d' % ('E' if lon >= 0 else 'W', abs(int(lon))) y = '%s%02d' % ('N' if lat >= 0 else 'S', abs(int(lat))) srtm_downloader = Downloader.from_config(('SRTM', 'SRTM3')) params = {'config': config, 'x': x, 'y': y} # If the URL doesn't exist then we are over sea/north/south of the # limits of the SRTM data and we return None. if srtm_downloader.url(params) is None: return None else: return self.downloader.path(params)
def srtm_fname(self, lon, lat): """ Return the filename for the given lon/lat SRTM tile (downloading if necessary), or None if no such tile exists (i.e. the tile would be entirely over water, or out of latitude range). """ if int(lon) != lon or int(lat) != lat: raise ValueError("Integer longitude/latitude values required.") x = "%s%03d" % ("E" if lon >= 0 else "W", abs(int(lon))) y = "%s%02d" % ("N" if lat >= 0 else "S", abs(int(lat))) srtm_downloader = Downloader.from_config(("SRTM", "SRTM" + str(self._resolution))) params = {"config": config, "resolution": self._resolution, "x": x, "y": y} # If the URL doesn't exist then we are over sea/north/south of the # limits of the SRTM data and we return None. if srtm_downloader.url(params) is None: return None else: return self.downloader.path(params)
def SRTM3_retrieve(lon, lat): x = '%s%03d' % ('E' if lon > 0 else 'W', abs(int(lon))) y = '%s%02d' % ('N' if lat > 0 else 'S', abs(int(lat))) srtm_downloader = Downloader.from_config(('SRTM', 'SRTM3')) return srtm_downloader.path({'config': config, 'x': x, 'y': y})
import cartopy.crs as ccrs # To create maps on several projections from cartopy.util import add_cyclic_point # To create cyclic coordinates for maps from cartopy.mpl.ticker import LongitudeFormatter from cartopy.mpl.ticker import LatitudeFormatter import os.path import math import warnings warnings.simplefilter(action='ignore', category=FutureWarning) # -- CARTOPY LOAD OF SHAPEFILES ----------------------------------------------------- from cartopy.io import Downloader shaped = '/ccc/cont003/home/dsm/checagar/.local/share/cartopy/shapefiles/' shapef = shaped + 'natural_earth/physical/ne_110m_coastline.shp' Downloader.from_config( ('shapefiles', 'natural_earth')).pre_downloaded_path_template = shapef Downloader.from_config( ('shapefiles', 'natural_earth')).target_path_template = shapef def myprint(mystr, finfo=None): print(mystr) if finfo != None: finfo.write(mystr + '\n') return def latlon_mean(datarray_input): ''' INPUT: DataArray (lat, lon) RETURN: floa