Commit e671ead3 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Add entry 'product_space'

parent 8e8ae258
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2021 Tiago de Paula Peixoto <>
# 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 <>.
from .. import *
title = "Atlas of Economic Complexity export network"
description = """Two networks of economic products, where a pair of products are connected if they are exported at similar rates by the same countries. The data are a projection from a bipartite network of nations and the products they export. Edges weights represent a similarity score (called \"proximity\"). Data based on UN Comtrade worldwide trade patterns. SITC network based on the Standard International Trade Classification and HS network based on the Harmonized Commodity Description and Coding System.[^icon]
[^icon]: Description obtained from the [ICON]( project."""
tags = ['Economic', 'Trade', 'Weighted', 'Projection', 'Metadata']
url = ''
citation = [('R. Hausmann et al., "The Atlas of Economic Complexity: Mapping paths to prosperity." MIT Press (2014)', ''),
('CA Hidalgo, R Hausmann, "The Building Blocks of Economic Complexity", Proc. Natl. Acad. Sci. 106(26):10570-10575 (2009)', ""),
('R Hausmann, CA Hidalgo, S Bustos, M Coscia, S Chung, J Jimenez, A Simoes, MA Yildirim, "The Atlas of Economic Complexity", Puritan Press (2011). ISBN-10: 0615546625', '')]
icon_hash = '577e7bf458d31bd664bac0d9'
ustream_license = None
upstream_prefix = ''
files = [(('', ''), 'HS', None),
(('', ''), 'SITC', None)]
def fetch_upstream(force=False):
return fetch_upstream_files(__name__.split(".")[-1], upstream_prefix, files,
def parse(alts=None):
global files
name = __name__.split(".")[-1]
for fnames, alt, fmt in files:
if alts is not None and alt not in alts:
if isinstance(fnames, str):
fnames = [fnames]
with ExitStack() as stack:
fs = [stack.enter_context(open_upstream_file(name, fn, "r")) for fn in fnames]
g = Graph(directed=False) = g.new_vp("int") = g.new_vp("int")
g.vp.size = g.new_vp("double")
g.vp.pos = g.new_vp("vector<double>")
g.vp.leamer = g.new_vp("string") = g.new_vp("string")
if alt == "SITC":
g.vp.color = g.new_vp("string")
vertices = {}
for line in fs[0]:
v = g.add_vertex()
if alt == "SITC":
pid, c, x, y, s, leamer, name, color = line.split("\t")
g.vp.color[v] = color
pid, c, x, y, s, leamer, name = line.split("\t")[v] = int(pid)
vertices[int(pid)] = v
g.vp.pos[v] = [float(x), float(y)]
g.vp.size[v] = s[v] = name
g.vp.leamer[v] = leamer
g.ep.width = g.new_ep("double")
g.ep.color = g.new_ep("string")
for line in fs[1]:
s, x_s, y_s, t, x_t, y_t, w, c = line.split("\t")
s = vertices[int(s)]
t = vertices[int(t)]
e = g.add_edge(s, t)
g.ep.width[e] = w
g.ep.color[e] = c
yield alt, g
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment