Impact factor
papertrail.metrics.impact_factor
Journal impact factor database for enriching publications.
The :class:ImpactFactorDatabase lets you load historically accurate journal
impact factors from your own CSV or JSON files and attach them to retrieved
publications.
Why a custom database?
OpenAlex exposes 2yr_mean_citedness on each source record, which serves as
a freely available proxy for the traditional Journal Impact Factor (JIF).
However, it reflects the current value at retrieval time, not the
historical value at the year of publication. If you need historically
accurate JIFs (e.g. from Clarivate JCR exports), load them via this class.
CSV format expected by :meth:ImpactFactorDatabase.load_csv:
.. code-block:: text
issn,year,impact_factor
0028-0836,2022,64.8
0028-0836,2021,49.96
0036-8075,2022,56.9
JSON format expected by :meth:ImpactFactorDatabase.load_json:
.. code-block:: json
{
"0028-0836": {"2022": 64.8, "2021": 49.96},
"0036-8075": {"2022": 56.9}
}
ImpactFactorDatabase
In-memory store of journal impact factors indexed by ISSN and year.
Example
from pathlib import Path db = ImpactFactorDatabase() db.load_csv(Path("jif_data.csv")) enriched = db.enrich_publications(publications)
Source code in src/papertrail/metrics/impact_factor.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | |
load_csv
Load impact factors from a CSV file.
The file must contain at minimum the columns issn, year, and
impact_factor. Additional columns are silently ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the CSV file. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If path does not exist. |
KeyError
|
If a required column is missing. |
ValueError
|
If a numeric field cannot be parsed. |
Source code in src/papertrail/metrics/impact_factor.py
load_json
Load impact factors from a JSON file.
The file must be a JSON object mapping ISSN strings to objects that map year strings (or integers) to float values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the JSON file. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If path does not exist. |
JSONDecodeError
|
If the file is not valid JSON. |
ValueError
|
If a numeric field cannot be parsed. |
Source code in src/papertrail/metrics/impact_factor.py
get_impact_factor
Return the impact factor for a journal in a given year.
If an exact match is not found, values within ±tolerance years
are checked in order of proximity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
issn
|
str
|
ISSN string (e.g. |
required |
year
|
int
|
Target year. |
required |
tolerance
|
int
|
How many years to search around year when an exact
match is unavailable. Defaults to |
1
|
Returns:
| Type | Description |
|---|---|
float | None
|
The impact factor as a float, or |
Source code in src/papertrail/metrics/impact_factor.py
enrich_publications
Return a copy of publications enriched with IF data from this database.
For each publication that has a journal with at least one ISSN, an IF
lookup is performed. If a value is found, the publication's
:attr:~papertrail.models.JournalInfo.impact_factor and
:attr:~papertrail.models.JournalInfo.impact_factor_year fields are
updated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
publications
|
list[Publication]
|
Original list of publications. |
required |
tolerance
|
int
|
Year tolerance passed to :meth: |
1
|
Returns:
| Type | Description |
|---|---|
list[Publication]
|
A new list of :class: |
list[Publication]
|
Publications without journal data are returned unchanged. |