{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "855a28ff",
   "metadata": {},
   "source": [
    "# Get references from DOI\n",
    "This notebook shows how it is possible to use the `qim3d` library to easily get well formatted references from a DOI"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "35b9fe6b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import qim3d\n",
    "qim3d.utils._logger.level(\"info\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "7962731c",
   "metadata": {},
   "outputs": [],
   "source": [
    "doi = \"https://doi.org/10.1007/s10851-021-01041-3\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "17720b94",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      " @article{Stephensen_2021, title={Measuring Shape Relations Using r-Parallel Sets}, volume={63}, ISSN={1573-7683}, url={http://dx.doi.org/10.1007/s10851-021-01041-3}, DOI={10.1007/s10851-021-01041-3}, number={8}, journal={Journal of Mathematical Imaging and Vision}, publisher={Springer Science and Business Media LLC}, author={Stephensen, Hans J. T. and Svane, Anne Marie and Villanueva, Carlos B. and Goldman, Steven A. and Sporring, Jon}, year={2021}, month=jun, pages={1069–1083} }\n",
      "\n"
     ]
    }
   ],
   "source": [
    "bibtext = qim3d.utils._doi.get_bibtex(doi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "a15baf83",
   "metadata": {},
   "outputs": [],
   "source": [
    "reference = qim3d.utils._doi.get_reference(doi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "6d4d215e",
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'indexed': {'date-parts': [[2023, 10, 20]],\n",
       "  'date-time': '2023-10-20T12:08:45Z',\n",
       "  'timestamp': 1697803725999},\n",
       " 'reference-count': 26,\n",
       " 'publisher': 'Springer Science and Business Media LLC',\n",
       " 'issue': '8',\n",
       " 'license': [{'start': {'date-parts': [[2021, 6, 26]],\n",
       "    'date-time': '2021-06-26T00:00:00Z',\n",
       "    'timestamp': 1624665600000},\n",
       "   'content-version': 'tdm',\n",
       "   'delay-in-days': 0,\n",
       "   'URL': 'https://www.springer.com/tdm'},\n",
       "  {'start': {'date-parts': [[2021, 6, 26]],\n",
       "    'date-time': '2021-06-26T00:00:00Z',\n",
       "    'timestamp': 1624665600000},\n",
       "   'content-version': 'vor',\n",
       "   'delay-in-days': 0,\n",
       "   'URL': 'https://www.springer.com/tdm'}],\n",
       " 'funder': [{'DOI': '10.13039/100008398',\n",
       "   'name': 'Villum Fonden',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'id': [{'id': '10.13039/100008398',\n",
       "     'id-type': 'DOI',\n",
       "     'asserted-by': 'publisher'}]},\n",
       "  {'DOI': '10.13039/501100005275',\n",
       "   'name': 'Region Hovedstaden',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'id': [{'id': '10.13039/501100005275',\n",
       "     'id-type': 'DOI',\n",
       "     'asserted-by': 'publisher'}]}],\n",
       " 'content-domain': {'domain': ['link.springer.com'],\n",
       "  'crossmark-restriction': False},\n",
       " 'published-print': {'date-parts': [[2021, 10]]},\n",
       " 'DOI': '10.1007/s10851-021-01041-3',\n",
       " 'type': 'journal-article',\n",
       " 'created': {'date-parts': [[2021, 6, 26]],\n",
       "  'date-time': '2021-06-26T15:02:20Z',\n",
       "  'timestamp': 1624719740000},\n",
       " 'page': '1069-1083',\n",
       " 'update-policy': 'http://dx.doi.org/10.1007/springer_crossmark_policy',\n",
       " 'source': 'Crossref',\n",
       " 'is-referenced-by-count': 3,\n",
       " 'title': 'Measuring Shape Relations Using r-Parallel Sets',\n",
       " 'prefix': '10.1007',\n",
       " 'volume': '63',\n",
       " 'author': [{'ORCID': 'http://orcid.org/0000-0001-8245-0571',\n",
       "   'authenticated-orcid': False,\n",
       "   'given': 'Hans J. T.',\n",
       "   'family': 'Stephensen',\n",
       "   'sequence': 'first',\n",
       "   'affiliation': []},\n",
       "  {'ORCID': 'http://orcid.org/0000-0001-6356-0484',\n",
       "   'authenticated-orcid': False,\n",
       "   'given': 'Anne Marie',\n",
       "   'family': 'Svane',\n",
       "   'sequence': 'additional',\n",
       "   'affiliation': []},\n",
       "  {'ORCID': 'http://orcid.org/0000-0001-9786-9439',\n",
       "   'authenticated-orcid': False,\n",
       "   'given': 'Carlos B.',\n",
       "   'family': 'Villanueva',\n",
       "   'sequence': 'additional',\n",
       "   'affiliation': []},\n",
       "  {'ORCID': 'http://orcid.org/0000-0002-5498-4303',\n",
       "   'authenticated-orcid': False,\n",
       "   'given': 'Steven A.',\n",
       "   'family': 'Goldman',\n",
       "   'sequence': 'additional',\n",
       "   'affiliation': []},\n",
       "  {'ORCID': 'http://orcid.org/0000-0003-1261-6702',\n",
       "   'authenticated-orcid': False,\n",
       "   'given': 'Jon',\n",
       "   'family': 'Sporring',\n",
       "   'sequence': 'additional',\n",
       "   'affiliation': []}],\n",
       " 'member': '297',\n",
       " 'published-online': {'date-parts': [[2021, 6, 26]]},\n",
       " 'reference': [{'key': '1041_CR1',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'DOI': '10.1201/b19708',\n",
       "   'volume-title': 'Spatial Point Patterns: Methodology and Applications with R',\n",
       "   'author': 'A Baddeley',\n",
       "   'year': '2015',\n",
       "   'unstructured': 'Baddeley, A., Rubak, E., Turner, R.: Spatial Point Patterns: Methodology and Applications with R. CRC Press, Boca Raton (2015)'},\n",
       "  {'key': '1041_CR2',\n",
       "   'series-title': 'Statistics Reference Online',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'DOI': '10.1002/9781118445112.stat07751',\n",
       "   'volume-title': 'Ripley’s $$k$$ Function',\n",
       "   'author': 'PM Dixon',\n",
       "   'year': '2014',\n",
       "   'unstructured': 'Dixon, P.M.: Ripley’s $$k$$ Function. Statistics Reference Online, Wiley, New York (2014)'},\n",
       "  {'issue': '1',\n",
       "   'key': '1041_CR3',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'first-page': '1',\n",
       "   'DOI': '10.1016/0962-8924(94)90025-6',\n",
       "   'volume': '4',\n",
       "   'author': 'R Fesce',\n",
       "   'year': '1994',\n",
       "   'unstructured': 'Fesce, R., Grohovaz, F., Valtorta, F., Meldolesi, J.: Neurotransmitter release: fusion or kiss-and-run? Trends Cell Biol. 4(1), 1–4 (1994)',\n",
       "   'journal-title': 'Trends Cell Biol.'},\n",
       "  {'issue': '8',\n",
       "   'key': '1041_CR4',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'first-page': '1953',\n",
       "   'DOI': '10.1007/s00138-014-0625-2',\n",
       "   'volume': '25',\n",
       "   'author': 'Y Gavet',\n",
       "   'year': '2014',\n",
       "   'unstructured': 'Gavet, Y., Fernandes, M., Debayle, J., Pinoli, J.C.: Dissimilarity criteria and their comparison for quantitative evaluation of image segmentation: application to human retina vessels. Mach. Vis. Appl. 25(8), 1953–1966 (2014)',\n",
       "   'journal-title': 'Mach. Vis. Appl.'},\n",
       "  {'key': '1041_CR5',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'first-page': '248',\n",
       "   'DOI': '10.3389/fncel.2018.00248',\n",
       "   'volume': '12',\n",
       "   'author': 'N Gavrilov',\n",
       "   'year': '2018',\n",
       "   'unstructured': 'Gavrilov, N., Golyagina, I., Brazhe, A., Scimemi, A., Turlapov, V., Semyanov, A.: Astrocytic coverage of dendritic spines, dendritic shafts, and axonal boutons in hippocampal neuropil. Front. Cell. Neurosci. 12, 248 (2018)',\n",
       "   'journal-title': 'Front. Cell. Neurosci.'},\n",
       "  {'issue': '498',\n",
       "   'key': '1041_CR6',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'first-page': '754',\n",
       "   'DOI': '10.1080/01621459.2012.688463',\n",
       "   'volume': '107',\n",
       "   'author': 'U Hahn',\n",
       "   'year': '2012',\n",
       "   'unstructured': 'Hahn, U.: A studentized permutation test for the comparison of spatial point patterns. J. Am. Stat. Assoc. 107(498), 754–764 (2012). https://doi.org/10.1080/01621459.2012.688463',\n",
       "   'journal-title': 'J. Am. Stat. Assoc.'},\n",
       "  {'issue': '4',\n",
       "   'key': '1041_CR7',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'first-page': '60:1',\n",
       "   'DOI': '10.1145/3197517.3201353',\n",
       "   'volume': '37',\n",
       "   'author': 'Y Hu',\n",
       "   'year': '2018',\n",
       "   'unstructured': 'Hu, Y., Zhou, Q., Gao, X., Jacobson, A., Zorin, D., Panozzo, D.: Tetrahedral meshing in the wild. ACM Trans. Gr. 37(4), 60:1-60:14 (2018). https://doi.org/10.1145/3197517.3201353',\n",
       "   'journal-title': 'ACM Trans. Gr.'},\n",
       "  {'key': '1041_CR8',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'unstructured': 'Khanmohammadi, M., Waagepetersen, R.P., Sporring, J.: Analysis of shape and spatial interaction of synaptic vesicles using data from focused ion beam scanning electron microscopy (FIB-SEM). Front. Neuroanatomy (2015). https://doi.org/10.3389/fnana.2015.00116',\n",
       "   'DOI': '10.3389/fnana.2015.00116'},\n",
       "  {'issue': '3',\n",
       "   'key': '1041_CR9',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'first-page': '797',\n",
       "   'DOI': '10.1083/jcb.135.3.797',\n",
       "   'volume': '135',\n",
       "   'author': 'J Koenig',\n",
       "   'year': '1996',\n",
       "   'unstructured': 'Koenig, J., Ikeda, K.: Synaptic vesicles have two distinct recycling pathways. J. Cell Biol. 135(3), 797–808 (1996)',\n",
       "   'journal-title': 'J. Cell Biol.'},\n",
       "  {'key': '1041_CR10',\n",
       "   'unstructured': 'Lucchi, A., Li, Y., Becker, C., Fua, P.: Electron microscopy dataset. https://cvlab.epfl.ch/data/data-em/. Accessed 14 Mar 2020'},\n",
       "  {'issue': '2',\n",
       "   'key': '1041_CR11',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'first-page': '568',\n",
       "   'DOI': '10.1002/mrm.24477',\n",
       "   'volume': '70',\n",
       "   'author': 'J Marques',\n",
       "   'year': '2013',\n",
       "   'unstructured': 'Marques, J., Genant, H.K., Lillholm, M., Dam, E.B.: Diagnosis of osteoarthritis and prognosis of tibial cartilage loss by quantification of tibia trabecular bone from MRI. Magn. Reson. Med. 70(2), 568–575 (2013). https://doi.org/10.1002/mrm.24477',\n",
       "   'journal-title': 'Magn. Reson. Med.'},\n",
       "  {'issue': '1654',\n",
       "   'key': '1041_CR12',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'first-page': '20140047',\n",
       "   'DOI': '10.1098/rstb.2014.0047',\n",
       "   'volume': '369',\n",
       "   'author': 'N Medvedev',\n",
       "   'year': '2014',\n",
       "   'unstructured': 'Medvedev, N., Popov, V., Henneberger, C., Kraev, I., Rusakov, D.A., Stewart, M.G.: Glia selectively approach synapses on thin dendritic spines. Philos. Trans. R Soc. B Biol. Sci. 369(1654), 20140047 (2014)',\n",
       "   'journal-title': 'Philos. Trans. R Soc. B Biol. Sci.'},\n",
       "  {'issue': '3',\n",
       "   'key': '1041_CR13',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'first-page': '551',\n",
       "   'DOI': '10.1016/S0896-6273(00)00065-9',\n",
       "   'volume': '27',\n",
       "   'author': 'D Richards',\n",
       "   'year': '2000',\n",
       "   'unstructured': 'Richards, D., Guatimosim, C., Betz, W.: Two endocytic recycling routes selectively fill two vesicle pools in frog motor nerve terminals. Neuron 27(3), 551–559 (2000)',\n",
       "   'journal-title': 'Neuron'},\n",
       "  {'issue': '3',\n",
       "   'key': '1041_CR14',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'first-page': '368',\n",
       "   'DOI': '10.1111/j.2517-6161.1979.tb01091.x',\n",
       "   'volume': '41',\n",
       "   'author': 'BD Ripley',\n",
       "   'year': '1979',\n",
       "   'unstructured': 'Ripley, B.D.: Tests of randomness for spatial point patterns. J. Roy. Stat. Soc. Ser. B (Methodol.) 41(3), 368–374 (1979). https://doi.org/10.1111/j.2517-6161.1979.tb01091.x',\n",
       "   'journal-title': 'J. Roy. Stat. Soc. Ser. B (Methodol.)'},\n",
       "  {'key': '1041_CR15',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'DOI': '10.1017/CBO9780511624131',\n",
       "   'volume-title': 'Statistical Inference for Spatial Processes',\n",
       "   'author': 'BD Ripley',\n",
       "   'year': '1988',\n",
       "   'unstructured': 'Ripley, B.D.: Statistical Inference for Spatial Processes. Cambridge University Press, Cambridge (1988)'},\n",
       "  {'key': '1041_CR16',\n",
       "   'doi-asserted-by': 'crossref',\n",
       "   'unstructured': 'Ronneberger, O., Fischer, P., Brox, T.: U-net: convolutional networks for biomedical image segmentation. In: International Conference on Medical Image Computing and Computer-Assisted Intervention, pp. 234–241. Springer (2015)',\n",
       "   'DOI': '10.1007/978-3-319-24574-4_28'},\n",
       "  {'key': '1041_CR17',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'DOI': '10.1007/978-3-540-78859-1',\n",
       "   'volume-title': 'Stochastic and Integral Geometry',\n",
       "   'author': 'R Schneider',\n",
       "   'year': '2008',\n",
       "   'unstructured': 'Schneider, R., Weil, W.: Stochastic and Integral Geometry. Springer, Heidelberg (2008)'},\n",
       "  {'key': '1041_CR18',\n",
       "   'unstructured': 'Scientific, T.F.: Amira-avizo software (2020)'},\n",
       "  {'key': '1041_CR19',\n",
       "   'doi-asserted-by': 'crossref',\n",
       "   'unstructured': 'Sethian, J.A.: Fast marching methods. SIAM Rev. 41(2), 199–235 (1999)',\n",
       "   'DOI': '10.1137/S0036144598347059'},\n",
       "  {'issue': '2',\n",
       "   'key': '1041_CR20',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'first-page': '1',\n",
       "   'DOI': '10.1145/2629697',\n",
       "   'volume': '41',\n",
       "   'author': 'H Si',\n",
       "   'year': '2015',\n",
       "   'unstructured': 'Si, H.: TetGen, a delaunay-based quality tetrahedral mesh generator. ACM Trans. Math. Softw. 41(2), 1–36 (2015)',\n",
       "   'journal-title': 'ACM Trans. Math. Softw.'},\n",
       "  {'key': '1041_CR21',\n",
       "   'doi-asserted-by': 'crossref',\n",
       "   'unstructured': 'Sporring, J., Waagepetersen, R., Sommer, S.: Generalizations of Ripley’s k-function with application to space curves. In: International Conference on Information Processing in Medical Imaging, pp. 731–742. Springer (2019)',\n",
       "   'DOI': '10.1007/978-3-030-20351-1_57'},\n",
       "  {'issue': '1',\n",
       "   'key': '1041_CR22',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'first-page': '1',\n",
       "   'DOI': '10.1038/s42003-020-0809-4',\n",
       "   'volume': '3',\n",
       "   'author': 'HJT Stephensen',\n",
       "   'year': '2020',\n",
       "   'unstructured': 'Stephensen, H.J.T., Darkner, S., Sporring, J.: Restoring drifted electron microscope volumes using synaptic vesicles at sub-pixel accuracy. Commun. Biol. 3(1), 1–7 (2020)',\n",
       "   'journal-title': 'Commun. Biol.'},\n",
       "  {'key': '1041_CR23',\n",
       "   'unstructured': 'Stephensen, H.J.T., Sporring, J.: Rodent neuronal volume annotations and segmentations (2020). https://www.doi.org/10.17894/ucph.33bd30d2-5796-48f4-a0a8-96fcc0ce6af5'},\n",
       "  {'key': '1041_CR24',\n",
       "   'doi-asserted-by': 'crossref',\n",
       "   'unstructured': 'Svane, A.M.: Valuations in image analysis. In: Tensor Valuations and Their Applications in Stochastic Geometry and Imaging, pp. 435–454. Springer (2017)',\n",
       "   'DOI': '10.1007/978-3-319-51951-7_15'},\n",
       "  {'key': '1041_CR25',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'unstructured': 'Virtanen, P., Gommers, R., Oliphant, T.E., Haberland, M., Reddy, T., Cournapeau, D., Burovski, E., Peterson, P., Weckesser, W., Bright, J., van der Walt, S.J., Brett, M., Wilson, J., Jarrod Millman, K., Mayorov, N., Nelson, A.R.J., Jones, E., Kern, R., Larson, E., Carey, C., Polat, İ, Feng, Y., Moore, E.W., Van der Plas, J., Laxalde, D., Perktold, J., Cimrman, R., Henriksen, I., Quintero, E.A., Harris, C.R., Archibald, A.M., Ribeiro, A.H., Pedregosa, F., van Mulbregt, P., Contributors, S., et al.: SciPy 1.0: fundamental algorithms for scientific computing in python. Nat. Methods 17, 261–272 (2020). https://doi.org/10.1038/s41592-019-0686-2',\n",
       "   'DOI': '10.1038/s41592-019-0686-2'},\n",
       "  {'issue': '1',\n",
       "   'key': '1041_CR26',\n",
       "   'doi-asserted-by': 'publisher',\n",
       "   'first-page': '1',\n",
       "   'DOI': '10.1016/j.patcog.2003.07.008',\n",
       "   'volume': '37',\n",
       "   'author': 'D Zhang',\n",
       "   'year': '2004',\n",
       "   'unstructured': 'Zhang, D., Lu, G.: Review of shape representation and description techniques. Pattern Recogn. 37(1), 1–19 (2004). https://doi.org/10.1016/j.patcog.2003.07.008',\n",
       "   'journal-title': 'Pattern Recogn.'}],\n",
       " 'container-title': 'Journal of Mathematical Imaging and Vision',\n",
       " 'original-title': [],\n",
       " 'language': 'en',\n",
       " 'link': [{'URL': 'https://link.springer.com/content/pdf/10.1007/s10851-021-01041-3.pdf',\n",
       "   'content-type': 'application/pdf',\n",
       "   'content-version': 'vor',\n",
       "   'intended-application': 'text-mining'},\n",
       "  {'URL': 'https://link.springer.com/article/10.1007/s10851-021-01041-3/fulltext.html',\n",
       "   'content-type': 'text/html',\n",
       "   'content-version': 'vor',\n",
       "   'intended-application': 'text-mining'},\n",
       "  {'URL': 'https://link.springer.com/content/pdf/10.1007/s10851-021-01041-3.pdf',\n",
       "   'content-type': 'application/pdf',\n",
       "   'content-version': 'vor',\n",
       "   'intended-application': 'similarity-checking'}],\n",
       " 'deposited': {'date-parts': [[2023, 1, 1]],\n",
       "  'date-time': '2023-01-01T16:48:24Z',\n",
       "  'timestamp': 1672591704000},\n",
       " 'score': 1,\n",
       " 'resource': {'primary': {'URL': 'https://link.springer.com/10.1007/s10851-021-01041-3'}},\n",
       " 'subtitle': [],\n",
       " 'short-title': [],\n",
       " 'issued': {'date-parts': [[2021, 6, 26]]},\n",
       " 'references-count': 26,\n",
       " 'journal-issue': {'issue': '8',\n",
       "  'published-print': {'date-parts': [[2021, 10]]}},\n",
       " 'alternative-id': ['1041'],\n",
       " 'URL': 'http://dx.doi.org/10.1007/s10851-021-01041-3',\n",
       " 'relation': {},\n",
       " 'ISSN': ['0924-9907', '1573-7683'],\n",
       " 'subject': [],\n",
       " 'container-title-short': 'J Math Imaging Vis',\n",
       " 'published': {'date-parts': [[2021, 6, 26]]},\n",
       " 'assertion': [{'value': '7 November 2020',\n",
       "   'order': 1,\n",
       "   'name': 'received',\n",
       "   'label': 'Received',\n",
       "   'group': {'name': 'ArticleHistory', 'label': 'Article History'}},\n",
       "  {'value': '2 June 2021',\n",
       "   'order': 2,\n",
       "   'name': 'accepted',\n",
       "   'label': 'Accepted',\n",
       "   'group': {'name': 'ArticleHistory', 'label': 'Article History'}},\n",
       "  {'value': '26 June 2021',\n",
       "   'order': 3,\n",
       "   'name': 'first_online',\n",
       "   'label': 'First Online',\n",
       "   'group': {'name': 'ArticleHistory', 'label': 'Article History'}},\n",
       "  {'order': 1,\n",
       "   'name': 'Ethics',\n",
       "   'group': {'name': 'EthicsHeading', 'label': 'Declarations'}},\n",
       "  {'value': 'The authors declare that they have no conflict of interest.',\n",
       "   'order': 2,\n",
       "   'name': 'Ethics',\n",
       "   'group': {'name': 'EthicsHeading', 'label': 'Conflict of interest'}}]}"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "qim3d.utils._doi.get_metadata(doi)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "qim3d",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}