Все,
При анализе среднемесячной приземной температуры в двух странах с использованием шейп-файла ESRI я обнаружил, что среднее значение температуры в этих двух странах не соответствует среднему значению суммы каждой страны в отдельности. Я попробовал это в разных странах, и возникла проблема.
< img alt="введите здесь описание изображения" src="https://i.sstatic.net/4tsq1zLj.png" />
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import xarray as xr
import geopandas as gpd
import regionmask
#%%
diri='/disk2/'
## Opening file
t2m_file = xr.open_dataset(diri+"era5_sublatlon.nc")
lonP = t2m_file['longitude']
latP = t2m_file['latitude']
t2m_k = t2m_file['t2m'][:101,...]
t2m = t2m_k - 273.15
#%%
shp_dir="/disk2/World_Countries_Generalized/"
shp_file =gpd.read_file(shp_dir+"World_Countries_Generalized.shp")
shp_file=shp_file.to_crs('EPSG:4326')
# in which units is in degress instead of meteres.
shp_region=regionmask.Regions(shp_file.geometry)
shp_file.plot()
plt.figure();shp_region.plot_regions()
#%%
region1=shp_file[shp_file.COUNTRY == 'Egypt']
shp_region1=regionmask.Regions(region1.geometry)
region2=shp_file[shp_file.COUNTRY == 'Tunisia']
shp_region2=regionmask.Regions(region2.geometry)
mycountries = ["Egypt", "Tunisia"]
region3_ = shp_file[shp_file.COUNTRY.isin(mycountries)]
region3_['test']='merge_me'
region3=region3_.dissolve(by='test')
shp_region3=regionmask.Regions(region3.geometry)
region2.plot(color='lightgray') # the same color
region2.plot(column='COUNTRY')# give diffent color for each country.
region3.plot(color='lightgray') # the same color
region3.plot(column='COUNTRY')# give diffent color for each country.
#%%
# generating the mask region which is zero at the region
# and null otherwise
mask_region1=shp_region1.mask(t2m.longitude,t2m.latitude)
mask_region2=shp_region2.mask(t2m.longitude,t2m.latitude)
mask_region3=shp_region3.mask(t2m.longitude,t2m.latitude)
# masked temperture of the raw data
tem_masked_region_1=t2m.where(mask_region1 == 0)
tem_masked_region_2=t2m.where(mask_region2 == 0)
tem_masked_region_3=t2m.where(mask_region3 == 0)
tem_1=np.nanmean(tem_masked_region_1,axis=(1,2))
tem_2=np.nanmean(tem_masked_region_2,axis=(1,2))
tem_3=np.nanmean(tem_masked_region_3,axis=(1,2))
#%%
plt.figure()
plt.plot((tem_1+tem_2)/2.,linewidth=2.5,color='gray')
#plt.plot(tem_1,'--b',linewidth=1.5)
#plt.plot(tem_2,'--k',linewidth=1.5)
plt.plot(tem_3,'--r',linewidth=1.5)
Все, При анализе среднемесячной приземной температуры в двух странах с использованием шейп-файла ESRI я обнаружил, что среднее значение температуры в этих двух странах не соответствует среднему значению суммы каждой страны в отдельности. Я попробовал это в разных странах, и возникла проблема. [img]https://i.sstatic.net/BSCSR6zu.png[/img] < img alt="введите здесь описание изображения" src="https://i.sstatic.net/4tsq1zLj.png" /> [code]#!/usr/bin/env python3 # -*- coding: utf-8 -*-
import numpy as np import matplotlib.pyplot as plt import xarray as xr
shp_file=shp_file.to_crs('EPSG:4326') # in which units is in degress instead of meteres. shp_region=regionmask.Regions(shp_file.geometry) shp_file.plot() plt.figure();shp_region.plot_regions()
region2.plot(color='lightgray') # the same color region2.plot(column='COUNTRY')# give diffent color for each country.
region3.plot(color='lightgray') # the same color region3.plot(column='COUNTRY')# give diffent color for each country.
#%% # generating the mask region which is zero at the region # and null otherwise mask_region1=shp_region1.mask(t2m.longitude,t2m.latitude) mask_region2=shp_region2.mask(t2m.longitude,t2m.latitude) mask_region3=shp_region3.mask(t2m.longitude,t2m.latitude)
# masked temperture of the raw data tem_masked_region_1=t2m.where(mask_region1 == 0) tem_masked_region_2=t2m.where(mask_region2 == 0) tem_masked_region_3=t2m.where(mask_region3 == 0)
#%% plt.figure() plt.plot((tem_1+tem_2)/2.,linewidth=2.5,color='gray') #plt.plot(tem_1,'--b',linewidth=1.5) #plt.plot(tem_2,'--k',linewidth=1.5) plt.plot(tem_3,'--r',linewidth=1.5) [/code] Я загрузил сюда данные файла netcdf и файл формы