Ratescale / spaceweather

宇宙天気の作業用
0 stars 0 forks source link

タスクログ #1

Open rensanrenren opened 1 year ago

rensanrenren commented 1 year ago

日本の送電線の全長は約179,922Ckm(回路キロメートル)で、送電線のスパン(塔と塔の間隔)は地形などにより変動しますが、一般的に数百メートルから数キロメートルとされている。

ただし、具体的な送電塔の数を算出するためには、平均的なスパン(塔と塔の間隔)が必要。仮に平均スパンを0.5km(500m)と仮定する。また、送電線の全長の単位がCkm(回路キロメートル)であるため、これを1回路平均でkm(キロメートル)に換算する。※実際の送電線の回路数は場所や線種により異なる可能性がある。

この仮定に基づくと、日本全国の送電塔の数は:

送電線の全長(km) ÷ 塔と塔の間隔(スパン)(km)

= 179,922km ÷ 0.5km

= 約359,844 塔

rensanrenren commented 1 year ago

以下に、OpenStreetMapから日本全体の送電線と送電塔のデータをダウンロードし、それをGeoJSONファイルとして保存する手順を示します:

  1. 必要なライブラリをインストールします。Pythonと以下のライブラリがインストールされていない場合は、それらをインストールします:

    • osmnx
    • pandas
    • geopandas

    これらのライブラリはpipを使用して簡単にインストールできます:

    pip install osmnx pandas geopandas
  2. Pythonスクリプトを作成します。以下のコードをPythonファイル(たとえば、download_power_data.py)にコピーします:

    import osmnx as ox
    import pandas as pd
    import geopandas as gpd
    
    # Japan's bounding box coordinates (approximate)
    north, south, east, west = 45.551483, 24.396308, 153.986672, 122.934570
    
    # Define the number of chunks
    num_chunks = 15
    
    # Calculate the latitude range for each chunk
    lat_ranges = pd.cut([north, south], bins=num_chunks).categories
    
    # Initialize empty GeoDataFrames for the power lines and towers
    power_lines = gpd.GeoDataFrame()
    power_towers = gpd.GeoDataFrame()
    
    # Download and append the data for each chunk
    for i in range(num_chunks):
       print(f"Downloading data for chunk {i+1}/{num_chunks}...")
       chunk_north, chunk_south = lat_ranges[i].right, lat_ranges[i].left
       chunk_power_lines = ox.geometries.geometries_from_bbox(chunk_north, chunk_south, east, west, tags={'power': 'line'})
       chunk_power_towers = ox.geometries.geometries_from_bbox(chunk_north, chunk_south, east, west, tags={'power': 'tower'})
       power_lines = power_lines.append(chunk_power_lines)
       power_towers = power_towers.append(chunk_power_towers)
    
    # Save the data to GeoJSON files
    power_lines.to_file("power_lines.geojson", driver='GeoJSON')
    power_towers.to_file("power_towers.geojson", driver='GeoJSON')
  3. Pythonスクリプトを実行します。作成したPythonファイルをターミナルやコマンドプロンプトから実行します:

    python download_power_data.py

    このスクリプトは、日本全体の送電線と送電塔のデータをダウンロードし、それをpower_lines.geojsonpower_towers.geojsonという名前のGeoJSONファイルに保存します。

  4. Mapbox Studioを開き、左側のメニューから「Datasets」を選択します。

  5. 「New dataset」をクリックします。

  6. 「Upload」をクリックし、作成したGeoJSONファイル(power_lines.geojsonpower_towers.geojson)を選択します。

これで、Mapbox Studioで日本全体の送電線と送電塔のデータを表示できるようになります。

ただし、上記のPythonスクリプトは、データの取得と処理に時間がかかる可能性があることに注意してください。そのため、プログレスバーやログ出力を使用して進行状況を確認することをお勧めします。上記のコードでは、各地域のデータ取得が開始されるたびにその旨がコンソールに出力されます。

rensanrenren commented 1 year ago

日本全国を網羅するのは大変そうなので、東京23区のみの送電網、送電塔を抽出する作戦に切り替え

rensanrenren commented 1 year ago
import osmnx as ox

# Bounding box coordinates for Tokyo's 23 wards (approximate)
north, south, east, west = 35.774143, 35.627472, 139.910177, 139.594515

# Download the data for the power lines and towers
print("Downloading data for Tokyo's 23 wards...")
power_lines = ox.geometries.geometries_from_bbox(north, south, east, west, tags={'power': 'line'})
power_towers = ox.geometries.geometries_from_bbox(north, south, east, west, tags={'power': 'tower'})

# Convert list type columns to string
for col in power_lines.columns:
    if isinstance(power_lines[col].iloc[0], list):
        power_lines[col] = power_lines[col].apply(lambda x: ', '.join(map(str, x)))

for col in power_towers.columns:
    if isinstance(power_towers[col].iloc[0], list):
        power_towers[col] = power_towers[col].apply(lambda x: ', '.join(map(str, x)))

# Save the data to GeoJSON files
power_lines.to_file("tokyo_power_lines.geojson", driver='GeoJSON')
power_towers.to_file("tokyo_power_towers.geojson", driver='GeoJSON')
rensanrenren commented 1 year ago

地区の変更

bounding box(地理的な範囲を定義するための北端、南端、東端、西端の座標)を変更する

# Bounding box coordinates for Tokyo's 23 wards (approximate)
north, south, east, west = 35.774143, 35.627472, 139.910177, 139.594515

ここで、north, south, east, westはそれぞれ北端、南端、東端、西端の座標を示している。これらの値を新しい地区の座標に置き換えれば、その地区のデータをダウンロードできる。

※北緯と東経はプラスの値、南緯と西経はマイナスの値を持つことを考慮。