seagrid.download.credentials#

Which data providers need an account, and whether its credentials are set up.

Three providers need a (free) account; every other source downloads without one. status() checks, without contacting any server, whether credentials for each provider can be found in the places seagrid and the provider’s own tools look. It does not check that they are correct: use seagrid check SOURCE (or glorys.check_auth()) for that.

See Credentials for how to set up each account.

Examples

>>> from seagrid.download import credentials
>>> sorted(credentials.PROVIDERS)
['copernicus', 'earthdata', 'mercator']
>>> sorted(credentials.status())
['copernicus', 'earthdata', 'mercator']

Module Attributes

PROVIDERS

Provider key -> Provider.

EARTHDATA_MACHINE

netrc machine names.

Functions

netrc_login(machine[, path])

Return True if a netrc file has a login and password for machine.

report([found])

Return a readable summary of status().

status()

Return where each provider's credentials were found.

Classes

Provider(title, sources, register)

A data provider that needs an account.

seagrid.download.credentials.PROVIDERS: dict[str, Provider] = {'copernicus': Provider(title='Copernicus Marine', sources=('cmems_globgc', 'glorys_carb', 'ostia', 'smoc'), register='https://data.marine.copernicus.eu/register'), 'earthdata': Provider(title='NASA Earthdata', sources=('avhrr', 'modis_a', 'mur25', 'olci', 'seawifs', 'viirs'), register='https://urs.earthdata.nasa.gov/users/new'), 'mercator': Provider(title='Mercator Ocean', sources=('glorys',), register='https://www.mercator-ocean.eu')}#

Provider key -> Provider.

class seagrid.download.credentials.Provider(title, sources, register)[source]#

Bases: object

A data provider that needs an account.

Variables:
  • title (str) – Name of the provider.

  • sources (tuple of str) – The seagrid sources that need the account.

  • register (str) – Where to create an account.

Parameters:
seagrid.download.credentials.netrc_login(machine, path=None)[source]#

Return True if a netrc file has a login and password for machine.

Parameters:
  • machine (str) – Host name, e.g. "urs.earthdata.nasa.gov".

  • path (str or os.PathLike, optional) – netrc file. Default $NETRC, else ~/.netrc.

Returns:

bool – False if the file is missing, cannot be parsed, or has no complete entry for machine.

Return type:

bool

Examples

>>> netrc_login("example.org", "/nonexistent/.netrc")
False
seagrid.download.credentials.report(found=None)[source]#

Return a readable summary of status().

Parameters:

found (dict, optional) – The result of status(). Default: call it.

Returns:

str – One line per provider, then where to read how to set up the missing ones.

Return type:

str

Examples

>>> print(report({"copernicus": None, "earthdata": "~/.netrc",
...               "mercator": None}))
Credentials (needed only for these sources; all others are open):
  Copernicus Marine  missing  cmems_globgc, glorys_carb, ostia, smoc
  NASA Earthdata     found    avhrr, modis_a, ... (~/.netrc)
  Mercator Ocean     missing  glorys
How to set them up: https://brorfred.github.io/seagrid/...
seagrid.download.credentials.status()[source]#

Return where each provider’s credentials were found.

Nothing is sent to any server, so a credential that is found may still be wrong.

Returns:

dict of str to str or None – Provider key (see PROVIDERS) -> where the credentials were found (a file, environment variables or settings sections), or None.

Return type:

dict[str, str | None]

Notes

The places checked, in order:

  • copernicus: COPERNICUSMARINE_SERVICE_USERNAME and _PASSWORD; the file written by copernicusmarine login (~/.copernicusmarine/.copernicusmarine-credentials, or in $COPERNICUSMARINE_CREDENTIALS_DIRECTORY); username and password in a Copernicus source’s settings (.secrets.toml).

  • earthdata: EARTHDATA_TOKEN; EARTHDATA_USERNAME and EARTHDATA_PASSWORD; machine urs.earthdata.nasa.gov in ~/.netrc (or $NETRC).

  • mercator: machine tds.mercator-ocean.fr in ~/.netrc.