Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use importlib as the import mode for pytest #3672

Merged
merged 5 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion esmvaltool/diag_scripts/aerosols/aod_aeronet_assess.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import matplotlib.pyplot as plt
import numpy as np
import scipy
from aero_utils import add_bounds, extract_pt
from matplotlib import colors, gridspec
from numpy import ma

from esmvaltool.diag_scripts.aerosols.aero_utils import add_bounds, extract_pt
from esmvaltool.diag_scripts.shared import group_metadata, run_diagnostic
from esmvaltool.diag_scripts.shared._base import get_plot_filename

Expand Down
16 changes: 8 additions & 8 deletions esmvaltool/diag_scripts/climate_patterns/climate_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@
"""

import logging
from pathlib import Path
import os
from pathlib import Path

import iris
import iris.coord_categorisation
import iris.cube
import numpy as np
import sklearn.linear_model

import sub_functions as sf
from plotting import (
plot_timeseries,
plot_patterns
)
from esmvalcore.preprocessor import (
area_statistics,
climate_statistics,
extract_time,
climate_statistics
)

import esmvaltool.diag_scripts.climate_patterns.sub_functions as sf
from esmvaltool.diag_scripts.climate_patterns.plotting import (
plot_patterns,
plot_timeseries,
)
from esmvaltool.diag_scripts.shared import run_diagnostic

Expand Down
11 changes: 9 additions & 2 deletions esmvaltool/diag_scripts/ensclus/ens_anom.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
"""Computation of ensemble anomalies based on a desired value."""

import os

import numpy as np
from scipy import stats

# User-defined packages
from read_netcdf import read_iris, save_n_2d_fields
from sel_season_area import sel_area, sel_season
from esmvaltool.diag_scripts.ensclus.read_netcdf import (
read_iris,
save_n_2d_fields,
)
from esmvaltool.diag_scripts.ensclus.sel_season_area import (
sel_area,
sel_season,
)


def ens_anom(filenames, dir_output, name_outputs, varname, numens, season,
Expand Down
4 changes: 2 additions & 2 deletions esmvaltool/diag_scripts/ensclus/ens_eof_kmeans.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from sklearn.cluster import KMeans

# User-defined libraries
from eof_tool import eof_computation
from read_netcdf import read_n_2d_fields
from esmvaltool.diag_scripts.ensclus.eof_tool import eof_computation
from esmvaltool.diag_scripts.ensclus.read_netcdf import read_n_2d_fields


def ens_eof_kmeans(dir_output, name_outputs, numens, numpcs, perc, numclus):
Expand Down
4 changes: 2 additions & 2 deletions esmvaltool/diag_scripts/ensclus/ens_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import math
import os

import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import numpy as np
import cartopy.crs as ccrs

# User-defined libraries
from read_netcdf import read_n_2d_fields
from esmvaltool.diag_scripts.ensclus.read_netcdf import read_n_2d_fields


def ens_plots(dir_output, dir_plot, name_outputs, numclus,
Expand Down
17 changes: 11 additions & 6 deletions esmvaltool/diag_scripts/ensclus/ensclus.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@
20170710-mavilia_irene: routines written.
"""

import os
import logging
import os

import numpy as np
from esmvaltool.diag_scripts.shared import group_metadata, run_diagnostic
from esmvaltool.diag_scripts.shared import ProvenanceLogger, sorted_metadata

# Import user diagnostic routines
from ens_anom import ens_anom
from ens_eof_kmeans import ens_eof_kmeans
from ens_plots import ens_plots
from esmvaltool.diag_scripts.ensclus.ens_anom import ens_anom
from esmvaltool.diag_scripts.ensclus.ens_eof_kmeans import ens_eof_kmeans
from esmvaltool.diag_scripts.ensclus.ens_plots import ens_plots
from esmvaltool.diag_scripts.shared import (
ProvenanceLogger,
group_metadata,
run_diagnostic,
sorted_metadata,
)

logger = logging.getLogger(os.path.basename(__file__))

Expand Down
2 changes: 1 addition & 1 deletion esmvaltool/diag_scripts/examples/correlate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from iris.analysis import MEAN
from iris.analysis.stats import pearsonr

from diagnostic import plot_diagnostic
from esmvaltool.diag_scripts.examples.diagnostic import plot_diagnostic
from esmvaltool.diag_scripts.shared import group_metadata, run_diagnostic

logger = logging.getLogger(os.path.basename(__file__))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import numpy as np
from iris import NameConstraint
from matplotlib import gridspec, rcParams
from poisson_solver import SphericalPoisson

from esmvaltool.diag_scripts.iht_toa.poisson_solver import SphericalPoisson
from esmvaltool.diag_scripts.shared import (
group_metadata,
run_diagnostic,
Expand Down
2 changes: 1 addition & 1 deletion esmvaltool/diag_scripts/mpqb/mpqb_lineplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import iris
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
from mpqb_utils import get_mpqb_cfg

import esmvaltool.diag_scripts.shared.iris_helpers as ih
from esmvaltool.diag_scripts.mpqb.mpqb_utils import get_mpqb_cfg
from esmvaltool.diag_scripts.shared import group_metadata, run_diagnostic
from esmvaltool.diag_scripts.shared._base import (
ProvenanceLogger,
Expand Down
2 changes: 1 addition & 1 deletion esmvaltool/diag_scripts/mpqb/mpqb_lineplot_anncyc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

import iris
import matplotlib.pyplot as plt
from mpqb_utils import get_mpqb_cfg

from esmvaltool.diag_scripts.mpqb.mpqb_utils import get_mpqb_cfg
from esmvaltool.diag_scripts.shared import group_metadata, run_diagnostic
from esmvaltool.diag_scripts.shared._base import (
ProvenanceLogger,
Expand Down
2 changes: 1 addition & 1 deletion esmvaltool/diag_scripts/mpqb/mpqb_lineplot_growthrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
import numpy as np
from mpqb_utils import get_mpqb_cfg

import esmvaltool.diag_scripts.shared.iris_helpers as ih
from esmvaltool.diag_scripts.mpqb.mpqb_utils import get_mpqb_cfg
from esmvaltool.diag_scripts.shared import group_metadata, run_diagnostic
from esmvaltool.diag_scripts.shared._base import (
ProvenanceLogger,
Expand Down
16 changes: 8 additions & 8 deletions esmvaltool/diag_scripts/weighting/climwip/calibrate_sigmas.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@
import matplotlib.pyplot as plt
import numpy as np
import xarray as xr
from core_functions import (
from scipy.optimize import brute

from esmvaltool.diag_scripts.shared import (
get_diagnostic_filename,
get_plot_filename,
)
from esmvaltool.diag_scripts.weighting.climwip.core_functions import (
area_weighted_mean,
calculate_model_distances,
calculate_weights,
combine_ensemble_members,
compute_overall_mean,
weighted_quantile,
)
from io_functions import (
from esmvaltool.diag_scripts.weighting.climwip.io_functions import (
read_metadata,
read_model_data,
read_model_data_ancestor,
)
from scipy.optimize import brute

from esmvaltool.diag_scripts.shared import (
get_diagnostic_filename,
get_plot_filename,
)

logger = logging.getLogger(os.path.basename(__file__))

Expand Down
18 changes: 10 additions & 8 deletions esmvaltool/diag_scripts/weighting/climwip/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@
import numpy as np
import seaborn as sns
import xarray as xr
from calibrate_sigmas import calibrate_performance_sigma
from core_functions import (

from esmvaltool.diag_scripts.shared import (
get_diagnostic_filename,
get_plot_filename,
run_diagnostic,
)
from esmvaltool.diag_scripts.weighting.climwip.calibrate_sigmas import (
calibrate_performance_sigma, )
from esmvaltool.diag_scripts.weighting.climwip.core_functions import (
area_weighted_mean,
calculate_model_distances,
calculate_weights,
combine_ensemble_members,
compute_overall_mean,
)
from io_functions import (
from esmvaltool.diag_scripts.weighting.climwip.io_functions import (
log_provenance,
read_metadata,
read_model_data,
Expand All @@ -27,11 +34,6 @@
read_observation_data_ancestor,
)

from esmvaltool.diag_scripts.shared import (
get_diagnostic_filename,
get_plot_filename,
run_diagnostic,
)

logger = logging.getLogger(os.path.basename(__file__))

Expand Down
3 changes: 2 additions & 1 deletion esmvaltool/diag_scripts/weighting/plot_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

import xarray as xr

from climwip.core_functions import weighted_quantile
from esmvaltool.diag_scripts.weighting.climwip.core_functions import (
weighted_quantile, )


def read_weights(filename: str) -> dict:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
import matplotlib.pyplot as plt
import numpy as np
import xarray as xr
from climwip.io_functions import log_provenance, read_model_data

from esmvaltool.diag_scripts.shared import (
get_diagnostic_filename,
get_plot_filename,
run_diagnostic,
)
from esmvaltool.diag_scripts.weighting.climwip.io_functions import (
log_provenance,
read_model_data,
)
from esmvaltool.diag_scripts.weighting.plot_utilities import (
calculate_percentiles,
read_metadata,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
import matplotlib.pyplot as plt
import numpy as np
from cartopy.mpl.ticker import LatitudeFormatter, LongitudeFormatter
from climwip.io_functions import log_provenance, read_model_data

from esmvaltool.diag_scripts.shared import (
get_diagnostic_filename,
get_plot_filename,
run_diagnostic,
)
from esmvaltool.diag_scripts.weighting.climwip.io_functions import (
log_provenance,
read_model_data,
)
from esmvaltool.diag_scripts.weighting.plot_utilities import (
calculate_percentiles,
read_metadata,
Expand Down
9 changes: 6 additions & 3 deletions esmvaltool/diag_scripts/zmnam/zmnam.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@

from esmvaltool.diag_scripts.shared import ProvenanceLogger, run_diagnostic
# Import zmnam diagnostic routines
from zmnam_calc import zmnam_calc
from zmnam_plot import zmnam_plot
from zmnam_preproc import (zmnam_preproc, zmnam_preproc_clean)
from esmvaltool.diag_scripts.zmnam.zmnam_calc import zmnam_calc
from esmvaltool.diag_scripts.zmnam.zmnam_plot import zmnam_plot
from esmvaltool.diag_scripts.zmnam.zmnam_preproc import (
zmnam_preproc,
zmnam_preproc_clean,
)

logger = logging.getLogger(__name__)

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[tool:pytest]
addopts =
--import-mode=importlib
--doctest-modules
--ignore=doc/sphinx/source/conf.py
--cov=esmvaltool
Expand Down