Download topic1/code/curate_inventory.py from eduzrh/helloworld: direct link, hf CLI and curl.
- Browser
- Download file 11.7 kB
-
https://huggingface.co/datasets/eduzrh/helloworld/resolve/main/topic1/code/curate_inventory.py
- Command line
-
hf download hf://datasets/eduzrh/helloworld/topic1/code/curate_inventory.py
-
curl -L -o curate_inventory.py https://huggingface.co/datasets/eduzrh/helloworld/resolve/main/topic1/code/curate_inventory.py
11.7 kB
| """整理并核验 Nature 系列子刊清单(课题1-任务1)。 | |
| 每条记录经 Crossref 校验 DOI—标题一致,并探测数据门户 / 代码仓库可达性。 | |
| 输出 topic1/ns_inventory_v2.json 与 topic1/ns_inventory_v2.md | |
| """ | |
| import difflib | |
| import json | |
| import os | |
| import urllib.error | |
| import urllib.request | |
| from concurrent.futures import ThreadPoolExecutor | |
| BASE = os.path.dirname(os.path.abspath(__file__)) | |
| UA = {"User-Agent": "Mozilla/5.0 (compatible; cdhe-inventory/1.0)"} | |
| # (分组, 期刊, 年, DOI, 中文说明, 数据/代码链接, GitHub 候选) | |
| ITEMS = [ | |
| # A 监测与数据集 | |
| ("A", "Scientific Data", 2014, "10.1038/sdata.2014.1", | |
| "全球干旱监测与预测系统(GIDMaPS),提供逐月 SPI/SPEI 与干旱概率预报网格", | |
| "https://drought.gsfc.nasa.gov/", ""), | |
| ("A", "Scientific Data", 2015, "10.1038/sdata.2015.66", | |
| "CHIRPS 卫星—站点融合降水,0.05°,用于极端降水与干旱监测", | |
| "https://www.chc.ucsb.edu/data/chirps", ""), | |
| ("A", "Scientific Data", 2017, "10.1038/sdata.2017.122", | |
| "CHELSA 高分辨率气候学底图,1 km 月值,是生态与事件研究的常用背景场", | |
| "https://chelsa-climate.org/", ""), | |
| ("A", "Scientific Data", 2018, "10.1038/sdata.2017.191", | |
| "TerraClimate 月尺度气候与气候水分平衡,1958 年起,含 PDSI、土壤湿度、AET", | |
| "https://www.climatologylab.org/terraclimate.html", ""), | |
| ("A", "Scientific Data", 2018, "10.1038/sdata.2018.206", | |
| "GHWR 全球热浪与暖期记录及配套工具箱,多方法阈值可复算", | |
| "https://doi.org/10.1038/sdata.2018.206", "https://github.com/abdulmal/ghwr"), | |
| ("A", "Scientific Data", 2019, "10.1038/s41597-019-0312-2", | |
| "全球野火数据集,统一火情记录,用于火情规律与火行为分析", | |
| "https://doi.org/10.1038/s41597-019-0312-2", ""), | |
| ("A", "Scientific Data", 2019, "10.1038/s41597-019-0326-9", | |
| "基于社交媒体的全球历史与实时洪水事件库(GFM)", | |
| "https://doi.org/10.1038/s41597-019-0326-9", | |
| "https://github.com/jensdebruijn/Global-Flood-Monitor"), | |
| ("A", "Scientific Data", 2019, "10.1038/s41597-019-0236-x", | |
| "1981 年起卫星海表温度时间序列,用于海洋热浪与 ENSO 背景监测", | |
| "https://doi.org/10.1038/s41597-019-0236-x", ""), | |
| ("A", "Scientific Data", 2020, "10.1038/s41597-020-0534-3", | |
| "FLUXNET2015 通量观测集与 ONEFlux 处理链,生产力异常验证的基准数据", | |
| "https://fluxnet.org/data/fluxnet2015-dataset/", ""), | |
| ("A", "Scientific Data", 2020, "10.1038/s41597-020-0554-z", | |
| "基于 ERA5 的全球气象火险图(FWI 类指标)", | |
| "https://doi.org/10.1038/s41597-020-0554-z", ""), | |
| ("A", "Scientific Data", 2021, "10.1038/s41597-021-00846-6", | |
| "GDIS 全球灾害地理位置库,把灾情记录落到行政单元", | |
| "https://doi.org/10.1038/s41597-021-00846-6", ""), | |
| ("A", "Scientific Data", 2022, "10.1038/s41597-022-01667-x", | |
| "全球灾害人员与经济影响数据的可信度评估,给出跨库一致性检验", | |
| "https://doi.org/10.1038/s41597-022-01667-x", ""), | |
| ("A", "Scientific Data", 2023, "10.1038/s41597-023-02255-3", | |
| "改进的全球植被健康指数(VHI)数据集,用于植被干旱识别", | |
| "https://doi.org/10.1038/s41597-023-02255-3", ""), | |
| ("A", "Scientific Data", 2023, "10.1038/s41597-023-01975-w", | |
| "Caravan 全球大样本水文数据集,统一径流与气象强迫", | |
| "https://doi.org/10.1038/s41597-023-01975-w", "https://github.com/kratzert/Caravan"), | |
| ("A", "Scientific Data", 2024, "10.1038/s41597-023-02856-y", | |
| "印度干旱图集 1901—2020,逐月多尺度干旱指标", | |
| "https://doi.org/10.1038/s41597-023-02856-y", | |
| "https://github.com/wcl-iitgn/india-drought-atlas-data"), | |
| ("A", "Scientific Data", 2025, "10.1038/s41597-025-04610-y", | |
| "GLEAM4 全球陆面蒸发与土壤湿度,0.1°,1980 年至今", | |
| "https://doi.org/10.1038/s41597-025-04610-y", ""), | |
| ("A", "Scientific Data", 2025, "10.1038/s41597-025-04896-y", | |
| "ERA5-Drought 全球干旱指数集,与再分析强迫配套", | |
| "https://doi.org/10.1038/s41597-025-04896-y", | |
| "https://github.com/jkeune/ERA5-Drought_data"), | |
| ("A", "Scientific Data", 2025, "10.1038/s41597-025-04447-5", | |
| "DeepExtremeCubes 时空立方体样本库,面向复合热浪—干旱的深度学习", | |
| "https://doi.org/10.1038/s41597-025-04447-5", ""), | |
| ("A", "Scientific Data", 2017, "10.1038/sdata.2017.165", | |
| "全球中等分辨率植被总初级生产力(GPP)数据集,2000—2016", | |
| "https://doi.org/10.1038/sdata.2017.165", ""), | |
| # B 复合事件与极端事件机制 | |
| ("B", "Nature Reviews Earth & Environment", 2020, "10.1038/s43017-020-0060-z", | |
| "复合天气气候事件的类型学,界定致灾组合、时空依赖与影响链", | |
| "https://doi.org/10.1038/s43017-020-0060-z", ""), | |
| ("B", "Nature Sustainability", 2023, "10.1038/s41893-022-01024-1", | |
| "复合干热事件对未来社会经济—生态系统生产力的威胁评估", | |
| "https://doi.org/10.1038/s41893-022-01024-1", ""), | |
| ("B", "Nature", 2016, "10.1038/nature16467", | |
| "极端天气灾害对全球作物产量的影响,区分干旱与热害的产量损失", | |
| "https://doi.org/10.1038/nature16467", ""), | |
| ("B", "Nature", 2015, "10.1038/nature15374", | |
| "生物多样性提高生态系统生产力对气候极端事件的抗性", | |
| "https://doi.org/10.1038/nature15374", ""), | |
| ("B", "Nature", 2017, "10.1038/nature23021", | |
| "全球干旱恢复的格局与时长,给出恢复时间的空间分异", | |
| "https://doi.org/10.1038/nature23021", ""), | |
| ("B", "Nature", 2018, "10.1038/s41586-018-0539-7", | |
| "森林水力多样性调节干旱期间的生态系统恢复力", | |
| "https://doi.org/10.1038/s41586-018-0539-7", ""), | |
| ("B", "Nature", 2019, "10.1038/s41586-018-0848-x", | |
| "土壤湿度对长期陆地碳吸收的大尺度影响", | |
| "https://doi.org/10.1038/s41586-018-0848-x", ""), | |
| ("B", "Nature", 2021, "10.1038/s41586-021-03325-5", | |
| "土壤湿度—大气反馈主导陆地碳吸收的年际变率", | |
| "https://doi.org/10.1038/s41586-021-03325-5", ""), | |
| ("B", "Nature", 2019, "10.1038/s41586-018-0872-x", | |
| "复杂网络揭示全球极端降雨的遥相关格局", | |
| "https://doi.org/10.1038/s41586-018-0872-x", ""), | |
| ("B", "Nature", 2019, "10.1038/s41586-019-1495-6", | |
| "气候变化同时增加和减少欧洲河流洪水,区域分异明显", | |
| "https://doi.org/10.1038/s41586-019-1495-6", ""), | |
| ("B", "Nature", 2020, "10.1038/s41586-020-2478-3", | |
| "近 500 年欧洲洪水记录比较,识别当前洪水多发期(已复现)", | |
| "https://doi.org/10.1038/s41586-020-2478-3", "https://github.com/tuwhydro/500yrfloods"), | |
| ("B", "Nature Water", 2023, "10.1038/s44221-023-00040-5", | |
| "GRACE/GRACE-FO 揭示水文极端事件的强度变化", | |
| "https://doi.org/10.1038/s44221-023-00040-5", ""), | |
| ("B", "Nature Water", 2023, "10.1038/s44221-023-00047-y", | |
| "全球洪水与干旱正在加剧的评述性证据汇总", | |
| "https://doi.org/10.1038/s44221-023-00047-y", ""), | |
| ("B", "Nature", 2022, "10.1038/s41586-022-04917-5", | |
| "前所未有的洪水与干旱给风险管理带来的挑战", | |
| "https://doi.org/10.1038/s41586-022-04917-5", ""), | |
| ("B", "Nature", 2024, "10.1038/s41586-024-07145-1", | |
| "无资料流域极端洪水的全球预报", | |
| "https://doi.org/10.1038/s41586-024-07145-1", ""), | |
| ("B", "Nature Reviews Earth & Environment", 2021, "10.1038/s43017-020-00128-6", | |
| "短历时强降雨的人为增强及其对城市与山洪的含义", | |
| "https://doi.org/10.1038/s43017-020-00128-6", ""), | |
| ("B", "Nature Reviews Earth & Environment", 2021, "10.1038/s43017-021-00195-3", | |
| "灾难性河流洪水的成因、影响与格局", | |
| "https://doi.org/10.1038/s43017-021-00195-3", ""), | |
| ("B", "Nature Sustainability", 2019, "10.1038/s41893-019-0353-8", | |
| "野火韧性的再思考,从抑制转向适应", | |
| "https://doi.org/10.1038/s41893-019-0353-8", ""), | |
| # C 人类与社会维度 | |
| ("C", "Nature Human Behaviour", 2022, "10.1038/s41562-022-01396-6", | |
| "野火烟雾暴露与行为响应,基于移动与查询数据的实证", | |
| "https://doi.org/10.1038/s41562-022-01396-6", ""), | |
| ("C", "Nature Human Behaviour", 2022, "10.1038/s41562-022-01467-8", | |
| "气候变化经影响、信息与政策三条路径作用于多维福祉", | |
| "https://doi.org/10.1038/s41562-022-01467-8", ""), | |
| ("C", "Nature Human Behaviour", 2023, "10.1038/s41562-023-01610-z", | |
| "自然灾害对美国人力资本的长期影响", | |
| "https://doi.org/10.1038/s41562-023-01610-z", ""), | |
| ("C", "Nature Human Behaviour", 2022, "10.1038/s41562-022-01315-9", | |
| "适应措施缓解温度冲击对家庭消费的负面影响", | |
| "https://doi.org/10.1038/s41562-022-01315-9", ""), | |
| ] | |
| def norm(s): | |
| return "".join(ch.lower() for ch in s if ch.isalnum()) | |
| def check_doi(doi): | |
| try: | |
| req = urllib.request.Request("https://api.crossref.org/works/" + doi, headers=UA) | |
| with urllib.request.urlopen(req, timeout=30) as r: | |
| m = json.loads(r.read().decode())["message"] | |
| return m.get("title", [""])[0], (m.get("container-title") or [""])[0], int( | |
| m.get("is-referenced-by-count", 0)) | |
| except Exception as e: # noqa: BLE001 | |
| return "", f"ERR {e}", 0 | |
| def head(url): | |
| if not url: | |
| return "—" | |
| try: | |
| req = urllib.request.Request(url, headers=UA, method="HEAD") | |
| with urllib.request.urlopen(req, timeout=20) as r: | |
| return str(r.status) | |
| except urllib.error.HTTPError as e: | |
| return str(e.code) | |
| except Exception: # noqa: BLE001 | |
| return "不可达" | |
| def one(it): | |
| grp, jn, yr, doi, note, link, gh = it | |
| title, cont, cites = check_doi(doi) | |
| sim = difflib.SequenceMatcher(None, norm(title)[:120], norm(ITEMS_TITLE[doi])[:120]).ratio() \ | |
| if title else 0 | |
| return dict(group=grp, journal=jn, year=yr, doi=doi, title=ITEMS_TITLE[doi], | |
| note=note, link=link, link_status=head(link), | |
| github=gh, github_status=head(gh) if gh else "—", | |
| crossref_title=title, crossref_journal=cont, cited_by=cites, | |
| title_match=round(sim, 3) if title else 0, doi_ok=bool(title)) | |
| def main(): | |
| global ITEMS_TITLE | |
| ITEMS_TITLE = {it[3]: it[4] for it in []} # placeholder | |
| ITEMS_TITLE = {} | |
| # 标题取自 ns_harvest_v2.json,避免手工录入 | |
| har = {r["doi"].lower(): r for r in json.load(open(os.path.join(BASE, "ns_harvest_v2.json")))} | |
| extra = { | |
| "10.1038/s41597-020-0534-3": "The FLUXNET2015 dataset and the ONEFlux processing " | |
| "pipeline for eddy covariance data", | |
| } | |
| for grp, jn, yr, doi, note, link, gh in ITEMS: | |
| rec = har.get(doi.lower()) | |
| ITEMS_TITLE[doi] = rec["title"] if rec else extra.get(doi, "") | |
| with ThreadPoolExecutor(max_workers=6) as ex: | |
| rows = list(ex.map(one, ITEMS)) | |
| ok = [r for r in rows if r["doi_ok"] and r["title_match"] >= 0.7] | |
| print(f"总计 {len(rows)},DOI 与标题一致 {len(ok)}") | |
| for r in rows: | |
| flag = "OK " if r in ok else "!! " | |
| print(f"{flag}{r['year']} {r['doi']:32s} sim={r['title_match']:.2f} " | |
| f"link={r['link_status']:>6s} gh={r['github_status']:>6s} {r['title'][:60]}") | |
| json.dump(rows, open(os.path.join(BASE, "ns_inventory_v2.json"), "w"), | |
| ensure_ascii=False, indent=1) | |
| if __name__ == "__main__": | |
| main() | |