History of un_migrations
The changes to the source code of this entry in the repository, newest first, each with the differences it made to the entry's files. They are also listed on GitLab.
[entries] Move unavailable upstream sources to verified alternatives 2137af6
The upstream sources of these entries are gone, moved, or refuse automated downloads; each now downloads the same data (byte-identical to the cached files, or for board_directors, identical apart from line endings) from: - add_health: the Wayback Machine (Moreno's site, as its sibling entries) - board_directors: T. Opsahl's site (opsahl.co.uk) - copenhagen, cow_signed_relations, fullerene_structures, german_power_grid: figshare's API (its downloader refuses the server) - drosophila_flybi: the same address, without a doubled slash - dutch_criticism: V. Batagelj's repository of Pajek data on GitHub - fly_larva: the copy of the supplementary files in Europe PMC - foursquare: the authors' Google Drive file - game_thrones, microsoft_concept, un_migrations: pinned Wayback Machine snapshots - internet_top_pop: the Topology Zoo repository on GitHub - scotus_majority: Harvard Dataverse and Wayback Machine snapshots
diff --git a/entries/un_migrations/__init__.py b/entries/un_migrations/__init__.py
index 3e8166e..53e08d6 100644
--- a/entries/un_migrations/__init__.py
+++ b/entries/un_migrations/__init__.py
@@ -26,16 +26,22 @@ from .. import *
title = "UN migration stock (2015)"
description = """A network of migration between countries, collected by the United Nations. Nodes are countries and areas, and a directed edge from A to B means that there are international migrants from A (origin) living in B (destination); the edge properties `migration_<year>_<sex>` give the number of such migrants (the migrant stock, not the flow of migration during a period), for each given year and sex (`total`, `male` or `female`). Estimates are presented for 1990, 1995, 2000, 2005, 2010 and 2015 and are available for all countries and areas of the world. The estimates are based on official statistics on the foreign-born or the foreign population."""
tags = ['Social', 'Economic', 'Travel', 'Political', 'Weighted', 'Metadata']
-url = 'https://www.un.org/en/development/desa/population/migration/data/estimates2/estimates15.asp'
+url = 'https://web.archive.org/web/20220828135525/https://www.un.org/en/development/desa/population/migration/data/estimates2/estimates15.asp'
citation = [('United Nations, Department of Economic and Social Affairs, Population Division (2015). "Trends in International Migrant Stock: The 2015 Revision." (United Nations database, POP/DB/MIG/Stock/Rev.2015)',
- 'https://www.un.org/en/development/desa/population/migration/data/estimates2/estimates15.asp')]
+ 'https://web.archive.org/web/20220828135525/https://www.un.org/en/development/desa/population/migration/data/estimates2/estimates15.asp')]
icon_hash = None
upstream_prefix = 'https://www.un.org/en/development/desa/population/migration/data/estimates2/data'
files = [('UN_MigrantStockByOriginAndDestination_2015.xlsx', None, None)]
+# The 2015 revision is no longer available from the UN site (which offers
+# only the later revisions); it is fetched from a pinned Internet Archive
+# snapshot
+archived_urls = {
+ 'UN_MigrantStockByOriginAndDestination_2015.xlsx': 'https://web.archive.org/web/20250821024723id_/https://www.un.org/en/development/desa/population/migration/data/estimates2/data/UN_MigrantStockByOriginAndDestination_2015.xlsx'}
+
def fetch_upstream(force=False):
- return fetch_upstream_files(__name__.split(".")[-1], upstream_prefix, files,
- force)
+ return fetch_archived_files(__name__.split(".")[-1], archived_urls, force,
+ tries=4)
@cache_network()
@coerce_props()
[entries] Fix parse bugs and improve descriptions and metadata 6bb6851
- parse fixes from the review of the descriptions, e.g. us_patents (directed), celegans_2019 (synapse direction), ecoli_transcription and yeast_transcription (regulator to target), bitcoin (direction, phantom node), ego_social (Google+ features and circles), scotus_majority, arxiv_authors and social_location (as in SNAP), caida_as, dnc, dom, mist, reuters and bibsonomy (names on the right nodes), uci_zoo - every description now states explicitly what the nodes and edges represent; corrected titles, years, tags, citations and licences - the "Hypergraph" tag is removed; very large entries are marked `huge = True` (see --skip-huge) - ICON ids of partial duplicates added (hiv_transmission, congress_bills, openflights, dutch_school)
diff --git a/entries/un_migrations/__init__.py b/entries/un_migrations/__init__.py
index 18bf5ef..3e8166e 100644
--- a/entries/un_migrations/__init__.py
+++ b/entries/un_migrations/__init__.py
@@ -24,7 +24,7 @@ import tempfile
from .. import *
title = "UN migration stock (2015)"
-description = """A network of migration between countries, collected by the United Nations. A directed edge gives the flow of migration, and an edge property gives the number of migrants, for each given year and sex. Estimates are presented for 1990, 1995, 2000, 2005, 2010 and 2015 and are available for all countries and areas of the world. The estimates are based on official statistics on the foreign-born or the foreign population."""
+description = """A network of migration between countries, collected by the United Nations. Nodes are countries and areas, and a directed edge from A to B means that there are international migrants from A (origin) living in B (destination); the edge properties `migration_<year>_<sex>` give the number of such migrants (the migrant stock, not the flow of migration during a period), for each given year and sex (`total`, `male` or `female`). Estimates are presented for 1990, 1995, 2000, 2005, 2010 and 2015 and are available for all countries and areas of the world. The estimates are based on official statistics on the foreign-born or the foreign population."""
tags = ['Social', 'Economic', 'Travel', 'Political', 'Weighted', 'Metadata']
url = 'https://www.un.org/en/development/desa/population/migration/data/estimates2/estimates15.asp'
citation = [('United Nations, Department of Economic and Social Affairs, Population Division (2015). "Trends in International Migrant Stock: The 2015 Revision." (United Nations database, POP/DB/MIG/Stock/Rev.2015)',
Update copyright information 73a4f0d
diff --git a/entries/un_migrations/__init__.py b/entries/un_migrations/__init__.py
index 8b45b69..18bf5ef 100644
--- a/entries/un_migrations/__init__.py
+++ b/entries/un_migrations/__init__.py
@@ -1,7 +1,7 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
-# Copyright (C) 2020-2024 Tiago de Paula Peixoto <tiago@skewed.de>
+# Copyright (C) 2020-2026 Tiago de Paula Peixoto <tiago@skewed.de>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
Update copyright information 3d288ea
diff --git a/entries/un_migrations/__init__.py b/entries/un_migrations/__init__.py
index 1bf2375..8b45b69 100644
--- a/entries/un_migrations/__init__.py
+++ b/entries/un_migrations/__init__.py
@@ -1,7 +1,7 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
-# Copyright (C) 2020-2023 Tiago de Paula Peixoto <tiago@skewed.de>
+# Copyright (C) 2020-2024 Tiago de Paula Peixoto <tiago@skewed.de>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
Update copyright information 8d005ae
diff --git a/entries/un_migrations/__init__.py b/entries/un_migrations/__init__.py
index 8655519..1bf2375 100644
--- a/entries/un_migrations/__init__.py
+++ b/entries/un_migrations/__init__.py
@@ -1,7 +1,7 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
-# Copyright (C) 2021 Tiago de Paula Peixoto <tiago@skewed.de>
+# Copyright (C) 2020-2023 Tiago de Paula Peixoto <tiago@skewed.de>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
Update copyright info db2efcc
diff --git a/entries/un_migrations/__init__.py b/entries/un_migrations/__init__.py
index d11f769..8655519 100644
--- a/entries/un_migrations/__init__.py
+++ b/entries/un_migrations/__init__.py
@@ -1,7 +1,7 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
-# Copyright (C) 2020 Tiago de Paula Peixoto <tiago@skewed.de>
+# Copyright (C) 2021 Tiago de Paula Peixoto <tiago@skewed.de>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
Add un_migrations entry 1814dee
diff --git a/entries/un_migrations/__init__.py b/entries/un_migrations/__init__.py
new file mode 100644
index 0000000..d11f769
--- /dev/null
+++ b/entries/un_migrations/__init__.py
@@ -0,0 +1,119 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2020 Tiago de Paula Peixoto <tiago@skewed.de>
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Affero General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Affero General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from openpyxl import load_workbook
+import pandas
+import shutil
+import subprocess
+import tempfile
+from .. import *
+
+title = "UN migration stock (2015)"
+description = """A network of migration between countries, collected by the United Nations. A directed edge gives the flow of migration, and an edge property gives the number of migrants, for each given year and sex. Estimates are presented for 1990, 1995, 2000, 2005, 2010 and 2015 and are available for all countries and areas of the world. The estimates are based on official statistics on the foreign-born or the foreign population."""
+tags = ['Social', 'Economic', 'Travel', 'Political', 'Weighted', 'Metadata']
+url = 'https://www.un.org/en/development/desa/population/migration/data/estimates2/estimates15.asp'
+citation = [('United Nations, Department of Economic and Social Affairs, Population Division (2015). "Trends in International Migrant Stock: The 2015 Revision." (United Nations database, POP/DB/MIG/Stock/Rev.2015)',
+ 'https://www.un.org/en/development/desa/population/migration/data/estimates2/estimates15.asp')]
+icon_hash = None
+upstream_prefix = 'https://www.un.org/en/development/desa/population/migration/data/estimates2/data'
+files = [('UN_MigrantStockByOriginAndDestination_2015.xlsx', None, None)]
+
+def fetch_upstream(force=False):
+ return fetch_upstream_files(__name__.split(".")[-1], upstream_prefix, files,
+ force)
+
+@cache_network()
+@coerce_props()
+@annotate()
+def parse(alts=None):
+ global files
+ name = __name__.split(".")[-1]
+ for fname, alt, fmt in files:
+ if alts is not None and alt not in alts:
+ continue
+
+ with open_upstream_file(name, fname, "rb") as f:
+ with tempfile.TemporaryDirectory(dir="./cache/temp", suffix="un_migration") as tdir:
+ with open(f"{tdir}/dump.xls", "wb") as fw:
+ shutil.copyfileobj(f, fw)
+ subprocess.run(["localc", "--convert-to", "xlsx",
+ f"dump.xls"], cwd=tdir, check=True)
+ wb = load_workbook(f"{tdir}/dump.xlsx")
+
+
+ g = Graph()
+ g.vp.name = g.new_vp("string")
+ g.vp.code = g.new_vp("int")
+ g.vp.region = g.new_vp("string")
+ g.vp.sub_region = g.new_vp("string")
+ is_region = g.new_vp("bool")
+
+ years = [1990, 1995, 2000, 2005, 2010, 2015]
+ sexes = ["total", "male", "female"]
+ regions = ["Africa", "Asia", "Europe", "Latin America and the Caribbean",
+ "Northern America", "Oceania"]
+
+ for year in years:
+ for sex in sexes:
+ g.ep[f"migration_{year}_{sex}"] = g.new_ep("int")
+
+ vertices = {}
+ def get_vertex(name):
+ v = vertices.get(name, None)
+ if v is None:
+ v = g.add_vertex()
+ vertices[name] = v
+ g.vp.name[v] = name
+ return v
+
+ wb = list(wb)
+ for ti, year in enumerate(years):
+ for si, sex in enumerate(sexes):
+ df = pandas.DataFrame(wb[ti * 3 + si + 1].values)
+ m = numpy.array(df.values)
+ src_names = m[15][1:]
+ m = m[16:, 1:]
+
+ active_region = ""
+ active_subregion = ""
+ for row in range(265):
+ for col in range(m.shape[1]):
+ if col == 0:
+ tgt = get_vertex(m[row, col])
+ g.vp.region[tgt] = active_region
+ g.vp.sub_region[tgt] = active_subregion
+ elif col == 2:
+ g.vp.code[tgt] = m[row, col]
+ elif col == 3:
+ if m[row, col] is None:
+ is_region[tgt] = True
+ if m[row, 0] in regions:
+ active_region = m[row, 0]
+ else:
+ active_subregion = m[row, 0]
+ elif col > 6:
+ if m[row, col] is None:
+ continue
+ src = get_vertex(src_names[col])
+ e = g.edge(src, tgt, add_missing=True)
+ g.ep[f"migration_{year}_{sex}"][e] = m[row, col]
+
+ vs = [v for v in g.vertices() if is_region[v]]
+ g.remove_vertex(vs)
+
+ yield alt, g