Различия
Показаны различия между двумя версиями страницы.
— |
calc:maps [2023/04/10 09:45] (текущий) root создано |
||
---|---|---|---|
Строка 1: | Строка 1: | ||
+ | <div slide> | ||
+ | ===== Карты ===== | ||
+ | |||
+ | Раньше для построения карт использовался модуль '' | ||
+ | |||
+ | * {{ : | ||
+ | * {{ : | ||
+ | * {{ : | ||
+ | * {{ : | ||
+ | |||
+ | Для выбора нужной проекции используем [[https:// | ||
+ | |||
+ | <sxh python> | ||
+ | import numpy as np | ||
+ | import matplotlib.pyplot as plt | ||
+ | import matplotlib.ticker as mticker | ||
+ | from cartopy import crs as ccrs | ||
+ | |||
+ | fig = plt.figure() | ||
+ | |||
+ | ax = fig.add_subplot(projection=ccrs.PlateCarree()) | ||
+ | |||
+ | ax.set_extent([-6, | ||
+ | |||
+ | gl = ax.gridlines(draw_labels=True) | ||
+ | gl.xlocator = mticker.FixedLocator(np.arange(-6.0, | ||
+ | gl.ylocator = mticker.FixedLocator(np.arange(48.0, | ||
+ | |||
+ | ax.scatter([-2], | ||
+ | |||
+ | ax.coastlines(resolution=' | ||
+ | </ | ||
+ | |||
+ | Рисование данных поверх карты выполняется обычными методами, | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== Пример карты построенной в cartopy ==== | ||
+ | |||
+ | {{: | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== Картографические данные Natural Earth ==== | ||
+ | |||
+ | Картографические данные '' | ||
+ | |||
+ | <sxh python> | ||
+ | import numpy as np | ||
+ | import matplotlib.pyplot as plt | ||
+ | import matplotlib.ticker as mticker | ||
+ | from cartopy import crs as ccrs | ||
+ | import cartopy.feature | ||
+ | |||
+ | #%% | ||
+ | |||
+ | fig = plt.figure() | ||
+ | |||
+ | ax = fig.add_subplot(projection=ccrs.PlateCarree()) | ||
+ | |||
+ | ax.set_extent([-6, | ||
+ | |||
+ | gl = ax.gridlines(draw_labels=True) | ||
+ | gl.xlocator = mticker.FixedLocator(np.arange(-6.0, | ||
+ | gl.ylocator = mticker.FixedLocator(np.arange(38.0, | ||
+ | |||
+ | resol = ' | ||
+ | bodr = cartopy.feature.NaturalEarthFeature(category=' | ||
+ | name=' | ||
+ | land = cartopy.feature.NaturalEarthFeature(' | ||
+ | scale=resol, | ||
+ | ocean = cartopy.feature.NaturalEarthFeature(' | ||
+ | scale=resol, | ||
+ | lakes = cartopy.feature.NaturalEarthFeature(' | ||
+ | scale=resol, | ||
+ | rivers = cartopy.feature.NaturalEarthFeature(' | ||
+ | scale=resol, | ||
+ | |||
+ | ax.add_feature(land) | ||
+ | ax.add_feature(ocean) | ||
+ | ax.add_feature(lakes) | ||
+ | ax.add_feature(rivers) | ||
+ | ax.add_feature(bodr, | ||
+ | </ | ||
+ | |||
+ | Какие именно картографические данные доступны см. по ссылке [[https:// | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== Пример карты построенной в cartopy ==== | ||
+ | |||
+ | {{: | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== Использование Tile-серверов в cartopy ==== | ||
+ | |||
+ | <sxh python> | ||
+ | from cartopy.io.img_tiles import GoogleWTS, OSM, GoogleTiles | ||
+ | |||
+ | |||
+ | class ArcGISWSR(GoogleWTS): | ||
+ | def _image_url(self, | ||
+ | x, y, z = tile | ||
+ | return f' | ||
+ | |||
+ | |||
+ | tiles_provider = OSM() | ||
+ | # | ||
+ | # | ||
+ | |||
+ | plt.figure(figsize=(16, | ||
+ | |||
+ | ax = plt.axes(projection=tiles_provider.crs) | ||
+ | |||
+ | ax.set_extent([-6, | ||
+ | |||
+ | ax.add_image(tiles_provider, | ||
+ | |||
+ | plt.show() | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== Пример карты построенной в cartopy ==== | ||
+ | |||
+ | {{: | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== Некоторые приемы работы с cartopy ==== | ||
+ | |||
+ | <sxh python> | ||
+ | |||
+ | # Скрытие части подписей по осям: | ||
+ | gridlines = ax.gridlines(draw_labels=True) | ||
+ | gridlines.top_labels = False | ||
+ | gridlines.right_labels = False | ||
+ | |||
+ | # Добавление теплокарты: | ||
+ | im = ax.imshow(data, | ||
+ | fig.colorbar(im, | ||
+ | |||
+ | # | ||
+ | ax.scatter([50.8667], | ||
+ | |||
+ | mpl_trans = ccrs.PlateCarree()._as_mpl_transform(ax) | ||
+ | ax.annotate(' | ||
+ | |||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== Построение карт из NetCDF файлов ==== | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | <sxh python> | ||
+ | |||
+ | import netCDF4 as nc | ||
+ | import numpy as np | ||
+ | import matplotlib.pyplot as plt | ||
+ | import matplotlib.ticker as mticker | ||
+ | from cartopy import crs as ccrs | ||
+ | |||
+ | # Добавляем encoding если 1. в Windows и 2. в пути к файлу есть русские буквы (и другие символы Unicode) | ||
+ | ds = nc.Dataset(" | ||
+ | |||
+ | print(ds) # обзор структуры NetCDF файла | ||
+ | |||
+ | data = ds[' | ||
+ | |||
+ | # | ||
+ | ax.set_extent([ds[' | ||
+ | |||
+ | </ | ||
+ | |||
+ | </ |