ThGaskin commited on
Commit
0f72235
·
verified ·
1 Parent(s): f0e36e7

Delete files Data/__init__.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. Data/__init__.py +0 -73
Data/__init__.py DELETED
@@ -1,73 +0,0 @@
1
- import pandas as pd
2
- import os
3
-
4
- # We make relevant datasets contained in this folder available across the project, for easier integration and plotting.
5
- # The base directory points to the folder containing this file:
6
- base_dir = os.path.dirname(__file__)
7
-
8
- # Make the ISO code lookup table available across the project. Also group countries by region.
9
- lookup_table = pd.read_csv(os.path.join(base_dir, "Iso_code_lookup.csv"))
10
- countries_by_region = pd.read_csv(os.path.join(base_dir, "countries_by_region.csv"))
11
- countries_by_region = countries_by_region.groupby('Region').agg(list).to_dict()['Country ISO']
12
- countries_by_region['Eastern Asia'].append('TWN')
13
- countries_by_region['Middle East'] = countries_by_region.pop('Western Asia')
14
- countries_by_region['South Asia'] = countries_by_region.pop('Southern Asia')
15
-
16
- # Make the world shapefile available for plotting
17
- import geopandas as gpd
18
- world = gpd.read_file(os.path.join(base_dir, "world_shapefile/ne_50m_admin_0_countries.shp"))
19
- world.to_crs("EPSG:3857", inplace=True) # Mercator projection by default
20
-
21
- # Make the coordinates available. These are regular latitude/longitude coordinates
22
- coordinates = pd.read_csv(os.path.join(base_dir, "Coordinates.csv"))[['Alpha-3 code', 'Latitude', 'Longitude']].set_index('Alpha-3 code').to_dict()
23
- coordinates = dict((k, (coordinates['Latitude'][k], coordinates['Longitude'][k])) for k in coordinates['Latitude'].keys())
24
-
25
- # Load the various comparison datasets into a dictionary for easy plotting, assigning consistent colours
26
- # and markers for each.
27
- import sys
28
- from os.path import dirname as up
29
- from dantro._import_tools import import_module_from_path
30
- sys.path.append(up(__file__))
31
- Plots = import_module_from_path(mod_path=up(__file__), mod_str="Plots")
32
- from Plots import colors
33
- import xarray as xr
34
- flow_dsets = {
35
- "Quantmig": dict(
36
- data=xr.open_dataset(os.path.join(base_dir, "Flow_data/QuantMig_data/Quantmig_flows.nc")),
37
- central='flow_50%', lower='flow_2.5%', upper='flow_97.5%',
38
- primary_color=colors['c_orange'], secondary_color=colors['c_yellow']
39
- ),
40
- "Statistics Sweden": dict(
41
- data=xr.open_dataarray(os.path.join(base_dir, "Flow_data/National_Statistics/SWE_flows.nc")),
42
- primary_color=colors['c_red'], secondary_color=colors['c_pink'], marker='v', s=10,
43
- ),
44
- "Statistics Finland": dict(
45
- data=xr.open_dataarray(os.path.join(base_dir, "Flow_data/National_Statistics/FIN_flows.nc")),
46
- primary_color=colors['c_lightblue'], secondary_color=colors['c_darkblue'], marker='s', s=10
47
- ),
48
- "StatNZ": dict(
49
- data=xr.open_dataarray(os.path.join(base_dir, "Flow_data/National_Statistics/NZL_flows.nc")),
50
- primary_color=colors['c_darkgreen'], secondary_color=colors['c_lightgreen'], marker='^', s=10
51
- ),
52
- "Facebook data": dict(
53
- data=xr.open_dataarray(os.path.join(base_dir, "Flow_data/Facebook/facebook_flows.nc")).where(lambda x: x>=25),
54
- primary_color=colors['c_purple'], secondary_color='#E1C6EC', ec=colors['c_darkgrey'], marker='o', s=10, lw=0.5
55
- )
56
- }
57
-
58
- # UN WPP data
59
- population = 1e3 * xr.open_dataset(os.path.join(base_dir, "UN_WPP_data/UN_WPP_data.nc"))['Total Population, as of 1 January (thousands)']
60
- death_rate = 1e-3 * xr.open_dataset(os.path.join(base_dir, "UN_WPP_data/UN_WPP_data.nc"))['Crude Death Rate (deaths per 1,000 population)']
61
- WPP_net_migration = 1e3 * xr.open_dataset(os.path.join(base_dir, "UN_WPP_data/UN_WPP_data.nc"))['Net Number of Migrants (thousands)']
62
- NatStat_net_migration = xr.open_dataarray(os.path.join(base_dir, "Net_migration/National_statistics.nc"))
63
- WPP_data = xr.open_dataset(os.path.join(base_dir, "UN_WPP_data/UN_WPP_data.nc"))
64
-
65
- # Calculate the fraction of population alive at start of 1990 in each destination country still alive at start of year
66
- import numpy as np
67
- gamma = (1-death_rate.sel({"Year": range(1989, 2024)})).assign_coords({"Year": np.arange(1990, 2025, 1)}).rename({
68
- "Country ISO": "Destination ISO"})
69
- gamma.loc[{"Year": 1990}] = 1.0
70
- gamma = gamma.cumprod('Year')
71
-
72
- # Stock data
73
- stock_data = xr.load_dataset(os.path.join(base_dir, "UN_stock_data/stock_data.nc"))