Scores

Deterministic scores

Created on 20 March 2018

@author: lafaysse

class scores.deterministic.DeterministicScores_CommonObs(obs_common, mask_sim, sim)[source]

Bases: DeterminsticScores

Constructor for observations and simulations covering different periods,

observations and simulation masks provided

Parameters:
  • obs_common – observations

  • mask_sim – mask for simulation data

  • sim – simulations data

property bias

Relative bias

diff()

Vector of difference between simulations and observations

property mae

Mean absolute error

property meanobs

Mean observation value over the common period.

property meansim

Mean simulation value over the common period.

nvalues()

Number of values accounted for in scores computation

read_sim_ifpresent(data_nc, varname)

read a variable from the simulation file if the variable is present in there. :param data_nc: open netcdf dataset :type data_nc: prosimu :param varname: variable name of the variable to be read :type varname: str :return: array with requested data

read_var_ifpresent(data_nc, varname, convert1d=False)

read a given variable from a netcdf file if it is present in the file. If the variable is not present under the given variable name, check if it is present under an alternate name from ESMSnowMIP.

Parameters:
  • data_nc (prosimu) – dataset to read in

  • varname (str) – variable name

  • convert1d

Returns:

Numpy data array containing the data of the selected variable, or an array filled with np.nan if the requested variable was not present in the file.

Return type:

numpy array

property rmse

Root mean square error

scores_all_values()

calculate scores (bias and RMSE) including cases of 0 values (no snow for example) :return: number of values, bias, RMSE, mean value of simulations

scores_with_positive_values_only()

calculate scores (bias and RMSE) excluding cases where both the observation and the simulation have a value of 0 :return: number of values, bias, RMSE, mean value of simulations

squarediff()

Vector of square difference between simulations and observations

class scores.deterministic.DeterministicScores_Heterogeneous(time_obs, time_sim, obs, sim)[source]

Bases: DeterministicScores_Mask

Constructor for observations and simulations covering different periods, times provided

Parameters:
  • time_obs – array of observation times

  • time_sim – array of simulation times

  • obs – array of observation values

  • sim – array of simulation values

property bias

Relative bias

diff()

Vector of difference between simulations and observations

extract_common_vectors(time_obs, time_sim, obs, sim)[source]

Extract common date between observations and simulations selecting only winter periods. :param time_obs: array of observation times :param time_sim: array of simulation times :param obs: array of observation values :param sim: array of simulation values :return:

property mae

Mean absolute error

property meanobs

Mean observation value over the common period.

property meansim

Mean simulation value over the common period.

nvalues()

Number of values accounted for in scores computation

read_sim_ifpresent(data_nc, varname)

read a variable from the simulation file if the variable is present in there. :param data_nc: open netcdf dataset :type data_nc: prosimu :param varname: variable name of the variable to be read :type varname: str :return: array with requested data

read_var_ifpresent(data_nc, varname, convert1d=False)

read a given variable from a netcdf file if it is present in the file. If the variable is not present under the given variable name, check if it is present under an alternate name from ESMSnowMIP.

Parameters:
  • data_nc (prosimu) – dataset to read in

  • varname (str) – variable name

  • convert1d

Returns:

Numpy data array containing the data of the selected variable, or an array filled with np.nan if the requested variable was not present in the file.

Return type:

numpy array

property rmse

Root mean square error

scores_all_values()

calculate scores (bias and RMSE) including cases of 0 values (no snow for example) :return: number of values, bias, RMSE, mean value of simulations

scores_with_positive_values_only()

calculate scores (bias and RMSE) excluding cases where both the observation and the simulation have a value of 0 :return: number of values, bias, RMSE, mean value of simulations

squarediff()

Vector of square difference between simulations and observations

class scores.deterministic.DeterministicScores_Homogeneous(obs, sim)[source]

Bases: DeterminsticScores

Constructor for observations and simulations covering the same periods

property bias

Relative bias

diff()

Vector of difference between simulations and observations

property mae

Mean absolute error

property meanobs

Mean observation value over the common period.

property meansim

Mean simulation value over the common period.

nvalues()

Number of values accounted for in scores computation

read_sim_ifpresent(data_nc, varname)

read a variable from the simulation file if the variable is present in there. :param data_nc: open netcdf dataset :type data_nc: prosimu :param varname: variable name of the variable to be read :type varname: str :return: array with requested data

read_var_ifpresent(data_nc, varname, convert1d=False)

read a given variable from a netcdf file if it is present in the file. If the variable is not present under the given variable name, check if it is present under an alternate name from ESMSnowMIP.

Parameters:
  • data_nc (prosimu) – dataset to read in

  • varname (str) – variable name

  • convert1d

Returns:

Numpy data array containing the data of the selected variable, or an array filled with np.nan if the requested variable was not present in the file.

Return type:

numpy array

property rmse

Root mean square error

scores_all_values()

calculate scores (bias and RMSE) including cases of 0 values (no snow for example) :return: number of values, bias, RMSE, mean value of simulations

scores_with_positive_values_only()

calculate scores (bias and RMSE) excluding cases where both the observation and the simulation have a value of 0 :return: number of values, bias, RMSE, mean value of simulations

squarediff()

Vector of square difference between simulations and observations

class scores.deterministic.DeterministicScores_Mask(mask_obs, mask_sim, obs, sim)[source]

Bases: DeterminsticScores

Constructor for observations and simulations covering different periods, masks provided :param mask_obs: mask array for observation :type mask_obs: ndarray of bool :param mask_sim: mask array for simulation :type mask_sim: ndarray of bool :param obs: array of observations :param sim: array of simulations

property bias

Relative bias

diff()

Vector of difference between simulations and observations

extract_common_vectors(mask_obs, mask_sim, obs, sim)[source]

Extract common date between observations and simulations

property mae

Mean absolute error

property meanobs

Mean observation value over the common period.

property meansim

Mean simulation value over the common period.

nvalues()

Number of values accounted for in scores computation

read_sim_ifpresent(data_nc, varname)

read a variable from the simulation file if the variable is present in there. :param data_nc: open netcdf dataset :type data_nc: prosimu :param varname: variable name of the variable to be read :type varname: str :return: array with requested data

read_var_ifpresent(data_nc, varname, convert1d=False)

read a given variable from a netcdf file if it is present in the file. If the variable is not present under the given variable name, check if it is present under an alternate name from ESMSnowMIP.

Parameters:
  • data_nc (prosimu) – dataset to read in

  • varname (str) – variable name

  • convert1d

Returns:

Numpy data array containing the data of the selected variable, or an array filled with np.nan if the requested variable was not present in the file.

Return type:

numpy array

property rmse

Root mean square error

scores_all_values()

calculate scores (bias and RMSE) including cases of 0 values (no snow for example) :return: number of values, bias, RMSE, mean value of simulations

scores_with_positive_values_only()

calculate scores (bias and RMSE) excluding cases where both the observation and the simulation have a value of 0 :return: number of values, bias, RMSE, mean value of simulations

squarediff()

Vector of square difference between simulations and observations

class scores.deterministic.DeterminsticScores[source]

Bases: object

Abstract class for deterministic scores

property bias

Relative bias

diff()[source]

Vector of difference between simulations and observations

property mae

Mean absolute error

property meanobs

Mean observation value over the common period.

property meansim

Mean simulation value over the common period.

nvalues()[source]

Number of values accounted for in scores computation

read_sim_ifpresent(data_nc, varname)[source]

read a variable from the simulation file if the variable is present in there. :param data_nc: open netcdf dataset :type data_nc: prosimu :param varname: variable name of the variable to be read :type varname: str :return: array with requested data

read_var_ifpresent(data_nc, varname, convert1d=False)[source]

read a given variable from a netcdf file if it is present in the file. If the variable is not present under the given variable name, check if it is present under an alternate name from ESMSnowMIP.

Parameters:
  • data_nc (prosimu) – dataset to read in

  • varname (str) – variable name

  • convert1d

Returns:

Numpy data array containing the data of the selected variable, or an array filled with np.nan if the requested variable was not present in the file.

Return type:

numpy array

property rmse

Root mean square error

scores_all_values()[source]

calculate scores (bias and RMSE) including cases of 0 values (no snow for example) :return: number of values, bias, RMSE, mean value of simulations

scores_with_positive_values_only()[source]

calculate scores (bias and RMSE) excluding cases where both the observation and the simulation have a value of 0 :return: number of values, bias, RMSE, mean value of simulations

squarediff()[source]

Vector of square difference between simulations and observations

class scores.deterministic.ESMSnowMIP[source]

Bases: S2M_Score

varobsname(varname)

get ESMSnowMIP variable name given a variable name from ESMSnowMIP_dicvarnames.keys() :param varname: variable name :type varname: str :return: ESMSnowMIP variable name :rtype: str

varsimname(varname)

get surfex variable name given a variable name from SURFEX_dicvarnames.keys() :param varname: variable name :type varname: str :return: surfex variable name :rtype: str

class scores.deterministic.ESMSnowMIP_DeterministicScores_Heterogeneous(profile, obsfile, varname)[source]

Bases: S2M_DeterministicScores_Heterogeneous, ESMSnowMIP

Parameters:
  • profile – surfex output file name containing the simulations

  • obsfile – netcdf file name containing the observations (will be read by prosimu)

  • varname – name of the variable to be analysed, one of SURFEX_dicvarnames.keys()

property bias

Relative bias

diff()

Vector of difference between simulations and observations

extract_common_vectors(time_obs, time_sim, obs, sim)

Extract common date between observations and simulations selecting only winter periods. :param time_obs: array of observation times :param time_sim: array of simulation times :param obs: array of observation values :param sim: array of simulation values :return:

property mae

Mean absolute error

property meanobs

Mean observation value over the common period.

property meansim

Mean simulation value over the common period.

nvalues()

Number of values accounted for in scores computation

read_sim_ifpresent(data_nc, varname)

read a variable from the simulation file if the variable is present in there. :param data_nc: open netcdf dataset :type data_nc: prosimu :param varname: variable name of the variable to be read :type varname: str :return: array with requested data

read_var_ifpresent(data_nc, varname, convert1d=False)

read a given variable from a netcdf file if it is present in the file. If the variable is not present under the given variable name, check if it is present under an alternate name from ESMSnowMIP.

Parameters:
  • data_nc (prosimu) – dataset to read in

  • varname (str) – variable name

  • convert1d

Returns:

Numpy data array containing the data of the selected variable, or an array filled with np.nan if the requested variable was not present in the file.

Return type:

numpy array

property rmse

Root mean square error

scores_all_values()

calculate scores (bias and RMSE) including cases of 0 values (no snow for example) :return: number of values, bias, RMSE, mean value of simulations

scores_with_positive_values_only()

calculate scores (bias and RMSE) excluding cases where both the observation and the simulation have a value of 0 :return: number of values, bias, RMSE, mean value of simulations

squarediff()

Vector of square difference between simulations and observations

varobsname(varname)

get ESMSnowMIP variable name given a variable name from ESMSnowMIP_dicvarnames.keys() :param varname: variable name :type varname: str :return: ESMSnowMIP variable name :rtype: str

varsimname(varname)

get surfex variable name given a variable name from SURFEX_dicvarnames.keys() :param varname: variable name :type varname: str :return: surfex variable name :rtype: str

class scores.deterministic.ESMSnowMIP_DeterministicScores_Mask(profile, obsfile, varname, mask_sim, mask_obs)[source]

Bases: S2M_DeterministicScores_Mask, ESMSnowMIP

Parameters:
  • profile – surfex output file name containing the simulations

  • obsfile – netcdf file name containing the observations (will be read by prosimu)

  • varname – name of the variable to be analysed, one of SURFEX_dicvarnames.keys()

  • mask_sim – simulation mask

  • mask_obs – observation mask

property bias

Relative bias

diff()

Vector of difference between simulations and observations

extract_common_vectors(mask_obs, mask_sim, obs, sim)

Extract common date between observations and simulations

property mae

Mean absolute error

property meanobs

Mean observation value over the common period.

property meansim

Mean simulation value over the common period.

nvalues()

Number of values accounted for in scores computation

read_sim_ifpresent(data_nc, varname)

read a variable from the simulation file if the variable is present in there. :param data_nc: open netcdf dataset :type data_nc: prosimu :param varname: variable name of the variable to be read :type varname: str :return: array with requested data

read_var_ifpresent(data_nc, varname, convert1d=False)

read a given variable from a netcdf file if it is present in the file. If the variable is not present under the given variable name, check if it is present under an alternate name from ESMSnowMIP.

Parameters:
  • data_nc (prosimu) – dataset to read in

  • varname (str) – variable name

  • convert1d

Returns:

Numpy data array containing the data of the selected variable, or an array filled with np.nan if the requested variable was not present in the file.

Return type:

numpy array

property rmse

Root mean square error

scores_all_values()

calculate scores (bias and RMSE) including cases of 0 values (no snow for example) :return: number of values, bias, RMSE, mean value of simulations

scores_with_positive_values_only()

calculate scores (bias and RMSE) excluding cases where both the observation and the simulation have a value of 0 :return: number of values, bias, RMSE, mean value of simulations

squarediff()

Vector of square difference between simulations and observations

varobsname(varname)

get ESMSnowMIP variable name given a variable name from ESMSnowMIP_dicvarnames.keys() :param varname: variable name :type varname: str :return: ESMSnowMIP variable name :rtype: str

varsimname(varname)

get surfex variable name given a variable name from SURFEX_dicvarnames.keys() :param varname: variable name :type varname: str :return: surfex variable name :rtype: str

class scores.deterministic.ESMSnowMIP_DeterministicScores_Time(profile, obsfile, varname, time_sim, time_obs)[source]

Bases: S2M_DeterministicScores_Time, ESMSnowMIP

Parameters:
  • profile – surfex output file name containing the simulations

  • obsfile – netcdf file name containing the observations (will be read by prosimu)

  • varname – name of the variable to be analysed, one of SURFEX_dicvarnames.keys()

  • time_sim – simulation times

  • time_obs – observation times

property bias

Relative bias

diff()

Vector of difference between simulations and observations

extract_common_vectors(time_obs, time_sim, obs, sim)

Extract common date between observations and simulations selecting only winter periods. :param time_obs: array of observation times :param time_sim: array of simulation times :param obs: array of observation values :param sim: array of simulation values :return:

property mae

Mean absolute error

property meanobs

Mean observation value over the common period.

property meansim

Mean simulation value over the common period.

nvalues()

Number of values accounted for in scores computation

read_sim_ifpresent(data_nc, varname)

read a variable from the simulation file if the variable is present in there. :param data_nc: open netcdf dataset :type data_nc: prosimu :param varname: variable name of the variable to be read :type varname: str :return: array with requested data

read_var_ifpresent(data_nc, varname, convert1d=False)

read a given variable from a netcdf file if it is present in the file. If the variable is not present under the given variable name, check if it is present under an alternate name from ESMSnowMIP.

Parameters:
  • data_nc (prosimu) – dataset to read in

  • varname (str) – variable name

  • convert1d

Returns:

Numpy data array containing the data of the selected variable, or an array filled with np.nan if the requested variable was not present in the file.

Return type:

numpy array

property rmse

Root mean square error

scores_all_values()

calculate scores (bias and RMSE) including cases of 0 values (no snow for example) :return: number of values, bias, RMSE, mean value of simulations

scores_with_positive_values_only()

calculate scores (bias and RMSE) excluding cases where both the observation and the simulation have a value of 0 :return: number of values, bias, RMSE, mean value of simulations

squarediff()

Vector of square difference between simulations and observations

varobsname(varname)

get ESMSnowMIP variable name given a variable name from ESMSnowMIP_dicvarnames.keys() :param varname: variable name :type varname: str :return: ESMSnowMIP variable name :rtype: str

varsimname(varname)

get surfex variable name given a variable name from SURFEX_dicvarnames.keys() :param varname: variable name :type varname: str :return: surfex variable name :rtype: str

scores.deterministic.ESMSnowMIP_alternate_varnames = {'snd_auto': 'snd_can_auto'}

dict mapping ESMSnowMIP_alternate_varnames

scores.deterministic.ESMSnowMIP_dicvarnames = {'albedo': 'albs', 'snowdepth': 'snd_auto', 'snowdepthman': 'snd_man', 'snowswe': 'snw_auto', 'snowsweman': 'snw_man', 'tsurf': 'ts'}

dict mapping common variable names to ESMSnowMIP variable names

class scores.deterministic.S2M_DeterministicScores_CommonObs(profile, varname, obs_common, mask_sim)[source]

Bases: DeterministicScores_CommonObs, S2M_Score

Parameters:
  • profile – surfex output file name containing the simulations

  • varname – name of the variable to be analysed, one of SURFEX_dicvarnames.keys()

  • obs_common – observations

  • mask_sim – simulation mask

property bias

Relative bias

diff()

Vector of difference between simulations and observations

property mae

Mean absolute error

property meanobs

Mean observation value over the common period.

property meansim

Mean simulation value over the common period.

nvalues()

Number of values accounted for in scores computation

read_sim_ifpresent(data_nc, varname)

read a variable from the simulation file if the variable is present in there. :param data_nc: open netcdf dataset :type data_nc: prosimu :param varname: variable name of the variable to be read :type varname: str :return: array with requested data

read_var_ifpresent(data_nc, varname, convert1d=False)

read a given variable from a netcdf file if it is present in the file. If the variable is not present under the given variable name, check if it is present under an alternate name from ESMSnowMIP.

Parameters:
  • data_nc (prosimu) – dataset to read in

  • varname (str) – variable name

  • convert1d

Returns:

Numpy data array containing the data of the selected variable, or an array filled with np.nan if the requested variable was not present in the file.

Return type:

numpy array

property rmse

Root mean square error

scores_all_values()

calculate scores (bias and RMSE) including cases of 0 values (no snow for example) :return: number of values, bias, RMSE, mean value of simulations

scores_with_positive_values_only()

calculate scores (bias and RMSE) excluding cases where both the observation and the simulation have a value of 0 :return: number of values, bias, RMSE, mean value of simulations

squarediff()

Vector of square difference between simulations and observations

varobsname(varname)

get ESMSnowMIP variable name given a variable name from ESMSnowMIP_dicvarnames.keys() :param varname: variable name :type varname: str :return: ESMSnowMIP variable name :rtype: str

varsimname(varname)

get surfex variable name given a variable name from SURFEX_dicvarnames.keys() :param varname: variable name :type varname: str :return: surfex variable name :rtype: str

class scores.deterministic.S2M_DeterministicScores_Heterogeneous(profile, obsfile, varname)[source]

Bases: DeterministicScores_Heterogeneous, S2M_Score

Parameters:
  • profile – surfex output file name containing the simulations

  • obsfile – netcdf file name containing the observations (will be read by prosimu)

  • varname – name of the variable to be analysed, one of SURFEX_dicvarnames.keys()

property bias

Relative bias

diff()

Vector of difference between simulations and observations

extract_common_vectors(time_obs, time_sim, obs, sim)

Extract common date between observations and simulations selecting only winter periods. :param time_obs: array of observation times :param time_sim: array of simulation times :param obs: array of observation values :param sim: array of simulation values :return:

property mae

Mean absolute error

property meanobs

Mean observation value over the common period.

property meansim

Mean simulation value over the common period.

nvalues()

Number of values accounted for in scores computation

read_sim_ifpresent(data_nc, varname)

read a variable from the simulation file if the variable is present in there. :param data_nc: open netcdf dataset :type data_nc: prosimu :param varname: variable name of the variable to be read :type varname: str :return: array with requested data

read_var_ifpresent(data_nc, varname, convert1d=False)

read a given variable from a netcdf file if it is present in the file. If the variable is not present under the given variable name, check if it is present under an alternate name from ESMSnowMIP.

Parameters:
  • data_nc (prosimu) – dataset to read in

  • varname (str) – variable name

  • convert1d

Returns:

Numpy data array containing the data of the selected variable, or an array filled with np.nan if the requested variable was not present in the file.

Return type:

numpy array

property rmse

Root mean square error

scores_all_values()

calculate scores (bias and RMSE) including cases of 0 values (no snow for example) :return: number of values, bias, RMSE, mean value of simulations

scores_with_positive_values_only()

calculate scores (bias and RMSE) excluding cases where both the observation and the simulation have a value of 0 :return: number of values, bias, RMSE, mean value of simulations

squarediff()

Vector of square difference between simulations and observations

varobsname(varname)

get ESMSnowMIP variable name given a variable name from ESMSnowMIP_dicvarnames.keys() :param varname: variable name :type varname: str :return: ESMSnowMIP variable name :rtype: str

varsimname(varname)

get surfex variable name given a variable name from SURFEX_dicvarnames.keys() :param varname: variable name :type varname: str :return: surfex variable name :rtype: str

class scores.deterministic.S2M_DeterministicScores_Mask(profile, obsfile, varname, mask_sim, mask_obs)[source]

Bases: DeterministicScores_Mask, S2M_Score

Parameters:
  • profile – surfex output file name containing the simulations

  • obsfile – netcdf file name containing the observations (will be read by prosimu)

  • varname – name of the variable to be analysed, one of SURFEX_dicvarnames.keys()

  • mask_sim – simulation mask

  • mask_obs – observation mask

property bias

Relative bias

diff()

Vector of difference between simulations and observations

extract_common_vectors(mask_obs, mask_sim, obs, sim)

Extract common date between observations and simulations

property mae

Mean absolute error

property meanobs

Mean observation value over the common period.

property meansim

Mean simulation value over the common period.

nvalues()

Number of values accounted for in scores computation

read_sim_ifpresent(data_nc, varname)

read a variable from the simulation file if the variable is present in there. :param data_nc: open netcdf dataset :type data_nc: prosimu :param varname: variable name of the variable to be read :type varname: str :return: array with requested data

read_var_ifpresent(data_nc, varname, convert1d=False)

read a given variable from a netcdf file if it is present in the file. If the variable is not present under the given variable name, check if it is present under an alternate name from ESMSnowMIP.

Parameters:
  • data_nc (prosimu) – dataset to read in

  • varname (str) – variable name

  • convert1d

Returns:

Numpy data array containing the data of the selected variable, or an array filled with np.nan if the requested variable was not present in the file.

Return type:

numpy array

property rmse

Root mean square error

scores_all_values()

calculate scores (bias and RMSE) including cases of 0 values (no snow for example) :return: number of values, bias, RMSE, mean value of simulations

scores_with_positive_values_only()

calculate scores (bias and RMSE) excluding cases where both the observation and the simulation have a value of 0 :return: number of values, bias, RMSE, mean value of simulations

squarediff()

Vector of square difference between simulations and observations

varobsname(varname)

get ESMSnowMIP variable name given a variable name from ESMSnowMIP_dicvarnames.keys() :param varname: variable name :type varname: str :return: ESMSnowMIP variable name :rtype: str

varsimname(varname)

get surfex variable name given a variable name from SURFEX_dicvarnames.keys() :param varname: variable name :type varname: str :return: surfex variable name :rtype: str

class scores.deterministic.S2M_DeterministicScores_Time(profile, obsfile, varname, time_sim, time_obs)[source]

Bases: DeterministicScores_Heterogeneous, S2M_Score

Parameters:
  • profile – surfex output file name containing the simulations

  • obsfile – netcdf file name containing the observations (will be read by prosimu)

  • varname – name of the variable to be analysed, one of SURFEX_dicvarnames.keys()

  • time_sim – simulation times

  • time_obs – observation times

property bias

Relative bias

diff()

Vector of difference between simulations and observations

extract_common_vectors(time_obs, time_sim, obs, sim)

Extract common date between observations and simulations selecting only winter periods. :param time_obs: array of observation times :param time_sim: array of simulation times :param obs: array of observation values :param sim: array of simulation values :return:

property mae

Mean absolute error

property meanobs

Mean observation value over the common period.

property meansim

Mean simulation value over the common period.

nvalues()

Number of values accounted for in scores computation

read_sim_ifpresent(data_nc, varname)

read a variable from the simulation file if the variable is present in there. :param data_nc: open netcdf dataset :type data_nc: prosimu :param varname: variable name of the variable to be read :type varname: str :return: array with requested data

read_var_ifpresent(data_nc, varname, convert1d=False)

read a given variable from a netcdf file if it is present in the file. If the variable is not present under the given variable name, check if it is present under an alternate name from ESMSnowMIP.

Parameters:
  • data_nc (prosimu) – dataset to read in

  • varname (str) – variable name

  • convert1d

Returns:

Numpy data array containing the data of the selected variable, or an array filled with np.nan if the requested variable was not present in the file.

Return type:

numpy array

property rmse

Root mean square error

scores_all_values()

calculate scores (bias and RMSE) including cases of 0 values (no snow for example) :return: number of values, bias, RMSE, mean value of simulations

scores_with_positive_values_only()

calculate scores (bias and RMSE) excluding cases where both the observation and the simulation have a value of 0 :return: number of values, bias, RMSE, mean value of simulations

squarediff()

Vector of square difference between simulations and observations

varobsname(varname)

get ESMSnowMIP variable name given a variable name from ESMSnowMIP_dicvarnames.keys() :param varname: variable name :type varname: str :return: ESMSnowMIP variable name :rtype: str

varsimname(varname)

get surfex variable name given a variable name from SURFEX_dicvarnames.keys() :param varname: variable name :type varname: str :return: surfex variable name :rtype: str

class scores.deterministic.S2M_Score[source]

Bases: object

Abstract class for Surfex scores

varobsname(varname)[source]

get ESMSnowMIP variable name given a variable name from ESMSnowMIP_dicvarnames.keys() :param varname: variable name :type varname: str :return: ESMSnowMIP variable name :rtype: str

varsimname(varname)[source]

get surfex variable name given a variable name from SURFEX_dicvarnames.keys() :param varname: variable name :type varname: str :return: surfex variable name :rtype: str

scores.deterministic.SURFEX_dicvarnames = {'albedo': 'ASN_ISBA', 'snowdepth': 'DSN_T_ISBA', 'snowdepthman': 'DSN_T_ISBA', 'snowswe': 'WSN_T_ISBA', 'snowsweman': 'WSN_T_ISBA', 'tsurf': 'TS_ISBA'}

dict mapping common variable names to surfex variable names

Ensemble scores

The ensemble score module

Created on 20 March 2018

@author: lafaysse

class scores.ensemble.ESCROC_EnsembleScores(profiles, obsfile, varname)[source]

Bases: EnsembleScores

Parameters:
  • profiles – list of simulation files (one per ensemble member

  • obsfile – observation file (netCDF format)

  • varname – variable name

CRPS()

CRPS is computed from https://pypi.python.org/pypi/properscoring#downloads :return: mean CRPS over the data period :rtype: float

CRPS_decomp()

BC implementing the Hersbach et al. formulation for decomposition. inspired on https://github.com/brankart/ensdam/blob/master/src/EnsScores/score_crps.F90 aggregated assuming that realizations are independant. :return: CRPS, Reliability, potential CRPS

dispersionEnsemble()

calculate ensemble spread, the RMSE of the ensemble mean and the spread/skill relationship :return: spread, RMSE of ensemble mean, spread/skill

property meanEnsemble

ensemble mean, dealing with only some members valid :return: ensemble mean for every date

read(profiles, obsfile, varname)[source]

read simulation files and observation file and extract dates with available observations in winter. sets self.obsCommon and self.ensCommon :param profiles: list of simulation files (one per ensemble member, netCDF format) :type profiles: list of path-likes :param obsfile: observation file in NetCDF format :type obsfile: pathlike :param varname: variable to be read

read_sim_ifpresent(dataNc, varname)[source]

read a variable from simulation file :param dataNc: dataset :type dataNc: prosimu :param varname: variable name to read :type varname: str :return:

read_var_ifpresent(dataNc, varname, convert1d=False)[source]

read a variable if present in file else return an empty numpy array.

convert degrees C to Kelvin if the variable name is Ts and convert1d=False. :param dataNc: dataset :type dataNc: prosimu :param varname: variable name :type varname: str :param convert1d: :type convert1d: bool :return: data array :rtype: np.array

varobsname(varname)[source]

convert variable name to ESMSnowMIP variable name :param varname: variable name :type varname: str :return: corresponding value from ESMSnowMIP_dicvarnames :rtype: str

varsimname(varname)[source]

convert variable name to variable name in SURFEX output :param varname: variable name :type varname: str :return: corresponding value from SURFEX_dicvarnames :rtype: str

scores.ensemble.ESMSnowMIP_alternate_varnames = {'snd_auto': 'snd_can_auto'}

dict mapping ESMSnowMIP_alternate_varnames

scores.ensemble.ESMSnowMIP_dicvarnames = {'albedo': 'albs', 'snowdepth': 'snd_auto', 'snowdepthman': 'snd_man', 'snowswe': 'snw_auto', 'snowsweman': 'snw_man', 'tsurf': 'ts'}

dict mapping common variable names to ESMSnowMIP variable names

class scores.ensemble.EnsembleScores(timeObs, timeSim, obs, ensemble)[source]

Bases: object

Ensemble scores

Parameters:
  • timeObs

  • timeSim

  • obs – array of observations dimension : time

  • ensemble – array of forecasts dimensions (member, time)

CRPS()[source]

CRPS is computed from https://pypi.python.org/pypi/properscoring#downloads :return: mean CRPS over the data period :rtype: float

CRPS_decomp()[source]

BC implementing the Hersbach et al. formulation for decomposition. inspired on https://github.com/brankart/ensdam/blob/master/src/EnsScores/score_crps.F90 aggregated assuming that realizations are independant. :return: CRPS, Reliability, potential CRPS

dispersionEnsemble()[source]

calculate ensemble spread, the RMSE of the ensemble mean and the spread/skill relationship :return: spread, RMSE of ensemble mean, spread/skill

property meanEnsemble

ensemble mean, dealing with only some members valid :return: ensemble mean for every date

scores.ensemble.SURFEX_dicvarnames = {'albedo': 'ASN_ISBA', 'snowdepth': 'DSN_T_ISBA', 'snowdepthman': 'DSN_T_ISBA', 'snowswe': 'WSN_T_ISBA', 'snowsweman': 'WSN_T_ISBA', 'tsurf': 'TS_ISBA'}

dict mapping common variable names to surfex variable names

Tool to compute individual deterministic score for each member

Created on 21 March 2018

@author: lafaysse

class scores.list_scores.ESCROC_list_scores[source]

Bases: object

Class for all deterministic scores of a given ESM-SnowMIP simulation member

Constructor

compute_scores_1member(profile, obsfile, list_scores, list_var)[source]
Parameters:
  • profile

  • obsfile

  • list_scores

  • list_var

Returns:

compute_scores_allmembers(list_pro, obsfile, list_scores, list_var)[source]

compute scores for every ensemble member

Parameters:
  • list_pro – list of simulation files

  • obsfile – observation file

  • list_scores – list of scores

  • list_var – list of variables

Returns:

array of scores dimensions : (score, member, variable)

Return type:

numpy array

read_data(profile, obsfile, varname)[source]
Parameters:
  • profile

  • obsfile

  • varname

Returns:

class scores.list_scores.SpatialScoreFile(list_of_experiments, list_of_kernels, list_of_thresholds, list_of_threshold_increments, filename='spatialscores.nc')[source]

Bases: Dataset

Class for writing spatial scores.

Parameters:
  • list_of_experiments

  • list_of_kernels

  • list_of_thresholds

  • list_of_threshold_increments

  • filename

create_dims(list_of_experiments, list_of_kernels, list_of_thresholds)[source]

create experiment, kernel and threshold dimensions

Parameters:
  • list_of_experiments

  • list_of_kernels

  • list_of_thresholds

create_vars(list_of_threshold_increments)[source]

Create threshold_increment and fuzzy score variables

Parameters:

list_of_threshold_increments

class scores.list_scores.ensemble_scores_file(*args, **kwargs)[source]

Bases: Dataset

`__init__(self, filename, mode=”r”, clobber=True, diskless=False, persist=False, keepweakref=False, memory=None, encoding=None, parallel=False, comm=None, info=None, format=’NETCDF4’)`

Dataset constructor.

`filename`: Name of netCDF file to hold dataset. Can also be a python 3 pathlib instance or the URL of an OpenDAP dataset. When memory is set this is just used to set the filepath().

`mode`: access mode. r means read-only; no data can be modified. w means write; a new file is created, an existing file with the same name is deleted. a and r+ mean append (in analogy with serial files); an existing file is opened for reading and writing. Appending s to modes r, w, r+ or a will enable unbuffered shared access to NETCDF3_CLASSIC, NETCDF3_64BIT_OFFSET or NETCDF3_64BIT_DATA formatted files. Unbuffered access may be useful even if you don’t need shared access, since it may be faster for programs that don’t access data sequentially. This option is ignored for NETCDF4 and NETCDF4_CLASSIC formatted files.

`clobber`: if True (default), opening a file with mode=’w’ will clobber an existing file with the same name. if False, an exception will be raised if a file with the same name already exists.

`format`: underlying file format (one of ‘NETCDF4’, ‘NETCDF4_CLASSIC’, ‘NETCDF3_CLASSIC’, ‘NETCDF3_64BIT_OFFSET’ or ‘NETCDF3_64BIT_DATA’. Only relevant if mode = ‘w’ (if mode = ‘r’,’a’ or ‘r+’ the file format is automatically detected). Default ‘NETCDF4’, which means the data is stored in an HDF5 file, using netCDF 4 API features. Setting format=’NETCDF4_CLASSIC’ will create an HDF5 file, using only netCDF 3 compatible API features. netCDF 3 clients must be recompiled and linked against the netCDF 4 library to read files in NETCDF4_CLASSIC format. ‘NETCDF3_CLASSIC’ is the classic netCDF 3 file format that does not handle 2+ Gb files. ‘NETCDF3_64BIT_OFFSET’ is the 64-bit offset version of the netCDF 3 file format, which fully supports 2+ GB files, but is only compatible with clients linked against netCDF version 3.6.0 or later. ‘NETCDF3_64BIT_DATA’ is the 64-bit data version of the netCDF 3 file format, which supports 64-bit dimension sizes plus unsigned and 64 bit integer data types, but is only compatible with clients linked against netCDF version 4.4.0 or later.

`diskless`: If True, create diskless (in-core) file. This is a feature added to the C library after the netcdf-4.2 release. If you need to access the memory buffer directly, use the in-memory feature instead (see memory kwarg).

`persist`: if diskless=True, persist file to disk when closed (default False).

`keepweakref`: if True, child Dimension and Variable instances will keep weak references to the parent Dataset or Group object. Default is False, which means strong references will be kept. Having Dimension and Variable instances keep a strong reference to the parent Dataset instance, which in turn keeps a reference to child Dimension and Variable instances, creates circular references. Circular references complicate garbage collection, which may mean increased memory usage for programs that create may Dataset instances with lots of Variables. It also will result in the Dataset object never being deleted, which means it may keep open files alive as well. Setting keepweakref=True allows Dataset instances to be garbage collected as soon as they go out of scope, potentially reducing memory usage and open file handles. However, in many cases this is not desirable, since the associated Variable instances may still be needed, but are rendered unusable when the parent Dataset instance is garbage collected.

`memory`: if not None, create or open an in-memory Dataset. If mode = ‘r’, the memory kwarg must contain a memory buffer object (an object that supports the python buffer interface). The Dataset will then be created with contents taken from this block of memory. If mode = ‘w’, the memory kwarg should contain the anticipated size of the Dataset in bytes (used only for NETCDF3 files). A memory buffer containing a copy of the Dataset is returned by the Dataset.close method. Requires netcdf-c version 4.4.1 for mode=’r, netcdf-c 4.6.2 for mode=’w’. To persist the file to disk, the raw bytes from the returned buffer can be written into a binary file. The Dataset can also be re-opened using this memory buffer.

`encoding`: encoding used to encode filename string into bytes. Default is None (sys.getdefaultfileencoding() is used).

`parallel`: open for parallel access using MPI (requires mpi4py and parallel-enabled netcdf-c and hdf5 libraries). Default is False. If True, comm and info kwargs may also be specified.

`comm`: MPI_Comm object for parallel access. Default None, which means MPI_COMM_WORLD will be used. Ignored if parallel=False.

`info`: MPI_Info object for parallel access. Default None, which means MPI_INFO_NULL will be used. Ignored if parallel=False.

class scores.list_scores.scores_file(*args, **kwargs)[source]

Bases: Dataset

class for writing scores with dimensions (member, variable, station)

open a netcdf dataset and create dimensions.

Parameters:
  • args – passed to netCDF4.Dataset

  • kwargs – passed to netCDF4.Dataset

cree_dims()[source]

create member, variable and stat dimensions

Rank histogram computation

Created on 19 juin 2018

@author: cluzetb, adapted from R. Champavier Talagrand_rank class

scores.generic.rankDiagram(ens, observations, isSorted=False, nbins=36, printrank=False, param=None, titreFig=None, pathFig=None)[source]

@author : B. Cluzet, june 2018 generic CRPS computation from Cluzet first version, Lafaysse and Champavier talagrand function Champavier code would be a good source of inspiration for optimisation through pandas (avoiding the for loop)

@paramsensNens x NDate matrix (np.array)

obs : NDate vector

/! - same dates for ens and obs
  • the user should adapt ens and obs beforehand to make it directly comparable

  • convention : nan value when a member is not defined

  • obs: no nan

  • ens not necessarily sorted

  • nbins better <= NMembers +1 ???

Spatial scores

Created on 23 April 2024

@author: radanovics

based on code from Ange Haddjeri thesis.

class scores.spatial.LocalMoranData(field, neighbors=3)[source]

Bases: object

class containing local Moran’s Is statistics.

Parameters:
  • field (xarray.DataArray) – field to analyse

  • neighbors (int (odd >=3)) – size of the neighborhood to consider for the local moran calculation. Total number of cells in one direction. Exemple: neighbors=3 will calculate the local moran Is for neighborhood of 3x3 grid cells.

get_quadrant_numbers(significance=0.0)[source]

construct an array of quadrant numbers indicating in which quadrant of the Moran Scatterplot a data point is situated. (from pysal.esda) :return: array of quadrant numbers :rtype: np.ndarray (2D)

get_random_sigma()[source]

calculate local moran Is for the randomized field and returns the standard deviation of the resulting local moran Is values. :return: standard deviation of local moran Is for the randomized anomaly field. :rtype: float

get_spatially_lagged_field(field=None)[source]

Create a spatially lagged field by applying weighted averages over rolling windows. :param field: Optional :type field: np.ndarray (2D) :return: padded (with np.nan) array with lagged anomalies :rtype: np.ndarray (2D)

get_weight_matrix()[source]

get weight matrix with constant weights over the neighborhood and zero weight for the center point :return: weight matrix with shape (neighbors, neighbors) :rtype: np.ndarray (2D)

plot_moran_scatter_colored(variable_name, filename=None, **kwargs)[source]

Do a colored moran scatter plot coloring the points according to the self.quadrant_numbers

Parameters:
  • variable_name (str) – which variable is plotted? used to construct axis labels

  • filename (pathlike) – optional output file name for the graphic

  • kwargs – used plot kwargs: ‘title’

plot_moran_scatter_simple(variable_name, filename=None, **kwargs)[source]

do a simple moran scatter plot with all the points the same color

Parameters:
  • variable_name (str) – which variable is plotted? used to construct axis labels

  • filename (pathlike) – optional output file name for the graphic

  • kwargs

Returns:

plot_quadrant_map(x, y, geometry, filename=None)[source]

plot a map where pixels are colored according to the quadrant of the Moran Scatter plot for its local Morans I.

Parameters:
  • x (1D array like) – x-coordinates

  • y (1D array like) – y-coordinates

  • geometry (epygram.geometry) – map projection

  • filename (pathlike) – ptional output file name for the graphic

class scores.spatial.ProVsPleiade(fc_filenames, list_of_experiments, obs_filename, varname, list_of_kernels, list_of_thresholds, list_of_threshold_increments, per_zone=None, score_file=True, score_file_name='spatialscores.nc', perf_plot=True, perf_plot_file='perfdiag.png')[source]

Bases: SpatialScores

class for comparing simulations data with a pleiade image.

apply_mask(maskfile='masque_glacier2017_foret_ville_riviere.nc', mask_varname='Band1', method='nearest')[source]

apply a mask to the forecast and observation data.

Parameters:
  • maskfile – a netcdf file defining the mask

  • mask_varname – netcdf variable name containing the mask

  • method – interpolation method to use in order to map the mask onto the observation data grid.

get_fc_data(filenames, list_of_experiments, varname)[source]

read forecast data for different experiments.

Parameters:
  • filenames (str or path-like) – list of filenames with path

  • list_of_experiments (list of strings) – list of experiment names or tags

  • varname (str) – variable name to get from the input files

Returns:

dict with forecast data with experiment names as keys and xarray data variables as values.

Return type:

dict

get_mask(maskfile='masque_glacier2017_foret_ville_riviere.nc', mask_varname='Band1', method='nearest')[source]

get a mask object.

Parameters:
  • maskfile – a netcdf file defining the mask

  • mask_varname – netcdf variable name containing the mask

  • method – interpolation method to use in order to map the mask onto the observation data grid.

Returns:

mask on self.obs_data grid.

get_obs_data(filename, varname)[source]

read pleiade observation data

Parameters:

filename – file name

Returns:

xarray data array

select_fc_at_obs()[source]

select a subset of the forecast data at times and location where the observation data (Pleiade image or alike) are available.

class scores.spatial.SpatialScores(fc_filenames, list_of_experiments, obs_filename, varname, list_of_kernels, list_of_thresholds, list_of_threshold_increments, per_zone=None, score_file=True, score_file_name='spatial_scores.nc', perf_plot=True, perf_plot_file='perfdiag.png')[source]

Bases: ABC

abstract get_fc_data(filenames, list_of_experiments, varname)[source]

read forecast data

Parameters:
  • list_of_experiments – list of experiment labels

  • filenames – list of forecast file names (paths)

  • varname (str) – variable name in data set

Returns:

dict with experiment labels as keys and xarray.DataArrays of forecast fields as values

abstract get_obs_data(filename, varname)[source]

read observation data

Parameters:
  • filename – observation filename

  • varname (str) – variable name in data set

Returns:

xarray.DataArray with observation field

make_fuzzy_scores(score_ds)[source]

calculate POD, FAR, TS, ETS, HK for different forecast experiments.

Parameters:
  • score_ds (SpatialScoreFile) – an open file to write scores

  • fc_experiments (dict) – dict of forecast fields where dict keys are experiment names and values the corresponding fields. (2d np.array)

  • observation (np.array (2d)) – observation or reference field

  • list_kernel_size – list of kernel sizes for which to calculate scores. neighbourhood (kernel) size in number of pixels in each direction ex. : 3 for a 3x3 pixel kernel impair number

  • list_thresholds (list) – list of event thresholds. lower bounds of event intervals.

  • list_threshold_increment (list) – list of corresponding sizes of event intervals.

  • perzone (float) – minimum fraction of values needed to be present in the neighborhood in order to take the pixel into account for score calculation. Default None will be set to 1 / (kl * kl)

Returns:

make_spatial_probability_score(score_ds)[source]

calculate spatial probability score (spatial CRPS) and write it in a new variable in self.score_ds

scores.spatial.call_crps(fc_in, obs_in)[source]

calls the crps subroutine :param fc_in: array or list of forcasted values (ensemble members) :param obs_in: array of observations or reference :return: crpsval

scores.spatial.mincoverage_small(fc, obs, kl, threshold_lower, threshold_increment, perzone=None)[source]

Calculate POD (probability of detection), FAR (false alarm ratio), TS (threat score), ETS (equitable threat score), HK (Hanssen & Kuipper’s Skill Score, True Skill Statistic (TSS) or Pierce’s Skill Score), ACC (accuracy), PAG (post agreement) between two fields using a given neighborhood size kl, and a given threshold and threshold increment to define an event.

Parameters:
  • fc (np.array (2d)) – forecast field

  • obs (np.array (2d)) – observation field

  • kl (int) – neighbourhood (kernel) size in number of pixels in each direction ex. : 3 for a 3x3 pixel kernel impair number

  • threshold_lower – lower bound of event interval

  • threshold_increment – size of event interval

  • perzone (float) – minimum fraction of values needed to be present in the neighborhood in order to take the pixel into account for score calculation. Default None will be set to 1 / (kl * kl)

Returns:

POD, FAR, TS, ETS, HK, ACC, PAG

scores.spatial.pearson_corr(simu_data, ref_data, p_value=True)[source]

Compute Pearson correlation coefficient and p-value for testing non-correlation (optional). Important: Nan areas must be identical.

Parameters:
  • simu_data (xarray dataset) – The simulation dataset.

  • ref_data (xarray dataset) – The reference dataset.

  • p_value (bool) – option to return p-value

Returns:

statisticfloat

Pearson product-moment correlation coefficient.

p-valuefloat (if option is True)

The p-value associated with the default scipy function options.

scores.spatial.rolling_window(array, window_shape)[source]

rolling window for 2D array :param array: 2d array :type array: np.ndarray :param window_shape: shape of the desired rolling window :type window_shape: tuple

Script for comparing simulations

The script is scores/CompareSimuPosteObsCsv.py.

Script scores/CompareSimuPosteObsCsv.py help:

usage: CompareSimuPosteObsCsv.py [--scores] [--plot] -b YYYYMMDD -e YYYYMMDD --dirsim=dirsim1,dirsim2 --labels=label1,labe2 --dirplot=dirplot --format=pdf,png,eps --yearly
       [-h] [--fileobs FILEOBS] [-b DATEBEGIN] [-e DATEEND] [--dirsim DIRSIM]
       [--labels LABELS] [--dirplot DIRPLOT] [--format FORMAT] [--yearly]
       [--decade] [--plot] [--scores] [--sim2]

options:
  -h, --help            show this help message and exit
  --fileobs FILEOBS     csv file with observations
  -b DATEBEGIN, --begin DATEBEGIN
                        First year of extraction
  -e DATEEND, --end DATEEND
                        Last year of extraction
  --dirsim DIRSIM       Directory of simulation outputs or list of directories
  --labels LABELS       list of labels. Lenght of list should correspond to
                        the number of simulation directories given
  --dirplot DIRPLOT     Directory where the figures are saved
  --format FORMAT       Format of plots
  --yearly              Yearly plots
  --decade              Decade plots
  --plot                do plots
  --scores              Compute scores
  --sim2                Specific case of SIM2 evaluations