前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >数据获取:如何在线获取的GFS雪深两周后预报

数据获取:如何在线获取的GFS雪深两周后预报

作者头像
用户11172986
发布2024-06-20 18:13:09
1120
发布2024-06-20 18:13:09
举报
文章被收录于专栏:气python风雨

NCSS GFS 0.25 snowdepth

上次测试的是0.5分辨率的GFS数据 这次试试更高分辨率0.25的效果 实际上TDSCatalog还有很多产品,可以在这里看看

数据获取

In [8]:

代码语言:javascript
复制
代码语言:javascript
复制
%matplotlib inline
from siphon.catalog import TDSCatalog
best_gfs = TDSCatalog('http://thredds.ucar.edu/thredds/catalog/grib/NCEP/GFS/'
                      'Global_0p25deg/catalog.xml?dataset=grib/NCEP/GFS/Global_0p25deg/Best')
best_gfs.datasets
代码语言:javascript
复制
代码语言:javascript
复制
['Best GFS Quarter Degree Forecast Time Series']

In [9]:

代码语言:javascript
复制
代码语言:javascript
复制
best_ds = list(best_gfs.datasets.values())[0]
ncss = best_ds.subset()
代码语言:javascript
复制

看看有啥变量

In [10]:

代码语言:javascript
复制
代码语言:javascript
复制
query = ncss.query()
ncss.variables
代码语言:javascript
复制
代码语言:javascript
复制
{'Absolute_vorticity_isobaric',
 'Albedo_surface_Mixed_intervals_Average',
 'Apparent_temperature_height_above_ground',
 'Best_4_layer_Lifted_Index_surface',
 'Categorical_Freezing_Rain_surface',
 'Categorical_Freezing_Rain_surface_Mixed_intervals_Average',
 'Categorical_Ice_Pellets_surface',
 'Categorical_Ice_Pellets_surface_Mixed_intervals_Average',
 'Categorical_Rain_surface',
 'Categorical_Rain_surface_Mixed_intervals_Average',
 'Categorical_Snow_surface',
 'Categorical_Snow_surface_Mixed_intervals_Average',
 'Cloud_Work_Function_entire_atmosphere_single_layer_Mixed_intervals_Average',
 'Cloud_mixing_ratio_hybrid',
 'Cloud_mixing_ratio_isobaric',
 'Cloud_water_entire_atmosphere_single_layer',
 'Composite_reflectivity_entire_atmosphere',
 'Convective_Precipitation_Rate_surface_Mixed_intervals_Average',
 'Convective_available_potential_energy_pressure_difference_layer',
 'Convective_available_potential_energy_surface',
 'Convective_inhibition_pressure_difference_layer',
 'Convective_inhibition_surface',
 'Convective_precipitation_rate_surface',
 'Convective_precipitation_surface_Mixed_intervals_Accumulation',
 'Dewpoint_temperature_height_above_ground',
 'Downward_Long-Wave_Radp_Flux_surface_Mixed_intervals_Average',
 'Downward_Short-Wave_Radiation_Flux_surface_Mixed_intervals_Average',
 'Field_Capacity_surface',
 'Frictional_Velocity_surface',
 'Geopotential_height_cloud_ceiling',
 'Geopotential_height_highest_tropospheric_freezing',
 'Geopotential_height_isobaric',
 'Geopotential_height_maximum_wind',
 'Geopotential_height_potential_vorticity_surface',
 'Geopotential_height_surface',
 'Geopotential_height_tropopause',
 'Geopotential_height_zeroDegC_isotherm',
 'Graupel_snow_pellets_hybrid',
 'Graupel_snow_pellets_isobaric',
 'Ground_Heat_Flux_surface_Mixed_intervals_Average',
 'Haines_index_surface',
 'High_cloud_cover_high_cloud',
 'High_cloud_cover_high_cloud_Mixed_intervals_Average',
 'ICAO_Standard_Atmosphere_Reference_Height_maximum_wind',
 'ICAO_Standard_Atmosphere_Reference_Height_tropopause',
 'Ice_cover_surface',
 'Ice_growth_rate_altitude_above_msl',
 'Ice_temperature_surface',
 'Ice_thickness_surface',
 'Ice_water_mixing_ratio_hybrid',
 'Ice_water_mixing_ratio_isobaric',
 'Land_cover_0__sea_1__land_surface',
 'Latent_heat_net_flux_surface_Mixed_intervals_Average',
 'Liquid_Volumetric_Soil_Moisture_non_Frozen_depth_below_surface_layer',
 'Low_cloud_cover_low_cloud',
 'Low_cloud_cover_low_cloud_Mixed_intervals_Average',
 'MSLP_Eta_model_reduction_msl',
 'Maximum_temperature_height_above_ground_Mixed_intervals_Maximum',
 'Medium_cloud_cover_middle_cloud',
 'Medium_cloud_cover_middle_cloud_Mixed_intervals_Average',
 'Meridional_Flux_of_Gravity_Wave_Stress_surface_Mixed_intervals_Average',
 'Minimum_temperature_height_above_ground_Mixed_intervals_Minimum',
 'Momentum_flux_u-component_surface_Mixed_intervals_Average',
 'Momentum_flux_v-component_surface_Mixed_intervals_Average',
 'Ozone_Mixing_Ratio_isobaric',
 'Per_cent_frozen_precipitation_surface',
 'Planetary_Boundary_Layer_Height_surface',
 'Plant_Canopy_Surface_Water_surface',
 'Potential_Evaporation_Rate_surface',
 'Potential_temperature_sigma',
 'Precipitable_water_entire_atmosphere_single_layer',
 'Precipitation_rate_surface',
 'Precipitation_rate_surface_Mixed_intervals_Average',
 'Pressure_convective_cloud_bottom',
 'Pressure_convective_cloud_top',
 'Pressure_height_above_ground',
 'Pressure_high_cloud_bottom_Mixed_intervals_Average',
 'Pressure_high_cloud_top_Mixed_intervals_Average',
 'Pressure_low_cloud_bottom_Mixed_intervals_Average',
 'Pressure_low_cloud_top_Mixed_intervals_Average',
 'Pressure_maximum_wind',
 'Pressure_middle_cloud_bottom_Mixed_intervals_Average',
 'Pressure_middle_cloud_top_Mixed_intervals_Average',
 'Pressure_of_level_from_which_parcel_was_lifted_pressure_difference_layer',
 'Pressure_potential_vorticity_surface',
 'Pressure_reduced_to_MSL_msl',
 'Pressure_surface',
 'Pressure_tropopause',
 'Rain_mixing_ratio_hybrid',
 'Rain_mixing_ratio_isobaric',
 'Reflectivity_height_above_ground',
 'Reflectivity_hybrid',
 'Relative_humidity_entire_atmosphere_single_layer',
 'Relative_humidity_height_above_ground',
 'Relative_humidity_highest_tropospheric_freezing',
 'Relative_humidity_isobaric',
 'Relative_humidity_pressure_difference_layer',
 'Relative_humidity_sigma',
 'Relative_humidity_sigma_layer',
 'Relative_humidity_zeroDegC_isotherm',
 'Sensible_heat_net_flux_surface_Mixed_intervals_Average',
 'Snow_depth_surface',
 'Snow_mixing_ratio_hybrid',
 'Snow_mixing_ratio_isobaric',
 'Soil_temperature_depth_below_surface_layer',
 'Soil_type_surface',
 'Specific_humidity_height_above_ground',
 'Specific_humidity_isobaric',
 'Specific_humidity_pressure_difference_layer',
 'Storm_relative_helicity_height_above_ground_layer',
 'Sunshine_Duration_surface',
 'Surface_Lifted_Index_surface',
 'Surface_roughness_surface',
 'Temperature_altitude_above_msl',
 'Temperature_height_above_ground',
 'Temperature_high_cloud_top_Mixed_intervals_Average',
 'Temperature_isobaric',
 'Temperature_low_cloud_top_Mixed_intervals_Average',
 'Temperature_maximum_wind',
 'Temperature_middle_cloud_top_Mixed_intervals_Average',
 'Temperature_potential_vorticity_surface',
 'Temperature_pressure_difference_layer',
 'Temperature_sigma',
 'Temperature_surface',
 'Temperature_tropopause',
 'Total_cloud_cover_boundary_layer_cloud_Mixed_intervals_Average',
 'Total_cloud_cover_convective_cloud',
 'Total_cloud_cover_entire_atmosphere',
 'Total_cloud_cover_entire_atmosphere_Mixed_intervals_Average',
 'Total_cloud_cover_isobaric',
 'Total_ozone_entire_atmosphere_single_layer',
 'Total_precipitation_surface_Mixed_intervals_Accumulation',
 'U-Component_Storm_Motion_height_above_ground_layer',
 'Upward_Long-Wave_Radp_Flux_atmosphere_top_Mixed_intervals_Average',
 'Upward_Long-Wave_Radp_Flux_surface_Mixed_intervals_Average',
 'Upward_Short-Wave_Radiation_Flux_atmosphere_top_Mixed_intervals_Average',
 'Upward_Short-Wave_Radiation_Flux_surface_Mixed_intervals_Average',
 'V-Component_Storm_Motion_height_above_ground_layer',
 'Vegetation_surface',
 'Ventilation_Rate_planetary_boundary',
 'Vertical_Speed_Shear_potential_vorticity_surface',
 'Vertical_Speed_Shear_tropopause',
 'Vertical_velocity_geometric_isobaric',
 'Vertical_velocity_pressure_isobaric',
 'Vertical_velocity_pressure_sigma',
 'Visibility_surface',
 'Volumetric_Soil_Moisture_Content_depth_below_surface_layer',
 'Water_equivalent_of_accumulated_snow_depth_surface',
 'Water_runoff_surface_Mixed_intervals_Accumulation',
 'Wilting_Point_surface',
 'Wind_speed_gust_surface',
 'Zonal_Flux_of_Gravity_Wave_Stress_surface_Mixed_intervals_Average',
 'u-component_of_wind_altitude_above_msl',
 'u-component_of_wind_height_above_ground',
 'u-component_of_wind_isobaric',
 'u-component_of_wind_maximum_wind',
 'u-component_of_wind_planetary_boundary',
 'u-component_of_wind_potential_vorticity_surface',
 'u-component_of_wind_pressure_difference_layer',
 'u-component_of_wind_sigma',
 'u-component_of_wind_tropopause',
 'v-component_of_wind_altitude_above_msl',
 'v-component_of_wind_height_above_ground',
 'v-component_of_wind_isobaric',
 'v-component_of_wind_maximum_wind',
 'v-component_of_wind_planetary_boundary',
 'v-component_of_wind_potential_vorticity_surface',
 'v-component_of_wind_pressure_difference_layer',
 'v-component_of_wind_sigma',
 'v-component_of_wind_tropopause'}

这得有上百个变量了 看看可获取的时间范围

In [4]:

代码语言:javascript
复制
代码语言:javascript
复制
from datetime import datetime
query.lonlat_box(north=50, south=20, east=130, west=100).time(datetime(2022, 2, 18, 18))
query.accept('netcdf4')
query.variables('Temperature_surface')
data = ncss.get_data(query)
代码语言:javascript
复制
代码语言:javascript
复制
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-4-8830d7806601> in <module>
      3 query.accept('netcdf4')
      4 query.variables('Temperature_surface')
----> 5 data = ncss.get_data(query)

/opt/conda/lib/python3.9/site-packages/siphon/ncss.py in get_data(self, query)
    112 
    113         """
--> 114         resp = self.get_query(query)
    115         return response_handlers(resp, self.unit_handler)
    116 

/opt/conda/lib/python3.9/site-packages/siphon/http_util.py in get_query(self, query)
    408         """
    409         url = self._base[:-1] if self._base[-1] == '/' else self._base
--> 410         return self.get(url, query)
    411 
    412     def url_path(self, path):

/opt/conda/lib/python3.9/site-packages/siphon/http_util.py in get(self, path, params)
    490             else:
    491                 text = resp.text
--> 492             raise requests.HTTPError('Error accessing {0}\n'
    493                                      'Server Error ({1:d}: {2})'.format(resp.request.url,
    494                                                                         resp.status_code,

HTTPError: Error accessing https://thredds.ucar.edu/thredds/ncss/grid/grib/NCEP/GFS/Global_0p25deg/Best?var=Temperature_surface&time=2022-02-18T18%3A00%3A00&west=100&east=130&south=20&north=50&accept=netcdf4
Server Error (400: Requested time 2022-02-18T18:00:00Z does not intersect actual time range 2024-02-07T00:00:00Z - 2024-03-01T06:00:00Z)

提示Requested time 2022-02-18T18:00:00Z does not intersect actual time range 2024-02-07T00:00:00Z - 2024-03-01T06:00:00Z) 那就取最新的 2024-03-01T06:00:00Z试试

In [11]:

代码语言:javascript
复制
代码语言:javascript
复制
from datetime import datetime
query.lonlat_box(north=70, south=20, east=130, west=100).time(datetime(2024, 3, 1, 6))
query.accept('netcdf4')
query.variables('Snow_depth_surface')
data = ncss.get_data(query)
代码语言:javascript
复制

In [12]:

代码语言:javascript
复制
ds = ncss.get_data(query)
list(ds.variables)
代码语言:javascript
复制
['reftime',
 'latitude',
 'time',
 'longitude',
 'Snow_depth_surface',
 'LatLon_721X1440-0p13S-180p00E-2']

数据处理与绘图

In [15]:

代码语言:javascript
复制
代码语言:javascript
复制
from netCDF4 import num2date
import numpy as np
snow_var = data.variables['Snow_depth_surface']

# Time variables can be renamed in GRIB collections. Best to just pull it out of the

time_name = snow_var.coordinates.split()[1]
time_var = data.variables[time_name]
lat_var = data.variables['latitude']
lon_var = data.variables['longitude']
# Get the actual data values and remove any size 1 dimensions
snow_vals = snow_var[:].squeeze()
lat_vals = lat_var[:].squeeze()
lon_vals = lon_var[:].squeeze()

# Convert the number of hours since the reference time to an actual date
time_val = num2date(time_var[:].squeeze(), time_var.units)


# Combine 1D latitude and longitudes into a 2D grid of locations
lon_2d, lat_2d = np.meshgrid(lon_vals, lat_vals)
代码语言:javascript
复制

In [17]:

代码语言:javascript
复制
代码语言:javascript
复制
import cmaps
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
# Create a new figure with proper size
fig = plt.figure(figsize=(15, 12))

# Add the map and set the extent
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
ax.set_extent([100., 130., 23, 70])

# Add coastlines and country borders
ax.coastlines()

# Contour temperature at each lat/lon
cf = ax.contourf(lon_2d, lat_2d, snow_vals, 200, transform=ccrs.PlateCarree(), cmap=cmaps.precip4_11lev)

# Plot a colorbar to show temperature and reduce the size of it
plt.colorbar(cf, ax=ax, fraction=0.032)

# Make a title with the time value
ax.set_title('Snow_depth_surface for {:%d %B %Y %H:%MZ}'.format(time_val), fontsize=20)

# Plot markers for each lat/long to show grid points for 0.25 deg GFS
ax.plot(lon_2d.flatten(), lat_2d.flatten(), marker='o', color='black', markersize=2,
        alpha=0.3, transform=ccrs.Geodetic(), linestyle='none')

plt.show()
代码语言:javascript
复制
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2024-02-15,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 气python风雨 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • NCSS GFS 0.25 snowdepth
    • 数据获取
      • 数据处理与绘图
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档