常规更新
This commit is contained in:
@ -2,11 +2,24 @@
|
||||
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
import skgstat as skg
|
||||
from scipy import integrate
|
||||
import os
|
||||
|
||||
from . import plotting
|
||||
|
||||
# Set matplotlib backend before importing anything that might use it
|
||||
os.environ['MPLBACKEND'] = 'Agg'
|
||||
|
||||
# Import matplotlib and set backend explicitly
|
||||
try:
|
||||
import matplotlib
|
||||
matplotlib.use('Agg')
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
# Import scikit-gstat
|
||||
import skgstat as skg
|
||||
|
||||
|
||||
def simpsonintegrate(array: np.ndarray, x_cell_size: float, y_cell_size: float) -> float:
|
||||
"""Function to obtain the volume of the krig in kgh⁻¹, i.e. the cut-fill volume
|
||||
@ -42,7 +55,6 @@ def ordinary_kriging(
|
||||
):
|
||||
"""Function to calculate the ordinary kriging of a gas in a dataframe, after calculating a semivariogram."""
|
||||
gasflux = f"{gas}_kg_h_m2"
|
||||
skg.plotting.backend("plotly") # type: ignore
|
||||
cut_ground = ordinary_kriging_settings["cut_ground"]
|
||||
semivariogram = directional_gas_semivariogram(df, x, y, gasflux, semivariogram_filter, **semivariogram_settings)
|
||||
ok = skg.OrdinaryKriging(
|
||||
@ -87,8 +99,11 @@ def ordinary_kriging(
|
||||
# np.nan_to_num(error_1s, copy=False, nan=0)
|
||||
volume_error = simpsonintegrate(error_1s, x_cell_size, y_cell_size)
|
||||
|
||||
contour_plot = plotting.contour_krig(df=df, gas=gas, xx=xx, yy=yy, field=field, x=x, y=y, cut_ground=cut_ground)
|
||||
grid_plot = plotting.heatmap_krig(xx, yy, field)
|
||||
# Plots disabled
|
||||
contour_plot = None
|
||||
grid_plot = None
|
||||
semivariogram_plot = None
|
||||
|
||||
output_text = (
|
||||
f"The emissions flux of {gas.upper()} is {volume:.3f}kgh⁻¹; "
|
||||
f"the cut and fill volumes of the grid are {volumepos:.3f} and {volumeneg:.3f}kgh⁻¹. "
|
||||
@ -107,7 +122,6 @@ def ordinary_kriging(
|
||||
"error field (1 sigma)": error_1s,
|
||||
"volume_error": volume_error,
|
||||
}
|
||||
semivariogram_plot = semivariogram.plot(show=False)
|
||||
|
||||
return krig_variables, output_text, contour_plot, grid_plot, semivariogram_plot
|
||||
|
||||
|
||||
Reference in New Issue
Block a user