예제 #1
1
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)))
예제 #2
0
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)))
예제 #3
0
 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)
예제 #4
0
 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)
예제 #5
0
 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)
예제 #6
0
파일: srtm.py 프로젝트: ajdawson/cartopy
 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)
예제 #7
0
파일: srtm.py 프로젝트: SciTools/cartopy
 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."
     )
예제 #8
0
파일: srtm.py 프로젝트: Grabkiak/cartopy
 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)
예제 #9
0
 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)
예제 #10
0
 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.')
예제 #11
0
    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)
예제 #12
0
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)
예제 #13
0
    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)
예제 #14
0
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)
예제 #15
0
파일: srtm.py 프로젝트: ajdawson/cartopy
    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)
예제 #16
0
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
    })
예제 #17
0
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)
예제 #18
0
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))
                        )
예제 #19
0
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)
예제 #20
0
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)
예제 #21
0
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)
예제 #22
0
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})
예제 #23
0
파일: srtm.py 프로젝트: Grabkiak/cartopy
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})
예제 #24
0
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)
예제 #25
0
    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)
예제 #26
0
    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)
예제 #27
0
파일: srtm.py 프로젝트: ajdawson/cartopy
    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)
예제 #28
0
파일: srtm.py 프로젝트: SciTools/cartopy
    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)
예제 #29
0
파일: srtm.py 프로젝트: rockdoc/cartopy
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})
예제 #30
0
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})
예제 #31
0
파일: plots.py 프로젝트: RCHG/pyIPSLtool
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