{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "93ee6ad3-baae-41d2-a7ac-1eb7842e52b6", "metadata": {}, "outputs": [], "source": [ "# find citations for the images extracted from astroexplorer.org" ] }, { "cell_type": "code", "execution_count": null, "id": "3f9f7b2c-8aec-4110-9e89-9d1eac5a56ce", "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": null, "id": "d52f4d42-da13-4047-859e-3320f419f2a9", "metadata": {}, "outputs": [], "source": [ "# add wasp26_lib to python path\n", "import sys\n", "sys.path.append('../')" ] }, { "cell_type": "code", "execution_count": null, "id": "64cc9fdb-6903-4f77-8eca-80bfabed0246", "metadata": {}, "outputs": [], "source": [ "from tqdm.auto import tqdm" ] }, { "cell_type": "code", "execution_count": null, "id": "01559fa4-1c6f-4c09-8b95-6c5f47add70e", "metadata": {}, "outputs": [], "source": [ "from wasp26_lib import *" ] }, { "cell_type": "code", "execution_count": null, "id": "bd282f6d-57d7-4272-8ae2-e530c617a04e", "metadata": {}, "outputs": [], "source": [ "# load base dataframe" ] }, { "cell_type": "code", "execution_count": null, "id": "0389d58e-a5f2-4eca-b7ac-0cced334b7dc", "metadata": {}, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": null, "id": "1b2ebc13-19d2-4ac0-87ea-6881741eeaba", "metadata": {}, "outputs": [], "source": [ "base_df = pd.read_csv('../data/wasp2026_shared_task_3_base_df.csv')" ] }, { "cell_type": "code", "execution_count": null, "id": "72a6b3cf-c149-4397-94e4-00c9610baa38", "metadata": {}, "outputs": [], "source": [ "base_df" ] }, { "cell_type": "code", "execution_count": null, "id": "ffa4974f-3417-42f6-a3b2-f49ad3f925ce", "metadata": {}, "outputs": [], "source": [ "# query ADS for citations and references" ] }, { "cell_type": "code", "execution_count": null, "id": "37fc6a77-f07b-4d6b-8752-45d7f089923b", "metadata": {}, "outputs": [], "source": [ "# load key\n", "with open('../data/private_scix_token.txt', 'r') as f:\n", " scix_token = f.readline()" ] }, { "cell_type": "code", "execution_count": null, "id": "76781083-69df-41af-8a78-97929aac09fa", "metadata": {}, "outputs": [], "source": [ "# test a single bib" ] }, { "cell_type": "code", "execution_count": null, "id": "dabcb278-6811-47c3-8c0b-5ba56e75bdc4", "metadata": {}, "outputs": [], "source": [ "doi = '10.3847/1538-4357/aca0dd'" ] }, { "cell_type": "code", "execution_count": null, "id": "2c453202-f99e-44b8-87f6-11f89c70d5eb", "metadata": {}, "outputs": [], "source": [ "ref_DOIs, ref_DOIs_alt, cit_DOIs, cit_DOIs_alt = get_citations_refs(doi, scix_token=scix_token)" ] }, { "cell_type": "code", "execution_count": null, "id": "4f8d4c7b-a669-4943-afaa-bfad5a81bb8d", "metadata": {}, "outputs": [], "source": [ "cit_DOIs[:10]" ] }, { "cell_type": "code", "execution_count": null, "id": "2a77f47e-9642-4937-92f9-bd8054932357", "metadata": {}, "outputs": [], "source": [ "# Use big query instead" ] }, { "cell_type": "code", "execution_count": null, "id": "ce5adbec-c6cd-4403-9539-a8efebb8905f", "metadata": {}, "outputs": [], "source": [ "DOIs = list(set([d[len('https://dx.doi.org/'):] for d in base_df['Paper DOI'].to_list()]))" ] }, { "cell_type": "code", "execution_count": null, "id": "6b1a599e-6de0-42de-b51b-7286d9013727", "metadata": {}, "outputs": [], "source": [ "len(DOIs)" ] }, { "cell_type": "code", "execution_count": null, "id": "8994e704-a14b-4d29-ae5b-6b4d6f3dff56", "metadata": {}, "outputs": [], "source": [ "ref_cit_df = big_query_citations_refs(DOIs, scix_token)" ] }, { "cell_type": "code", "execution_count": null, "id": "bb96c447-fb73-416c-b47e-8338751a8e8d", "metadata": {}, "outputs": [], "source": [ "ref_cit_df" ] }, { "cell_type": "code", "execution_count": null, "id": "e6e0b1af-39f5-47d2-9020-d5ec6a7cdfbe", "metadata": {}, "outputs": [], "source": [ "BIBs = set(ref_cit_df['Paper Bibcode'])" ] }, { "cell_type": "code", "execution_count": null, "id": "73974ae7-fa01-4212-b2d2-370fd9382331", "metadata": {}, "outputs": [], "source": [ "len(BIBs)" ] }, { "cell_type": "code", "execution_count": null, "id": "be1b9dfd-94c9-4276-a284-13cb60c23b1d", "metadata": {}, "outputs": [], "source": [ "# check for non-symmetrical links\n", "trouble_bibs = set()\n", "trouble_refs = set()\n", "trouble_cits = set()\n", "\n", "for i, r in tqdm(ref_cit_df.iterrows(), total=len(ref_cit_df)):\n", " bib = r['Paper Bibcode']\n", " refs = set(r['References Bibcodes'])\n", " cits = set(r['Citing Bibcodes'])\n", "\n", " for ref_bib in refs.intersection(BIBs):\n", " err_p = False\n", " if ref_bib==bib:\n", " print(f'error 00: {i} {bib}')\n", " err_p = True\n", " trouble_bibs.add(bib)\n", " \n", " if not bib in ref_cit_df[ref_cit_df['Paper Bibcode']==ref_bib]['Citing Bibcodes'].values[0]:\n", " print(f'error 01: {i} {bib} {ref_bib}')\n", " print(f'{ref_bib} in {bib} refs but not the reverse')\n", " print(f'references(bibcode:{bib}) bibcode:{ref_bib}')\n", " print(f'citations(bibcode:{ref_bib}) bibcode:{bib}')\n", " trouble_refs.add(ref_bib)\n", " err_p = True\n", " \n", " if err_p:\n", " ref_cit_df.iat[i,2] = sorted(refs.difference({bib}))\n", " print()\n", " \n", " \n", " for cit_bib in cits.intersection(BIBs):\n", " err_p = False\n", " if cit_bib==bib:\n", " print(f'error 02: {i} {bib}')\n", " err_p = True\n", " trouble_bibs.add(bib)\n", " \n", " if not bib in ref_cit_df[ref_cit_df['Paper Bibcode']==cit_bib]['References Bibcodes'].values[0]:\n", " print(f'error 03: {i} {bib} {cit_bib}')\n", " print(f'{cit_bib} in {bib} citings but not the reverse')\n", " print(f'citations(bibcode:{bib}) bibcode:{cit_bib}')\n", " print(f'references(bibcode:{cit_bib}) bibcode:{bib}')\n", " trouble_cits.add(cit_bib)\n", " err_p = True\n", " \n", " if err_p:\n", " ref_cit_df.iat[i,3]=list(cits.difference({bib}))\n", " print()\n" ] }, { "cell_type": "code", "execution_count": null, "id": "bf3b830f-223c-46b7-9bd0-08cb4817484c", "metadata": {}, "outputs": [], "source": [ "# check again\n", "trouble_bibs = set()\n", "trouble_refs = set()\n", "trouble_cits = set()\n", "\n", "for i, r in tqdm(ref_cit_df.iterrows(), total=len(ref_cit_df)):\n", " bib = r['Paper Bibcode']\n", " refs = set(r['References Bibcodes'])\n", " cits = set(r['Citing Bibcodes'])\n", "\n", " for ref_bib in refs.intersection(BIBs):\n", " err_p = False\n", " if ref_bib==bib:\n", " print(f'error 00: {i} {bib}')\n", " err_p = True\n", " trouble_bibs.add(bib)\n", " \n", " if not bib in ref_cit_df[ref_cit_df['Paper Bibcode']==ref_bib]['Citing Bibcodes'].values[0]:\n", " print(f'error 01: {i} {bib} {ref_bib}')\n", " print(f'{ref_bib} in {bib} refs but not the reverse')\n", " print(f'references(bibcode:{bib}) bibcode:{ref_bib}')\n", " print(f'citations(bibcode:{ref_bib}) bibcode:{bib}')\n", " trouble_refs.add(ref_bib)\n", " err_p = True\n", " \n", " if err_p:\n", " print()\n", " \n", " \n", " for cit_bib in cits.intersection(BIBs):\n", " err_p = False\n", " if cit_bib==bib:\n", " print(f'error 02: {i} {bib}')\n", " err_p = True\n", " trouble_bibs.add(bib)\n", " \n", " if not bib in ref_cit_df[ref_cit_df['Paper Bibcode']==cit_bib]['References Bibcodes'].values[0]:\n", " print(f'error 03: {i} {bib} {cit_bib}')\n", " print(f'{cit_bib} in {bib} citings but not the reverse')\n", " print(f'citations(bibcode:{bib}) bibcode:{cit_bib}')\n", " print(f'references(bibcode:{cit_bib}) bibcode:{bib}')\n", " trouble_cits.add(cit_bib)\n", " err_p = True\n", " \n", " if err_p:\n", " print()\n" ] }, { "cell_type": "code", "execution_count": null, "id": "e2556ffe-311f-4a98-8371-eca15e639245", "metadata": {}, "outputs": [], "source": [ "ref_cit_df.iloc[0]" ] }, { "cell_type": "code", "execution_count": null, "id": "901298c2-da24-4541-9b54-9d51aab22afa", "metadata": {}, "outputs": [], "source": [ "# missing DOIs from the original set in our database?\n", "set(DOIs).difference(set(ref_cit_df['Paper DOI']))" ] }, { "cell_type": "code", "execution_count": null, "id": "b5205ca3-1b8a-4388-9db9-266c7a394aaf", "metadata": {}, "outputs": [], "source": [ "for missing_doi in set(DOIs).difference(set(ref_cit_df['Paper DOI'])):\n", " base_df = base_df.drop(base_df[base_df['Paper DOI']== 'https://dx.doi.org/'+missing_doi].index)" ] }, { "cell_type": "code", "execution_count": null, "id": "b4a65ae4-521e-4e41-aab7-b2c1ee491eea", "metadata": {}, "outputs": [], "source": [ "# update\n", "base_df.to_csv('../data/wasp2026_shared_task_3_base_02_df.csv', index=False)" ] }, { "cell_type": "code", "execution_count": null, "id": "b7ba582f-3069-40bd-86e3-58dab0a98ff1", "metadata": {}, "outputs": [], "source": [ "# none of the new dois are not in the original set\n", "set(ref_cit_df['Paper DOI']).difference(set(DOIs))" ] }, { "cell_type": "code", "execution_count": null, "id": "7dc07733-ead1-4d5b-89f3-4929840847c4", "metadata": {}, "outputs": [], "source": [ "len(set(ref_cit_df['Paper DOI'])), len(set(base_df['Paper DOI']))" ] }, { "cell_type": "code", "execution_count": null, "id": "58d84639-ea62-4000-8819-83dd3e5c6b78", "metadata": {}, "outputs": [], "source": [ "# add in the ref DOIs" ] }, { "cell_type": "code", "execution_count": null, "id": "0921a6ae-3429-40c4-b3a5-216b2c1bde0c", "metadata": {}, "outputs": [], "source": [ "all_bibs = list(set(ref_cit_df['Paper Bibcode']).union(set(r for refs in ref_cit_df['References Bibcodes'] for r in refs)).union(set(c for cits in ref_cit_df['Citing Bibcodes'] for c in cits)))" ] }, { "cell_type": "code", "execution_count": null, "id": "392da3c3-0009-48c9-89a3-11a631476a08", "metadata": {}, "outputs": [], "source": [ "len(all_bibs)" ] }, { "cell_type": "code", "execution_count": null, "id": "b1427dac-c85f-47db-8a00-47e7479f56a5", "metadata": {}, "outputs": [], "source": [ "bib_to_doi = build_bib_to_doi_dict(bibs_list=all_bibs, base_dois=DOIs, scix_token=scix_token)" ] }, { "cell_type": "code", "execution_count": null, "id": "e4bc718d-9cee-4f46-ae8b-35515a382f9e", "metadata": {}, "outputs": [], "source": [ "len(bib_to_doi)" ] }, { "cell_type": "code", "execution_count": null, "id": "169fcacc-6e8b-4c45-8ded-33eb32cd92e7", "metadata": {}, "outputs": [], "source": [ "doi_to_bib = {v:k for k,v in bib_to_doi.items()}" ] }, { "cell_type": "code", "execution_count": null, "id": "bfd04ade-c187-443f-b40e-2cb4798d03e6", "metadata": {}, "outputs": [], "source": [ "len(doi_to_bib)" ] }, { "cell_type": "code", "execution_count": null, "id": "e35db489-e774-4e84-bff1-a4429921e2f3", "metadata": {}, "outputs": [], "source": [ "# add to ref cit df\n", "ref_cit_df['References DOIs'] = [[bib_to_doi[r] for r in ref_bibs] for ref_bibs in ref_cit_df['References Bibcodes'] ]\n", "ref_cit_df['Citing DOIs'] = [[bib_to_doi[c] for c in cit_bibs] for cit_bibs in ref_cit_df['Citing Bibcodes'] ]" ] }, { "cell_type": "code", "execution_count": null, "id": "f5ddb51c-f21b-48ec-b4d7-8b39ef7b5b07", "metadata": {}, "outputs": [], "source": [ "base_df[base_df['Paper DOI']=='https://dx.doi.org/'+'10.3847/2041-8213/acfdab']" ] }, { "cell_type": "code", "execution_count": null, "id": "5ee201ba-a9ce-4ca8-8c3b-c07cee2eb3d7", "metadata": {}, "outputs": [], "source": [ "base_df[base_df['Paper DOI']=='https://dx.doi.org/'+'10.3847/2041-8213/acfc3b']" ] }, { "cell_type": "code", "execution_count": null, "id": "47ff23d1-1c62-4b5e-b6f5-b50d3c28e786", "metadata": {}, "outputs": [], "source": [ "# any duplicates?" ] }, { "cell_type": "code", "execution_count": null, "id": "bdce9ab7-6654-4232-bef4-c2fc7b28838b", "metadata": {}, "outputs": [], "source": [ "ref_cit_df[ref_cit_df.duplicated('Paper DOI', keep=False)]" ] }, { "cell_type": "code", "execution_count": null, "id": "df7df648-ef4c-4250-8ce4-84be7e18b364", "metadata": {}, "outputs": [], "source": [ "# verify that 2023ApJ...956L..32G only appears once (used to be bugged)\n", "ref_cit_df[ref_cit_df['Paper Bibcode']=='2023ApJ...956L..32G']" ] }, { "cell_type": "code", "execution_count": null, "id": "ed3c6fc8-1d01-49d2-91e5-2124f49f2aa7", "metadata": {}, "outputs": [], "source": [ "ref_cit_df[ref_cit_df['Paper DOI']=='10.3847/2041-8213/acfdab']" ] }, { "cell_type": "code", "execution_count": null, "id": "7600a58e-1981-453e-bf0b-883d4a0b350e", "metadata": {}, "outputs": [], "source": [ "# both still seem bugged, remove them" ] }, { "cell_type": "code", "execution_count": null, "id": "2995bbd0-59d9-41cf-a4b1-b341be207e96", "metadata": {}, "outputs": [], "source": [ "ref_cit_df = ref_cit_df.drop(index=ref_cit_df[ref_cit_df['Paper Bibcode']=='2023ApJ...956L..32G'].index.values[0])\n", "ref_cit_df = ref_cit_df.drop(index=ref_cit_df[ref_cit_df['Paper Bibcode']=='2023ApJ...956L..29Z'].index.values[0])" ] }, { "cell_type": "code", "execution_count": null, "id": "8b88c8ef-bad3-45b6-90c6-2efadf093e41", "metadata": {}, "outputs": [], "source": [ "# verify that every link is two way" ] }, { "cell_type": "code", "execution_count": null, "id": "e24a1d49-e60e-4e0f-8aae-6237f0f67cf6", "metadata": {}, "outputs": [], "source": [ "DOIs = list(set(ref_cit_df['Paper DOI']))" ] }, { "cell_type": "code", "execution_count": null, "id": "1b299dbf-ab7f-408c-8263-bfed54709057", "metadata": {}, "outputs": [], "source": [ "trouble_dois = set()\n", "trouble_refs = set()\n", "trouble_cits = set()\n", "\n", "for i, r in tqdm(ref_cit_df.iterrows(), total=len(ref_cit_df)):\n", " doi = r['Paper DOI']\n", " refs = set(r['References DOIs']).intersection(DOIs)\n", " cits = set(r['Citing DOIs']).intersection(DOIs)\n", "\n", " for ref_doi in refs:\n", " err_p = False\n", " if ref_doi==doi:\n", " print(f'error 00: {i} {doi}')\n", " err_p = True\n", " trouble_dois.add(doi)\n", " # if ref_doi in DOIs:\n", " # print(doi)\n", " # print(ref_doi)\n", " # print(ref_cit_df[ref_cit_df['Paper DOI']==ref_doi])\n", " # print(ref_cit_df[ref_cit_df['Paper DOI']==ref_doi]['Citing DOIs'].values)\n", " \n", " if not doi in ref_cit_df[ref_cit_df['Paper DOI']==ref_doi]['Citing DOIs'].values[0]:\n", " print(f'error 01: {i} {doi} {ref_doi}')\n", " print(f'{ref_doi} in {doi} refs but not the reverse')\n", " print(f'references(doi:{doi}) doi:{ref_doi}')\n", " print(f'citations(doi:{ref_doi}) doi:{doi}')\n", " trouble_refs.add(ref_doi)\n", " err_p = True\n", " \n", " if err_p:\n", " print()\n", " \n", " \n", " for cit_doi in cits:\n", " err_p = False\n", " if cit_doi==doi:\n", " print(f'error 02: {i} {doi}')\n", " err_p = True\n", " trouble_dois.add(doi)\n", " # if cit_doi in DOIs:\n", " # print(doi)\n", " # print(ref_doi)\n", " # print(ref_cit_df[ref_cit_df['Paper DOI']==ref_doi])\n", " # print(ref_cit_df[ref_cit_df['Paper DOI']==ref_doi]['Citing DOIs'].values)\n", " if not doi in ref_cit_df[ref_cit_df['Paper DOI']==cit_doi]['References DOIs'].values[0]:\n", " print(f'error 03: {i} {doi} {cit_doi}')\n", " print(f'{cit_doi} in {doi} citings but not the reverse')\n", " print(f'citations(doi:{doi}) doi:{cit_doi}')\n", " print(f'references(doi:{cit_doi}) doi:{doi}')\n", " trouble_cits.add(cit_doi)\n", " err_p = True\n", " \n", " if err_p:\n", " print()\n" ] }, { "cell_type": "code", "execution_count": null, "id": "9281dee9-a1b9-4272-861c-8bd56d739196", "metadata": {}, "outputs": [], "source": [ "# save locally\n", "ref_cit_df.to_csv('../data/wasp2026_shared_task_3_ref_cit_df.csv', index_label=False)" ] }, { "cell_type": "code", "execution_count": null, "id": "496be372-8604-4d16-80f3-8db095e45c8b", "metadata": {}, "outputs": [], "source": [ "# reload\n", "import pandas as pd\n", "from ast import literal_eval" ] }, { "cell_type": "code", "execution_count": null, "id": "adbb7b0f-eabf-451b-a8db-d2120844007c", "metadata": {}, "outputs": [], "source": [ "ref_cit_df = pd.read_csv('../data/wasp2026_shared_task_3_ref_cit_df.csv', converters={'References Bibcodes': literal_eval,\n", " 'Citing Bibcodes': literal_eval,\n", " 'References DOIs': literal_eval,\n", " 'Citing DOIs': literal_eval,\n", " })" ] }, { "cell_type": "code", "execution_count": null, "id": "c0633720-8777-4577-9ff6-8b803146fb97", "metadata": {}, "outputs": [], "source": [ "ref_cit_df" ] }, { "cell_type": "code", "execution_count": null, "id": "856aba48-423c-4324-8ed1-3a34586e8aa1", "metadata": {}, "outputs": [], "source": [ "# how many links do we have in the base data?" ] }, { "cell_type": "code", "execution_count": null, "id": "cfa4d10f-2e97-4dd0-81e7-f16c8668cd5b", "metadata": {}, "outputs": [], "source": [ "base_bibs = set(ref_cit_df['Paper Bibcode'])\n", "refs_bibs = set(r for refs in ref_cit_df['References Bibcodes'] for r in refs)\n", "citing_bibs = set(c for cits in ref_cit_df['Citing Bibcodes'] for c in cits)" ] }, { "cell_type": "code", "execution_count": null, "id": "654a8452-a283-4a54-a32c-b06421692914", "metadata": {}, "outputs": [], "source": [ "len(base_bibs), len(base_bibs.intersection(refs_bibs)), len(base_bibs.intersection(citing_bibs))" ] }, { "cell_type": "code", "execution_count": null, "id": "0f35b596-3bd4-44bd-9e6e-5cae95dd8536", "metadata": {}, "outputs": [], "source": [ "# total links\n", "len(base_bibs.intersection(refs_bibs.union(citing_bibs)))" ] }, { "cell_type": "code", "execution_count": null, "id": "78194e1b-1a1e-49b3-8301-b7b08df8bc53", "metadata": {}, "outputs": [], "source": [ "len(set(ref_cit_df['Paper DOI'])), len(set(base_df['Paper DOI']))," ] }, { "cell_type": "code", "execution_count": null, "id": "4e7bbdfc-882b-4297-ae41-c151456ee1ac", "metadata": {}, "outputs": [], "source": [ "base_dois = set(ref_cit_df['Paper DOI'])\n", "refs_dois = set(r for refs in ref_cit_df['References DOIs'] for r in refs)\n", "citing_dois = set(c for cits in ref_cit_df['Citing DOIs'] for c in cits)" ] }, { "cell_type": "code", "execution_count": null, "id": "1b177201-aed0-461f-a092-db7d30f8e9e0", "metadata": {}, "outputs": [], "source": [ "len(base_dois), len(base_dois.intersection(refs_dois)), len(base_dois.intersection(citing_dois))" ] }, { "cell_type": "code", "execution_count": null, "id": "3078286a-34ba-4b44-a214-f45ee0e598aa", "metadata": {}, "outputs": [], "source": [ "len(base_dois.intersection(refs_dois.union(citing_dois)))" ] }, { "cell_type": "code", "execution_count": null, "id": "7c8b3103-12ec-463f-add2-db98e15e8d3a", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3.11.6 (astroBERT)\n", "language": "python", "name": "py3.11_astrobert" }, "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.11.6" } }, "nbformat": 4, "nbformat_minor": 5 }