Post-processing#
ddeq provides functions for post-processing, which includes methods for estimating annual emissions from individual estimates, for converting NO2 to NOx emissions, for visualizing the results and for writing data output in standardized NetCDF format.
NO2 to NOx conversion#
To convert NO2 to NOx emissions the following function can be used that scales all fields starting with “NO2” that have units of “kg s-1” with a scaling factor:
- ddeq.emissions.convert_NO2_to_NOx_emissions(results, f=1.32)#
Convert NO2 fluxes/emissions (i.e. units: “kg s-1”) to NOx fluxes/emissions using the NO2 to NOx conversion factor assuming that a fraction of NOx is in is nitrogen monoxide.
- Parameters:
results (xr.Dataset) – Results dataset with estimated emissions.
f (float, optional) – The scaling factor using a default value of 1.32.
- Returns:
The results dataset with added variables for NOx emissions.
- Return type:
xr.Dataset
Annual emissions#
Methods that are applied to individual images (i.e. GP, CSF, LCSF and IME) provide emission estimates at measurement time. A time series of individual estimates can be extrapolated to annual emissions fitting a seasonal cycle. A detailed example is available here. The following function can be used
- ddeq.timeseries.fit(times, ts, ts_std, n_knots=None, gamma=None, use_std=True, last_years_value=None)#
Fit periodic C-spline to indvidual emission estimates, which can be used to estimate the seasonal cycle of the emissions and for computing the annual total and its uncertainty. The function does not account for temporal sampling biases.
- Parameters:
times (pd.datetime) – The times of the individual emission estimates.
ts (np.array) – Individual emission estimates at the given times.
ts_std (np.array) – Uncertainty of individual emission estimates (one standard deviation) at given times.
n_knots (integer, optional) – Number of knots used in the C-spline. By default uses n_years*3 + 1.
gamma (float, optional) – If given, the fit will additional constraint by minimzing the difference between the sum of absolute differences between the control points scaled by gamma.
- Returns:
OptimizeResult – Results from the least square fit.
SeasonalCycle – Data class with the individual estimates and their uncertainties.
np.array – Array with seconds since starting time every hour.
np.array – Seasonal cycle at seconds since starting time.
float – chi2 value of the fit.
Visualization#
A large number of functions are provided that can be used to visualize the results from the different methods. The functions below are the main function for plotting the results of GP, CSF, LCSF and DIV method. More examples for plotting results are shown in several Jupyter Notebooks.
- ddeq.vis.plot_gauss_result(data, results, sources, gas, curves, domain=None, crs=None, vmin=None, vmax=None)#
Plot results from Gaussian plume inversion.
- Parameters:
data (xr.Dataset) – Remote sensing dataset
results (xr.Dataset) – Results from Gaussian plume inversion.
sources (list) – List of names of sources in data and results.
gas (str) – Name of gas (e.g., “CO2” or “NO2”).
curves (dict) – Dictionary with center curves.
domain (ddeq.misc.Domain) – The plotting region. If given as None, domain expand will be created from lon and lat variable in data.
crs (cartopy.crs) – The coordinate reference system used for the center curves.
vmin (float) – Minimum value on colorbar (in kg m-2).
vmax (float) – Maximum value on colorbar (in kg m-2).
- Return type:
plt.figure
- ddeq.vis.plot_csf_result(gases, data, winds, line_densities, curves, source, domain=None, crs=None, scalings=None, vmins=None, vmaxs=None)#
Plot results from cross sectional flux method.
- Parameters:
gases (list of str) – List of maximum two gases.
data (xr.Dataset) – Remote sensing dataset.
winds (xr.Dataset) – Wind dataset at each source.
line_densities (xr.Dataset) – Results from cross sectional flux method.
curves (dict) – Dictionary with center curves.
source (str) – Name of sources in data and results.
domain (ddeq.misc.Domain) – The plotting region. If given as None, domain expand will be created from lon and lat variable in data.
crs (cartopy.crs) – The coordinate reference system used for the center curves.
scalings (list of floats) – Scaling applied to data[gas] for plotting.
vmins (list of floats) – Minimum values on colorbar for given gases.
vmaxs (list of floats) – Maximum values on colorbar for given gases.
- Return type:
plt.figure
- ddeq.vis.plot_lcsf_result(source_name, results, data, sources, gases, true_emis=None, domain=None, vmin=None, vmax=None)#
Plot results from the light cross-sectional method (LCSF) method for a given source.
- Parameters:
source_name (str) – Name of the source whose results are shown
results (xr.Dataset) – Result dataset from the LCSF method.
data (xr.Dataset) – Remote sensing data
gases (str or list of str) – List of trace gases.
true_emis (dict, optional) – If not None should be a dictionary with true emissions for given gases.
domain (ddeq.misc.Domain, optional) – The plotting region. If given as None, domain will be created from lat and lat variable in data.
vmin (float, optional) – Minimum value for colorbar.
vmax (float, optional) – Maximum value for colorbar.
- Return type:
plt.figure
- ddeq.vis.plot_divergence_maps(NOx_div, CO2_div, center_lon, center_lat, lon_km=50.0, lat_km=50.0, grid_reso=50.0, sources=None, ms=5, fontsize='x-large', cbar_fraction=0.051)#
Plot results from divergence method.
- Parameters:
NOx_div (np.array) – NOx divergence map (in g/m2/s)
CO2_div (np.array) – CO2 divergence map (in g/m2/s).
center_lon (float) – Longitude of source.
center_lat (float) – Latitude of source.
lon_km (float, optional) – The east-west extension of the grid around a source in kilometers.
lat_km (float, optional) – The south-north extension of the grid around a source in kilometers.
grid_reso (float, optional) – The resolution of the grid in kilometers.
sources (xr.Dataset) – Dataset with source locations.
ms (int) – Size of point source markers.
fontsize (str, optional) – Font size in plot.
cbar_fraction (float, optional) – Fraction of colorbar.
- Return type:
plt.Figure