USA flag An official website of the United States governmentv

Module cdasws.doi

Module defines utility functions related to Digital Object Identifiers (DOI).

Copyright © 2025 United States Government as represented by the National Aeronautics and Space Administration. No copyright is claimed in the United States under Title 17, U.S.Code. All Other Rights Reserved.

Expand source code
#!/usr/bin/env python3

#
# NOSA HEADER START
#
# The contents of this file are subject to the terms of the NASA Open
# Source Agreement (NOSA), Version 1.3 only (the "Agreement").  You may
# not use this file except in compliance with the Agreement.
#
# You can obtain a copy of the agreement at
#   docs/NASA_Open_Source_Agreement_1.3.txt
# or
#   https://cdaweb.gsfc.nasa.gov/WebServices/NASA_Open_Source_Agreement_1.3.txt.
#
# See the Agreement for the specific language governing permissions
# and limitations under the Agreement.
#
# When distributing Covered Code, include this NOSA HEADER in each
# file and include the Agreement file at
# docs/NASA_Open_Source_Agreement_1.3.txt.  If applicable, add the
# following below this NOSA HEADER, with the fields enclosed by
# brackets "[]" replaced with your own identifying information:
# Portions Copyright [yyyy] [name of copyright owner]
#
# NOSA HEADER END
#
# Copyright (c) 2025 United States Government as represented by
# the National Aeronautics and Space Administration. No copyright is
# claimed in the United States under Title 17, U.S.Code. All Other
# Rights Reserved.
#


"""
Module defines utility functions related to Digital Object Identifiers
(DOI).<br>

Copyright &copy; 2025 United States Government as represented by the
National Aeronautics and Space Administration. No copyright is claimed in
the United States under Title 17, U.S.Code. All Other Rights Reserved.
"""


def get_canonical_doi(
        doi: str
    ) -> str:
    """
    Returns a canonical representation (no leading https://doi.org/ and 
    lower case) Digital Object Identifier (DOI) value.

    Parameters
    ----------
    doi
        digital object identifier.
    Returns
    -------
    str
        The canonical DOI value.
    """
    return doi.replace('https://doi.org/', '').lower()


def get_doi_landing_page_url(
        doi: str
    ) -> str:
    """
    Returns a URL to the given Digital Object Identifier's landing
    page (metadata for the DOI).

    Parameters
    ----------
    doi
        digital object identifier.
    Returns
    -------
    str
        A URL to the DOI's landing page.
    """

    if not doi.startswith('http'):
        return 'https://doi.org/' + doi
    return doi


def get_doi_badge_url(
        doi: str
    ) -> str:
    """
    Returns a URL to the given Digital Object Identifier's badge.

    Parameters
    ----------
    doi
        digital object identifier.
    Returns
    -------
    str
        A URL to the DOI's badge.
    """

    canonical_doi = get_canonical_doi(doi)

    return 'https://img.shields.io/badge/DOI-' + \
           canonical_doi.replace('-', '--') + '-blue'


def get_doi_hdp_url(
        doi: str
    ) -> str:
    """
    Returns a URL to the given Digital Object Identifier's Heliophysics
    Data Portal (HDP) page.

    Parameters
    ----------
    doi
        digital object identifier.
    Returns
    -------
    str
        A URL to the DOI's HDP page.
    """

    canonical_doi = get_canonical_doi(doi)

    return 'https://heliophysicsdata.gsfc.nasa.gov/WS/hdp/1/Spase/' \
           'NumericalData;DisplayData?DOI=' + canonical_doi

Functions

def get_canonical_doi(doi: str) ‑> str

Returns a canonical representation (no leading https://doi.org/ and lower case) Digital Object Identifier (DOI) value.

Parameters

doi
digital object identifier.

Returns

str
The canonical DOI value.
Expand source code
def get_canonical_doi(
        doi: str
    ) -> str:
    """
    Returns a canonical representation (no leading https://doi.org/ and 
    lower case) Digital Object Identifier (DOI) value.

    Parameters
    ----------
    doi
        digital object identifier.
    Returns
    -------
    str
        The canonical DOI value.
    """
    return doi.replace('https://doi.org/', '').lower()
def get_doi_badge_url(doi: str) ‑> str

Returns a URL to the given Digital Object Identifier's badge.

Parameters

doi
digital object identifier.

Returns

str
A URL to the DOI's badge.
Expand source code
def get_doi_badge_url(
        doi: str
    ) -> str:
    """
    Returns a URL to the given Digital Object Identifier's badge.

    Parameters
    ----------
    doi
        digital object identifier.
    Returns
    -------
    str
        A URL to the DOI's badge.
    """

    canonical_doi = get_canonical_doi(doi)

    return 'https://img.shields.io/badge/DOI-' + \
           canonical_doi.replace('-', '--') + '-blue'
def get_doi_hdp_url(doi: str) ‑> str

Returns a URL to the given Digital Object Identifier's Heliophysics Data Portal (HDP) page.

Parameters

doi
digital object identifier.

Returns

str
A URL to the DOI's HDP page.
Expand source code
def get_doi_hdp_url(
        doi: str
    ) -> str:
    """
    Returns a URL to the given Digital Object Identifier's Heliophysics
    Data Portal (HDP) page.

    Parameters
    ----------
    doi
        digital object identifier.
    Returns
    -------
    str
        A URL to the DOI's HDP page.
    """

    canonical_doi = get_canonical_doi(doi)

    return 'https://heliophysicsdata.gsfc.nasa.gov/WS/hdp/1/Spase/' \
           'NumericalData;DisplayData?DOI=' + canonical_doi
def get_doi_landing_page_url(doi: str) ‑> str

Returns a URL to the given Digital Object Identifier's landing page (metadata for the DOI).

Parameters

doi
digital object identifier.

Returns

str
A URL to the DOI's landing page.
Expand source code
def get_doi_landing_page_url(
        doi: str
    ) -> str:
    """
    Returns a URL to the given Digital Object Identifier's landing
    page (metadata for the DOI).

    Parameters
    ----------
    doi
        digital object identifier.
    Returns
    -------
    str
        A URL to the DOI's landing page.
    """

    if not doi.startswith('http'):
        return 'https://doi.org/' + doi
    return doi