### Install metdig from source Source: https://github.com/nmcdev/metdig/blob/main/README.md Clone the metdig repository and install it locally using setup.py. This method is useful for development or when installing from a downloaded archive. ```bash git clone --recursive https://github.com/nmcdev/metdig.git cd metdig python setup.py install ``` -------------------------------- ### Install metdig from GitHub repository Source: https://github.com/nmcdev/metdig/blob/main/README.md Install metdig directly from its GitHub repository using pip. This command clones the repository and installs the package. ```bash pip install git+git://github.com/nmcdev/metdig.git ``` -------------------------------- ### Install Cartopy and metdig via pip Source: https://github.com/nmcdev/metdig/blob/main/README.md Use this command to install Cartopy from conda-forge, followed by metdig via pip. Ensure you are in a suitable conda environment. ```bash conda install -c conda-forge cartopy=0.19.0 pip install metdig ``` -------------------------------- ### Extract Vertical Cross-Section Data Source: https://context7.com/nmcdev/metdig/llms.txt Extracts vertical cross-section data along a specified path using 3D grid data. Requires defining start and end points as [lat, lon] coordinates. ```python import metdig.cal as mdgcal import metdig.io as mdgio from datetime import datetime init_time = datetime(2023, 7, 15, 8) levels = [1000, 925, 850, 700, 500, 300, 200] # Read 3D data rh = mdgio.get_model_3D_grid( data_source='cassandra', data_name='ecmwf', init_time=init_time, fhour=24, var_name='rh', levels=levels, extent=[100, 140, 20, 50] ) tmp = mdgio.get_model_3D_grid( data_source='cassandra', data_name='ecmwf', init_time=init_time, fhour=24, var_name='tmp', levels=levels, extent=[100, 140, 20, 50] ) # Define cross-section path st_point = [30, 110] # Start point [lat, lon] ed_point = [40, 130] # End point [lat, lon] # Extract cross-section cross_rh = mdgcal.cross_section(rh, st_point, ed_point) cross_tmp = mdgcal.cross_section(tmp, st_point, ed_point) print(f"Cross-section shape: {cross_rh.shape}") ``` -------------------------------- ### Initialize Data Source Connections Source: https://context7.com/nmcdev/metdig/llms.txt Configure connections to various meteorological data services including CMADaaS, MICAPS, THREDDS, and Copernicus CDS. Ensure all required credentials and server details are provided. ```python import metdig.io as mdgio # Initialize data source configurations mdgio.config_init( CMADaaS_DNS='xxx.xxx.xxx.xxx', # CMADaaS server IP CMADaaS_PORT='xxx', # CMADaaS port CMADaaS_USER_ID='your_user_id', # CMADaaS user ID CMADaaS_PASSWORD='your_password', # CMADaaS password CMADaaS_serviceNodeId='node_id', # CMADaaS service node ID MICAPS_GDS_IP='xxx.xxx.xxx.xxx', # MICAPS GDS server IP MICAPS_GDS_PORT='xxx', # MICAPS GDS port THREDDS_IP='xxx.xxx.xxx.xxx', # THREDDS server IP THREDDS_PORT='xxx', # THREDDS port CDS_API_TOKEN='your_cds_token', # Copernicus CDS API token CACHE_DIR='/path/to/cache' # Local cache directory ) ``` -------------------------------- ### Generate Height, Wind, and Precipitation Analysis Source: https://context7.com/nmcdev/metdig/llms.txt Produces weather charts visualizing geopotential height, wind barbs, and precipitation accumulation. The atime parameter specifies the accumulation period in hours. ```python import metdig.onestep as mdgonestep from datetime import datetime import matplotlib.pyplot as plt # Generate 500hPa height + 850hPa wind + precipitation chart result = mdgonestep.hgt_uv_rain( data_source='cassandra', data_name='ecmwf', init_time=datetime(2023, 7, 15, 8), fhour=24, atime=6, # Precipitation accumulation period (hours) hgt_lev=500, # Height contour level uv_lev=850, # Wind barbs level is_mask_terrain=True, area='华北', # Analysis area is_return_data=True, is_draw=True, output_dir='/path/to/output', png_name='hgt_wind_rain.png' ) plt.show() ``` -------------------------------- ### Analyze Temperature Extremes Source: https://context7.com/nmcdev/metdig/llms.txt Visualizes 24-hour maximum and minimum temperature forecasts. Requires specific data sources like 'nwfd_scmoc'. ```python import metdig.onestep as mdgonestep from datetime import datetime import matplotlib.pyplot as plt # Generate 24-hour maximum temperature chart result_max = mdgonestep.t2m_mx24( data_source='cassandra', data_name='nwfd_scmoc', init_time=datetime(2023, 7, 15, 8), fhour=24, area='全国', is_return_data=True, is_draw=True, output_dir='/path/to/output', png_name='t2m_max24.png' ) # Generate 24-hour minimum temperature chart result_min = mdgonestep.t2m_mn24( data_source='cassandra', data_name='nwfd_scmoc', init_time=datetime(2023, 7, 15, 8), fhour=24, area='全国', is_return_data=True, is_draw=True, output_dir='/path/to/output', png_name='t2m_min24.png' ) plt.show() ``` -------------------------------- ### Create Skew-T Log-P Diagram Source: https://context7.com/nmcdev/metdig/llms.txt Generates a Skew-T Log-P diagram for thermodynamic soundings. Initializes a SkewT composition object with a title and output parameters, then allows plotting of profiles. ```python import metdig.graphics.draw_compose as dc import metdig.io as mdgio from datetime import datetime import matplotlib.pyplot as plt # Create Skew-T composition skew_obj = dc.skewt_compose( title='Model Sounding', description='Beijing 2023-07-15 08UTC', output_dir='/path/to/output', png_name='skewt_diagram.png' ) # The skew object provides access to: # - skew_obj.fig: matplotlib figure # - skew_obj.skew: SkewT object for plotting profiles # Save composition result = skew_obj.save() ``` -------------------------------- ### Generate Time-Height Cross-Section with Divergence and Vorticity Source: https://context7.com/nmcdev/metdig/llms.txt Generates a time-height cross-section displaying divergence, vorticity, relative humidity, and wind. Requires specifying data source, initialization time, forecast hours, levels, and geographical points. ```python result_dv = mdgonestep.time_div_vort_rh_uv( data_source='cassandra', data_name='ecmwf', init_time=datetime(2023, 7, 15, 8), fhours=range(0, 72, 3), levels=[1000, 925, 850, 700, 500, 300], points={'lon': [120], 'lat': [30]}, is_draw=True ) plt.show() ``` -------------------------------- ### Read Multi-Level 3D Model Grid Data Source: https://context7.com/nmcdev/metdig/llms.txt Retrieve 3D model data (e.g., temperature, wind components) across multiple pressure levels for a single time step. Specify the data source, model name, initialization time, forecast hour, variable name, a list of pressure levels, and geographic extent. ```python import metdig.io as mdgio from datetime import datetime # Read multi-level 3D grid data for a single time levels = [1000, 925, 850, 700, 500, 300, 200] tmp_3d = mdgio.get_model_3D_grid( data_source='cassandra', data_name='ecmwf', init_time=datetime(2023, 7, 15, 8), fhour=24, var_name='tmp', # Temperature levels=levels, # Multiple pressure levels extent=[100, 130, 20, 50] ) # Read u and v wind components u_3d = mdgio.get_model_3D_grid( data_source='cassandra', data_name='ecmwf', init_time=datetime(2023, 7, 15, 8), fhour=24, var_name='u', levels=levels, extent=[100, 130, 20, 50] ) v_3d = mdgio.get_model_3D_grid( data_source='cassandra', data_name='ecmwf', init_time=datetime(2023, 7, 15, 8), fhour=24, var_name='v', levels=levels, extent=[100, 130, 20, 50] ) print(f"3D Temperature shape: {tmp_3d.shape}") ``` -------------------------------- ### Read Single-Level Model Grid Data Source: https://context7.com/nmcdev/metdig/llms.txt Retrieve single-level, single-time model grid data from specified sources like 'cassandra', 'cmadaas', 'cds', or 'thredds'. Requires model name, initialization time, forecast hour, variable name, pressure level, and geographic extent. ```python import metdig.io as mdgio from datetime import datetime # Read single-level, single-time grid data hgt_500 = mdgio.get_model_grid( data_source='cassandra', # Data source: cassandra, cmadaas, cds, thredds, custom data_name='ecmwf', # Model name: ecmwf, cma_gfs, etc. init_time=datetime(2023, 7, 15, 8), # Model initialization time fhour=24, # Forecast hour var_name='hgt', # Variable name: hgt, tmp, u, v, rh, etc. level=500, # Pressure level (hPa) extent=[60, 145, 15, 55] # Geographic extent [lon_min, lon_max, lat_min, lat_max] ) print(f"Data shape: {hgt_500.shape}") print(f"Variable units: {hgt_500.attrs['var_units']}") ``` -------------------------------- ### Generate Synoptic Composite Analysis Source: https://context7.com/nmcdev/metdig/llms.txt Creates comprehensive synoptic charts combining multiple meteorological fields like height, wind, and vorticity. Set is_return_data to True to access the underlying data dictionary. ```python import metdig.onestep as mdgonestep from datetime import datetime import matplotlib.pyplot as plt # Generate synoptic composite chart with 500hPa height, # 850hPa wind, 200hPa jet, vorticity, MSLP, and TCWV result = mdgonestep.syn_composite( data_source='cassandra', data_name='ecmwf', init_time=datetime(2023, 7, 15, 8), fhour=24, hgt_lev=500, # Geopotential height level uv_lev=850, # Wind barbs level wsp_lev=200, # Wind speed (jet) level vort_lev=500, # Vorticity level is_mask_terrain=True, # Mask terrain-blocked regions area='全国', # Analysis area (China) is_return_data=True, # Return data for further analysis is_draw=True, # Generate visualization add_city=True, # Add city markers output_dir='/path/to/output', png_name='synoptic_composite.png' ) plt.show() # Access returned data if 'data' in result: hgt = result['data']['hgt'] prmsl = result['data']['prmsl'] ``` -------------------------------- ### Read Multi-Time Model Grid Data Source: https://context7.com/nmcdev/metdig/llms.txt Retrieve model data for multiple forecast hours for time-series analysis. This can be single-level data (e.g., 2-meter temperature) or multi-level 3D data (e.g., temperature at various pressure levels). Specify a range or array of forecast hours. ```python import metdig.io as mdgio from datetime import datetime import numpy as np # Read single-level, multi-time grid data fhours = np.arange(0, 73, 3) # 0 to 72 hours, 3-hour intervals t2m_series = mdgio.get_model_grids( data_source='cassandra', data_name='ecmwf', init_time=datetime(2023, 7, 15, 8), fhours=fhours, # Multiple forecast hours var_name='t2m', # 2-meter temperature extent=[100, 130, 20, 50] ) # Read multi-level, multi-time 3D grid data levels = [850, 500, 200] tmp_4d = mdgio.get_model_3D_grids( data_source='cassandra', data_name='ecmwf', init_time=datetime(2023, 7, 15, 8), fhours=np.arange(0, 49, 6), var_name='tmp', levels=levels, extent=[100, 130, 20, 50] ) print(f"4D data dimensions: {tmp_4d.dims}") ``` -------------------------------- ### Calculate Moisture Diagnostics Source: https://context7.com/nmcdev/metdig/llms.txt Computes dewpoint, specific humidity, and equivalent potential temperature from temperature and relative humidity. Requires reading temperature and relative humidity at a specific level and extent. The output includes units and ranges. ```python import metdig.cal as mdgcal import metdig.io as mdgio import metdig.utl as mdgstda from datetime import datetime init_time = datetime(2023, 7, 15, 8) # Read temperature and relative humidity tmp = mdgio.get_model_grid( data_source='cassandra', data_name='ecmwf', init_time=init_time, fhour=24, var_name='tmp', level=850, extent=[100, 130, 20, 50] ) rh = mdgio.get_model_grid( data_source='cassandra', data_name='ecmwf', init_time=init_time, fhour=24, var_name='rh', level=850, extent=[100, 130, 20, 50] ) # Calculate dewpoint from relative humidity td = mdgcal.dewpoint_from_relative_humidity(tmp, rh) # Calculate specific humidity from dewpoint pressure = mdgstda.gridstda_full_like_by_levels(td, [850]) spfh = mdgcal.specific_humidity_from_dewpoint(pressure, td) print(f"Specific humidity units: {spfh.attrs['var_units']}") # Calculate equivalent potential temperature theta_e = mdgcal.equivalent_potential_temperature(pressure, tmp, td) print(f"Theta-e range: {float(theta_e.min()):.1f} - {float(theta_e.max()):.1f} K") ``` -------------------------------- ### Generate Wind, Theta, and Vorticity Cross-Section Source: https://context7.com/nmcdev/metdig/llms.txt Generates a cross-section plot showing wind, equivalent potential temperature, and specific humidity. Requires specifying data source, initialization time, forecast hour, levels, start/end points, and averaging windows. Can optionally mask terrain and return data. ```python result = mdgonestep.wind_theta_spfh( data_source='cassandra', data_name='ecmwf', init_time=datetime(2023, 7, 15, 8), fhour=24, levels=[1000, 950, 925, 900, 850, 800, 700, 600, 500, 400, 300, 200], st_point=[25, 110], # Start point [lat, lon] ed_point=[40, 125], # End point [lat, lon] lon_mean=1.0, # Longitude averaging window (degrees) lat_mean=1.0, # Latitude averaging window (degrees) is_mask_terrain=True, area='华东', is_return_data=True, is_draw=True, output_dir='/path/to/output', png_name='cross_theta_spfh.png' ) plt.show() ``` ```python result_vort = mdgonestep.wind_theta_vort( data_source='cassandra', data_name='ecmwf', init_time=datetime(2023, 7, 15, 8), fhour=24, levels=[1000, 925, 850, 700, 500, 300, 200], st_point=[25, 110], ed_point=[40, 125], is_draw=True ) plt.show() ``` -------------------------------- ### Create Custom Horizontal Map Composition Source: https://context7.com/nmcdev/metdig/llms.txt Composes a custom horizontal map with multiple overlays, such as height contours and wind barbs. Requires reading data for different variables and levels, then using the graphics module to add elements. ```python import metdig.graphics.draw_compose as dc import metdig.graphics.contourf_method as cm import metdig.graphics.contour_method as ct import metdig.graphics.barbs_method as bm import metdig.io as mdgio import metdig.cal as mdgcal from datetime import datetime import matplotlib.pyplot as plt init_time = datetime(2023, 7, 15, 8) # Read data hgt = mdgio.get_model_grid( data_source='cassandra', data_name='ecmwf', init_time=init_time, fhour=24, var_name='hgt', level=500, extent=[60, 145, 15, 55] ) u = mdgio.get_model_grid( data_source='cassandra', data_name='ecmwf', init_time=init_time, fhour=24, var_name='u', level=850, extent=[60, 145, 15, 55] ) v = mdgio.get_model_grid( data_source='cassandra', data_name='ecmwf', init_time=init_time, fhour=24, var_name='v', level=850, extent=[60, 145, 15, 55] ) wsp = mdgcal.other.wind_speed(u, v) # Create horizontal composition obj = dc.horizontal_compose( map_extent=(60, 145, 15, 55), description='500hPa Height + 850hPa Wind', output_dir='/path/to/output', png_name='custom_composite.png', figsize=(16, 12) ) # Add wind speed shading cm.wind_speed_pcolormesh(obj.ax, wsp) # Add height contours ct.hgt_contour(obj.ax, hgt, levels=range(5400, 5900, 40)) # Add wind barbs bm.uv_barbs(obj.ax, u, v, regrid_shape=20) # Save and display obj.save() plt.show() ``` -------------------------------- ### Generate Time-Height Cross-Section of RH, Wind, and Theta Source: https://context7.com/nmcdev/metdig/llms.txt Creates a time-height cross-section showing relative humidity, wind, and theta. Requires specifying data source, initialization time, forecast hours, levels, and geographical points. Can mask terrain and return data. ```python import metdig.onestep as mdgonestep from datetime import datetime import matplotlib.pyplot as plt # Time-height cross-section of RH, wind, and theta result = mdgonestep.time_rh_uv_theta( data_source='cassandra', data_name='ecmwf', init_time=datetime(2023, 7, 15, 8), fhours=range(0, 72, 3), # Forecast hours levels=[1000, 925, 850, 700, 500, 300, 200], points={'lon': [116.4], 'lat': [39.9]}, # Beijing coordinates mean_area=1.0, # Area averaging radius (degrees) is_mask_terrain=True, is_return_data=True, is_draw=True, output_dir='/path/to/output', png_name='time_height_rh_theta.png' ) plt.show() ``` -------------------------------- ### Read Multi-Time Station Observation Data Source: https://context7.com/nmcdev/metdig/llms.txt Reads surface observation data for multiple time points from a specified data source. Requires specifying a list of observation times, data name, variable name, and geographic extent. ```python obs_series = mdgio.get_obs_stations_multitime( data_source='cassandra', times=[datetime(2023, 7, 15, i) for i in range(0, 24, 3)], data_name='sfc_chn_hor', var_name='TEM', extent=[100, 130, 20, 50] ) ``` -------------------------------- ### Read Single-Time Station Observation Data Source: https://context7.com/nmcdev/metdig/llms.txt Reads surface observation data for a single time point from a specified data source. Requires specifying the observation time, data name, variable name, and geographic extent. ```python obs_data = mdgio.get_obs_stations( data_source='cassandra', obs_time=datetime(2023, 7, 15, 8), data_name='sfc_chn_hor', # Surface observation data type var_name='TEM', # Temperature variable extent=[100, 130, 20, 50] ) ``` -------------------------------- ### Set Log Level for Debugging Source: https://context7.com/nmcdev/metdig/llms.txt Configures the logging level for the MetDig library to 'debug' to enable detailed output for troubleshooting data retrieval and computation issues. This setting affects subsequent operations. ```python import metdig # Set log level for debugging metdig.set_loglevel('debug') # Options: notset, debug, info, warning, error, critical # Now all metdig operations will output detailed logs import metdig.io as mdgio from datetime import datetime data = mdgio.get_model_grid( data_source='cassandra', data_name='ecmwf', init_time=datetime(2023, 7, 15, 8), fhour=24, var_name='hgt', level=500 ) ``` -------------------------------- ### Calculate Potential Vorticity Source: https://context7.com/nmcdev/metdig/llms.txt Computes baroclinic potential vorticity (PVU) using temperature, pressure, and wind components. Requires reading temperature, U, and V wind fields at specified levels and extent. The output includes units. ```python import metdig.cal as mdgcal import metdig.io as mdgio import metdig.utl as mdgstda from datetime import datetime levels = [700, 500, 300, 200] init_time = datetime(2023, 7, 15, 8) # Read required fields tmp = mdgio.get_model_3D_grid( data_source='cassandra', data_name='ecmwf', init_time=init_time, fhour=24, var_name='tmp', levels=levels, extent=[100, 130, 20, 50] ) u = mdgio.get_model_3D_grid( data_source='cassandra', data_name='ecmwf', init_time=init_time, fhour=24, var_name='u', levels=levels, extent=[100, 130, 20, 50] ) v = mdgio.get_model_3D_grid( data_source='cassandra', data_name='ecmwf', init_time=init_time, fhour=24, var_name='v', levels=levels, extent=[100, 130, 20, 50] ) # Create pressure field and calculate potential temperature pressure = mdgstda.gridstda_full_like_by_levels(tmp, levels) theta = mdgcal.potential_temperature(pressure, tmp) # Calculate baroclinic potential vorticity (PVU) pv = mdgcal.potential_vorticity_baroclinic(theta, pressure, u, v) print(f"PV units: {pv.attrs['var_units']}") ``` -------------------------------- ### Calculate Vorticity and Divergence Source: https://context7.com/nmcdev/metdig/llms.txt Computes vorticity and divergence from U and V wind components. Ensure U and V are read with appropriate levels and extent. The output includes units and maximum values. ```python import metdig.cal as mdgcal import metdig.io as mdgio from datetime import datetime # Read wind components levels = [850, 500] u = mdgio.get_model_3D_grid( data_source='cassandra', data_name='ecmwf', init_time=datetime(2023, 7, 15, 8), fhour=24, var_name='u', levels=levels, extent=[100, 130, 20, 50] ) v = mdgio.get_model_3D_grid( data_source='cassandra', data_name='ecmwf', init_time=datetime(2023, 7, 15, 8), fhour=24, var_name='v', levels=levels, extent=[100, 130, 20, 50] ) # Calculate vorticity (1/s) vort = mdgcal.vorticity(u, v) print(f"Vorticity units: {vort.attrs['var_units']}") # Calculate absolute vorticity (includes planetary vorticity) absv = mdgcal.absolute_vorticity(u, v) # Calculate divergence (1/s) div = mdgcal.divergence(u, v) print(f"Divergence max: {float(div.max()):.2e}") ``` -------------------------------- ### Calculate Advection Source: https://context7.com/nmcdev/metdig/llms.txt Computes horizontal advection of a scalar variable using wind components. Requires reading the scalar variable (e.g., temperature) and U, V wind components at a specific level and extent. The output includes units. ```python import metdig.cal as mdgcal import metdig.io as mdgio from datetime import datetime init_time = datetime(2023, 7, 15, 8) level = 850 # Read temperature and wind tmp = mdgio.get_model_grid( data_source='cassandra', data_name='ecmwf', init_time=init_time, fhour=24, var_name='tmp', level=level, extent=[100, 130, 20, 50] ) u = mdgio.get_model_grid( data_source='cassandra', data_name='ecmwf', init_time=init_time, fhour=24, var_name='u', level=level, extent=[100, 130, 20, 50] ) v = mdgio.get_model_grid( data_source='cassandra', data_name='ecmwf', init_time=init_time, fhour=24, var_name='v', level=level, extent=[100, 130, 20, 50] ) # Calculate temperature advection tmp_adv = mdgcal.var_advect(tmp, u, v) print(f"Temperature advection units: {tmp_adv.attrs['var_units']}") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.