diff --git a/cpp/simulations/paper_202011.cpp b/cpp/simulations/paper_202011.cpp index a8f2d32749..9287373d40 100644 --- a/cpp/simulations/paper_202011.cpp +++ b/cpp/simulations/paper_202011.cpp @@ -515,7 +515,7 @@ mio::IOResult set_edges(const fs::path& data_dir, { //migration between nodes BOOST_OUTCOME_TRY(migration_data_commuter, - mio::read_mobility_plain((data_dir / "mobility" / "commuter_migration_scaled.txt").string())); + mio::read_mobility_plain((data_dir / "mobility" / "commuter_mobility_scaled.txt").string())); BOOST_OUTCOME_TRY(migration_data_twitter, mio::read_mobility_plain((data_dir / "mobility" / "twitter_scaled_1252.txt").string())); if (size_t(migration_data_commuter.rows()) != params_graph.nodes().size() || diff --git a/data/mobility/county_centers_dim400.json b/data/mobility/county_centers_dim400.json new file mode 100644 index 0000000000..9ef8e0e0d5 --- /dev/null +++ b/data/mobility/county_centers_dim400.json @@ -0,0 +1 @@ +[{"01001":9.445720205,"01002":10.1328367704,"01003":10.723672945,"01004":9.9909155313,"01051":9.1115286419,"01053":10.6063142269,"01054":8.9671138443,"01055":10.770974213,"01056":9.7457166902,"01057":10.3639025329,"01058":9.7838865852,"01059":9.4999288387,"01060":10.1456999704,"01061":9.5190001644,"01062":10.3372712145,"02000":10.0219589124,"03101":10.5244254212,"03102":10.3690960264,"03103":10.7852816541,"03151":10.6076802931,"03153":10.3987720463,"03154":10.8958025558,"03155":9.8477480903,"03157":10.2501530923,"03158":10.6506489556,"03159":10.0945917849,"03241":9.718007146,"03251":8.6998891832,"03252":9.3954249279,"03254":9.947657946,"03255":9.5527325259,"03256":9.1149358217,"03257":9.2061048695,"03351":10.102293569,"03352":8.8063814777,"03353":9.9635632031,"03354":11.1289774269,"03355":10.5743556874,"03356":8.8118649291,"03357":9.3031045066,"03358":9.7731896364,"03359":9.4166131334,"03360":10.5545577464,"03361":9.1781783575,"03401":8.6488795252,"03402":7.176085073,"03403":8.2339205488,"03404":8.0584846728,"03405":8.0777242825,"03451":8.0087530181,"03452":7.372895054,"03453":7.908177463,"03454":7.4048014538,"03455":7.9851124153,"03456":7.0186542831,"03457":7.4985384689,"03458":8.3970865937,"03459":8.0427190583,"03460":8.2210480627,"03461":8.3930621529,"03462":7.7181018594,"04011":8.7992774587,"04012":8.5791192382,"05111":6.8087115966,"05112":6.7315201332,"05113":7.0164290752,"05114":6.5758238513,"05116":6.4050352714,"05117":6.8758133618,"05119":6.8475642519,"05120":7.2281332255,"05122":7.0507773643,"05124":7.1724324835,"05154":6.2640220484,"05158":6.9654949516,"05162":6.6399037695,"05166":6.3261382577,"05170":6.6184058248,"05314":7.1146523871,"05315":6.9742895435,"05316":7.0044961684,"05334":6.21730394,"05358":6.4447895646,"05362":6.7229383264,"05366":6.635991869,"05370":6.1605645398,"05374":7.5098491903,"05378":7.1887923176,"05382":7.2258638906,"05512":6.9150776915,"05513":7.0701994457,"05515":7.6215297281,"05554":6.9064164988,"05558":7.3682016323,"05562":7.1511320038,"05566":7.5845626505,"05570":7.9528582304,"05711":8.5411696471,"05754":8.3520179983,"05758":8.6408779491,"05762":9.1840454112,"05766":8.9494345957,"05770":8.7408869056,"05774":8.7225270592,"05911":7.2228029049,"05913":7.4717787301,"05914":7.506996061,"05915":7.8166673588,"05916":7.2107491337,"05954":7.3297386543,"05958":8.3842585919,"05962":7.7120343729,"05966":7.9764957376,"05970":8.1966052481,"05974":8.2150667848,"05978":7.6364826515,"06411":8.6644847172,"06412":8.6413922097,"06413":8.7856573374,"06414":8.2599987917,"06431":8.6412604954,"06432":8.7933396813,"06433":8.4680003843,"06434":8.5114522226,"06435":9.280207352,"06436":8.4269621969,"06437":8.9728816721,"06438":8.8031924874,"06439":8.07546985,"06440":8.9194647197,"06531":8.8012772307,"06532":8.367352154,"06533":8.2031020532,"06534":8.7376794296,"06535":9.2657454878,"06611":9.4588850985,"06631":9.751829682,"06632":9.7511302453,"06633":9.4075185822,"06634":9.3730443867,"06635":8.8918573184,"06636":9.9281178839,"07111":7.5785243731,"07131":7.0521152704,"07132":7.7421796221,"07133":7.6908241436,"07134":7.27243936,"07135":7.1755875217,"07137":7.3231256817,"07138":7.4706002013,"07140":7.5002941404,"07141":7.8418192019,"07143":7.8674915386,"07211":6.660069872,"07231":6.9701461286,"07232":6.415888434,"07233":6.7512801794,"07235":6.6903192159,"07311":8.3711045737,"07312":7.7546917331,"07313":8.1126666667,"07314":8.4016153412,"07315":8.2351292019,"07316":8.142680757,"07317":7.5914878607,"07318":8.4390342824,"07319":8.3315039703,"07320":7.3650608418,"07331":8.1602073137,"07332":8.1063836409,"07333":7.9071342993,"07334":8.2501702636,"07335":7.6841802283,"07336":7.4696580426,"07337":8.0588027614,"07338":8.3565182757,"07339":8.0849494979,"07340":7.6579110632,"08111":9.1707177622,"08115":8.9516820896,"08116":9.367179658,"08117":9.7161667308,"08118":9.1212915146,"08119":9.4975909978,"08121":9.1808570647,"08125":9.1916212654,"08126":9.6202166166,"08127":9.9106789355,"08128":9.7290547225,"08135":10.1821015513,"08136":10.0924369666,"08211":8.2277238852,"08212":8.4087219741,"08215":8.5641840229,"08216":8.2410079784,"08221":8.6849782678,"08222":8.5005651529,"08225":9.2805923829,"08226":8.7657685335,"08231":8.7062344938,"08235":8.6374689496,"08236":8.7313476272,"08237":8.4628685447,"08311":7.8137961239,"08315":7.9168675449,"08316":7.8958298659,"08317":8.0148557087,"08325":8.532062164,"08326":8.414845829,"08327":8.7986487967,"08335":8.9121811792,"08336":7.7757118412,"08337":8.2182364147,"08415":9.3692998192,"08416":8.9823162164,"08417":8.9358689399,"08421":9.9491466973,"08425":9.8325665704,"08426":9.7697026509,"08435":9.408548327,"08436":9.7801535185,"08437":9.2375143921,"09161":11.3968180148,"09162":11.5505696526,"09163":12.1017242372,"09171":12.7015156034,"09172":12.9021961998,"09173":11.4823684388,"09174":11.3558724504,"09175":11.9118726368,"09176":11.3694919468,"09177":11.9991539023,"09178":11.7361157979,"09179":11.1933324277,"09180":11.125728322,"09181":10.9444149825,"09182":11.8060425427,"09183":12.3742043805,"09184":11.6234263923,"09185":11.1975913481,"09186":11.5208268742,"09187":12.1568571956,"09188":11.2792849379,"09189":12.580617045,"09190":11.0540560419,"09261":12.178,"09262":13.4237424547,"09263":12.5742065698,"09271":12.9947621134,"09272":13.5137239822,"09273":11.8619419276,"09274":12.1977781382,"09275":13.3601144014,"09276":13.1033185969,"09277":12.8683792855,"09278":12.5856552543,"09279":12.612319795,"09361":11.8388666667,"09362":12.1109633082,"09363":12.1504726986,"09371":11.804571095,"09372":12.6927748503,"09373":11.5706933431,"09374":12.1055885065,"09375":12.1211930997,"09376":12.2479906408,"09377":12.1982294464,"09461":10.8896666667,"09462":11.5895806852,"09463":10.9650102146,"09464":11.8941254902,"09471":10.8912112364,"09472":11.5501456152,"09473":10.9457304282,"09474":11.1784347209,"09475":11.8187969738,"09476":11.376022315,"09477":11.4830664641,"09478":11.1182059593,"09479":12.0320582612,"09561":10.5689649355,"09562":10.9832861549,"09563":10.9669484579,"09564":11.0698814289,"09565":11.028,"09571":10.4783982802,"09572":10.9174995202,"09573":10.8430622501,"09574":11.3657973389,"09575":10.4625820498,"09576":11.1258388684,"09577":10.8911802396,"09661":9.1439095877,"09662":10.2166666667,"09663":9.9351619346,"09671":9.2375947494,"09672":9.9605430671,"09673":10.246440179,"09674":10.6058026911,"09675":10.2538393703,"09676":9.2250738367,"09677":9.6575284858,"09678":10.2636783822,"09679":9.9372659248,"09761":10.8947221385,"09762":10.6206666667,"09763":10.3050144536,"09764":10.1652987495,"09771":11.0561663226,"09772":10.7314777514,"09773":10.5241733834,"09774":10.3786164181,"09775":10.144762971,"09776":9.888920092,"09777":10.6402302515,"09778":10.3950224336,"09779":10.713133513,"09780":10.2666323371,"10041":6.9584648992,"10042":6.6871076964,"10043":7.1227646841,"10044":6.7749544315,"10045":7.2450529898,"10046":7.0938894873,"11000":13.3995233004,"12051":12.5109545077,"12052":14.3696747877,"12053":14.4917441916,"12054":13.0334251358,"12060":13.7026957512,"12061":13.8199336057,"12062":13.4678454642,"12063":12.629251696,"12064":14.1512526331,"12065":13.2102298911,"12066":13.9493046124,"12067":14.2118277401,"12068":12.6412115875,"12069":12.6902680116,"12070":11.9657802936,"12071":14.4297213001,"12072":13.2735890507,"12073":13.8626391892,"13003":12.1416516735,"13004":11.4190128509,"13071":13.0014290942,"13072":12.2245416746,"13073":12.8070589283,"13074":11.2462766434,"13075":13.7803695712,"13076":11.5368692393,"14511":12.9162676793,"14521":12.9467634985,"14522":13.1367572596,"14523":12.2336570503,"14524":12.5264006383,"14612":13.7932993105,"14625":14.2311511879,"14626":14.7535069856,"14627":13.4838976987,"14628":13.8790847723,"14713":12.3792916759,"14729":12.5939570205,"14730":12.7919276144,"15001":12.2236368187,"15002":11.9745883562,"15003":11.6417661617,"15081":11.2329202225,"15082":12.1387221577,"15083":11.3514962746,"15084":11.8956726171,"15085":10.9543694733,"15086":12.0317481038,"15087":11.3514163044,"15088":11.8790112163,"15089":11.6379244181,"15090":11.8350287492,"15091":12.6995378625,"16051":11.0189167263,"16052":12.08245984,"16053":11.5901874925,"16054":10.6874671384,"16055":11.3179645589,"16061":10.2560470274,"16062":10.7322890736,"16063":10.2150460337,"16064":10.5478743638,"16065":10.9780269605,"16066":10.4048306509,"16067":10.6951671126,"16068":11.1542475403,"16069":10.7381499716,"16070":10.9689664962,"16071":11.3650226134,"16072":11.1371984168,"16073":11.3029843304,"16074":11.7365465187,"16075":11.7090318201,"16076":12.0686099591,"16077":12.4023769496},{"01001":54.7883332098,"01002":54.3195019409,"01003":53.8690910876,"01004":54.0787251589,"01051":54.1364413387,"01053":53.5898215396,"01054":54.597562528,"01055":54.1450763123,"01056":53.719567184,"01057":54.2462081427,"01058":54.2923217793,"01059":54.6275781144,"01060":53.9219054532,"01061":53.9296733146,"01062":53.7225049839,"02000":53.5445592919,"03101":52.2750621552,"03102":52.1198645306,"03103":52.4089218389,"03151":52.5802001767,"03153":51.8731698432,"03154":52.2584628998,"03155":51.7411793244,"03157":52.3051129141,"03158":52.13720032,"03159":51.565929685,"03241":52.4224473294,"03251":52.7270941047,"03252":52.0954508164,"03254":52.090515494,"03255":51.8861430938,"03256":52.6137130429,"03257":52.2930490617,"03351":52.7125636727,"03352":53.612996569,"03353":53.315766016,"03354":53.0197048246,"03355":53.2298966365,"03356":53.2483538621,"03357":53.2545882554,"03358":52.9305401781,"03359":53.5786764206,"03360":52.9782094635,"03361":52.9775861847,"03401":53.0541659743,"03402":53.3609943285,"03403":53.1451211349,"03404":52.2737098094,"03405":53.5730712673,"03451":53.2152494077,"03452":53.4888636656,"03453":52.9087049979,"03454":52.7384557212,"03455":53.5063328223,"03456":52.4782438711,"03457":53.2266474514,"03458":52.9876410547,"03459":52.3834299723,"03460":52.6618968113,"03461":53.3493549265,"03462":53.5562504504,"04011":53.1023733756,"04012":53.5411205418,"05111":51.2297268444,"05112":51.441093023,"05113":51.43571111,"05114":51.346153838,"05116":51.1693532487,"05117":51.4165840911,"05119":51.5104809306,"05120":51.1800398463,"05122":51.1607694665,"05124":51.2464694681,"05154":51.6518286643,"05158":51.256146659,"05162":51.1421740096,"05166":51.2857926329,"05170":51.626583815,"05314":50.6999802109,"05315":50.9494358674,"05316":51.0580260621,"05334":50.7327670554,"05358":50.8229314139,"05362":50.9001296458,"05366":50.5327960503,"05370":51.0512469457,"05374":51.0104948909,"05378":51.0289211164,"05382":50.7614941087,"05512":51.5716281427,"05513":51.554431316,"05515":51.9551148313,"05554":51.9654111445,"05558":51.86343094,"05562":51.6739368049,"05566":52.2086750888,"05570":51.8710857684,"05711":52.0106682884,"05754":51.9296918182,"05758":52.1688705786,"05762":51.6856119864,"05766":51.9809217149,"05770":52.352338248,"05774":51.6620215495,"05911":51.4728603529,"05913":51.5179110317,"05914":51.3537416688,"05915":51.6677638926,"05916":51.5363215523,"05954":51.3455507618,"05958":51.3061412076,"05962":51.262359709,"05966":51.0841266593,"05970":50.9363922761,"05974":51.5653482322,"05978":51.5806549468,"06411":49.8747633437,"06412":50.1168063147,"06413":50.0949633762,"06414":50.0774257896,"06431":49.632923653,"06432":49.8543380822,"06433":49.9099679396,"06434":50.2766955568,"06435":50.2424243181,"06436":50.101616799,"06437":49.6676570367,"06438":50.0169148705,"06439":50.1430234654,"06440":50.35497872,"06531":50.567240567,"06532":50.6502191402,"06533":50.4288175044,"06534":50.8363949268,"06535":50.6399084537,"06611":51.3146053726,"06631":50.5645454865,"06632":50.9078964566,"06633":51.4044368866,"06634":51.0286384501,"06635":51.1905575689,"06636":51.1911855775,"07111":50.3457274206,"07131":50.4732269472,"07132":50.7489105397,"07133":49.8292345276,"07134":49.7132067906,"07135":50.1356756587,"07137":50.3317622929,"07138":50.5590223681,"07140":50.0469796359,"07141":50.2647567618,"07143":50.5472725355,"07211":49.7678215926,"07231":49.9253326416,"07232":50.0585753403,"07233":50.2375838618,"07235":49.6991512715,"07311":49.5388638244,"07312":49.4275573162,"07313":49.1876666667,"07314":49.4792581312,"07315":49.9820753052,"07316":49.3461898484,"07317":49.197234845,"07318":49.3270338409,"07319":49.6481994676,"07320":49.2554704169,"07331":49.7540497033,"07332":49.4534913377,"07333":49.628626269,"07334":49.1195807231,"07335":49.4432902886,"07336":49.5539112331,"07337":49.1925417015,"07338":49.414535347,"07339":49.9222595817,"07340":49.2080184892,"08111":48.7735135352,"08115":48.6843069342,"08116":48.6430482368,"08117":48.6607075582,"08118":48.9390704634,"08119":48.8977072922,"08121":49.1535516953,"08125":49.1736157576,"08126":49.2737060837,"08127":49.1425213538,"08128":49.5603033271,"08135":48.6622332755,"08136":48.8737352858,"08211":48.74929241,"08212":49.0098543248,"08215":49.0839850903,"08216":48.7595248294,"08221":49.4052523426,"08222":49.4998194145,"08225":49.4684986573,"08226":49.3715301958,"08231":48.8810968671,"08235":48.680363096,"08236":48.9109416604,"08237":48.4754147347,"08311":47.9999150651,"08315":47.9258593287,"08316":48.1471664812,"08317":48.4193180944,"08325":48.2563693803,"08326":48.0198720049,"08327":48.0122306958,"08335":47.7999091074,"08336":47.7025183803,"08337":47.695858008,"08415":48.4063081201,"08416":48.4851537321,"08417":48.2658873614,"08421":48.3983118138,"08425":48.3958892511,"08426":48.1065069744,"08435":47.73081919,"08436":47.8268511553,"08437":48.0411834866,"09161":48.7520864194,"09162":48.157927953,"09163":47.8427009211,"09171":48.2124975372,"09172":47.6950042158,"09173":47.7276602697,"09174":48.3319545338,"09175":48.0775958329,"09176":48.8997394401,"09177":48.3017746782,"09178":48.449066451,"09179":48.1883906445,"09180":47.5560787341,"09181":48.0272340431,"09182":47.746046719,"09183":48.2359941066,"09184":48.0693821169,"09185":48.6640813919,"09186":48.5972382826,"09187":47.8729095124,"09188":48.0098659041,"09189":47.8961201385,"09190":47.7933538999,"09261":48.543,"09262":48.5853501006,"09263":48.8813176115,"09271":48.7785157079,"09272":48.8255338161,"09273":48.8205201824,"09274":48.5578301434,"09275":48.5593349966,"09276":49.0235000014,"09277":48.4234609886,"09278":48.8979555359,"09279":48.6402083326,"09361":49.4499333333,"09362":49.0148710238,"09363":49.6742160706,"09371":49.4843931954,"09372":49.2350979351,"09373":49.2160314612,"09374":49.6859430838,"09375":49.0196050647,"09376":49.3680657902,"09377":49.899134716,"09461":49.889,"09462":49.9368471035,"09463":50.2583642792,"09464":50.3116666667,"09471":49.8960578207,"09472":49.8845638919,"09473":50.2688648514,"09474":49.7218360642,"09475":50.2769092937,"09476":50.3256369975,"09477":50.105505992,"09478":50.116570931,"09479":50.0928481359,"09561":49.2933099529,"09562":49.5812311881,"09563":49.4910980341,"09564":49.4388126211,"09565":49.337,"09571":49.2507306327,"09572":49.6368069083,"09573":49.4498861214,"09574":49.4899982326,"09575":49.5735290233,"09576":49.2051677687,"09577":49.0343608826,"09661":49.9637675112,"09662":50.0476666667,"09663":49.7829976226,"09671":50.0086965524,"09672":50.2206359682,"09673":50.3759407187,"09674":50.0631272904,"09675":49.7551462604,"09676":49.7590465323,"09677":49.9916583995,"09678":50.0141396585,"09679":49.739178154,"09761":48.3483257476,"09762":47.8796666667,"09763":47.7429716331,"09764":47.990176271,"09771":48.4281344956,"09772":48.3559006702,"09773":48.5945622537,"09774":48.3566628569,"09775":48.2990263728,"09776":47.6052338247,"09777":47.7686487735,"09778":48.0408889099,"09779":48.808094219,"09780":47.5807266909,"10041":49.2558293185,"10042":49.4944070815,"10043":49.3740335188,"10044":49.3565035732,"10045":49.2480906911,"10046":49.5160280043,"11000":52.4990949978,"12051":52.3968652266,"12052":51.7761737117,"12053":52.3158789938,"12054":52.4220291007,"12060":52.8210154228,"12061":52.0429179395,"12062":51.6160855899,"12063":52.6187221515,"12064":52.6086409559,"12065":52.9108281588,"12066":51.6197670362,"12067":52.245302714,"12068":52.9898788552,"12069":52.2432862169,"12070":53.1133666775,"12071":51.7555625972,"12072":52.0707683664,"12073":53.2055588547,"13003":54.1488613691,"13004":53.6158832476,"13071":53.5420099636,"13072":53.9120446966,"13073":54.2118651757,"13074":53.8208136976,"13075":53.7861718857,"13076":53.451917341,"14511":50.8274408928,"14521":50.611103845,"14522":50.9569249775,"14523":50.4579546794,"14524":50.7505814552,"14612":51.0695962421,"14625":51.2701799305,"14626":51.2231911489,"14627":51.2410843386,"14628":50.9191101584,"14713":51.3458797475,"14729":51.2220218247,"14730":51.4728427251,"15001":51.8557598377,"15002":51.4811924965,"15003":52.11131316,"15081":52.6792602075,"15082":51.7987672475,"15083":52.2200529084,"15084":51.1442471439,"15085":51.8214230297,"15086":52.2669375184,"15087":51.5330292326,"15088":51.4324827853,"15089":51.851277957,"15090":52.7013601698,"15091":51.8212575086,"16051":50.9819431382,"16052":50.8912572335,"16053":50.9165363342,"16054":50.6140234704,"16055":50.9767429584,"16061":51.3834208596,"16062":51.4996713865,"16063":50.8916557381,"16064":51.1853576065,"16065":51.3234771734,"16066":50.6336928377,"16067":50.9108984979,"16068":51.1581093648,"16069":50.4372988278,"16070":50.7378645291,"16071":50.9719718617,"16072":50.4063033701,"16073":50.631813032,"16074":50.9037978123,"16075":50.5800002585,"16076":50.7433983369,"16077":50.9499059988}] \ No newline at end of file diff --git a/data/mobility/county_centers_dim401.json b/data/mobility/county_centers_dim401.json new file mode 100644 index 0000000000..e66de948cd --- /dev/null +++ b/data/mobility/county_centers_dim401.json @@ -0,0 +1 @@ +[{"01001":9.4386269631,"01002":10.1321722459,"01003":10.7272072028,"01004":9.9844502661,"01051":9.1083333223,"01053":10.6020308894,"01054":8.930972198,"01055":10.7689707471,"01056":9.7461003294,"01057":10.363750943,"01058":9.7816307147,"01059":9.4987382599,"01060":10.140992159,"01061":9.5194404604,"01062":10.3319171407,"02000":10.0273190825,"03101":10.5241911827,"03102":10.3705941511,"03103":10.7845414605,"03151":10.6043679643,"03153":10.4002294974,"03154":10.8887942341,"03155":9.8488666127,"03157":10.2553427564,"03158":10.6469459551,"03159":10.0877172003,"03241":9.7198004092,"03251":8.7019170317,"03252":9.3893968429,"03254":9.9433766938,"03255":9.5515561336,"03256":9.1146071534,"03257":9.2063415115,"03351":10.1035336483,"03352":8.8123155275,"03353":9.9631369318,"03354":11.1225738755,"03355":10.5731558608,"03356":8.8083076406,"03357":9.3065338794,"03358":9.7695152985,"03359":9.4174230257,"03360":10.5478206979,"03361":9.1754967317,"03401":8.6461036241,"03402":7.1806537274,"03403":8.2241704104,"03404":8.0466087267,"03405":8.087579826,"03451":8.0135341318,"03452":7.3774378822,"03453":7.9047645551,"03454":7.4027694658,"03455":7.9837310363,"03456":7.0195095075,"03457":7.5010842495,"03458":8.3896976867,"03459":8.0455250515,"03460":8.2230817308,"03461":8.3903715616,"03462":7.7107910084,"04011":8.7864554975,"04012":8.5866978131,"05111":6.810513912,"05112":6.7347077301,"05113":7.016562111,"05114":6.5794246729,"05116":6.4116718071,"05117":6.8784740339,"05119":6.8468108551,"05120":7.2242306839,"05122":7.0661198076,"05124":7.1690142092,"05154":6.2586800821,"05158":6.9687983975,"05162":6.6490441675,"05166":6.3262103371,"05170":6.6185267599,"05314":7.110000686,"05315":6.9731746901,"05316":7.0154160802,"05334":6.21697065,"05358":6.4453445351,"05362":6.7163952785,"05366":6.6439641769,"05370":6.1641253557,"05374":7.5163773819,"05378":7.1947337475,"05382":7.2345144127,"05512":6.9195840336,"05513":7.0714698456,"05515":7.6234243359,"05554":6.899520297,"05558":7.3662183977,"05562":7.1591089252,"05566":7.5794703131,"05570":7.9581518298,"05711":8.5408084455,"05754":8.3510614179,"05758":8.6442715221,"05762":9.1780990174,"05766":8.9508706395,"05770":8.7390971568,"05774":8.7196453576,"05911":7.2249833561,"05913":7.4750671097,"05914":7.4980721024,"05915":7.823444673,"05916":7.20837805,"05954":7.32357119,"05958":8.3849917947,"05962":7.7129526054,"05966":7.9763276927,"05970":8.1950230931,"05974":8.217465915,"05978":7.6364887845,"06411":8.6646559789,"06412":8.6443578539,"06413":8.7807571664,"06414":8.2604703913,"06431":8.643320962,"06432":8.795518469,"06433":8.4701424131,"06434":8.5045274307,"06435":9.2864439299,"06436":8.4345669768,"06437":8.9796894224,"06438":8.8116463268,"06439":8.0812218001,"06440":8.9072824921,"06531":8.8076376311,"06532":8.3653683778,"06533":8.1992750616,"06534":8.737746984,"06535":9.2713224039,"06611":9.4595148018,"06631":9.7593913982,"06632":9.75297609,"06633":9.4068636529,"06634":9.3738233826,"06635":8.8889895441,"06636":9.9288584709,"07111":7.5789914355,"07131":7.0453118437,"07132":7.7441965131,"07133":7.6865212276,"07134":7.2774926093,"07135":7.1744410124,"07137":7.3321048932,"07138":7.4690278518,"07140":7.5002844502,"07141":7.8428091205,"07143":7.8655470936,"07211":6.6548171237,"07231":6.9672156598,"07232":6.410207369,"07233":6.7490992423,"07235":6.6913160737,"07311":8.3569419136,"07312":7.7611130479,"07313":8.1101876504,"07314":8.3968806236,"07315":8.2411783625,"07316":8.1523442029,"07317":7.5944225177,"07318":8.4345537374,"07319":8.3245623479,"07320":7.3656989512,"07331":8.1577026236,"07332":8.1102944329,"07333":7.9148919517,"07334":8.2463391195,"07335":7.6849519063,"07336":7.471268744,"07337":8.0532149403,"07338":8.3601978997,"07339":8.0795731041,"07340":7.6551792354,"08111":9.1721683811,"08115":8.9427985997,"08116":9.3692287225,"08117":9.7176538503,"08118":9.122947031,"08119":9.5010858077,"08121":9.1826133036,"08125":9.1900500731,"08126":9.6143941218,"08127":9.908954244,"08128":9.7251858777,"08135":10.1822459238,"08136":10.0901502972,"08211":8.2320976172,"08212":8.41308865,"08215":8.5625208316,"08216":8.2392873687,"08221":8.6940550472,"08222":8.5004625114,"08225":9.2801379663,"08226":8.7663919247,"08231":8.7126100517,"08235":8.6359698712,"08236":8.7372473744,"08237":8.465375284,"08311":7.8182795454,"08315":7.9246598554,"08316":7.8976762672,"08317":8.0162968496,"08325":8.5323841496,"08326":8.4110715834,"08327":8.7943167235,"08335":8.9122120439,"08336":7.7740808921,"08337":8.2190683821,"08415":9.3657214578,"08416":8.9877577342,"08417":8.9371927792,"08421":9.9500051497,"08425":9.827678576,"08426":9.774031861,"08435":9.4005020265,"08436":9.7800362823,"08437":9.2407808795,"09161":11.3949650037,"09162":11.5470452041,"09163":12.1091054426,"09171":12.7057376838,"09172":12.9015839086,"09173":11.4830640638,"09174":11.3571538482,"09175":11.9134916052,"09176":11.3706138287,"09177":12.0004411943,"09178":11.7406626142,"09179":11.2014788772,"09180":11.1297229832,"09181":10.9492516499,"09182":11.8089422452,"09183":12.3817706903,"09184":11.6311482682,"09185":11.1972991831,"09186":11.5241753719,"09187":12.1610693459,"09188":11.2816435919,"09189":12.579376567,"09190":11.0480248945,"09261":12.1593326531,"09262":13.4147538356,"09263":12.5736939208,"09271":13.000836175,"09272":13.5131227747,"09273":11.8577401111,"09274":12.1937153214,"09275":13.3666615078,"09276":13.0998414376,"09277":12.8673834646,"09278":12.5818896555,"09279":12.6103053191,"09361":11.8451094994,"09362":12.1135712965,"09363":12.1549520165,"09371":11.8027672964,"09372":12.6942009191,"09373":11.5666611715,"09374":12.1007915302,"09375":12.1202851318,"09376":12.2525111754,"09377":12.2002005327,"09461":10.8986386307,"09462":11.5852829282,"09463":10.9645360904,"09464":11.8974280883,"09471":10.8840305199,"09472":11.5566261723,"09473":10.9440752063,"09474":11.173063756,"09475":11.82383465,"09476":11.3721137785,"09477":11.4821135076,"09478":11.1170031537,"09479":12.0419936626,"09561":10.5638035644,"09562":10.9781613351,"09563":10.9653702198,"09564":11.0789119353,"09565":11.0234921925,"09571":10.4727927217,"09572":10.9153496072,"09573":10.8499795192,"09574":11.3690899946,"09575":10.4654229109,"09576":11.1233312617,"09577":10.8937261048,"09661":9.1451950393,"09662":10.2206469649,"09663":9.9407979531,"09671":9.2379148961,"09672":9.9647705399,"09673":10.2547852759,"09674":10.6069486398,"09675":10.2560636196,"09676":9.2347721825,"09677":9.6629087408,"09678":10.2582696694,"09679":9.9284493734,"09761":10.885588788,"09762":10.6161812968,"09763":10.3083006896,"09764":10.1634940853,"09771":11.052867631,"09772":10.7321934593,"09773":10.5277107398,"09774":10.3811242207,"09775":10.141553317,"09776":9.8829219236,"09777":10.6391815552,"09778":10.3914173587,"09779":10.7123886723,"09780":10.2607742579,"10041":6.9570965019,"10042":6.6805265615,"10043":7.1168796101,"10044":6.7759450781,"10045":7.2421475092,"10046":7.1005379413,"11000":13.4022750478,"12051":12.5184760875,"12052":14.3667364154,"12053":14.4903650993,"12054":13.0288034252,"12060":13.7037746894,"12061":13.8201611285,"12062":13.4595991446,"12063":12.6283127066,"12064":14.1466168538,"12065":13.2051559729,"12066":13.9438712704,"12067":14.218970505,"12068":12.6360547277,"12069":12.6891589462,"12070":11.9618325382,"12071":14.426993659,"12072":13.2762047185,"12073":13.8609781883,"13003":12.1436066435,"13004":11.4162215264,"13071":13.0023876803,"13072":12.2210526242,"13073":12.8140430572,"13074":11.2487309936,"13075":13.7583886198,"13076":11.5340935938,"14511":12.9120255498,"14521":12.9451642969,"14522":13.137519888,"14523":12.2351308417,"14524":12.5258472911,"14612":13.7838975796,"14625":14.2310123703,"14626":14.7509080907,"14627":13.4833645335,"14628":13.8734385957,"14713":12.3745898837,"14729":12.5994861702,"14730":12.779653628,"15001":12.2312537426,"15002":11.9687117845,"15003":11.6413105085,"15081":11.2271165639,"15082":12.1433356332,"15083":11.3481954164,"15084":11.8833566527,"15085":10.9585657711,"15086":12.0269604873,"15087":11.3564998047,"15088":11.8746258651,"15089":11.6427021298,"15090":11.839719225,"15091":12.7016917535,"16051":11.0201466024,"16052":12.0824375531,"16053":11.5870548615,"16054":10.6881949011,"16055":11.3179293376,"16056":10.300132664,"16061":10.2534585469,"16062":10.7310423573,"16063":10.2108766845,"16064":10.5517071321,"16065":10.9849341222,"16066":10.4051735324,"16067":10.6938898377,"16068":11.1545982911,"16069":10.7341410941,"16070":10.9665105452,"16071":11.3680720652,"16072":11.133149453,"16073":11.3089607811,"16074":11.7313900509,"16075":11.7105811921,"16076":12.0741477133,"16077":12.3991123252},{"01001":54.7848532568,"01002":54.3248988171,"01003":53.8723043901,"01004":54.0811876605,"01051":54.134131406,"01053":53.5889178207,"01054":54.6120858975,"01055":54.1473311804,"01056":53.7169167032,"01057":54.2434452893,"01058":54.2897204475,"01059":54.6233699255,"01060":53.9200258981,"01061":53.9289963474,"01062":53.720849951,"02000":53.5446957664,"03101":52.2752436303,"03102":52.1244179594,"03103":52.4105490782,"03151":52.5802045362,"03153":51.874708031,"03154":52.260603315,"03155":51.7434475131,"03157":52.3040085272,"03158":52.1353303988,"03159":51.5638782886,"03241":52.4218776992,"03251":52.7284108353,"03252":52.0952722554,"03254":52.0901927329,"03255":51.8808486559,"03256":52.6092684695,"03257":52.2929788714,"03351":52.7133096609,"03352":53.6165602676,"03353":53.3158092004,"03354":53.0200034359,"03355":53.2326657898,"03356":53.2510335465,"03357":53.2506467436,"03358":52.9284051239,"03359":53.5784774574,"03360":52.9835850903,"03361":52.9733371043,"03401":53.0495432217,"03402":53.3610205767,"03403":53.1446708543,"03404":52.2775101595,"03405":53.5668578077,"03451":53.2183661265,"03452":53.4890475243,"03453":52.9110320753,"03454":52.7382383489,"03455":53.5050569345,"03456":52.4762288673,"03457":53.2303625502,"03458":52.9882601118,"03459":52.3815468097,"03460":52.6604537336,"03461":53.3561051132,"03462":53.5646050343,"04011":53.1086608332,"04012":53.5378272004,"05111":51.2354204848,"05112":51.4390363984,"05113":51.4343438139,"05114":51.3455053375,"05116":51.1672138837,"05117":51.4135198907,"05119":51.5127569438,"05120":51.1827738259,"05122":51.1625618423,"05124":51.2505748673,"05154":51.6522696069,"05158":51.2568112798,"05162":51.14383235,"05166":51.2828513915,"05170":51.6269619719,"05314":50.7059464097,"05315":50.945665693,"05316":51.0532313906,"05334":50.7327767571,"05358":50.8180634367,"05362":50.9050280332,"05366":50.5363854424,"05370":51.0494272977,"05374":51.0128693951,"05378":51.0229035963,"05382":50.7607231518,"05512":51.5721483446,"05513":51.5539317256,"05515":51.954539593,"05554":51.9613570758,"05558":51.8667127224,"05562":51.6724982371,"05566":52.2115975024,"05570":51.8703004153,"05711":52.0109278689,"05754":51.9317811243,"05758":52.1675579495,"05762":51.6849530909,"05766":51.981417216,"05770":52.3523703148,"05774":51.6640987143,"05911":51.4699389456,"05913":51.5162283624,"05914":51.3480283314,"05915":51.6653379978,"05916":51.5373171995,"05954":51.3470243399,"05958":51.3068766093,"05962":51.262472256,"05966":51.0860004273,"05970":50.9375636348,"05974":51.5645158375,"05978":51.5784392051,"06411":49.8812934705,"06412":50.117790337,"06413":50.0908270351,"06414":50.0790219647,"06431":49.6314298509,"06432":49.8553750661,"06433":49.9047474394,"06434":50.2815035133,"06435":50.2437734407,"06436":50.102423887,"06437":49.6715227536,"06438":50.0215696493,"06439":50.1420266775,"06440":50.3547177683,"06531":50.570271568,"06532":50.6479679851,"06533":50.427389927,"06534":50.8367796414,"06535":50.6379609253,"06611":51.3110888731,"06631":50.5640386361,"06632":50.906206471,"06633":51.4013842456,"06634":51.0236903859,"06635":51.1906388286,"06636":51.1905895322,"07111":50.3486852189,"07131":50.4677455737,"07132":50.7506890958,"07133":49.8248967662,"07134":49.712635762,"07135":50.1328755963,"07137":50.3315779719,"07138":50.5576246298,"07140":50.0443139837,"07141":50.2632080695,"07143":50.5523359531,"07211":49.7630552787,"07231":49.9246967074,"07232":50.0623630379,"07233":50.238210595,"07235":49.7027705044,"07311":49.5328571777,"07312":49.4328186639,"07313":49.1963405305,"07314":49.4822636884,"07315":49.9738554789,"07316":49.3416015636,"07317":49.1971374552,"07318":49.3295017283,"07319":49.6493099799,"07320":49.2482678664,"07331":49.7594246307,"07332":49.4531257838,"07333":49.6320030504,"07334":49.1158739561,"07335":49.4461341624,"07336":49.5497212149,"07337":49.1907461042,"07338":49.4167222731,"07339":49.9221002857,"07340":49.2076020009,"08111":48.7747656107,"08115":48.6781745579,"08116":48.6480787685,"08117":48.6631785255,"08118":48.9398036513,"08119":48.8990774687,"08121":49.1528943399,"08125":49.1750622564,"08126":49.2717269344,"08127":49.1445062766,"08128":49.5606786912,"08135":48.6623091517,"08136":48.8775006141,"08211":48.7481814207,"08212":49.0113079264,"08215":49.0817783754,"08216":48.7596160564,"08221":49.4050437574,"08222":49.4994006639,"08225":49.4666993013,"08226":49.3681696526,"08231":48.8765008291,"08235":48.6790839379,"08236":48.9144512545,"08237":48.4746610676,"08311":47.9925575884,"08315":47.9248384853,"08316":48.1485147948,"08317":48.4207449945,"08325":48.2543461736,"08326":48.0191187824,"08327":48.0112364788,"08335":47.7988518893,"08336":47.703526529,"08337":47.6971259811,"08415":48.4065959558,"08416":48.4817125972,"08417":48.2673465933,"08421":48.3908394161,"08425":48.4016585422,"08426":48.107632886,"08435":47.7333555272,"08436":47.8250429597,"08437":48.0392546628,"09161":48.7551666564,"09162":48.1530675378,"09163":47.8448468727,"09171":48.2097889597,"09172":47.6987733527,"09173":47.7274976684,"09174":48.3346812346,"09175":48.0762984901,"09176":48.8979832549,"09177":48.3004083828,"09178":48.4474104957,"09179":48.187906434,"09180":47.5563420724,"09181":48.0244950034,"09182":47.7416670535,"09183":48.2392656659,"09184":48.0744478266,"09185":48.66453344,"09186":48.5961498729,"09187":47.8771342527,"09188":48.006037406,"09189":47.8946365065,"09190":47.7874455781,"09261":48.5448152774,"09262":48.5820812635,"09263":48.8807345981,"09271":48.7787284109,"09272":48.8269444534,"09273":48.824900472,"09274":48.5571645223,"09275":48.5587698448,"09276":49.0228329451,"09277":48.4247330419,"09278":48.8987710567,"09279":48.6412787915,"09361":49.4509120586,"09362":49.0130750805,"09363":49.6691603734,"09371":49.4853419011,"09372":49.2370742697,"09373":49.2159813186,"09374":49.685897541,"09375":49.0210004054,"09376":49.3684758942,"09377":49.8993864836,"09461":49.8871408877,"09462":49.9377095321,"09463":50.2642257597,"09464":50.3108074942,"09471":49.8930395508,"09472":49.8865771437,"09473":50.2675592766,"09474":49.7209581507,"09475":50.2755163984,"09476":50.3280240695,"09477":50.1026534421,"09478":50.1092574141,"09479":50.09007758,"09561":49.2921391374,"09562":49.5823282075,"09563":49.4913090291,"09564":49.4363164911,"09565":49.3354036848,"09571":49.2502890255,"09572":49.6398388975,"09573":49.4467503369,"09574":49.4915673217,"09575":49.5694711078,"09576":49.2029906074,"09577":49.0325947235,"09661":49.9641343495,"09662":50.0469238417,"09663":49.7843478954,"09671":50.0081449816,"09672":50.2223942756,"09673":50.3713136103,"09674":50.0626262827,"09675":49.753127208,"09676":49.7577006885,"09677":49.9935083846,"09678":50.0180519447,"09679":49.7415838628,"09761":48.3458038657,"09762":47.8796728141,"09763":47.7381402113,"09764":47.9791495201,"09771":48.4274765309,"09772":48.3541857158,"09773":48.5962769713,"09774":48.3528973116,"09775":48.2981341479,"09776":47.6051833493,"09777":47.7732699224,"09778":48.0402146867,"09779":48.8069767011,"09780":47.5792776271,"10041":49.2513440488,"10042":49.4955858255,"10043":49.3755428074,"10044":49.355423526,"10045":49.248739151,"10046":49.5193364745,"11000":52.501347186,"12051":52.4018210512,"12052":51.7725278879,"12053":52.324654271,"12054":52.4260351019,"12060":52.8230577348,"12061":52.0421197305,"12062":51.6123635655,"12063":52.62073,"12064":52.6067170893,"12065":52.9066037345,"12066":51.6162583627,"12067":52.2440404872,"12068":52.9913981807,"12069":52.2463998899,"12070":53.109332304,"12071":51.7599913826,"12072":52.0732728676,"12073":53.2057907315,"13003":54.1475689107,"13004":53.6216929914,"13071":53.5437595099,"13072":53.911920814,"13073":54.2132706161,"13074":53.8186505379,"13075":53.768784453,"13076":53.4499068144,"14511":50.8261750583,"14521":50.6090087864,"14522":50.955917888,"14523":50.4570515105,"14524":50.7509298132,"14612":51.0663354569,"14625":51.2688838243,"14626":51.2256830124,"14627":51.2394890799,"14628":50.9166618728,"14713":51.3422246672,"14729":51.221514675,"14730":51.472748318,"15001":51.8535008167,"15002":51.4798750225,"15003":52.1165294326,"15081":52.6801170008,"15082":51.7953359633,"15083":52.2208383548,"15084":51.1470496636,"15085":51.821279162,"15086":52.2608892205,"15087":51.5355673379,"15088":51.4302553157,"15089":51.8516287211,"15090":52.6975918533,"15091":51.8201050072,"16051":50.9832276505,"16052":50.8939392316,"16053":50.9245088061,"16054":50.6117259783,"16055":50.978091732,"16056":50.9897501061,"16061":51.3837216366,"16062":51.5022228597,"16063":50.8857821839,"16064":51.1851605931,"16065":51.3246921946,"16066":50.630600275,"16067":50.9106356795,"16068":51.1577508632,"16069":50.4339267955,"16070":50.7378786701,"16071":50.9722081556,"16072":50.4145676486,"16073":50.6378626839,"16074":50.9041441991,"16075":50.5807830472,"16076":50.7486748106,"16077":50.9563509581}] \ No newline at end of file diff --git a/pycode/memilio-epidata/memilio/epidata/getCommuterMobility.py b/pycode/memilio-epidata/memilio/epidata/getCommuterMobility.py index b282e5f14a..d4a0acc3a2 100644 --- a/pycode/memilio-epidata/memilio/epidata/getCommuterMobility.py +++ b/pycode/memilio-epidata/memilio/epidata/getCommuterMobility.py @@ -1,7 +1,7 @@ ############################################################################# # Copyright (C) 2020-2021 German Aerospace Center (DLR-SC) # -# Authors: Martin J. Kuehn, Lena Ploetzke +# Authors: Martin J. Kuehn, Lena Ploetzke, Henrik Zunker # # Contact: Martin J. Kuehn # @@ -23,15 +23,18 @@ @brief gets data related to county mobility from "Bundesagentur fuer Arbeit" """ import collections +import geojson import os import wget import numpy as np import pandas as pd from zipfile import ZipFile +from shapely import geometry from memilio.epidata import getPopulationData as gPd from memilio.epidata import getDataIntoPandasDataFrame as gd from memilio.epidata import geoModificationGermany as geoger from memilio.epidata import defaultDict as dd +from os.path import dirname as up def verify_sorted(countykey_list): @@ -127,31 +130,182 @@ def assign_geographical_entities(countykey_list, govkey_list): return countykey2govkey, countykey2localnumlist, gov_county_table, state_gov_table +def get_distance(coordinates_from, coordinates_to): + """! Calculates the distance between two coordinates + + @param coordinates_from Vector containing two start coordinates + @param coordinates_to Vector containing two end coordinates + """ + dist_x = np.abs(coordinates_from[0] - coordinates_to[0]) + dist_y = np.abs(coordinates_from[1] - coordinates_to[1]) + return np.sqrt(dist_x**2 + dist_y**2) + + +def get_counties_center_coordinates( + path_geojson, + file_format=dd.defaultDict['file_format'], + out_folder=dd.defaultDict['out_folder']): + """! Computes centers of counties based on a geojson file of Germany. + + In the case of multipolygons, we choose the largest polygon and take its center. + The results are saved in a json file. + + Keyword arguments: + @param path_geojson geojson file which should contain the geodata for all counties in Germany + @param out_folder Path to folder where data is saved + """ + + with open(path_geojson) as f: + file = geojson.load(f) + + countykey_list = geoger.get_county_ids(merge_eisenach=False, zfill=True) + len_features = len(file.features) + + # If number of features not equal to number of county keys, then we set + # merge_eisenach as True. If it stays unequal -> output error message + if len_features != len(countykey_list): + countykey_list = geoger.get_county_ids( + merge_eisenach=True, zfill=True) + if len_features != len(countykey_list): + raise ValueError( + 'Dimension of countykeylist and given geojson is different') + + # Create list of center points coordinates. + # List is sorted in ascending order of regional county keys. + centers_counties = np.zeros((len_features, 2)) + + # iterate over all regional counties and calculate their center. + for i in range(0, len_features): + features = file.features[i] + + # check if countykeys are the same in geojson and countykey_list + if countykey_list[i] != features.properties["RS"]: + raise ValueError( + 'Regional county keys are not the same or sorted differently') + + # Special cases are multipolygons. Here we calculate the largest polygon and take his center. + if features['geometry']['type'] == 'MultiPolygon': + area_polygon = 0. + for j in features['geometry']['coordinates']: + features['geometry']['coordinates'] + # cast coordinates to polygons and calculate center points + poly = geometry.Polygon(j[0]) + if area_polygon < poly.area: + area_polygon = poly.area + centers_counties[i][0] = poly.centroid.x + centers_counties[i][1] = poly.centroid.y + else: + # In case of regular Polygons, cast coordinates to polygons and calculate center points + poly = geometry.Polygon(features['geometry']['coordinates'][0]) + centers_counties[i][0] = poly.centroid.x + centers_counties[i][1] = poly.centroid.y + + directory = os.path.join(up(out_folder), 'mobility/') + gd.check_dir(directory) + df_centers_counties = pd.DataFrame( + data=centers_counties.transpose(), columns=countykey_list) + filename = 'county_centers_dim' + str(centers_counties.shape[0]) + gd.write_dataframe(df_centers_counties, directory, filename, file_format) + + return None + + +def get_distances_from_centers(center_coordinates): + """! Computes the distances between all counties based on the center points. + + By using center points, distances between counties can be significantly larger than they actually are. + + Keyword arguments: + @param center_coordinates Json file which contain the center coordinates for all counties in germany + """ + + num_counties = center_coordinates.shape[0] + + if num_counties == 400: + countykey_list = geoger.get_county_ids(merge_eisenach=True, zfill=True) + else: + countykey_list = geoger.get_county_ids(merge_eisenach=False, zfill=True) + + # calculate distances between counties + distances = np.zeros((num_counties, num_counties)) + for lk1 in range(0, num_counties): + id_lk1 = countykey_list[lk1] + lk1_coor = [center_coordinates[0][lk1], center_coordinates[1][lk1]] + for lk2 in range(0, num_counties): + id_lk2 = countykey_list[lk2] + + # distance to itself + if id_lk1 == id_lk2: + distances[lk1][lk2] = 0. + else: + lk2_coor = [center_coordinates[0][lk2], center_coordinates[1][lk2]] + distances[lk1][lk2] = get_distance(lk1_coor, lk2_coor) + + return distances + + +def scale_commuter_mobility(commuter_mobility, center_coordinates): + """! Computes scaled commuter mobility patterns based on the Federal + Agency of Work data. The scaling is presented in https://www.sciencedirect.com/science/article/abs/pii/S0025556421000845 + + The Scaling is still a very heuristic approach and based on the distances between the counties. + + Keyword arguments: + @param commuter_mobility DataFrame of commuter mobility patterns based on the Federal Agency of Work data without any scaling + @param center_coordinates Json file which contain the center coordinates for all counties in germany + + @return commuter_mobility Array of scaled commuter mobility. + commuter_mobility[i][j] = scaled number of commuters from county with county-id i to county with county-id j + """ + + dim_data = commuter_mobility.shape[0] + distances_counties = get_distances_from_centers(center_coordinates) + + # Distances and commuter_mobility should have the same size + if dim_data != distances_counties.shape[0]: + raise ValueError( + 'Dimensions of distances and commuter mobility are different') + + for i in range(0, dim_data): + for j in range(0, dim_data): + + # Commuting between 100-200km happens two/three times a week -> Scale with 1/2 + if distances_counties[i][j] > 1 and distances_counties[i][j] < 2: + commuter_mobility[i][j] *= 0.5 + + # Commuting +200km happens only once a week -> Scale with 1/5 + if distances_counties[i][j] > 2: + commuter_mobility[i][j] *= 0.2 + + return commuter_mobility + + def get_commuter_data(setup_dict='', + center_coordinates=None, read_data=dd.defaultDict['read_data'], file_format=dd.defaultDict['file_format'], out_folder=dd.defaultDict['out_folder'], make_plot=dd.defaultDict['make_plot'], no_raw=dd.defaultDict['no_raw']): - """! Computes DataFrame of commuter migration patterns based on the Federal + """! Computes DataFrame of commuter mobility patterns based on the Federal Agency of Work data. Keyword arguments: @param setup_dict dictionary with necessary values: - 'path': String with datapath where migration files can be found + 'path': String with datapath where mobility files can be found 'abs_tol': tolerated undetected people 'rel_tol': relative Tolerance to undetected people - @return df_commuter_migration DataFrame of commuter migration. - df_commuter_migration[i][j]= number of commuters from county with county-id i to county with county-id j - In commuter migration files is a cumulative value per county for number of commuters from whole Germany given. + @return df_commuter_mobility_scaled DataFrame of commuter mobility. + df_commuter_mobility_scaled[i][j]= number of commuters from county with county-id i to county with county-id j + In commuter mobility files is a cumulative value per county for number of commuters from whole Germany given. The printed errors are refering to the absolute and relative errors from included numbers per county in DataFrame and this cumulative values. """ if setup_dict == '': ref_year = 2020 - abs_tol = 100 # maximum absolute error allowed per county migration - rel_tol = 0.01 # maximum relative error allowed per county migration + abs_tol = 100 # maximum absolute error allowed per county mobility + rel_tol = 0.01 # maximum relative error allowed per county mobility path = 'https://statistik.arbeitsagentur.de/Statistikdaten/Detail/' + \ str(ref_year) + '12/iiia6/beschaeftigung-sozbe-krpend/' @@ -167,7 +321,7 @@ def get_commuter_data(setup_dict='', # get population data for all countys (TODO: better to provide a corresponding method for the following lines in getPopulationData itself) # This is not very nice either to have the same file with either Eisenach merged or not... - + population = gPd.get_population_data( out_folder=out_folder, merge_eisenach=False, read_data=read_data) @@ -181,7 +335,7 @@ def get_commuter_data(setup_dict='', (countykey2govkey, countykey2localnumlist, gov_county_table, state_gov_table) = assign_geographical_entities( countykey_list, govkey_list) - mat_commuter_migration = np.zeros( + mat_commuter_mobility = np.zeros( [len(countykey_list), len(countykey_list)]) # maxium errors (of people not detected) @@ -210,7 +364,7 @@ def get_commuter_data(setup_dict='', # Read the file filename = item.split('-20')[0] + '.xlsb' file = filename.replace('-','_') - commuter_migration_file = pd.read_excel(filepath + file, **param_dict) + commuter_mobility_file = pd.read_excel(filepath + file, **param_dict) # pd.read_excel(os.path.join(setup_dict['path'], item), sheet_name=3) # delete zip folder after extracting @@ -218,54 +372,54 @@ def get_commuter_data(setup_dict='', # delete file after reading os.remove(os.path.join(filepath, file)) - counties_done = [] # counties considered as 'migration from' + counties_done = [] # counties considered as 'mobility from' # current_row = -1 # row of matrix that belongs to county migrated from current_col = -1 # column of matrix that belongs to county migrated to - checksum = 0 # sum of county migration from, to be checked against sum in document + checksum = 0 # sum of county mobility from, to be checked against sum in document - for i in range(0, commuter_migration_file.shape[0]): - if (len(str(commuter_migration_file.iloc[i][0])) == 5 - and (commuter_migration_file.iloc[i][0]).isdigit()): + for i in range(0, commuter_mobility_file.shape[0]): + if (len(str(commuter_mobility_file.iloc[i][0])) == 5 + and (commuter_mobility_file.iloc[i][0]).isdigit()): checksum = 0 # make zero'd list of counties explicitly migrated to from county considered - # 'implicit' migration means 'migration to' which is summed in a larger regional entity and not given in + # 'implicit' mobility means 'mobility to' which is summed in a larger regional entity and not given in # detail per county counties_migratedfrom = [] for j in range(0, len(gov_county_table)): counties_migratedfrom.append( np.zeros(len(gov_county_table[j]))) - counties_done.append(commuter_migration_file.iloc[i][0]) - current_col = countykey2numlist[commuter_migration_file.iloc[i][0]] - curr_county_migratedto = commuter_migration_file.iloc[i][1] - current_key = commuter_migration_file.iloc[i][0] - # migration to itself excluded! + counties_done.append(commuter_mobility_file.iloc[i][0]) + current_col = countykey2numlist[commuter_mobility_file.iloc[i][0]] + curr_county_migratedto = commuter_mobility_file.iloc[i][1] + current_key = commuter_mobility_file.iloc[i][0] + # mobility to itself excluded! counties_migratedfrom[countykey2govkey[current_key] ][countykey2localnumlist[current_key]] = 1 - if not isinstance(commuter_migration_file.iloc[i][2], float): + if not isinstance(commuter_mobility_file.iloc[i][2], float): # removal of nan's, regional keys are stored as strings # check if entry is a digit - if (commuter_migration_file.iloc[i][2]).isdigit(): - # explicit migration from county to county - if len(str(commuter_migration_file.iloc[i][2])) == 5: + if (commuter_mobility_file.iloc[i][2]).isdigit(): + # explicit mobility from county to county + if len(str(commuter_mobility_file.iloc[i][2])) == 5: # check if entry refers to a specific county, then set matrix value - current_row = countykey2numlist[commuter_migration_file.iloc[i][2]] + current_row = countykey2numlist[commuter_mobility_file.iloc[i][2]] # TODO - val = commuter_migration_file.iloc[i][4] - mat_commuter_migration[current_row, current_col] = val + val = commuter_mobility_file.iloc[i][4] + mat_commuter_mobility[current_row, current_col] = val checksum += val - counties_migratedfrom[countykey2govkey[commuter_migration_file.iloc[i][2]]][ - countykey2localnumlist[commuter_migration_file.iloc[i][2]]] = 1 + counties_migratedfrom[countykey2govkey[commuter_mobility_file.iloc[i][2]]][ + countykey2localnumlist[commuter_mobility_file.iloc[i][2]]] = 1 # take summed values of other REMAINING counties of government region # here, some counties of the region are stated explicitly and the rest is summed - elif (str(commuter_migration_file.iloc[i][3]) == 'Übrige Kreise (Regierungsbezirk)' and str( - commuter_migration_file.iloc[i][4]).isdigit()): + elif (str(commuter_mobility_file.iloc[i][3]) == 'Übrige Kreise (Regierungsbezirk)' and str( + commuter_mobility_file.iloc[i][4]).isdigit()): # remove trailing zeros (dummy key w/o zeros: dummy_key_wozeros) dummy_key_wozeros = str( - commuter_migration_file.iloc[i][2]) + commuter_mobility_file.iloc[i][2]) if len(dummy_key_wozeros) > 2 and dummy_key_wozeros[2] == '0': dummy_key_wozeros = dummy_key_wozeros[0:2] @@ -279,50 +433,50 @@ def get_commuter_data(setup_dict='', # sum up dummy_pop_sum += countypop_list[globindex] - # distribute emigration relatively to county population where migration comes from + # distribute emigration relatively to county population where mobility comes from for k in range(0, len(gov_county_table[govkey2numlist[dummy_key_wozeros]])): if counties_migratedfrom[govkey2numlist[dummy_key_wozeros]][k] < 1: # get identifier (0-401) for county key globindex = countykey2numlist[gov_county_table[govkey2numlist[dummy_key_wozeros]][k]] counties_migratedfrom[govkey2numlist[dummy_key_wozeros]][k] = 1 - # set value computed relatively to county size and effective migration + # set value computed relatively to county size and effective mobility current_row = globindex - val = commuter_migration_file.iloc[i][4] * \ + val = commuter_mobility_file.iloc[i][4] * \ countypop_list[globindex] / dummy_pop_sum checksum += val - mat_commuter_migration[current_row, + mat_commuter_mobility[current_row, current_col] = val # take summed values of ALL counties of a government region # here, no single county of the region is stated explicitly, all counties are summed together - elif (commuter_migration_file.iloc[i][2] in govkey_list and sum( - counties_migratedfrom[govkey2numlist[commuter_migration_file.iloc[i][2]]]) == 0): + elif (commuter_mobility_file.iloc[i][2] in govkey_list and sum( + counties_migratedfrom[govkey2numlist[commuter_mobility_file.iloc[i][2]]]) == 0): # sum population of all counties not explicitly migrated to # of the current gov region migrated to dummy_pop_sum = 0 - for k in range(0, len(gov_county_table[govkey2numlist[commuter_migration_file.iloc[i][2]]])): - if counties_migratedfrom[govkey2numlist[commuter_migration_file.iloc[i][2]]][k] < 1: + for k in range(0, len(gov_county_table[govkey2numlist[commuter_mobility_file.iloc[i][2]]])): + if counties_migratedfrom[govkey2numlist[commuter_mobility_file.iloc[i][2]]][k] < 1: # get identifier (0-401) for county key globindex = countykey2numlist[gov_county_table[govkey2numlist[ - commuter_migration_file.iloc[i][2]]][k]] + commuter_mobility_file.iloc[i][2]]][k]] # sum up dummy_pop_sum += countypop_list[globindex] - # distribute emigration relatively to county population where migration comes from - for k in range(0, len(gov_county_table[govkey2numlist[commuter_migration_file.iloc[i][2]]])): - if counties_migratedfrom[govkey2numlist[commuter_migration_file.iloc[i][2]]][k] < 1: + # distribute emigration relatively to county population where mobility comes from + for k in range(0, len(gov_county_table[govkey2numlist[commuter_mobility_file.iloc[i][2]]])): + if counties_migratedfrom[govkey2numlist[commuter_mobility_file.iloc[i][2]]][k] < 1: # get identifier (0-401) for county key globindex = countykey2numlist[gov_county_table[govkey2numlist[ - commuter_migration_file.iloc[i][2]]][k]] - counties_migratedfrom[govkey2numlist[commuter_migration_file.iloc[i][2]]][k] = 1 + commuter_mobility_file.iloc[i][2]]][k]] + counties_migratedfrom[govkey2numlist[commuter_mobility_file.iloc[i][2]]][k] = 1 - # set value computed relatively to county size and effective migration + # set value computed relatively to county size and effective mobility current_row = globindex - val = commuter_migration_file.iloc[i][4] * \ + val = commuter_mobility_file.iloc[i][4] * \ countypop_list[globindex] / dummy_pop_sum checksum += val - mat_commuter_migration[current_row, + mat_commuter_mobility[current_row, current_col] = val # take summed values of other REMAINING counties of a whole Bundesland @@ -333,19 +487,19 @@ def get_commuter_data(setup_dict='', # explicitly # although there are existent government regions in this federal state (i.e., the state itself is # not considered a governement region according to gov_list) - elif ((str(commuter_migration_file.iloc[i][3]) == 'Übrige Regierungsbezirke (Bundesland)' and str( - commuter_migration_file.iloc[i][4]).isdigit()) - or ((commuter_migration_file.iloc[i][2]).isdigit() and str( - commuter_migration_file.iloc[i - 1][2]).startswith('nan')) - or (len(str(commuter_migration_file.iloc[i][2])) == 2 and - abs(float(commuter_migration_file.iloc[i][2]) - float( - commuter_migration_file.iloc[i - 1][2])) == 1) - or (len(str(commuter_migration_file.iloc[i][2])) == 2 and - abs(float(commuter_migration_file.iloc[i][2]) - float( - commuter_migration_file.iloc[i - 1][2])) == 2)): + elif ((str(commuter_mobility_file.iloc[i][3]) == 'Übrige Regierungsbezirke (Bundesland)' and str( + commuter_mobility_file.iloc[i][4]).isdigit()) + or ((commuter_mobility_file.iloc[i][2]).isdigit() and str( + commuter_mobility_file.iloc[i - 1][2]).startswith('nan')) + or (len(str(commuter_mobility_file.iloc[i][2])) == 2 and + abs(float(commuter_mobility_file.iloc[i][2]) - float( + commuter_mobility_file.iloc[i - 1][2])) == 1) + or (len(str(commuter_mobility_file.iloc[i][2])) == 2 and + abs(float(commuter_mobility_file.iloc[i][2]) - float( + commuter_mobility_file.iloc[i - 1][2])) == 2)): # auxiliary key of Bundesland (key translated to int starting at zero) - dummy_key = int(commuter_migration_file.iloc[i][2]) - 1 + dummy_key = int(commuter_mobility_file.iloc[i][2]) - 1 # sum population of all counties not explicitly migrated # from the current gov region migrated from @@ -362,7 +516,7 @@ def get_commuter_data(setup_dict='', # sum up dummy_pop_sum += countypop_list[globindex] - # distribute emigration relatively to county population where migration comes from + # distribute emigration relatively to county population where mobility comes from for j in range(0, len( state_gov_table[dummy_key])): # over all government regions not explicitly stated gov_index = govkey2numlist[state_gov_table[dummy_key][j]] @@ -374,18 +528,18 @@ def get_commuter_data(setup_dict='', globindex = countykey2numlist[gov_county_table[gov_index][k]] counties_migratedfrom[gov_index][k] = 1 - # set value computed relatively to county size and effective migration + # set value computed relatively to county size and effective mobility current_row = globindex - val = commuter_migration_file.iloc[i][4] * \ + val = commuter_mobility_file.iloc[i][4] * \ countypop_list[globindex] / \ dummy_pop_sum checksum += val - mat_commuter_migration[current_row, + mat_commuter_mobility[current_row, current_col] = val - # sum of total migration 'from' - if str(commuter_migration_file.iloc[i][3]) == 'Einpendler aus dem Bundesgebiet': - abs_err = abs(checksum - commuter_migration_file.iloc[i][4]) + # sum of total mobility 'from' + if str(commuter_mobility_file.iloc[i][3]) == 'Einpendler aus dem Bundesgebiet': + abs_err = abs(checksum - commuter_mobility_file.iloc[i][4]) if abs_err > max_abs_err: max_abs_err = abs_err if abs_err / checksum > max_rel_err: @@ -395,13 +549,13 @@ def get_commuter_data(setup_dict='', else: print('Error in calculations for county ', curr_county_migratedto, '\nAccumulated values:', checksum, - ', correct sum:', commuter_migration_file.iloc[i][4]) + ', correct sum:', commuter_mobility_file.iloc[i][4]) print('Absolute error:', abs_err, ', relative error:', abs_err / checksum) n += 1 print(' Federal state read. Progress ', n, '/ 16') - if np.isnan(mat_commuter_migration).any(): + if np.isnan(mat_commuter_mobility).any(): raise gd.DataError( 'NaN encountered in mobility matrix, exiting ' 'getCommuterMobility(). Mobility data will be incomplete.') @@ -412,12 +566,12 @@ def get_commuter_data(setup_dict='', print('Maximum relative error:', max_rel_err) countykey_list = [int(id) for id in countykey_list] - df_commuter_migration = pd.DataFrame( - data=mat_commuter_migration, columns=countykey_list) - df_commuter_migration.index = countykey_list - filename = 'migration_bfa_20' + files[0].split( - '-20')[1][0:2] + '_dim' + str(mat_commuter_migration.shape[0]) - gd.write_dataframe(df_commuter_migration, directory, filename, file_format) + df_commuter_mobility = pd.DataFrame( + data=mat_commuter_mobility, columns=countykey_list) + df_commuter_mobility.index = countykey_list + filename = 'mobility_bfa_20' + files[0].split( + '-20')[1][0:2] + '_dim' + str(mat_commuter_mobility.shape[0]) + gd.write_dataframe(df_commuter_mobility, directory, filename, file_format) # this is neither a very elegant nor a very general way to merge... # better options to be searched for! @@ -425,30 +579,51 @@ def get_commuter_data(setup_dict='', new_idx = countykey_list.index(geoger.CountyMerging[merge_id][0]) old_idx = countykey_list.index(geoger.CountyMerging[merge_id][1]) - mat_commuter_migration[new_idx, :] = mat_commuter_migration[new_idx, - :] + mat_commuter_migration[old_idx, :] - mat_commuter_migration[:, new_idx] = mat_commuter_migration[:, - new_idx] + mat_commuter_migration[:, old_idx] - mat_commuter_migration[new_idx, new_idx] = 0 + mat_commuter_mobility[new_idx, :] = mat_commuter_mobility[new_idx, + :] + mat_commuter_mobility[old_idx, :] + mat_commuter_mobility[:, new_idx] = mat_commuter_mobility[:, + new_idx] + mat_commuter_mobility[:, old_idx] + mat_commuter_mobility[new_idx, new_idx] = 0 - mat_commuter_migration = np.delete(mat_commuter_migration, old_idx, axis=0) - mat_commuter_migration = np.delete(mat_commuter_migration, old_idx, axis=1) + mat_commuter_mobility = np.delete(mat_commuter_mobility, old_idx, axis=0) + mat_commuter_mobility = np.delete(mat_commuter_mobility, old_idx, axis=1) countykey_list = geoger.get_county_ids() - df_commuter_migration = pd.DataFrame( - data=mat_commuter_migration, columns=countykey_list) - df_commuter_migration.index = countykey_list - commuter_sanity_checks(df_commuter_migration) - filename = 'migration_bfa_20' + files[0].split( - '-20')[1][0:2] + '_dim' + str(mat_commuter_migration.shape[0]) - gd.write_dataframe(df_commuter_migration, directory, filename, file_format) + df_commuter_mobility = pd.DataFrame( + data=mat_commuter_mobility, columns=countykey_list) + df_commuter_mobility.index = countykey_list + commuter_sanity_checks(df_commuter_mobility) + filename = 'mobility_bfa_20' + files[0].split( + '-20')[1][0:2] + '_dim' + str(mat_commuter_mobility.shape[0]) + gd.write_dataframe(df_commuter_mobility, directory, filename, file_format) gd.check_dir(os.path.join(directory.split('pydata')[0], 'mobility')) - df_commuter_migration.to_csv( - directory.split('pydata')[0] + 'mobility/commuter_migration_scaled' + + df_commuter_mobility.to_csv( + directory.split('pydata')[0] + 'mobility/commuter_mobility' + '_20' + files[0].split('-20')[1][0: 2] + '.txt', sep=' ', index=False, header=False) - return df_commuter_migration + # Short end for cases where no center coordinates are given. + # this is especially important for 'test_epidata_get_vaccination_data' + if center_coordinates is None: + return df_commuter_mobility + + commuter_mobility_scaled = scale_commuter_mobility( + mat_commuter_mobility, center_coordinates) + + df_commuter_mobility_scaled = pd.DataFrame( + data=commuter_mobility_scaled, columns=countykey_list) + df_commuter_mobility_scaled.index = countykey_list + filename = 'commuter_mobility_scaled_20' + files[0].split( + '-20')[1][0:2] + '_dim' + str(mat_commuter_mobility.shape[0]) + gd.write_dataframe(df_commuter_mobility_scaled, + directory, filename, file_format) + gd.check_dir(os.path.join(directory.split('pydata')[0], 'mobility')) + df_commuter_mobility_scaled.to_csv( + directory.split('pydata')[0] + 'mobility/commuter_mobility_scaled' + + '_20' + files[0].split('-20')[1][0: 2] + '.txt', sep=' ', index=False, + header=False) + + return df_commuter_mobility_scaled def commuter_sanity_checks(df): @@ -463,7 +638,8 @@ def commuter_sanity_checks(df): def get_neighbors_mobility( countyid, direction='both', abs_tol=0, rel_tol=0, tol_comb='or', - merge_eisenach=True, out_folder=dd.defaultDict['out_folder']): + merge_eisenach=True, out_folder=dd.defaultDict['out_folder'], + center_coordinates=None): '''! Returns the neighbors of a particular county ID depening on the commuter mobility and given absolute and relative thresholds on the number of commuters. @@ -498,7 +674,8 @@ def get_neighbors_mobility( directory, "migration_bfa_2020_dim401.json")) except ValueError: print("Commuter data was not found. Download and process it from the internet.") - commuter = get_commuter_data(out_folder=out_folder) + commuter = get_commuter_data( + out_folder=out_folder, center_coordinates=center_coordinates) countykey_list = commuter.columns commuter.index = countykey_list @@ -522,7 +699,8 @@ def get_neighbors_mobility( def get_neighbors_mobility_all( direction='both', abs_tol=0, rel_tol=0, tol_comb='or', - merge_eisenach=True, out_folder=dd.defaultDict['out_folder']): + merge_eisenach=True, out_folder=dd.defaultDict['out_folder'], + center_coordinates=None): '''! Returns the neighbors of all counties ID depening on the commuter mobility and given absolute and relative thresholds on the number of commuters. @@ -552,7 +730,8 @@ def get_neighbors_mobility_all( id, direction=direction, abs_tol=abs_tol, rel_tol=rel_tol, tol_comb=tol_comb, merge_eisenach=merge_eisenach, - out_folder=out_folder)) + out_folder=out_folder, + center_coordinates=center_coordinates)) return dict(zip(countyids, neighbors_table)) @@ -563,8 +742,8 @@ def main(): arg_dict = gd.cli("commuter_official") ref_year = 2020 - abs_tol = 100 # maximum absolute error allowed per county migration - rel_tol = 0.01 # maximum relative error allowed per county migration + abs_tol = 100 # maximum absolute error allowed per county mobility + rel_tol = 0.01 # maximum relative error allowed per county mobility path = 'https://statistik.arbeitsagentur.de/Statistikdaten/Detail/' + \ str(ref_year) + '12/iiia6/beschaeftigung-sozbe-krpend/' @@ -572,10 +751,23 @@ def main(): 'rel_tol': rel_tol, 'path': path} + memilio_path = up(up(up(up(up(__file__))))) + path_json = os.path.join( + memilio_path, 'data', 'mobility' , 'county_centers_dim400.json') + + if os.path.isfile(path_json): + center_coordinates = pd.read_json(path_json) + else: + center_coordinates = None + + + get_neighbors_mobility(1001, abs_tol=0, rel_tol=0, tol_comb='or', - merge_eisenach=True, out_folder=dd.defaultDict['out_folder']) + merge_eisenach=True, out_folder=dd.defaultDict['out_folder'], + center_coordinates=center_coordinates) - mat_commuter_migration = get_commuter_data(setup_dict, **arg_dict) + mat_commuter_mobility = get_commuter_data( + setup_dict, **arg_dict, center_coordinates=center_coordinates) if __name__ == "__main__": diff --git a/pycode/memilio-epidata/memilio/epidata/transformMobilityData.py b/pycode/memilio-epidata/memilio/epidata/transformMobilityData.py index 4dc6d412d8..b1e112d2c0 100644 --- a/pycode/memilio-epidata/memilio/epidata/transformMobilityData.py +++ b/pycode/memilio-epidata/memilio/epidata/transformMobilityData.py @@ -132,11 +132,11 @@ def main(): # Merge Eisenach and Wartbugkreis in Input Data if need be updateMobility2022(directory, mobility_file='twitter_scaled_1252') - updateMobility2022(directory, mobility_file='commuter_migration_scaled') + updateMobility2022(directory, mobility_file='commuter_mobility_scaled') # create federal states mobility matrix (not used in simulation for now) createFederalStatesMobility(directory, mobility_file='twitter_scaled_1252') createFederalStatesMobility( - directory, mobility_file='commuter_migration_scaled') + directory, mobility_file='commuter_mobility_scaled') if __name__ == "__main__": diff --git a/pycode/memilio-epidata/memilio/epidata_test/test_epidata_getCommuterMobility.py b/pycode/memilio-epidata/memilio/epidata_test/test_epidata_getCommuterMobility.py index cc5ea38cdc..96143f4c10 100644 --- a/pycode/memilio-epidata/memilio/epidata_test/test_epidata_getCommuterMobility.py +++ b/pycode/memilio-epidata/memilio/epidata_test/test_epidata_getCommuterMobility.py @@ -24,6 +24,7 @@ import pandas as pd import os import collections +from os.path import dirname as up from memilio.epidata import getCommuterMobility as gcm from memilio.epidata import geoModificationGermany as geoger from memilio.epidata import getDataIntoPandasDataFrame as gD @@ -63,6 +64,10 @@ class TestCommuterMigration(fake_filesystem_unittest.TestCase): ['05512', '05513', '05515', '05554', '05558', '05562', '05566', '05570'], ['05711', '05754', '05758', '05762', '05766', '05770', '05774']) + + memilio_path = up(up(up(up(up(__file__))))) + center_coordinates = pd.read_json(os.path.join( + memilio_path, 'data', 'mobility' , 'county_centers_dim400.json')) def setUp(self): self.setUpPyfakefs() @@ -317,14 +322,20 @@ def test_some_errors(self, mock_print): self.assertEqual(len(os.listdir(self.path)), 17) def test_commuter_data(self): - """! Tests migration data by some randomly chosen tests. + """! Tests mobility data by some randomly chosen tests. """ - df_commuter_migration = gcm.get_commuter_data(out_folder=self.path) + df_commuter_mobility_no_scale = gcm.get_commuter_data( + out_folder=self.path) + df_commuter_mobility_scaled = gcm.get_commuter_data( + out_folder=self.path, center_coordinates=self.center_coordinates) # the first column and first row are just the county IDs - # mat_commuter_migration is the real Data that should be tested - mat_commuter_migration = df_commuter_migration.iloc[:, 0:] - mat_commuter_migration = mat_commuter_migration.iloc[0:, :] + # mat_commuter_mobility is the real Data that should be tested + mat_commuter_mobility_scaled = df_commuter_mobility_scaled.iloc[:, 0:] + mat_commuter_mobility_scaled = mat_commuter_mobility_scaled.iloc[0:, :] + + mat_commuter_mobility_no_scale = df_commuter_mobility_no_scale.iloc[:, 0:] + mat_commuter_mobility_no_scale = mat_commuter_mobility_no_scale.iloc[0:, :] countykey2numlist = collections.OrderedDict( zip(self.countykey_list, list(range(0, len(self.countykey_list))))) @@ -334,9 +345,9 @@ def test_commuter_data(self): self.write_commuter_all_federal_states(self.path) self.assertEqual(len(os.listdir(self.path)), 18) - # just do some tests on randomly chosen migrations + # just do some tests on randomly chosen mobility - # check migration from Leverkusen (averaged from NRW, 05) to Hildburghausen + # check mobility from Leverkusen (averaged from NRW, 05) to Hildburghausen city_from = countykey2numlist['05316'] city_to = countykey2numlist['16069'] population = gpd.get_population_data( @@ -344,22 +355,27 @@ def test_commuter_data(self): countypop_list = list(population[dd.EngEng['population']]) self.assertEqual(countypop_list[city_from], 163905) self.assertAlmostEqual( - mat_commuter_migration.iat[city_from, city_to], 1.526, 2) + mat_commuter_mobility_scaled.iat[city_from, city_to], 0.305, 2) + self.assertAlmostEqual( + mat_commuter_mobility_no_scale.iat[city_from, city_to], 1.526, 2) - # check migration from Duisburg to Oberspreewald-Lausitz + # check mobility from Duisburg to Oberspreewald-Lausitz city_from = countykey2numlist['05112'] city_to = countykey2numlist['12066'] - self.assertEqual(mat_commuter_migration.iat[city_from, city_to], 11) + self.assertEqual(mat_commuter_mobility_scaled.iat[city_from, city_to], 2.2) + self.assertEqual(mat_commuter_mobility_no_scale.iat[city_from, city_to], 11) - # check migration from Lahn-Dill-Kreis to Hamburg + # check mobility from Lahn-Dill-Kreis to Hamburg city_from = countykey2numlist['06532'] city_to = countykey2numlist['02000'] - self.assertEqual(mat_commuter_migration.iat[city_from, city_to], 96) + self.assertAlmostEqual(mat_commuter_mobility_scaled.iat[city_from, city_to], 19.2, 2) + self.assertEqual(mat_commuter_mobility_no_scale.iat[city_from, city_to], 96, 2) - # check migration from Herzogtum Lauenburg to Flensburg, Stadt + # check mobility from Herzogtum Lauenburg to Flensburg, Stadt city_from = countykey2numlist['01001'] city_to = countykey2numlist['01053'] - self.assertEqual(mat_commuter_migration.iat[city_from, city_to], 14) + self.assertEqual(mat_commuter_mobility_scaled.iat[city_from, city_to], 7) + self.assertEqual(mat_commuter_mobility_no_scale.iat[city_from, city_to], 14) @patch('builtins.print') def test_get_neighbors_mobility(self, mock_print): @@ -369,30 +385,33 @@ def test_get_neighbors_mobility(self, mock_print): #direction = both (countykey_list, commuter_all) = gcm.get_neighbors_mobility( tci, direction='both', abs_tol=0, rel_tol=0, - tol_comb='or', merge_eisenach=True, out_folder=self.path) + tol_comb='or', merge_eisenach=True, out_folder=self.path, + center_coordinates=self.center_coordinates) self.assertEqual(len(countykey_list), 398) self.assertAlmostEqual(228, commuter_all[0], 2) self.assertAlmostEqual(2146, commuter_all[9], 2) - self.assertAlmostEqual(293, commuter_all[11], 2) - self.assertAlmostEqual(1, commuter_all[397], 2) + self.assertAlmostEqual(146.5, commuter_all[11], 2) + self.assertAlmostEqual(.2, commuter_all[397], 2) # direction = in (countykey_list, commuter_all) = gcm.get_neighbors_mobility( tci, direction='in', abs_tol=0, rel_tol=0, - tol_comb='or', merge_eisenach=True, out_folder=self.path) + tol_comb='or', merge_eisenach=True, out_folder=self.path, + center_coordinates=self.center_coordinates) self.assertEqual(len(countykey_list), 393) self.assertAlmostEqual(48, commuter_all[0], 2) self.assertAlmostEqual(842, commuter_all[9], 2) - self.assertAlmostEqual(92, commuter_all[11], 2) + self.assertAlmostEqual(46, commuter_all[11], 2) # direction = out (countykey_list, commuter_all) = gcm.get_neighbors_mobility( tci, direction='out', abs_tol=0, rel_tol=0, - tol_comb='or', merge_eisenach=True, out_folder=self.path) + tol_comb='or', merge_eisenach=True, out_folder=self.path, + center_coordinates=self.center_coordinates) self.assertEqual(len(countykey_list), 375) self.assertAlmostEqual(180, commuter_all[0], 2) self.assertAlmostEqual(1304, commuter_all[9], 2) - self.assertAlmostEqual(201, commuter_all[11], 2) + self.assertAlmostEqual(100.5, commuter_all[11], 2) if __name__ == '__main__': diff --git a/pycode/memilio-epidata/setup.py b/pycode/memilio-epidata/setup.py index 6684ce399c..f1872105af 100644 --- a/pycode/memilio-epidata/setup.py +++ b/pycode/memilio-epidata/setup.py @@ -78,7 +78,9 @@ def run(self): 'xlrd', 'requests', 'pyxlsb', - 'wget' + 'wget', + 'geojson', + 'shapely' ], extras_require={ 'dev': [