Datasets:
Download code/wasp26_lib/build_base_df.py from adsabs/AstroCLIMB: direct link, hf CLI and curl.
- Browser
- Download file 2.26 kB
-
https://huggingface.co/datasets/adsabs/AstroCLIMB/resolve/main/code/wasp26_lib/build_base_df.py
- Command line
-
hf download hf://datasets/adsabs/AstroCLIMB/code/wasp26_lib/build_base_df.py
-
curl -L -o build_base_df.py https://huggingface.co/datasets/adsabs/AstroCLIMB/resolve/main/code/wasp26_lib/build_base_df.py
2.26 kB
| import pandas as pd | |
| from tqdm.auto import tqdm | |
| from .encode_search_string import encode_search_string | |
| from .get_all_image_links import get_all_image_links | |
| from .extract_image_info import extract_image_info | |
| def build_base_df(save_df_path=None): | |
| """ | |
| Builds the WASP 2026 - Shared task 3 base dataframe, images will be downloaded later. | |
| If save_df is set to a path, saves to disk every loop (no checking, could be overwriting important files) | |
| """ | |
| # build dataframe | |
| cols =["Image ID","Paper DOI", "Paper Title", "Image Caption", "Caption Title", "Image Bibliographic", "Image Copyright", "Image Authors", "Image Link",] | |
| image_df = pd.DataFrame(columns=cols) | |
| # total of 1092 pages for 2020 per page | |
| # (bugs out after 50? 10K images) | |
| # since searches are limited to 10K images returned (for now) | |
| # go through by publication and year | |
| for year in [2022, 2023, 2024, 2025]: | |
| for pub in ["The Astrophysical Journal", "The Astronomical Journal", "The Astrophysical Journal Supplement Series", "The Astrophysical Journal Letters", "The Planetary Science Journal","Research Notes of the AAS"]: | |
| print(f'year:{year} pub:{pub}') | |
| for page in tqdm(range(1, 51)): | |
| # Encode the proper 64 bit search url for a given page | |
| url = encode_search_string(publication=pub, | |
| fromYear=year, | |
| toYear=year, | |
| page=page) | |
| # extract all image links | |
| image_ids = get_all_image_links(url) | |
| if image_ids: | |
| # Loop through all the hyperlink tags, access the image details page and | |
| # extract the relevant info and place in a dataframe | |
| for image_id in image_ids: | |
| out_dict = extract_image_info(image_id) | |
| image_df = pd.concat([image_df, pd.DataFrame([out_dict])], ignore_index=True) | |
| print('Dataframe size:', image_df.shape) | |
| if save_df_path is not None: | |
| image_df.to_csv(save_df_path, index=False) | |
| return(image_df) |