mit-jp / mit-climate-data-viz

Plotting climate data for the MIT Joint Program on the Science and Policy of Global Change
https://cypressf.shinyapps.io/eppa-dashboard/
0 stars 0 forks source link

Add a global map #274

Closed cypressf closed 1 year ago

cypressf commented 2 years ago
cypressf commented 2 years ago

We are going to use all of asia for now. The data we have for russia is for all of russia right now, not for all of rusia only in asia, but kilian will split out the data for the asian portion of rusia.

cypressf commented 2 years ago

I'm looking to find some geojson files for africa and asia

cypressf commented 2 years ago

Going to use the data behind https://observablehq.com/@fil/map-of-africa or https://observablehq.com/@djr4/gdp-per-capita-ppp-africa-vs-serbia for the map of africa. Potentially could use the same data with a different filter and projection for the map of asia.

cypressf commented 2 years ago

whatever map file I use, I plan to use the iso-3 format for countries

cypressf commented 2 years ago

I'm going to use https://github.com/topojson/world-atlas for my map. I'll find a way to filter by region if we want to show only africa and asia. For now, I'm going to experiment with it and see if I can get some data displaying on a country-level globally.

cypressf commented 2 years ago

database modification

Column Type Nullable
id int2 NO
name text NO

primary key: id

Column Type Nullable Foreign key
dataset int4 NO dataset(id)
source int4 NO data_source(id)
start_date date NO
end_date date NO
country_id int2 NO country(id)
value float8 YES
Column Type Nullable
id int4 NO
name varchar(100) NO
Column Type Nullable Foreign key
geography_type int4 NO geography_type(id)
Column Type Nullable Foreign key
geography_type int4 NO geography_type(id)
cypressf commented 2 years ago

controller modification

#[get("/country-data/{id}")]
fn get(id,{source, start_date, end_date})

Similarly add and rename daos, and models.

Note: instead I'm putting everything inside the same data_controller.rs

cypressf commented 2 years ago

Frontend modification

cypressf commented 2 years ago

world-atlas uses ISO 3166-1 numeric 3-digit country codes instead of the iso-3 alphabetical format. Let's use those in the database and for all data as well. Perhaps I could add a column for alphabetical format if needed, but I'll keep them numeric for now.

cypressf commented 2 years ago

there are 249 countries in kilian's dataset

cypressf commented 1 year ago

There are 174 countries in the world map I'm using. It's worth examining which countries are missing between Kilian's datasets and my world map to see if we can show a more complete picture. Is this because the world map is outdated? Because it's missing labels? Because Kilian's dataset is outdated?

cypressf commented 1 year ago

Based on my test (https://github.com/cypressf/map-data-cleaning/commit/8aa2f6abf28535a2344e133add956a32a7a81b43), the following 75 countries are missing from the map:

๐Ÿ‡ต๐Ÿ‡ณ Pitcairn ๐Ÿ‡ธ๐Ÿ‡ญ Saint Helena, Ascension and Tristan da Cunha ๐Ÿ‡ฒ๐Ÿ‡ถ Martinique ๐Ÿ‡ฐ๐Ÿ‡ฒ Comoros ๐Ÿ‡ฏ๐Ÿ‡ช Jersey ๐Ÿ‡ป๐Ÿ‡ฌ Virgin Islands, British ๐Ÿ‡ฒ๐Ÿ‡บ Mauritius ๐Ÿ‡ธ๐Ÿ‡ฏ Svalbard and Jan Mayen ๐Ÿ‡จ๐Ÿ‡ป Cabo Verde ๐Ÿ‡ฒ๐Ÿ‡ด Macao ๐Ÿ‡จ๐Ÿ‡ฐ Cook Islands ๐Ÿ‡ง๐Ÿ‡ฒ Bermuda ๐Ÿ‡ต๐Ÿ‡ผ Palau ๐Ÿ‡ป๐Ÿ‡ฎ Virgin Islands, U.S. ๐Ÿ‡น๐Ÿ‡ฐ Tokelau ๐Ÿ‡ฆ๐Ÿ‡ธ American Samoa ๐Ÿ‡ฒ๐Ÿ‡ซ Saint Martin (French part) ๐Ÿ‡ฌ๐Ÿ‡บ Guam ๐Ÿ‡พ๐Ÿ‡น Mayotte ๐Ÿ‡จ๐Ÿ‡ผ Curaรงao ๐Ÿ‡ญ๐Ÿ‡ฐ Hong Kong ๐Ÿ‡ธ๐Ÿ‡ฒ San Marino ๐Ÿ‡ง๐Ÿ‡ง Barbados ๐Ÿ‡ฒ๐Ÿ‡จ Monaco ๐Ÿ‡ผ๐Ÿ‡ซ Wallis and Futuna ๐Ÿ‡น๐Ÿ‡ด Tonga ๐Ÿ‡ฆ๐Ÿ‡ฌ Antigua and Barbuda ๐Ÿ‡จ๐Ÿ‡ฝ Christmas Island ๐Ÿ‡ญ๐Ÿ‡ฒ Heard Island and McDonald Islands ๐Ÿ‡ซ๐Ÿ‡ด Faroe Islands ๐Ÿ‡ฌ๐Ÿ‡ธ South Georgia and the South Sandwich Islands ๐Ÿ‡ฐ๐Ÿ‡พ Cayman Islands ๐Ÿ‡ผ๐Ÿ‡ธ Samoa ๐Ÿ‡ต๐Ÿ‡ฒ Saint Pierre and Miquelon ๐Ÿ‡ซ๐Ÿ‡ฒ Micronesia, Federated States of ๐Ÿ‡ฒ๐Ÿ‡ป Maldives ๐Ÿ‡ฐ๐Ÿ‡ฎ Kiribati ๐Ÿ‡ณ๐Ÿ‡ซ Norfolk Island ๐Ÿ‡ง๐Ÿ‡ป Bouvet Island ๐Ÿ‡ฐ๐Ÿ‡ณ Saint Kitts and Nevis ๐Ÿ‡ฌ๐Ÿ‡ซ French Guiana ๐Ÿ‡ต๐Ÿ‡ซ French Polynesia ๐Ÿ‡น๐Ÿ‡ป Tuvalu ๐Ÿ‡ธ๐Ÿ‡น Sao Tome and Principe ๐Ÿ‡ฒ๐Ÿ‡ญ Marshall Islands ๐Ÿ‡ป๐Ÿ‡จ Saint Vincent and the Grenadines ๐Ÿ‡ณ๐Ÿ‡บ Niue ๐Ÿ‡ฌ๐Ÿ‡ฌ Guernsey ๐Ÿ‡ท๐Ÿ‡ช Rรฉunion ๐Ÿ‡ฎ๐Ÿ‡ฒ Isle of Man ๐Ÿ‡จ๐Ÿ‡จ Cocos (Keeling) Islands ๐Ÿ‡ฉ๐Ÿ‡ฒ Dominica ๐Ÿ‡ง๐Ÿ‡ถ Bonaire, Sint Eustatius and Saba ๐Ÿ‡ฒ๐Ÿ‡น Malta ๐Ÿ‡ฌ๐Ÿ‡ฎ Gibraltar ๐Ÿ‡ฎ๐Ÿ‡ด British Indian Ocean Territory ๐Ÿ‡บ๐Ÿ‡ฒ United States Minor Outlying Islands ๐Ÿ‡ฆ๐Ÿ‡ผ Aruba ๐Ÿ‡ณ๐Ÿ‡ท Nauru ๐Ÿ‡ฌ๐Ÿ‡ฉ Grenada ๐Ÿ‡ฌ๐Ÿ‡ต Guadeloupe ๐Ÿ‡ธ๐Ÿ‡ฝ Sint Maarten (Dutch part) ๐Ÿ‡ฑ๐Ÿ‡จ Saint Lucia ๐Ÿ‡ง๐Ÿ‡ญ Bahrain ๐Ÿ‡ฒ๐Ÿ‡ต Northern Mariana Islands ๐Ÿ‡ฆ๐Ÿ‡ฎ Anguilla ๐Ÿ‡ธ๐Ÿ‡จ Seychelles ๐Ÿ‡ฑ๐Ÿ‡ฎ Liechtenstein ๐Ÿ‡ฒ๐Ÿ‡ธ Montserrat ๐Ÿ‡ฆ๐Ÿ‡ฝ ร…land Islands ๐Ÿ‡ธ๐Ÿ‡ฌ Singapore ๐Ÿ‡ป๐Ÿ‡ฆ Holy See (Vatican City State) ๐Ÿ‡น๐Ÿ‡จ Turks and Caicos Islands ๐Ÿ‡ง๐Ÿ‡ฑ Saint Barthรฉlemy ๐Ÿ‡ฆ๐Ÿ‡ฉ Andorra

cypressf commented 1 year ago

Many of the countries that are missing are possibly map units (smaller units than countries) https://www.naturalearthdata.com/downloads/10m-cultural-vectors/10m-admin-0-details/

See https://peakbagger.com/pbgeog/countries.aspx#depentab

cypressf commented 1 year ago

For now I'm going to add the sovereign nations in the map to the database, and ignore the countries listed above. Next, I'll investigate how to add them to the map.

cypressf commented 1 year ago

Frontend architecture

  1. Request map_visualizations with param geography_type (values: 1: usa-county,2: country). If geography_type is set to neither or both it will include all map_visualizations, but if it is set to one or the other, it will only return items of that type.
  2. If any data tabs are empty given the current filter, do not display them.
  3. The geography_type param will be set by a tab or a radio toggle for now. It should persist in the redux store, but doesn't need to appear in the url for now.
cypressf commented 1 year ago

We're planning on sticking with ISO standard 3166-1 numeric country codes as of 2022.

cypressf commented 1 year ago

I'm resuming work on this now that I've released county report cards

cypressf commented 1 year ago

I'm running into an issue where Table<MapVisualization>.all(true, None) returns duplicate map visualizations and doesn't return any that are not in a tab. The SQL query needs experimenting with and I need to write some tests for it.

cypressf commented 1 year ago

Fixed that issue!

cypressf commented 1 year ago

Now I'm seeing a crash when I toggle to Global view. I'll investigate tomorrow.

cypressf commented 1 year ago

It was crashing because there were no world maps for the selected tab when I toggled from USA to world. The solution is twofold: pass an empty object instead of undefined as the state to components that expect map visualizations, and automatically filter tabs out if they are empty, and select the first non-empty tab.

cypressf commented 1 year ago

I had to modify the data processor so it could handle country codes because it had assumed that all data was index by usa-county SIPS code: https://github.com/mit-jp/climate-risk-map/commit/aacee71f7bb1d4366397ffe4aa0479931adfc9e7

cypressf commented 1 year ago

It might make more sense to add geography_type to dataset instead of map_visualization because each dataset is inherently associated with either the world or the USA. Someone can't modify a map visualization to be of the World if geographic region of the dataset is the USA

cypressf commented 1 year ago
cypressf commented 1 year ago

It's looking like it'd be easier to use one table for all data, and make the primary key a composite of the id column and a geography_type column. That way, we wouldn't have to make a separate queries for every geography type. Instead, it would be one query, with the geography type specified in the query. For state-filters, however, we'd need to filter by id prefix since we could no longer have the id in the query itself.

cypressf commented 1 year ago

Okay. Global maps are ready to go. I just need to add data.