1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Igor_感染者マップ表示

Last updated at Posted at 2021-09-02

Graph5.jpg
日本地図上に特定の日の感染者数を表示する動画を作成するのに使用したProcedure一覧です。そのうちもう少しちゃんと形を整えてから個別にある程度ちゃんと説明を入れた記事を書こうとは思っていますがいつになるかわからないのでとりあえず使用したコードだけおいておきます。
基本forloopとif文でごり押しする力技で書いてしまっているのでもっと効率よくかける方法や不要な個所など気づく点がありましたら教えていただけると大変ありがたいです。
また、説明が必要な個所なども教えてもらえれば追記します。

感染者数は厚生労働省のオープンデータ(https://www.mhlw.go.jp/stf/covid-19/open-data.html)
日本地図はStart point(https://www.start-point.net/maps/material/) の地図を使用しました

ダウンロードした感染者数データが全都道府県をまとめたものだったので分割するために使用したProcedure
Function DivPre()

Variable i,j

Wave/t PreName = name
Wave ori	= original_all
Variable Num_ori,Num_date
	Num_ori	= rightx(ori)
	Num_date	= Num_ori/48

String FolderName = "Divide"
Newdatafolder/o $(FolderName)
	cd root:$(Foldername)

String Pre,Name_Wave

for(i = 0 ; i < 47 ; i += 1)
	Pre = Prename[i]
	Name_Wave = Pre+"_positive"
	
	Make/o/d/n = (Num_date) $(Name_Wave)
	Wave NewWave = $(Name_Wave)

	for(j = 0 ; j < Num_date ; j += 1)
		NewWave[j] = Ori[i+j*48]	
	endfor

endfor

cd root:
end
読み込んだ地図のtiffファイルから都道府県ごとの色情報の数値を取得するためのProcedure(Colortableは手作業で都道府県内の任意の位置の座標を入力したtable)
Function Makecolor()
Wave Map = Map_tiff
Wave color = colortable
Make/o/d/n = (743,582) Map_RGB

Variable i,j
for(i=0 ; i < 743 ; i += 1)
for(j = 0 ; j <582 ; j += 1)
Map_RGB[i][j] = ((Map[i][j][0])*10+(Map[i][j][1])*(Map[i][j][2]))
endfor
endfor

Variable k,k_x,k_y
for(k = 0 ; k < 48 ; k += 1)
	k_x = color[k][0]
	k_y = color[k][1]

color[k][2] = Map_RGB[k_x][k_y]
endfor
end
各都道府県に対応するxy座標を地図から取得するためのProcedure。
Function LocPre()

Variable pre
Variable i,j

Wave color		= colortable
Wave/t PreName	= Name
Wave ori			= map_RGB
Variable Num_x,Num_y
	Num_x	= dimsize(Ori,0)
	Num_y	= dimsize(Ori,1)

String FolderName = "location" 
	Newdatafolder/o $(FolderName)
	cd root:$(FolderName)

for(Pre = 1 ; Pre < 48 ; Pre += 1)
Variable set = color[pre][2]
String Name = PreName[pre]+"_xy"
	Make/o/d/n = (1,2) $(Name)
	Wave Stock = $(Name)


Variable check,k

for(i = 0 ; i < Num_x ; i += 1)
	for(j = 0 ; j < Num_y ; j += 1)
		check = ori[i][j]
		if(check == set)
			k = rightx(Stock)
			Redimension/n = (k+1,2) Stock
			stock[k-1][0] = i
			stock[k-1][1] = j			
		endif				
	endfor
endfor

endfor
cd root:
end
地図の各都道府県に指定した日にちの感染者数を格納するProcedure。
Function MakeMap(day)

Variable day
Variable i
Variable c,l
Variable Pre
Wave/t PreName	= Name
Wave origin		= map_RGB

Variable Num_x,Num_y
	Num_x	= dimsize(Origin,0)
	Num_y	= dimsize(Origin,1)
	Make/o/d/n = (Num_x,Num_y) PositiveMap
	Wave Map = PositiveMap
		Map = 0

String Folder_Loc,Folder_posi
	Folder_Loc = "Location" 
	Folder_posi	= "Divide"

String Pre_posi,Pre_loc	
Variable Num_loc
for(Pre = 1 ; Pre < 48 ; Pre += 1)
	pre_posi = PreName[Pre]+"_positive"
	Wave PreWave = root:$(Folder_posi):$(pre_posi)
	
	Pre_loc = PreName[pre]+"_xy"
	Wave LocWave = root:$(Folder_Loc):$(Pre_loc)
		Num_loc = rightx(locWave)

	for(i = 0 ; i < Num_loc ; i += 1)			
			c = LocWave[i][0]
			l = LocWave[i][1]
			Map[c][l] = PreWave[day]///num_loc
	endfor	
endfor
end
指定した日にちの画像を表示(log表示)
Function DispMap(Day)
Variable day
String DispName = "PositiveMap"
	Wave DispWave = $(DispName)
	NewImage/k=1 DispWave
	ModifyGraph nticks=0
	ModifyImage $(DispName) ctab= {0.1,1000,YellowHot,0},log=1
	ColorScale/C/N=text0/F=0/B=1/G=(65535,65535,65535)/A=LT/X=2.00/Y=2.00 image=$(DispName),tickLen=3.00
	ColorScale/C/N=text0 "Number (log)"
	ColorScale/C/N=text0 width=8,heightPct=40
	ColorScale/C/N=text0 log=1
   TextBox/C/N=text1/F=0/B=1/G=(65535,65535,65535)/A=RB "\\Z20Day: "+num2str(Day)
	
end
動画作成
Function Makemovie()
   String MoviePath = "C:Users:PCUser:Desktop:plactice.mov"
   Variable Day
	
	DispMap(0)
	NewMovie/F=12/CF=10/O as MoviePath 
   for (Day=0 ; Day< 582 ; Day+=1)

      MakeMap(Day)
      TextBox/C/N=text1/F=0/B=1/G=(65535,65535,65535)/A=RB "\\Z20Day: "+num2str(Day)
      Doupdate
      AddMovieFrame
     //killwindow #
   endfor
    CloseMovie
    //PlayMovie as MoviePath
End
1
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?