filter exposure to remove buildings that are not built yet

    Args:
        exp (climada.entity.Exposures): exposure to be filtered
        yearMin (int): minimum year to be kept (usually 0, except if only subset
                                                of buildings is to be kept)
        yearMax (max): maximum year to be kept (usually the year of the hazard event)

    Returns:
        exp_out: filtered exposure


        for agriculture, assign average field area from exposure to each
        reported damage claim if damage is reported in a region without exposure,
        use Swiss average field area


    Parameters
    ----------
    damages : climada.Impact
        damages impact object
    haz : climada.Hazard
        hazard object
    variable : str
        variable name

    Returns
    -------
    damages : climada.Impact
        damages with new attribute haz_intensity


    Parameters
    ----------
    exp_at_centroid : pd.DataFrame
        Dataframe containing exposure data at centroids
    variable : str
        hazard variable
    date_now : datetime
        current date
    dmg_at_centroid : pd.DataFrame, optional
        Dataframe containing damage data at centroids. The default is None.
    variable_2 : str, optional
        secondary hazard variable to be traced along analysis. The default is None.
    get_PVA : boolean, optional
        get PVA and MDD in output, requires a column 'value_affected' in
        dmg_at_centroids. The default is False.

    Returns
    -------
    at_centroid_dict : Dictionary
        Dictionary containing the important values at all centroids
        that have at least a damage or an overlap between
        exposure and hazard (i.e., a damage prediction)


    main function for calibration - computes a range of variables as
    function of values of the hazard variable

    Parameters
    ----------
    hazard_object: climada.hazard
            hazard object used for calibraiton
    exposure_object: climada.entity.exposures.base.Exposures
            exposure object used for calibration
    damages: dict or climada.engine.impact.Impact
            either dictionary of exposure objects, dictionary of impact objects
            or a single impact objects hat contain damage claims
    exposure_type: str
            type of exposure ('agriculture' or 'GVZ')
    variable: str
            hazard variable name
    hazard_object_2: climada.hazard
            hazard object with a secondary hazard variable that is traced trough the analysis
    variable_2: str
            secondary hazard variable name
    filter_year : tuple
            (yearMin,yearMax): to filter exposure data by year when an exposure was built
    dates_modeled_imp : np.array
        array of dt.datetime() with all dates where modelled impact is not zero
        (i.e. there is a hazard_intensity>0 somewhere)
    roll_window_size : int
        Size of rolling window. default to 10 for 10mm moving window in MESHS

    Returns
    -------

    ds: xarray.Dataset
        Dataset with additive calibration-relevant variables as function of hazard variable for each event
            count_cell: number of grid cells with non-zero exposure
            count_all: number of exposed assets
            value_all: total value of exposed assets
            count_dmg: number of affected assets
            value_dmg: total damage
            value_affected: total value affected
    df_all: pandas.Dataframe
        Dataframe which corresponds to the sum of the data in ds over all events
    ds_roll: xarray.Dataset
        ds with rolling average applied
    ds_roll_cut: xarray.Dataset
        ds_roll with cutoff for high values of hazard variable
    values_at_centroid_all: pandas.Dataframe
        A Dataframe with information on damages per gridpoint (PAA, MDD, MDR, n_dmgs),
        and exposure (n_exp), as well as hazard intensity (variable and variable_2)
    intensity_range: numpy.array
        Intensity array for hazard variable used in the calibration


    Parameters
    ----------
    ds: xarray.Dataset
        Dataset with relevant values grouped per MESHS value
    ds_roll: xarray.Dataset
        moving average of ds
    ds_roll_cut: xarray.Dataset
        moving average of ds but with a cutoff after MESHS=60

    Returns
    --------
    df: pandas.Dataframe
        Dataframe with values computed over all events
    df_roll: pandas.Dataframe
        moving average of df
    df_roll_cut: pandas.Dataframe
        moving average of ds but with acutoff
    n_dmgs: pandas.Dataframe
        number of damage claims per intensity value


 get tuple for mapping used to initialized xarray.Dataset
    var name: (tuple of dimension names, array-like)

    Parameters
    ---------
    n_intensity: int
        number of intensity values / length of dimension "variable"
    n_samples: int
        number of bootstrap samples / length of dimension 'b_sample'

    Returns
    --------
    tuple of dimension names and array-like


    Parameters
    ds: xarray.Dataset with date for each sample date
    ds_roll: ds but for rolling averages
    variable: hazard variable
    n_samples: number of bootstrap samples
    cut_off: intensity value where function is cut off (default to 60 for MESHS=60mm)
    Returns
    -------


fit monotonic function to variables in df (MDR, PAA, MDD, PVA) and
    return a new dataframe with fitted values

    Parameters
    ----------
    df : pandas.Dataframe
        dataframe with values of MDR, PAA, MDD, PVA that a monotonic fit needs
        to be applied to
    Returns
    -------
    df_monotonic : pandas.Dataframe
        dataframe with monotonic fot of values in df


extend hazard object with empty events for calibration

    Args:
        haz (climada.hazard): hazard object to extend
        dates_to_extent (array-like): dates to extend hazard object with


        Parameters
        ----------
        datadir : str
            directory of data at centroid .p files
        croptypes : list of str
            croptypes to be read, if more than one the data is merged together
        variable : str, optional
            hazard variable name. The default is 'MESHS'.
        sample_id : str, optional
            ID of the random sample (only used if random samples are read. The default is None.

        Returns
        -------
        at_centroid_data_out : pandas.DataFrame
            Dataframe including exposure, damage, and hazard information at hazard centroids
        croptype : str
            croptype (if more than one, they are concatenated with a '_').


    read exposure from a file that is readable as geopandas.GeoDataFrame.
    Here used to read crop-specific exposure data gridded on a 1x1km grid

    Parameters
    ----------
        filename:  string
            Name of the file to read as GeoDataFrame and create Exposure from
        description: string
            String describing the exposure. Is added to the Exposure.tag.
        value_column: string
            Name of the column in the GeoDataFrame that is interpreted as 'value' column of the Exposure (default: 'area_ha')
        value_unit: string
            unit of the exposure values (default: ha)
        return_cell_gdf: boolean
            whether or not to return the original GeoDataFrame with geometry of the gridcell saved as polygons (which is neat for plotting)
            default: False
    Returns
    -----------
        exp: climada.entity.exposures.base.Exposures
            Climada exposure
        cell_gdf: GeoDataFrame
            orignal GeoDataFrame with gridcells explicityl specified in geometry


    Read damage netcdf data as climada.impact

    Parameters
    ----------
    filename_dmg : str
        name of the damage file
    impact_metric : str, optional
        variable used as impact metric. The default is 'n_fields_dmg'.
    binary_damage : Boolean, optional
        Whether to return a binary field (damage yes/no). The default is False.

    Returns
    -------
    imp_out : climada.enginge.Impact
        Resulting climada impact object


Create a new Hail hazard from MeteoCH radar data
    or COSMO HAILCAST ouput (single- or multi-member)

    Parameters
    ----------
    files : list of str or xarray Dataset
        list of netcdf filenames (string) or xarray Dataset object
    varname : string
        the netcdf variable name to be read from the file
    time_dim : str
        Name of time dimension, default: 'time'
    forecast_init : datetime object
        List with datetimes of forecast initializations,
        needs to have same length as time, default: None
    ensemble_dim : str
        Name of ensemble dimension, default: None
    spatial_dims : list of str
        Names of spatial dimensions
    country_code : int
        ISO 3166 country code to filter the data
    extent : list / array
        [lon_min, lon_max, lat_min, lat_max]
    ignore_date : boolean
        If True: ignores netcdf dates (e.g. for synthetic data).
    n_year_input : int
        Number of years: will only be used if ignore_date=True
    Returns
    -------
    haz : Hazard object
        Hazard object containing radar data with hail intensity (MESHS)


 compute percent area affected from damages and exposure
    Parameters
    ---------

    exposure_damages_object: climada.entity.exposure
                damage claims of a single event stored as exposure object
    exposure:  climada.entity.exposure
                exposure data for a given croptype

    Returns
    -------

    exposure_damages_object_new: climada.entity.exposure
                a copy of exposure_damages_object but with values for PAA and total area affected


Read Excel file

    Parameters
    ----------
    csv_file : csv
        file with GVZ exposure (or damage) data
    croptype : string
        string denoting croptype, for several croptypes use underscore (_) to separate between names
    on_grid : bool
        whether or not data should be interpolated on regular grid (not implemented yet)
    w_rel_dmg : bool
        if relative damage should be saved in gdf too
    return_type: str
        if 'imp': return imp object
        if 'exp_dict': returns dict of exposures
    haz: climada.hazard
        climada.hazard object to get event_ids. Only needed if return_type='imp'
    Returns
    -------
    exp_dict : dict
        Dictionary with Exposure objects for each event


Create GeoDataFrame from hazard object with columns 'intensity', 'date', 'event_id', and hazard centroids as geometry

    Parameters
    ----------
    hazard : climada.hazard
        Climada hazard
    Returns
    -------
    gdf : pandas.GeoDataFrame
        geodataframe with hazard information


    Parameters
    ----------
    df : pandas.Dataframe
        At centroid dataframe
    variable : str
        hazard variable.

    Returns
    -------
    events : pandas.Dataframe
        dataframe including all events (prediction or damages).
    no_damages : pandas.Dataframe
        dataframe including all centroids without damage


    Parameters
    ----------
    at_centroid_data : pandas.Dataframe
        Dataframe with verification data at centroids
    variable : str, optional
       hazard variable. The default is 'MESHS'.
    exposure_thresh : int, optional
       minimum number of fields for a grid point to count as exposure.
       The default is 1.

    Returns
    -------
    df : pandas.DataFrame
        dataframe with hazard values as indices and verification metrics as columns
    npred : int
        total number of predictions


    Plot verification measures per hazard value

    Parameters
    ----------
    df : pandas.Dataframe
        dataframe with verification scores per hazard value
    x : np.array
        hazard values
    ax : matplotlib.axes
        axes to plot on
    npred : np.array or list, optional
        number of predictions per hazard valur. The default is None.

    Returns
    -------
    ax : matplotlib.axes
        axes with plotted measures.


    plot measures per event

    Parameters
    ----------
    at_centroid_data_MESHS : TYPE
        DESCRIPTION.
    variable : TYPE
        DESCRIPTION.
    ax : TYPE
        DESCRIPTION.
    measures : TYPE, optional
        DESCRIPTION. The default is ['FAR','POD','HSS','HK'].
    thresh : TYPE, optional
        DESCRIPTION. The default is 0.
    fontsize : TYPE, optional
        DESCRIPTION. The default is 25.

    Returns
    -------
    handles : TYPE
        DESCRIPTION.
    labs : TYPE
        DESCRIPTION.
    ax : TYPE
        DESCRIPTION.
    dates_all : TYPE
        DESCRIPTION.
    npred_per_date : TYPE
        DESCRIPTION.
    all_data : TYPE
        DESCRIPTION.


    Parameters
    ----------
    at_centroid_data_wheat : TYPE
        DESCRIPTION.
    at_centroid_data_grapevine : TYPE
        DESCRIPTION.
    variable : TYPE
        DESCRIPTION.
    unit : TYPE
        DESCRIPTION.
    figdir : TYPE
        DESCRIPTION.
    thresh : TYPE, optional
        DESCRIPTION. The default is 0.
    resolution : TYPE, optional
        DESCRIPTION. The default is '1km'.

    Returns
    -------
    fig : TYPE
        DESCRIPTION.
    ax : TYPE
        DESCRIPTION.


Plot a Figure of a map of Switzerland optionally using the Stamen terrain background map (http://maps.stamen.com/#toner/12/37.7706/-122.3782)
    Parameters
    ----------

    stamen_map: boolean
            if True, plot Stamen terrain map, otherwise no background (default is True)
    figsize: tuple
            the figsize keyword argument for matplotlib.figure

    Returns
    -------
    matplotlib.axes._subplots.AxesSubplot


Returns list of (x,y)'s for a rectangle


    plot a performance diagram

    parameters
    ----------
    ax : matplotlib.axes
        axes to plot on

    returns
    -------
    ax : matplotlib.axes
        axes with performance  diagram
    h : handle
        contour handle for csi
    hl : handle
        contour handle for bias


    Plot a ROC diagram

    Parameters
    ----------
    ax : matplotlib.axes
        axes to plot on

    Returns
    -------
    ax : matplotlib.axes
        axes with ROC diagram
    h : handle
        contour handle for HK


        Plot points in Performance diagram

        Parameters
        ----------
        at_centroid_data_var : TYPE
            DESCRIPTION.
        variable : TYPE
            DESCRIPTION.
        opt_resolutions : TYPE
            DESCRIPTION.
        exp_thresh : TYPE
            DESCRIPTION.
        opt_threshs : TYPE
            DESCRIPTION.
        unit : TYPE
            DESCRIPTION.
        score : TYPE
            DESCRIPTION.
        colors : TYPE
            DESCRIPTION.
        markers : TYPE
            DESCRIPTION.
        fontsize : TYPE
            DESCRIPTION.
        ax : TYPE
            DESCRIPTION.
        labeled : TYPE, optional
            DESCRIPTION. The default is True.
        label_resolutions : TYPE, optional
            DESCRIPTION. The default is True.
        loc_thresh_labels : TYPE, optional
            DESCRIPTION. The default is 'l'.

        Returns
        -------
        ax : TYPE
            DESCRIPTION.


Make plot of skill scores with countries on x-axis, methods in legend


Make plot of skill scores with method on x-axis, countries in legend


Make boxplot of skill scores with method on x-axis


    Simple running mean.
    CAUTION: Data is *extended* at the edges by repeating the
    edge values; thereby any trend present in the data will
    become attenuated at the edges!


    This function adjusts for vulnerability, applying a GDP fit, either in the
    log space or the linear space. Not used in the paper output!
    Parameters
    ----------
    dataFrame : DataFrame
        regionally aggregated model medians
    use_log : bool
        if True apply logarithmic (not used)
    column_name : string
        independent regression variable
    column_nameY : string
        dependent regression variable

    Returns
    -------
    RegressionObject
        regionally aggregated damages and other indicators


    Function calculated upper and lower cutoff values
    for outlier removal
    ----------
    ratio : Column of DataFrame
        Ratio of recorded to modeled damages

    Returns
    -------
    floats
        lower cutoff, upper cutoff


    This functions estimates a vulnerability function, by flattening the ration
    of observed and modeled damages. Provided is a smoothing with different
    window-sizes for running means and a smoothing with the SSA tool. For
    further analysis only ssa_5 was considered (11-yr running mean)
    Parameters
    ----------
    ratio : Column of DataFrame
        Ratio of recorded to modeled damages

    Returns
    -------
    np.arrays
        Ratios with different window sizes


    This functions adjusts modeled damages for vulnerability changes using
    vulnerability functions
    ----------
    data : DataFrame
        DataFrame with modeled damages
    vul_func : np.array
        time dependent vulnerability function
    dis : string
        discharge group

    Returns
    -------
    np.arrays
        damages after accounting for vulnerability, including onethird and two-
        third model quantiles


    This functions adjusts modeled damages for vulnerability changes depending
    GDP ot time obtained from a regression.
    ----------
    reg : RegressionObject
        result from the vulnerability fit
    data : DataFrame
        DataFrame with modeled damages
    log_char : string
        double logarithmic or semi-logarithmic fit
    disch : string
        discharge group
    Returns
    -------
    np.arrays
        damages after accounting for vulnerability, including onethird and two-
        third model quantiles


    Correlation of modeled and observed damages
    ----------
    corr_obs_ts : np.array
        observed damages
    corr_ts : np.array
        damages to be correlated
    use_log : string
        correlation in log space
    Returns
    -------
    CorrelationObject


    Spearman-rank-correlation of modeled and observed damages
    ----------
    corr_obs_ts : np.array
        observed damages
    corr_ts : np.array
        damages to be correlated
    use_log : string
        correlation in log space
    Returns
    -------
    CorrelationObject


    Pearson-Correlation of modeled and observed damages, applying a running
    mean before (3yr)
    ----------
    corr_obs_ts : np.array
        observed damages
    corr_ts : np.array
        damages to be correlated
    use_log : string
        correlation in log space
    Returns
    -------
    CorrelationObject


    Sums up annual damages to total damages
    ----------/home/insauer/projects/Attribution/Floods/Paper_NC_Review_Data/vulnerability_test/modeled/outlier_3
    data : DataFrame
        DataFrame with modeled damages

    Returns
    -------
    total_oberved_damages
    total_model_damages
    total_pred_damages


    Prepares dataframe for file output

    Parameters
    ----------
    region : string
        shortage of region
    corr_mod : CorrelationObject
        pearson correlation coefficient (model/observed)
    corr_pred : CorrelationObject
        pearson correlation coefficient (vulnerability adjusted
                                         model/observed)
    tot_obs_dam : float
        total observed damages 1980-2010
    tot_mod_dam : float
        total modeled damages 1980-2010
    tot_pred_dam : float
        total vulnerability adjusted damages 1980-2010
    disch : string
        discharge region

    Returns
    -------
    DataFrame
        all output variables for one region


    Wrapper function for vulnerability estimation and correlation

    Parameters
    ----------
    dataFrame : DataFrame
        DataFrame containing full time series
    log_char : string
        Aplling logarithmic metrics
    x_dep : TYPE
        variable used for fit time or GDP (not relevant in current version)
    rm_columns : string list, optional
        columns selected for running-mean consideration

    Returns
    -------
    region_data : DataFrame
        All damage Time series including those with vulnerability estimates
    fit_data : DataFrame
        Other metrics, such as correlation, total damages...


    Aggregates global data to provide GLB as additional region

    Parameters
    ----------
    time_series : DataFrame
        Time series of all damages

    Returns
    -------
    time_series : DataFrame
        Damage time series including GLB


    Theil-Sen-Slope estimation and Mann-Kendall-Test to estimate the
    contribution of each driver!

    Parameters
    ----------
    dataFrame71 : time series
        Time series

    Returns
    -------
    regH : List MK-output
        Sen_slope and MK-test result with uncertainty range of hazard
        (with 1980 fixed exposure)(TS_Haz) 1980-2010
    regHE : List MK-output
        Sen_slope and MK-test result with uncertainty range of TS_HazExp
        1980-2010
    regF : List MK-output
        Sen_slope and MK-test result with uncertainty range of TS_Full
        1980-2010.
    regH7 : List MK-output
        Sen_slope and MK-test result with uncertainty range of hazard
        (with 1980 fixed exposure)(TS_Haz) 1971-2010
    regH107 : List MK-output
        Sen_slope and MK-test result with uncertainty range of hazard
        (with 2010 fixed exposure)(TS_Haz) 1971-2010
    regH10 : List MK-output
        Sen_slope and MK-test result with uncertainty range of hazard
        (with 2010 fixed exposure)(TS_Haz) 1980-2010
    regE : List MK-output
        Sen_slope and MK-test result with uncertainty range of exposure
        difference function (TS_HazExp - TS_Haz) 1980-2010 (not used)
    regE7 : List MK-output
        Sen_slope and MK-test result with uncertainty range of exposure
        difference function (TS_HazExp - TS_Haz) 1971-2010 (not used)
    regV : List MK-output
        Sen_slope and MK-test result with uncertainty range of vulnerability
        difference function (TS_full - TS_Haz_Exp)(not used)
    regI : List MK-output
        Sen_slope and MK-test result with uncertainty range of modeled damges
        (including vulnerability)
    regN : List MK-output
        Sen_slope and MK-test result with uncertainty range of observed damages


    Normalisation of time series. Normalisation for trends estimation
    normalises everything to total observed damage. Normalisation for plotting
    shifts time series to the same starting point in 1980.
    ----------
    region : string
        Abbrevation of region
    dataFrame : DataFrame
        Time series

    Returns
    -------
    dataFrame : DataFrame
        Time series + normalised time series


    Prepare output table for attribution done with Mann-Kendall and Theil-Sen slope

    Parameters
    ----------
    region : string
        Abbrevation of region
    dat : DataFrame
        Time series
    regMeta : DataFrame
        Fitting info (not used)
    regLHaz : List MK-output
        Sen_slope and MK-test result with uncertainty range of hazard
        (with 1980 fixed exposure)(TS_Haz) 1980-2010
    regLHazExp :  List MK-output
        Sen_slope and MK-test result with uncertainty range of TS_HazExp
        1980-2010
    regLFull : List MK-output
        Sen_slope and MK-test result with uncertainty range of TS_Full
        1980-2010..
    regH7 : List MK-output
        Sen_slope and MK-test result with uncertainty range of hazard
        (with 1980 fixed exposure)(TS_Haz) 1971-2010
    regH107 : List MK-output
        Sen_slope and MK-test result with uncertainty range of hazard
        (with 2010 fixed exposure)(TS_Haz) 1971-2010
    regH10 : List MK-output
        Sen_slope and MK-test result with uncertainty range of hazard
        (with 2010 fixed exposure)(TS_Haz) 1980-2010
    regE : List MK-output
        Sen_slope and MK-test result with uncertainty range of exposure
        difference function (TS_HazExp - TS_Haz) 1980-2010 (not used)
    regE7 : List MK-output
        Sen_slope and MK-test result with uncertainty range of exposure
        difference function (TS_HazExp - TS_Haz) 1971-2010 (not used)
    regV : List MK-output
        Sen_slope and MK-test result with uncertainty range of vulnerability
        difference function (TS_full - TS_Haz_Exp)(not used)
    regI : List MK-output
        Sen_slope and MK-test result with uncertainty range of modeled damges
        (including vulnerability)
    regN : List MK-output
        Sen_slope and MK-test result with uncertainty range of observed damages

    Returns
    -------
    table1 : DataFrame
        final output for one region


    Wrapper function that coordinates attribution and prepares data output
    for each region.

    Parameters
    ----------
    dataFrame : DataFrame
        Time series
    metaData : DataFrame
        Vulnerability fit info
    normalisation : string
        parameter used for normalistion (not really used)
    regr : string
        regression method used for trend estimation

    Returns
    -------
    normData : DataFrame
        normalised time series
    attrTable : DataFrame
        attribution output


    Prepares dataframe for file output

    Parameters
    ----------
    region : string
        shortage of region
    corr_mod : CorrelationObject
        pearson correlation coefficient (model/observed)
    corr_pred : CorrelationObject
        pearson correlation coefficient (vulnerability adjusted
                                         model/observed)
    corr_mod_log : CorrelationObject
        pearson correlation coefficient (model/observed) in the log-space
    corr_pred_log : CorrelationObject
        pearson correlation coefficient (vulnerability adjusted
                                         model/observed) in the log-space
    sp_corr_pred : CorrelationObject
        spearman correlation coefficient (vulnerability adjusted
                                         model/observed)
    corr_mod_log90 : CorrelationObject
        pearson correlation coefficient (model/observed) in the log-space
         (1990-2010)
    corr_pred_log90 : CorrelationObject
        pearson correlation coefficient (vulnerability adjusted
                                         model/observed) in the log-space
                                         1990-2010
    corr_pred90 : CorrelationObject
        pearson correlation coefficient (vulnerability adjusted
                                         model/observed) 1990-2010
    corr_mod90 : CorrelationObject
        pearson correlation coefficient (model/observed) 1990-2010
    sp_corr_pred90 : CorrelationObject
        spearman correlation coefficient (vulnerability adjusted
                                         model/observed) 1990-2010
    tot_obs_dam : float
        total observed damages 1980-2010
    tot_mod_dam : float
        total modeled damages 1980-2010
    tot_pred_dam : float
        total vulnerability adjusted damages 1980-2010
    disch : string
        discharge region

    Returns
    -------
    DataFrame
        all output variables for one region


    Theil-Sen-Slope estimation and Mann-Kendall-Test to estimate the
    contribution of each driver!

    Parameters
    ----------
    dataFrame71 : time series
        Time series.
    disch : string
        discharge group

    Returns
    -------
    regH : List MK-output
        Sen_slope and MK-test result with uncertainty range of hazard
        (with 1980 fixed exposure)(TS_Haz) 1980-2010
    regHE : List MK-output
        Sen_slope and MK-test result with uncertainty range of TS_HazExp
        1980-2010
    regF : List MK-output
        Sen_slope and MK-test result with uncertainty range of TS_Full
        1980-2010.
    regH7 : List MK-output
        Sen_slope and MK-test result with uncertainty range of hazard
        (with 1980 fixed exposure)(TS_Haz) 1971-2010
    regH107 : List MK-output
        Sen_slope and MK-test result with uncertainty range of hazard
        (with 2010 fixed exposure)(TS_Haz) 1971-2010
    regH10 : List MK-output
        Sen_slope and MK-test result with uncertainty range of hazard
        (with 2010 fixed exposure)(TS_Haz) 1980-2010
    regE : List MK-output
        Sen_slope and MK-test result with uncertainty range of exposure
        difference function (TS_HazExp - TS_Haz) 1980-2010 (not used)
    regE7 : List MK-output
        Sen_slope and MK-test result with uncertainty range of exposure
        difference function (TS_HazExp - TS_Haz) 1971-2010 (not used)
    regV : List MK-output
        Sen_slope and MK-test result with uncertainty range of vulnerability
        difference function (TS_full - TS_Haz_Exp)(not used)
    regI : List MK-output
        Sen_slope and MK-test result with uncertainty range of modeled damges
        (including vulnerability)
    regN : List MK-output
        Sen_slope and MK-test result with uncertainty range of observed damages


    Prepare output table for attribution done with Mann-Kendall and Theil-Sen slope

    Parameters
    ----------
    region : string
        Abbrevation of region
    dat : DataFrame
        Time series
    regLHaz : List MK-output
        Sen_slope and MK-test result with uncertainty range of hazard
        (with 1980 fixed exposure)(TS_Haz) 1980-2010
    regLHazExp :  List MK-output
        Sen_slope and MK-test result with uncertainty range of TS_HazExp
        1980-2010
    regLFull : List MK-output
        Sen_slope and MK-test result with uncertainty range of TS_Full
        1980-2010..
    regH7 : List MK-output
        Sen_slope and MK-test result with uncertainty range of hazard
        (with 1980 fixed exposure)(TS_Haz) 1971-2010
    regH107 : List MK-output
        Sen_slope and MK-test result with uncertainty range of hazard
        (with 2010 fixed exposure)(TS_Haz) 1971-2010
    regH10 : List MK-output
        Sen_slope and MK-test result with uncertainty range of hazard
        (with 2010 fixed exposure)(TS_Haz) 1980-2010
    regE : List MK-output
        Sen_slope and MK-test result with uncertainty range of exposure
        difference function (TS_HazExp - TS_Haz) 1980-2010 (not used)
    regE7 : List MK-output
        Sen_slope and MK-test result with uncertainty range of exposure
        difference function (TS_HazExp - TS_Haz) 1971-2010 (not used)
    regV : List MK-output
        Sen_slope and MK-test result with uncertainty range of vulnerability
        difference function (TS_full - TS_Haz_Exp)(not used)
    regI : List MK-output
        Sen_slope and MK-test result with uncertainty range of modeled damges
        (including vulnerability)
    regN : List MK-output
        Sen_slope and MK-test result with uncertainty range of observed damages
    dis : string
        discharge group

    Returns
    -------
    table1 : DataFrame
        final output for one region


    This function aggregates country-level damages and variables to
    regional level.
    Parameters
    ----------
    x : DataFrame
        country-level damages and other indicators for all model combinations

    Returns
    -------
    DataFrame
        regionally aggregated damages and other indicators


    This function aggregates the damages and other indicators from the
    different model runs to the model median and adds basic statistics such as
    the one-third and two-third quantiles.

    Parameters
    ----------
    x : DataFrame
        regionally aggregated damages and other indicators for all model
        combinations

    Returns
    -------
    DataFrame
         model medians of regionally aggregated damages and other indicators


    This function inserts national annual variables in the MegaDataFrame
    containing all the data. Damages are all converted to capital stock by
    applying a corresponding annual national conversion factor.
    Inserted are:
        GDP (not relevant for final paper)
        GDP 10 yr running mean (not relevant for final paper)
        GDP per capita (not relevant for final paper)
        Population (not relevant for final paper)
        Capital Stock (not relevant for final paper)
        GMT (not relevant for final paper)
        recorded damages (NatCat Munich Re)

    Parameters
    ----------
    megaDataFrame : DataFrame
        big data set containing all the data from all model runs
    years : int array
        years to be considered
    gdp_resc : bool
        gdp to capital stock conversion

    Returns
    -------
    DataFrame
         model medians of regionally aggregated damages and other indicators


    This function combines world regions to bigger regions

    Parameters
    ----------
    dataFrame : DataFrame
        DataFrame containig smaller regions

    Returns
    -------
    DataFrame
         DataFrame with manipulated regions


    This function is a wrapper for the aggregation and selects the columns to
    be aggregated to regional level.

    Parameters
    ----------
    out_cols : string list
        Columns to be aggregated

    Returns
    -------
    DataFrame
         regionally aggregated damages and other indicators regions


    This function is a wrapper for the multi-model aggregation and provides
    the model median for each region of all variables.

    Parameters
    ----------
    out_cols : string list
        Columns to be aggregated

    Returns
    -------
    DataFrame
         regionally aggregated model medians


    This function gathers all the data from all model runs and
    provides one big data set containing damage data for all model runs

    Parameters
    ----------
    path : string
        Path to directory on cluster where all runs are stored
    years : int array

    Returns
    -------
    DataFrame
         full data


    This function adjusts for vulnerability, applying a GDP fit, either in the
    log space or the linear space. All relevant columns are normalised before
    they are correlated.
    Parameters
    ----------
    ratio : Column of DataFrame
        Ratio of recorded to modeled damages

    Returns
    -------
    np.arrays
        Ratios with different window sizes


    This functions adjusts modeled damages for vulnerability changes depending
    GDP ot time obtained from a regression.
    ----------
    reg : RegressionObject
        result from the vulnerability fit
    data : DataFrame
        DataFrame with modeled damages
    log_char : string
        double logarithmic or semi-logarithmic fit
    x_dep : string
        independance variable (Year, GDPpc)
    Returns
    -------
    np.arrays
        damages after accounting for vulnerability, including onethird and two-
        third model quantiles


    Pearson-Correlation of modeled and observed damages
    ----------
    corr_obs_ts : np.array
        observed damages
    corr_ts : np.array
        damages to be correlated
    use_log : string
        correlation in log space
    Returns
    -------
    CorrelationObject


    Spearman-Rank-Correlation of modeled and observed damages, applying a
    running mean before (3yr)
    ----------
    corr_obs_ts : np.array
        observed damages
    corr_ts : np.array
        damages to be correlated
    use_log : string
        correlation in log space
    Returnsf3_ax1.scatter(DATA_regionFull['Year'], DATA_regionFull['ratios'], label='Ratio', color='black', marker = 'o', s = 2)
    -------
    CorrelationObject


    This function adjusts modeled damages for vulnerability changes using
    vulnerability functions
    ----------
    data : DataFrame
        DataFrame with modeled damages
    vul_func : np.array
        time dependent vulnerability function

    Returns
    -------
    np.arrays
        damages after accounting for vulnerability, including onethird and two-
        third model quantiles


    This function adjusts modeled damages for vulnerability changes using
    the paramter from the sen-slope
    ----------
    data : DataFrame
        DataFrame with modeled damages
    trend_info: np.array
        parameters from the TheilSenSlope estimation

    Returns
    -------
    np.arrays
        damages after accounting for vulnerability, including onethird and two-
        third model quantiles


    Sums up annual damages to total damages
    ----------
    data : DataFrame
        DataFrame with modeled damages

    Returns
    -------
    total_oberved_damages
    total_model_damages
    total_pred_damages


Prepares dataframe for file output
    ----------
    region : string
         shortage of region
    p_corr_mod : CorrelationObject
         pearson correlation coefficient (model/observed)
    p_corr_pred : CorrelationObject
         pearson correlation coefficient (vulnerability adjusted
                                         model/observed)
    tot_obs_dam : float
         total observed damages 1980-2010
    tot_mod_dam : float/home/insauer/projects/Attribution/Floods/Paper_NC_Resubmission_data/Supplement
         total modeled damages 1980-2010
    tot_pred_dam : float
         total vulnerability adjusted damages 1980-2010

    Returns
    -------
    DataFrame
        all output variables for one region


    This function gathers all the data from all model_runs and
    provides one big data set containing all model runs

    Parameters
    ----------
    path : string
        Path to directory on cluster where all runs are stored
    sort : string list
        columns used for sorting
    years : int array

    Returns
    -------
    DataFrame
         full data


    Wrapper function to select the best model. Function provides all possible
    combination of predictors and a constant and evaluates the model applying
    the LooCV. It selects the model with the smallest out-of sample error.

    Parameters
    ----------
    climateDat : np.array
        damage time series
    telecon : DataFrame
        teleconnections and GMT

    Returns
    -------
    best_model: GLMObject
        full GLM object of the best model
    best_model_indices[0]: int
        x-index of the best model (indicates combination of predictors)
    best_model_indices[1]: int
        y-index of the best model (indicates link function)
    iter_max: int
        number iterations needed for convergence of the best model
    pearson_corr: float
        pearson correlation of model and data
    best_loo: float
        out-of-sample-error of the best model
    looICs_lf: np.array
        all out-off-sample errors


    Reads the coefficients and p-values for each predictor of the best model
    and saves data in a csv file. To achieve comparability between coefficients of
    models with different link functions the partial devaritive in a centric
    development point is calculated.

    Parameters
    ----------
    region : string
        region abbreviation
    model : GLMObject
        best model (1971-2010, 1980 fixed exposure)
    link : int
        index of link function (1971-2010, 1980 fixed exposure)
    model10 : GLMObject
        best model (1971-2010, 2010 fixed exposure)
    link10 : int
        index of link function (1971-2010, 2010 fixed exposure)
    model80 : GLMObject
        best model (1980-2010, 1980 fixed exposure)
    link80 : int
        index of link function (1980-2010, 1980 fixed exposure)
    model8010 : GLMObject
        best model (1980-2010, 2010 fixed exposure)
    link8010 : int
        index of link function (1980-2010, 1980 fixed exposure)
    dis : string
        discharge group


    Check for the presence of an unexplainable trend after adjustment for
    teleconnections

    Parameters
    ----------
    pval : float
        p-value of residual trend
    slope : float
        slope of residual trend
    test_region : string
        region
    change : slope
        slope of trend in damages
    sign : float
        significance of slope in damages

    Returns
    -------
    bool


This function calculates the the leave-one-out-Cross-Validation

    Parameters
    ----------
    clim : damage time series
        DESCRIPTION.
    predic : DataFrame
        DESCRIPTION.
    fnc : LinkFunctionObject
        link function

    Returns
    -------
    out of sample error


    Wrapper function to select the best model. Function provides all possible
    combination of predictors and a constant and evaluates the model applying
    the LooCV. It selects the model with the smallest out-of-sample-error.

    Parameters
    ----------
    climateDat : np.array
        damage time series
    telecon : DataFrame
        teleconnections and GMT

    Returns
    -------
    best_model: GLMObject
        full GLM object of the best model
    best_model_indices[0]: int
        x-index of the best model (indicates combination of predictors)
    best_model_indices[1]: int
        y-index of the best model (indicates link function)
    iter_max: int
        number iterations needed for convergence of the best model
    pearson_corr: float
        pearson correlation of model and data
    best_loo: float
        out-of-sample-error of the best model
    looICs_lf: np.array
        all out-off-sample errors


    Reads the coefficients and p-values for each predictor of the best model
    and saves data in a csv file. To achieve comparability between coefficients of
    models with different link functions the partial devaritive in a centric
    development point is calculated.

    Parameters
    ----------
    region : string
        region abbreviation
    model : GLMObject
        best model (1971-2010, 1980 fixed exposure)
    link : int
        index of link function (1971-2010, 1980 fixed exposure)
    model10 : GLMObject
        best model (1971-2010, 2010 fixed exposure)
    link10 : int
        index of link function (1971-2010, 2010 fixed exposure)
    model80 : GLMObject
        best model (1980-2010, 1980 fixed exposure)
    link80 : int
        index of link function (1980-2010, 1980 fixed exposure)
    model8010 : GLMObject
        best model (1980-2010, 2010 fixed exposure)
    link8010 : int
        index of link function (1980-2010, 1980 fixed exposure)


    Generate file paths for CSV and NPZ files based on hazard, exposure, and warming.

    Parameters:
    - hazard (str): The type of hazard (e.g., 'TC', 'RF').
    - exposure (str): The type of exposure (e.g., 'pop', 'assets').
    - warming (str): The warming scenario (e.g., '1', '2').
    - file_type (str): Type of the file ('csv' or 'npz'). Defaults to 'csv'.

    Returns:
    - A string representing the file path.


    Load impacts from CSV and NPZ files for a given hazard, exposure, and warming scenario.

    Parameters:
    - hazard (str): The type of hazard.
    - exposure (str): The type of exposure.
    - warming (str): The warming scenario.

    Returns:
    - An Impact object loaded with data from the files.


    Combine impacts for given hazards and save the combined impact to CSV and NPZ files.

    Parameters:
    - impacts (dict): Dictionary of Impact objects with exposure types as keys.
    - exposure (str): The exposure type.
    - warming (str): The warming level.
    - combination (tuple): Tuple of hazard types to combine.
    - occur_together (bool): Indicates whether events from different hazards occur together.
    - how (str): Method to combine impacts, default is 'sum'.


    Order event names based on given strings contained in the event names.

    Parameters
    ----------
    impact: Impact
        with event_name based on the given strings
    n_events: Int
        Number of events in the output. Default: 1
    list_string : list
        A list of string based on which to order the events.
        For example climate models ['miroc5','ipsl-cm5a-lr','gfdl-esm2m','hadgem2-es']
        default is None

    Raises
    ------
    AttributeError
        If no list is providing

    Returns
    -------
    impact : Impact
        Impact yearset.


    Aggregate the impact per year to make yearsets. Maximum impact per year
    at each exposure point is exposure value if exp is not None.

    Parameters
    ----------
    impact : Impact
        Impact with an impact matrix and events with dates per year
    how : How to aggregate impacts, options are 'sum' or 'max'
    exp : Exposure
        Exposure of Impact to cap the impact value at the value of the exposure
    Raises
    ------
    AttributeError
        If impact matrix is empty.

    Returns
    -------
    impact : Impact
        Impact yearset.


    Parameters
    ----------
    impact_list : list  or dict of impacts
    how : how to combine the impacts, options are 'sum', 'max' or 'min'
    exp : If the exposures are given, the impacts are caped at their value

    Returns
    -------
    imp : Impact
        Combined impact


    Parameters
    ----------
    impact_dict : dict of Impact
        dictionary of impacts
    n_years : number of years
    exposures : If the exposures are given, the impacts are caped at their value

    Returns
    -------
    imp : Impact
        Combined impact


    Parameters
    ----------
    impact_dict : dict of Impact objects
        dictionary or list of impacts.
    n_samples : number of samples, the total number of events will be of len(list_samples_string)*n
    list_string : List of string to look for in the event names

    Returns
    -------
    ordered_impact_dict : dict of Impact objects
        Ordered impact dictionary


    Parameters
    ----------
    impact_dict : dict of Impacts
    temporal : bool, rather to consider the temporal dimension
    spatial : bool, rather to consider the spatial dimension

    Returns
    -------
    corr_df : pd.DataFrame


    Parameters
    ----------
    impact : Impact
    countries : list of countries iso3 code

    Returns
    -------
    corr_df : dict of imp_mat, keys are country iso3 codes


    Load impact data for a specific hazard, exposure, and warming scenario.

    Parameters:
    - hazard (str): Type of hazard ('TC' or 'RF').
    - exposure (str): Type of exposure ('pop' or 'assets').
    - warming (str): Warming scenario ('1' or '2').
    - cap_str (str): String indicating whether impacts are capped ('_caped' or '').

    Returns:
    - Impact: An instance of the Impact class loaded with data.


    Save the combined impact data to CSV and NPZ files.

    Parameters:
    - combined_impact (Impact): The combined impact object to be saved.
    - exposure (str): Type of exposure.
    - combi (tuple): Tuple of combined hazards.
    - warming (str): Warming scenario.
    - cap_str (str): String indicating whether impacts are capped.


    Combine impacts for different hazards, log messages, and save the results.

    Parameters:
    - impacts_yearsets_ordered (dict): Dictionary of ordered Impact objects.
    - exposure_dict (dict): Dictionary containing exposure data.
    - exposure (str): Type of exposure.
    - warming (str): Warming scenario.
    - cap_str (str): String indicating whether impacts are capped.


    Adjusted main function to compute combined impacts for specific exposure and warming settings.

    Parameters:
    - exposure (str): The exposure setting to compute impacts for.
    - warming (str): The warming scenario to compute impacts for.
    - cap_at_exp (bool): Flag to indicate whether to cap impacts at exposure levels each year. Defaults to True.


    Selects hazard events within specified geographical bounds.

    Parameters:
    - haz (Hazard): A CLIMADA Hazard object.
    - bounds (tuple): A tuple of (lonmin, lonmax, latmin, latmax) defining the geographical bounds.

    Returns:
    - haz (Hazard): A modified CLIMADA Hazard object with events outside the specified bounds removed.


    Loads tropical cyclone hazard realizations from CSV files and filters them by year and basin.

    Parameters:
    - path (str): Path to the CSV file containing tropical cyclone data.
    - year_start (int): Start year for filtering.
    - year_end (int): End year for filtering.
    - basin (str): Specific basin to filter the cyclones (default is None).
    - draws_subset (array-like): Specific subset of realization IDs to include (default is None).

    Returns:
    - hazard (Hazard): A CLIMADA Hazard object containing filtered tropical cyclone events.


    Generates and stores tropical cyclone hazards for specified RCP scenarios and warming levels.

    This function iterates over different RCP scenarios, GCM models, and warming levels to generate
    a set of tropical cyclone hazards. The hazards are then concatenated and stored in a specified
    HDF5 file.


Load and process combined impact data for given exposure, hazard combination, and warming scenario.


Process individual hazard data for the identified 100-year event.


        Process wildfire hazard data from a global scale down to individual countries.

        The function reads the global wildfire hazard data and saves the hazard data for each individual country.


            Process STORM TC hazard data from a global scale down to individual countries.

            The function reads the global hazard data and saves the hazard data for each individual country.


        Compute river floods hazard for given years and scenario and write results to an HDF5 file.

        Parameters:
            years (list of int, optional): List of start and end year. Default is [1980, 2010].
            scenario (str, optional): Scenario to consider. Default is 'hist'.


    Create centroids for a given bounding box, with given resolution for land and ocean, and then combine both.

    The function reads the geographical boundaries, creates centroids for both land and ocean,
    combines them, computes additional attributes, and saves the centroids to an output file.

    Parameters:
        out_file_path (str): Path for saving the output centroids.
        bounds (tuple, optional): Boundaries for creating centroids in the format (lon_min, lat_min, lon_max, lat_max).
                                  Default is (-180, -60, 180, 60).
        res_land_arcsec (int, optional): Resolution for land in arcseconds. Default is 150.
        res_ocean_arcsec (int, optional): Resolution for ocean in arcseconds. Default is 1800.
        land_buffer (float, optional): Buffer around land in degrees, to still consider the land resolution.
        Default is 0.1.

    Returns:
        None


    Process tropical cyclone hazard data from a global scale down to individual countries.

    The function reads the global tropical cyclone hazard data, filters and saves the hazard
    data for each individual country based on the provided scenarios and years.

    Parameters:
        years_list (list of int, optional): List of years to consider. Default is [2040, 2060].
        scenarios (list of str, optional): List of scenarios to consider. Default is ['rcp85'].
        n_tracks (int, optional): Number of synthetic tracks. Default is 10.
        replace (bool, optional): If True, existing country-specific tropical cyclone hazard
                                  files will be overwritten. Default is True.


     Process river flood hazard data from a global scale down to individual countries.

     The function reads the global river flood hazard data for a specified scenario and years,
     then filters and saves the hazard data for each individual country.

     Parameters:
         years (list of str, optional): List of start and end year. Default is ['2010', '2030'].
         scenario (str, optional): Scenario to consider (e.g., 'rcp26'). Default is 'rcp26'.
         replace (bool, optional): If True, existing country-specific river flood hazard
                                   files will be overwritten. Default is True.

     Returns:
         None


    Compute climate change scenarios for tropical cyclones for specified basins, scenarios, and years.

    The function reads the historical tropical cyclone hazard data, applies the climate change scenarios,
    and saves the modified hazard data.

    Parameters:
        basin (str, optional): Name of the tropical cyclone genesis basin. Default is 'EP'.
        climate_scenarios (list of int, optional): List of climate scenarios (RCPs) to consider. Default is [85].
        future_years (list of int, optional): List of years to consider for the climate change scenarios. Default is [2040, 2060, 2080].
        n_tracks (int, optional): Number of synthetic tracks. Default is 10.


    Read tropical cyclone tracks from the IBTrACS dataset, with a given number of synthetic tracks
    using thetc_tracks.calc_perturbed_trajectories() method

    Parameters:
        basin (str, optional): Name of the tropical cyclone genesis basin. Default is 'EP'.
        n_tracks (int or str, optional): Number of synthetic tracks to generate. If set to 0,
                                         no synthetic tracks are generated. Default is 10.

    Returns:
        None


    Create LitPop exposures at a country level and then concatenate them to create a global exposure.

    The function reads data, computes LitPop exposures for each country, and then combines
    them to create a global exposure dataset. The results are saved to predefined output directories.

    Parameters:
        exposure (str): Type of exposure to consider (e.g., 'pop', 'default', 'assets').


    Create a TropCyclone hazard set based on TCTracks for a specific basin. Should be ran
    after compute_tc_tracks.py

    The function reads the TC tracks for the specified basin, calculates the hazard,
    and saves the TropCyclone hazard set to an output file.

    Parameters:
        basin (str, optional): Name of the TC basin. Default is 'EP'.
        n_tracks (int, optional): Number of synthetic tracks to consider. Default is 10.


 Compute cost and MDR of investing current year in retrofitting. No
    maintenance.

    Parameter:
        reg_id (int): region where retroffiting applied
        exp (Exposures): exposures
        cost_deg (float): in [0,1]: 0 no willingness to pay (cheap),
            1 maximum willingness to pay (expensive)


Compute or load existing exposure islands using BlackMarble


Compute or load existing tracks from ibtracs data.


Add sea raster surrounding each island


 Compute tropical cyclone wind gust from tracks at every island group,
    if not contained in OUT_FOLDER.


Compute or load resulting impact statistics


 Combine events that are identified as different fire to one event

        Orig fires are removed and a new fire id created; max intensity at
        overlapping centroids is assigned.

        Parameters
        ----------
        event_id_merge : array of int, optional
            events to be merged
        remove_rest : bool, optional
            if set to true, only the merged event is returned.
        probabilistic : bool, optional
            differentiate, because probabilistic events have no date.

        Returns
        -------
        self : climada.hazard.WildFire instance


 Summarize historic fires into fire seasons.

        Fires are summarized by taking the max intensity at each grid point.

        Parameters
        ----------
        year_start : int, optional
            start year; fires before that are cut; no cut if not specified
        year_end : int, optional
            end year; fires after that are cut; no cut if not specified
        hemisphere : str, optional
            'SHS' or 'NHS' to define fire seasons

        Returns
        -------
        self : climada.hazard.WildFire instance


Read and remove low confidence data from firms:
            - MODIS: remove data where confidence values are lower than CLEAN_THRESH
            - VIIRS: remove data where confidence values are set to low (keep
                nominal and high values)

        Parameters
        ----------
        df_firms : pd.DataFrame
            FIRMS data as pd.Dataframe

        Returns
        -------
        df_firms : pd.DataFrame


 Returns resolution of satellite used in FIRMS in degrees

        Parameters
        ----------
        csv_firms : pd.DataFrame or str
            path to csv file of FIRMS data or FIRMS data as pd.Dataframe

        Returns
        -------
        res_data/ONE_LAT_KM : float
            resolution in degrees


 Create centroids according to the extent of the firms data.

        Parameters
        ----------
        df_firms : pd.DataFrame
            FIRMS data
        res_data : float
            FIRMS instrument resolution in degrees
        centr_res_factor : float
            the factor applied to voluntarly decrease/increase the
            centroids resolution. Hence, in order to set hazard resolution
            of MODIS data to 4 km, a centr_res_factor of 0.25 is applied.

        Returns
        -------
        centroids : Centroids


 Return resolution of the scalar grid of the centroids

        Parameters
        ----------
        centroids (Centroids): centroids instance

        Returns
        -------
        res_centr : float
            grid resolution of centroids


 Compute clusters of consecutive days (temporal clusters).

        An interruption of n days (as defined in self.days_thresh_firms) is
        necessary to be set in two different temporal clusters.

        Parameters
        ----------
        df_firms : pd.DataFrame
            FIRMS data

        Returns
        -------
        df_firms : pd.DataFrame
            FIRMS data including info on temporal cluster per point


 Compute geographic clusters and sort firms with ascending clus_id
        for each cons_id. Geographic clusters are identified using sci-kit
        learn's DBSCAN algorithm, which finds core samples of high density
        and expands clusters from them.

        https://scikit-learn.org/stable/modules/generated/sklearn.cluster.DBSCAN.html

        Parameters
        ----------
        df_firms : pd.DataFrame
            FIRMS data
        res_data : float
            FIRMS instrument resolution in degrees
        clus_thres : int
            Clustering factor which multiplies instrument resolution

        Returns
        -------
        df_firms : pd.DataFrame
            FIRMS data including info on spacial cluster per point


 Creation of event_id for each dataset point.
        A fire is characterized by a unique combination of 'cons_id' and 'clus_id'.

        Parameters
        ----------
        days_thres : int
            Temporal threshold for clustering
        df_firms : pd.DataFrame
            FIRMS data including info on temporal and spatial cluster per point

        Returns
        -------
        df_firms : pd.DataFrame
            FIRMS data including info on final cluster (=event) per point


Remove fires containg fewer FIRMS entries than threshold.
        A fire is characterized by a unique combination of 'cons_id' and 'clus_id'.

        Parameters
        ----------
        df_firms : pd.DataFrame
            FIRMS data
        minor_fires_thres : int
            threshold of FIRMS data points for an event

        Returns
        -------
        df_firms : pd.DataFrame
            FIRMS data excluding minor fire events


 Compute intensity matrix per fire with the maximum brightness at
        each centroid and all other hazard attributes.

        Parameters
        ----------
        df_firms : pd.DataFrame
            FIRMS data
        centroids : Centroids
        res_centr : float
            centroids resolution in centroids unit

        Returns
        -------
        self : climada.hazard.WildFire instance


 For a given fire, fill in an intensity np.array with the maximum brightness
        at each centroid.

        Parameters
        ----------
        df_firms : pd.DataFrame
            FIRMS data
        centroids : Centroids
        ev_id : int
            id of the selected event

        Returns
        -------
        brightness_ev : lil_matrix
            maximum brightness at each centroids


 Removes instances which were identified as an eventbut which
        contain no intensity. This happens for events which occur
        outside of the defined centroids.

        Parameters
        ----------
        bright_list : list
            idnividual wild fires
        firms : pd.DataFrame
            FIRMS data

        Returns
        -------
        bright_list_nonzero : list
            list with events that occured on the defined centroids
        firms : pd.DataFrame
            FIRMS data (with data that occured on the defined centroids)


 Generate a probabilistic fire season.

        Parameters
        ----------
        n_ignitions : int
            number of wild fires for the season
        seed : int

        Returns
        -------
        proba_fires : lil_matrix
            probablistic hazard


 Run one bushfire on a fire propagation probability matrix.
            If the matrix is not defined, it is constructed using past fire
            experience -> a fire can only propagate on centroids that burned
            in the past including a exponentially blurred range around the
            historic fires.
            The ignition point of a fire can be on any centroid, on which
            the propagation probability equals 1. The fire is then propagated
            with a cellular automat.
            If the fire has not stopped burning after a defined number of
            iterations (self.max_it_propa, default=500'000), the propagation
            is interrupted.

            Propagation rules:
                1. select a burning centroid (at the start there is only one,
                    afterwards select one randomly)
                2. every adjunct centroid to the selected centroid can start
                    burning with a probability of the overall propagation
                    probability (self.prop_proba) times the centroid specific
                    propagation probability (which is defined on the
                    fire_propa_matrix).
                3. the selected burning centroid becomes an ember centroid
                    which can not start burning again and thus no longer
                    propagate any fire.
            Properties from centr_burned:
                0 = unburned centroid
                1 = burning centroid
                2 = ember centroid
            Stop criteria: the propagation stops when no centroid is burning.
            The initial version of this code was inspired by
            https://scipython.com/blog/the-forest-fire-model/

        Parameters
        ----------
        self : climada.hazard.WildFire instance
            needs to contain information of at least 1 historic wildfire

        Returns
        -------
        centr_burned : np.array
            array indicating which centroids burned


 Propagation of the fire in the 8 neighbouring cells around
        (centr_ix, centr_iy) according to propagation rules.

        Parameters
        ----------
        centr_shape : np.array
            shape of centroids array
        fire_propa_matrix : np.array
            fire proagation matrix indicating centroid specific fire
            spread probability
        prop_proba : float
            global propagation probability
        centr_ix : int
            x coordinates of the burning centroid in the centroids matrix
        centr_iy : int
            y coordinates of the burning centroid in the centroids matrix
        centr_burned : np.array
            array containing information on burned centroids
        prob_array: np.array
            array of random numbers to draw from for random fire propagation

        Returns
        -------
        centr_burned : np.array
            updated centr_burned matrix


 The intensity values are chosen randomly at every burned centroid
        from the intensity values of the historical fire

        Parameters
        ----------
        self : climada.hazard.WildFire instance
        centr_burned : np.array
            array indicating which centroids burned

        Returns
        -------
        proba_intensity : lil_matrix
            hazard intensity matrix of generated probabilistic fire


 sets fire propagation matrix which is used to propagate
        probabilistic fires. The matrix is set so that burn probability on
        centroids which burned historically is set to 1. A blurr with
        exponential decay of burn probabilities is set around these
        centroids.
        Alternatively, the fire propagation probability matrix can be any
        matrix that coresponds to the shape of the centroids and thus not have
        to be set this way.

        Parameters
        ----------
        self : climada.hazard.WildFire instance
        n_blurr : int
            blurr width around historical fires

        Returns
        -------
        self.centroids.fire_propa_matrix : np.array


 Plots fire propagation probability matrix as contour plot.
        At this point just to check the matrix but could easily be improved to
        normal map.

        Parameters
        ----------
        self : climada.hazard.WildFire instance

        Returns
        -------
        contour plot : plt
            contour plot of fire_propa_matrix


 Selects data to create historic fire season. Need to
        differentiate between Northern & Souther hemisphere

        Parameters
        ----------
        firms : pd.DataFrame
            FIRMS data
        year : int
        hemisphere : str, optional
            'NHS' or 'SHS'
        Returns
        -------
        firms : pd.DataFrame
            FIRMS data for specified fire season


Set hazard frequency from intensity matrix.

        Parameters
        ----------
        self : climada.hazard.WildFire instance

        Returns
        -------
        self.frequency : np.array


 Assigns maximum intensity value for each centroid. This is required
    as it can happen that several firms data points are mapped on to one
    centroid.

        Parameters
        ----------
        num_centr : int
            number of centroids
        ind : np.array
            index of closest centroid of each firms point
        index_uni : np.array
            unique index of each centroid
        lat_lon_cpy : np.array
            lat /lon information of each firms point
        fir_bright : np.array
            brightness of each firms data point

        Returns:
        -------
        brightness_ev : np.array
            maximum brightness at each centroids


    calculates the absolute value impacted by hazard category
    :param exp: exposure dataframe
    :param impf_set: Impact function set
    :param haz: hazard dataframe
    :param path: string file path for output csv files
    :return:


    creates the impact function set based on the hazard categories and assigns 1 as their impact
    an impact function specific for the chosen hazard
    :param haz_type: abbreviation of hazard type
    :return:
    an impact function set for all hazard categories


    creates a 2-step impact function, with the impact being 1 between the two thresholds
    and 0 outside of the thresholds
    :type intensity: object
    :param intensity: Four windspeeds to define the step
    :param haz_type: Abbreviation of hazard type
    :return:
    an impact function for a specific hazard category


Split impact dataframes into regions for analysis


Read or generate hazard and or exposure


Generate cats in circles


    Read historic TC tracks, generate perturbed tracks and compute wind fields

    Parameters
    ----------
    basin : str
        The basin where a TC is formed is not defined in IBTrACS. However, this filter option
        allows to restrict to storms whose first valid eye position is in the specified basin,
        which simulates the genesis location. Note that the resulting genesis basin of a
        particular track may depend on the selected `provider` and on `estimate_missing`
        because only the first *valid* eye position is considered. Possible values are 'NA'
        (North Atlantic), 'SA' (South Atlantic), 'EP' (Eastern North Pacific, which includes
        the Central Pacific region), 'WP' (Western North Pacific), 'SP' (South Pacific),
        'SI' (South Indian), 'NI' (North Indian). If None, this filter is not applied.
        Default: None.
    bounds : tuple (lon_min, lat_min, lon_max, lat_max)

    Returns
    -------
    tc : TropCyclone


Cut out hazard in circles with specific radius


Git-specific installation logic for Versioneer.

    For Git, this means creating/changing .gitattributes to mark _version.py
    for export-time keyword substitution.


    Compute the vertical coordinate (y_coord) for a dataset.

    Parameters:
        ds (xarray.Dataset): Dataset containing the variables.
        time_indices (numpy.ndarray): Indices of the time range to average over.
        height_cord (str): Vertical coordinate type ('z' or 'p').
        var_name (str): Variable name for which the vertical coordinate is required.

    Returns:
        numpy.ndarray: The computed y-coordinate.


    Compute the diurnal composite for a given variable in a dataset.
    Returns:
        composite (np.ndarray), hour_labels (np.ndarray), success (bool), ndim (int)


    Compute the difference in days (as a floating-point value) between two dates and times.

    Parameters:
        date1 (str): First date in 'yyyymmdd' format.
        time1_seconds (int): Time of the first date in seconds (0 to 86400).
        date2 (str): Second date in 'yyyymmdd' format.
        time2_seconds (int): Time of the second date in seconds (0 to 86400).

    Returns:
        float: Difference in days, including the fractional day component.


Full parameter space combinations from a dict with iterables.

    parameters = {'A': [34, 56, 567], 'C': [12, 0], 'G': [1245]}
    This format is similar to sklearn ParameterGrid


Generate uniform random distributions.


Single row plot for BT, QT, TT.


Time benchmark plot.


Write this instance to a file using pickle.


Load a pickled TimeReport instance.


Difference of times between two TimeReport instances, diff = a - b.

    Note: Both reports must have the same axes atribute.


Create time benchmark statistics.


Validate init params: data.


Validate init params: N_cells.


Epsilon used to expand the grid.


Cell size in each dimension.


Return bins values.


Return data bin index.


Build the grid.


Check if points are contained within the grid.

        Parameters
        ----------
        points: ndarray, shape (m,k)
            The point or points to check against the grid domain.

        Returns
        -------
        bool: ndarray, shape (m,)
            Boolean array indicating if a point is contained within the grid.


Return grid cell indices for a given point.

        Parameters
        ----------
        points: ndarray, shape (m,k)
            The point or points to calculate the cell indices.

        Returns
        -------
        digits: ndarray, shape (m,k)
            Array of cell indices with same shape as `points`. If a point is
            outside of the grid edges `-1` is returned.


Return grid cell unique id for a given point.

        Parameters
        ----------
        points: ndarray, shape (m,k)
            The point or points to calculate the cell unique id.

        Returns
        -------
        ids: ndarray, shape (m,)
            Array of cell unique ids for each point. If a point is
            outside of the grid edges `-1` is returned.


Return unique id of cells given their digits.

        Parameters
        ----------
        digits: ndarray, shape (m,k)
            Array of cell indices. Must be integers.

        Returns
        -------
        ids: ndarray, shape (m,)
            Array of cell unique ids for each point.


Return cell digits given their unique id.

        Parameters
        ----------
        ids: ndarray, shape (m,)
            Array of cell unique ids for each point.

        Returns
        -------
        digits: ndarray, shape (m,k)
            Array of cell indices.


Return cell wall coordinates for given cell digits.

        Parameters
        ----------
        digits: ndarray, shape (m,k)
            Array of cell indices. Must be integers.

        Returns
        -------
        lower: ndarray, shape (m, 3)
            Lower cell wall values for each point.
        upper: ndarray, shape (m, 3)
            Upper cell wall values for each point.


Return cell centre coordinates for given cell digits.

        Parameters
        ----------
        digits: ndarray, shape (m,k)
            Array of cell indices. Must be integers.

        Returns
        -------
        centres: ndarray, shape (m, k)
            Cell centre for each point.


Return number of points within given cell digits.

        Parameters
        ----------
        digits: ndarray, shape (m,k)
            Array of cell indices. Must be integers.

        Returns
        -------
        count: ndarray, shape (m,)
            Cell count for each for each cell.


Return indices of points within given cell digits.

        Parameters
        ----------
        digits: ndarray, shape (m,k)
            Array of cell indices. Must be integers.

        Returns
        -------
        points: list, length m
            List of m arrays. Each array has the indices to the
            neighbors of that cell.


Validate init params: metric.


Cleanup the periodicity configuration.

        Remove the unnecessary axis from the periodic dict and also creates
        a configuration for use in the search.


Compute distance between points.

        metric options: 'euclid', 'sphere'

        Notes: In the case of 'sphere' metric, the input units must be degrees.


Retrieve neighbor distances whithin the given cells.


Retrieve cells touched by the search radius.


Generate Terran centres in the Mirror Universe.


Find all points within given distances of each centre.

        Parameters
        ----------
        centres: ndarray, shape (m,k)
            The point or points to search for neighbors of.
        distance_upper_bound: scalar or ndarray of length m
            The radius of points to return. If a scalar is provided, the same
            distance will apply for every centre. An ndarray with individual
            distances can also be rovided.
        sorted: bool, optional
            If True the returned neighbors will be ordered by increasing
            distance to the centre. Default: False.
        kind: str, optional
            When sorted = True, the sorting algorithm can be specified in this
            keyword. Available algorithms are: ['quicksort', 'mergesort',
            'heapsort', 'stable']. Default: 'quicksort'
        njobs: int, optional
            Number of jobs for parallel computation. Not implemented yet.

        Returns
        -------
        distances: list, length m
            Returns a list of m arrays. Each array has the distances to the
            neighbors of that centre.

        indices: list, length m
            Returns a list of m arrays. Each array has the indices to the
            neighbors of that centre.


Find all points within given lower and upper distances of each centre.

        The distance condition is:
            `distance_lower_bound <= distance < distance_upper_bound`

        Parameters
        ----------
        centres: ndarray, shape (m,k)
            The point or points to search for neighbors of.
        distance_lower_bound: scalar or ndarray of length m
            The minimum distance of points to return. If a scalar is provided,
            the same distance will apply for every centre. An ndarray with
            individual distances can also be rovided.
        distance_upper_bound: scalar or ndarray of length m
            The maximum distance of points to return. If a scalar is provided,
            the same distance will apply for every centre. An ndarray with
            individual distances can also be rovided.
        sorted: bool, optional
            If True the returned neighbors will be ordered by increasing
            distance to the centre. Default: False.
        kind: str, optional
            When sorted = True, the sorting algorithm can be specified in this
            keyword. Available algorithms are: ['quicksort', 'mergesort',
            'heapsort', 'stable']. Default: 'quicksort'
        njobs: int, optional
            Number of jobs for parallel computation. Not implemented yet.

        Returns
        -------
        distances: list, length m
            Returns a list of m arrays. Each array has the distances to the
            neighbors of that centre.

        indices: list, length m
            Returns a list of m arrays. Each array has the indices to the
            neighbors of that centre.


Find the n nearest-neighbors for each centre.

        Parameters
        ----------
        centres: ndarray, shape (m,k)
            The point or points to search for neighbors of.
        n: int, optional
            The number of neighbors to fetch for each centre. Default: 1.
        kind: str, optional
            The returned neighbors will be ordered by increasing distance
            to the centre. The sorting algorithm can be specified in this
            keyword. Available algorithms are: ['quicksort', 'mergesort',
            'heapsort', 'stable']. Default: 'quicksort'
        njobs: int, optional
            Number of jobs for parallel computation. Not implemented yet.

        Returns
        -------
        distances: list, length m
            Returns a list of m arrays. Each array has the distances to the
            neighbors of that centre.

        indices: list, length m
            Returns a list of m arrays. Each array has the indices to the
            neighbors of that centre.


Classic Euclidean distance.

    In mathematics, the Euclidean distance or Euclidean metric is the
    "ordinary" straight-line distance between two points in Euclidean space.
    With this distance, Euclidean space becomes a metric space. The associated
    norm is called the Euclidean norm. Older literature refers to the metric as
    the Pythagorean metric. A generalized term for the Euclidean norm is the L2
    norm or L2 distance. More info:
    https://en.wikipedia.org/wiki/Euclidean_distance


Distance using the Haversine formulae.

    The haversine formula determines the great-circle distance between two
    points on a sphere given their longitudes and latitudes. Important in
    navigation, it is a special case of a more general formula in spherical
    trigonometry, the law of haversines, that relates the sides and angles of
    spherical triangles. More info:
    https://en.wikipedia.org/wiki/Haversine_formula


Calculate distance  on the surface of a spheroid with Vincenty Formulae.

    Vincenty's formulae are two related iterative methods used in geodesy to
    calculate the distance between two points on the surface of a spheroid,
    developed by Thaddeus Vincenty (1975a). They are based on the assumption
    that the figure of the Earth is an oblate spheroid, and hence are more
    accurate than methods that assume a spherical Earth, such as great-circle
    distance. More info: https://en.wikipedia.org/wiki/Vincenty%27s_formulae


Validate method params: digits.


Validate method params: ids.


Validate method params: centres.


Distance bounds, upper and lower, can be scalar or numpy array.


Check if bool.


Define valid sorting algorithm names.


Validate method params: n_nearest.


Uniform[0:1]  ->  Gaussian[mean=mu,variance=sigma**2]


Needs to be tested


from stacker.py (modified)


    Could use map/reduce/ufuncs etc. to compute the median bins
    But for now just do this manually...


 Generate simulated data of antenna temperature spectrum measurement

    Args:
        rp (dict): Runtime parameter dictionary, as generated by parse_config()
        plot_data (bool): Plot the simulated data.

    Returns:
        (Tmeas, freqs): tuple of simulated temperature-frequency pairs


Joint prior - HI and foregrounds


    Form of lhood assumes uncertainties are gaussian and uncorrelated
    The latter can be extended later


    Generate Tf given foreground model coefficients
    T_sky(\nu) = 10^{\sum a_i (log10(\nu/60 MHz))^i}


Units are MHz and mK


    Noise model
    Units are K, Hz and sec


 Open a config.ini file and parse it into a dictionary of config values

    Args:
        filename (str): Filename of config file, including path.

    Returns:
        confdict (dict): Python dictionary of runtime parameters, as generated from config file.


    Finds the 95% and 68% confidence intervals, given a 2d histogram
    of the likelihood


Original alias for contourSingle


    #Given a chain, labels and a list of which parameters to plot, plots the contours
    # Arguments:
    # chain=an array of the chain (not using weights, i.e. each row counts only once)
    # p= a list of integers: the two parameters you want to plot (refers to two columns in the chain)
    #kwargs:        labels= the labels of the parameters (list of strings)
    #               col=a tuple of the two colours for the contour plot
    #               line=boolean whether or not to just do a line contour plot
    #               outfile='outf.png'


    #Given a chain, labels and a list of which parameters to plot, plots the contours
    # Arguments:
    # chain=an array of the chain (not using weights, i.e. each row counts only once)
    # p= a list of integers: the two parameters you want to plot (refers to two columns in the chain)
    #kwargs:        labels= the labels of the parameters (list of strings)
    #               col=a tuple of the two colours for the contour plot
    #               line=boolean whether or not to just do a line contour plot
    #               outfile='triangle.png'
    #               binsize=50
    #               reconstruct=boolean whether or not to plot reconstruction
    #               autoscale=boolean whether or not to autoscale axes
    #               ranges=dictionary of plot range lists, labelled by
    #                      parameter name, e.g. {'A':[0.0,1.0],etc.}
    #               title=outdir
    p is now ignored


Opens a logged-in CSDA client.


Sends a request to an auth endpoint.


Downloads a single asset from a STAC item to a local file.


Sends a request.

        This is useful to re-use an auth token, e.g. retrieved via `CsdaClient.login()`.


Log in this client with an Earthdata username and password.

        The retrieved token is saved in the session headers.

        Needless to say, you shouldn't be saving your username or password in code.


Return the data/ directory.


Make lots of Gaussian profiles.


Perform weighted simple linear regression on 2D data.


Decorator to return scalar outputs for wave2pix and pix2wave


    Convert wavelength to pixel given wavelength array

    Parameters
    ----------
       wave(s) : wavelength(s) (\AA) to get pixel of
       wave0 : array with wavelength as a function of pixel number
    Returns
    -------
       pixel(s) in the chip


    Convert pixel(s) to wavelength(s).

    Parameters
    ----------
       pix : pixel(s) to get wavelength at
       wave0 : array with wavelength as a function of pixel number

    Returns
    -------
    wavelength(s) in \AA


Modify the msa shutter table to expand the slits.


Check if a file is binary.


Make the labels array from a dictionary.


Make bounds for input parameter names.


Check that the parameters are in range.


Print out parameters and errors.


Create random parameters for initial guesses.


Model function for curve_fit.


        Method to return Jacobian matrix.
        This includes the contribution of the lookup table.

        Parameters
        ----------
        args : float
            Model parameter values as separate positional input parameters.
        retmodel : boolean, optional
            Return the model as well.  Default is retmodel=False.

        Returns
        -------
        if retmodel==False
        jac : numpy array
          Jacobian matrix of partial derivatives [N,Npars].
        model : numpy array
          Array of (1-D) model values for the input xdata and parameters.
          If retmodel==True, then (model,jac) are returned.

        Examples
        --------

        jac = JWSTSyn.jac(wave,*pars)


        Fit an observed spectrum with the ANN models and curve_fit.

        Parameters
        ----------
        spec : Spec1D
           Spectrum to fit.
        vrel : list
           Input list of doppler shifts for the spectra.
        cont : int, optional
           Continuum parameter:
            1   polynomial fitting  (ncont order, 0-constant, 1-linear)
            2   segmented normaleization  (ncont segments)
            3   running mean  (ncont pixels)
        ncont : int, optional
           Number for continuum normalization.  If cont=1, then ncont
            gives the polynomial order.  If cont=2, then ncont is the
            number of segements.  If cont=3, then ncont is the number
            of pixels for the running mean.
        loggrelation : bool, optional
           Use the logg-relation as a function of Teff/feh/alpha.

        Returns
        -------
        tab : table
           Output table of values.
        info : list
           List of dictionaries, one per spectrum, that includes spectra and arrays.

        Examples
        --------

        tab,info = fit(spec)


Simple Monte Carlo test to recover elemental abundances.


 Use sinc interpolation to get resampled values

        x : desired positions
        nres : number of pixels per resolution element (2=Nyquist)
        speclist : list of [quantity, variance] pairs (variance can be None)


Fit a spectral profile.


Trace a spectrum. Assumed to be in the horizontal direction.


    Compute the PSF from the image using "optimal extraction" techniques.

    Parameters
    ----------
    im : numpy array
       Flux image with the spectral trace.
    ytrace : numpy array
       Array giving the position of the trace in the Y-direction.
    err : numpy array, optional
       Uncertainty array for "im".
    off : int, optional
       The region around ytrace that is used to construct the spectral PSF.
         Default is 10.
    backoff : int, optional
       Vertical size of subimage to work on and use to estimate the
         background.  The Y boundary is median(ytrace)+/-backoff.
         Default is 50.
    smlen : int, optional
       Smoothing width in the spectral dimension.  Default is 31.

    Returns
    -------
    psf : numpy array
       The 2D normalized PSF for the spectral trace.

    Examples
    --------

    psf = optimalpsf(im,ytrace,err)


    Extract a spectrum using optimal extraction (Horne 1986).
    This uses an empirical PSF constructed from the image itself.

    Parameters
    ----------
    im : numpy array
       Flux image with the spectral trace.
    ytrace : numpy array
       Array giving the position of the trace in the Y-direction.
    imerr : numpy array, optional
       Uncertainty array for "im".
    verbose : bool, optional
       Verbose output to the screen.  Default is False.
    off : int, optional
       The region around ytrace that is used to construct the spectral PSF.
         Default is 10.
    backoff : int, optional
       Vertical size of subimage to work on and use to estimate the
         background.  The Y boundary is median(ytrace)+/-backoff.
         Default is 50.
    smlen : int, optional
       Smoothing width in the spectral dimension.  Default is 31.

    Returns
    -------
    flux : numpy array
       Spectral flux array.
    fluxerr : numpy array
       Flux uncertainty array.
    trace : numpy array
       Array giving the position of the trace in the Y-direction derived
         from the empirical PSF.
    psf : numpy array
       The 2D normalized PSF for the spectral trace.

    Examples
    --------

    flux,fluxerr,trace,psf = extract_optimal(im,ytrace,imerr)


    Extract spectrum with a PSF using weighted
    linear regression.

    Parameters
    ----------
    im : numpy array
       Flux image with the spectral trace.
    psf : numpy array
       2D normalized PSF to use for the extraction.
    err : numpy array, optional
       Uncertainty array for "im".
    skyfit : bool, optional
       Fit the sky/background.  Default is True.

    Returns
    -------
    flux : numpy array
       Spectral flux array.
    fluxerr : numpy array
       Flux uncertainty array.
    If skyfit is True, two additional values are returned.
    sky : numpy array
       Sky/background flux array.
    skyerr : numpy array
       Uncertainty in the sky flux array.

    Examples
    --------

    flux,fluxerr,sky,skyerr = extract_psf(im,psf,imerr,skyfit=True)


    Optimal extraction of a single column.

    Parameters
    ----------
    im : numpy array
       Flux 1D array column for the spectral trace.
    err : numpy array, optional
       Uncertainty array for "im".
    psf : numpy array
       1D normalized PSF to use for the extraction.

    Returns
    -------
    flux : numpy array
       Spectral flux array.
    fluxerr : numpy array
       Flux uncertainty array.

    Examples
    --------

    flux,fluxerr = extractcol(im,err,psf)


Find worst outlier pixel in a column


Fix outlier pixels using the PSF.


Fix large outlier pixels in an image.


    Extract the spectrum for a single slit using optiomal (Horne) extraction.
    reduce.extractexp() runs this function for all the slits in an exposure.

    Parameters
    ----------
    input_model :
       The cal file information as loaded by datamodels.open(calfile).
    slit : slit object
       Single slit object from the reduced cal file.
    backslit : slit object
       Slit object for the same source but from the background/dithered
         exposure.
    verbose : bool, optional
       Verbose output to the screen.  Default is False.
    applyslitcorr : bool, optional
       Apply SPyderWebb slit correction to the wavelengths.
       NOTE, the wavecorr correction in reduce.py applies the slit correction
       but only to the wavelength array/extension.  But this function does
       *NOT* use the wavelength array, but instead uses the WCS directly.
       However, the slit correction applied here should give the same result
       as the wavecorr correction.
    plotbase : str, optional
       Output base name for the plot.  Default is "extract".
         The diagnostic plot has filename plotbase+'_flux.png"

    Returns
    -------
    sp : Spec1D object
       The fully extracted spectrum as a Spec1D object.

    Examples
    --------

    sp = extract_slit(input_model,slit,backslit=None,ocalhdu=False)


Extract one slit.


Make QA html pages.


Apply extinction to the photometry.


Run Doppler jointly on visit files for a star.


Run Doppler one visit stellar spectrum.


Run Doppler on the stacked stellar spectrum.


Run Doppler on all the stars.


    Run FERRE on list of spectra

    Parameters
    ----------
    files : list
       Input list of spectrum files.
    vrel : list
       Input list of doppler shifts for the spectra.
    inter : int, optional
       Interpolation algorithm.
         0   nearest neighbor
         1   linear
         2   quadratic Bezier
         3   cubic Bezier
         4   cubic spline
       Default is 3.
    algor : int, optional
       Search algorithm?
        -1   weighted average over the grid  likely
         0   pixel with lowest value         minlocus
         1   Nelder-mead method (Miller's)   minim
         2   BTR method (Csendes/Miller)     global
         3   uobyqa method (Powell/Miller)    uobyqa
         4   truncated Newton                lmqnbc
         5   MCMC                             mcmcde
       Default is 1.
    init : int, optional
       Starting point for search.
         0   use the values in pfile
         1   follow the rules set by keyword indini
       Default is 1.
    indini : list, optional
       Individual control of starting points for each parameter.
    nruns : int, optional
       Number of searches to be done.  Default is 1.
    cont : int, optional
       Continuum parameter:
         1   polynomial fitting  (ncont order, 0-constant, 1-linear)
         2   segmented normaleization  (ncont segments)
         3   running mean  (ncont pixels)
    ncont : int, optional
       Number for continuum normalization.  If cont=1, then ncont
         gives the polynomial order.  If cont=2, then ncont is the
         number of segments.  If cont=3, then ncont is the number
         of pixels for the running mean.
    errbar : int, optional
       Choice of algorithm to compute error bars.
         0   adopt the distance from solution at which chisq=min(chisq)+1
         1   invert the curvature matrix
       Default is 1.
    save : bool, optional
       Do not delete the temporary directory.  Default is save=False.

    Returns
    -------
    tab : table
       Output table of values.
    info : list
       List of dictionaries, one per spectrum, that includes spectra and arrays.

    Examples
    --------

    tab,info = run_ferre(files,vrel,algor=1,nruns=5)


Derives distances from isochrones.


Calculate the relative flux correction.


Return the slope.


Return the Y-intercept.


Return the X-value where the line intercepts Y.


Return the two edge lines.


 Get the polygon with the full width of the line and
            input xr/yr ranges.


Return the covering fraction of a grid defined by xr/yr ranges.


Return the points of the polygon.


Return a vertical line with step i (+ or - integer) from the center (left or right).


Return a horizontal line with step i (+ or - integer) from the center (up or down).


Check if the shutters are working in the input images.


Determine shutter parameters by fitting image.


Model a NIRSPEC MSATA image with just the background.


Get information about the FERRE grid.


    Interpolate in the FERRE grid.

    Parameters
    ----------
    pars : numpy array
       Array of parameters/labels.  This can be a 2D array [Nstars,Nlabels].
    wave : numpy array, optional
       Output wavelengths.  By default, all wavelengths of the grid are used.
    cont : int, optional
       FERRE "cont" continuum parameter.
    ncont : int, optional
       FERRE "ncont" continuum parameter.
    grid : str, optional
       The FERRE grid name.
    griddir : str, optional
       Directory of the FERRE grids.
    ferresrc : str, optional
       Filename of FERRE executable.

    Returns
    -------
    out : dict
       Output parameters.  Dictionary with 'wave' and 'flux'.  If a 2D parameter
         is input, then 'flux' will be 2D but 'wave' will still be 1D.

    Examples
    --------

    out = interp([5000.0, 2.5, -1.2, 0.2])


Normalize a spectrum.


        Method to return Jacobian matrix.
        This includes the contribution of the lookup table.

        Parameters
        ----------
        wave : numpy array
            Wavelength array.
        args : float
            Model parameter values as separate positional input parameters,
            [amp, xcen, ycen, sky]. If allpars=True, then the model
            parameters are added at the end, i.e.
            [amp, xcen, ycen, sky, model parameters].
        retmodel : boolean, optional
            Return the model as well.  Default is retmodel=False.

        Returns
        -------
        if retmodel==False
        jac : numpy array
          Jacobian matrix of partial derivatives [N,Npars].
        model : numpy array
          Array of (1-D) model values for the input xdata and parameters.
          If retmodel==True, then (model,jac) are returned.

        Examples
        --------

        jac = ferre.jac(xdata,*pars)


    Run FERRE on list of spectra

    Parameters
    ----------
    slist : list
       A list of dictionaries with wave, flux, err and vrel.
    vrel : list
       Input list of doppler shifts for the spectra.
    inter : int, optional
       Interpolation algorithm.
         0   nearest neighbor
         1   linear
         2   quadratic Bezier
         3   cubic Bezier
         4   cubic spline
       Default is 3.
    algor : int, optional
       Search algorithm?
        -1   weighted average over the grid  likely
         0   pixel with lowest value         minlocus
         1   Nelder-mead method (Miller's)   minim
         2   BTR method (Csendes/Miller)     global
         3   uobyqa method (Powell/Miller)    uobyqa
         4   truncated Newton                lmqnbc
         5   MCMC                             mcmcde
       Default is 1.
    init : int, optional
       Starting point for search.
         0   use the values in pfile
         1   follow the rules set by keyword indini
       Default is 1.
    indini : list, optional
       Individual control of starting points for each parameter.
    nruns : int, optional
       Number of searches to be done.  Default is 1.
    cont : int, optional
       Continuum parameter:
         1   polynomial fitting  (ncont order, 0-constant, 1-linear)
         2   segmented normalization  (ncont segments)
         3   running mean  (ncont pixels)
    ncont : int, optional
       Number for continuum normalization.  If cont=1, then ncont
         gives the polynomial order.  If cont=2, then ncont is the
         number of segements.  If cont=3, then ncont is the number
         of pixels for the running mean.
    errbar : int, optional
       Choice of algorithm to compute error bars.
         0   adopt the distance from solution at which chisq=min(chisq)+1
         1   invert the curvature matrix
       Default is 1.
    save : bool, optional
       Do not delete the temporary directory.  Default is save=False.

    Returns
    -------
    tab : table
       Output table of values.
    info : list
       List of dictionaries, one per spectrum, that includes spectra and arrays.

    Examples
    --------

    tab,info = fit(files,vrel,algor=1,nruns=5)


Prepare the spectra for input to FERRE


    Fit spectrum with curve_fit running FERRE to get the models
    for each set of parameters.

    Parameters
    ----------
    slist : list
       A list of dictionaries with wave, flux, err and vrel.
    vrel : list
       Input list of doppler shifts for the spectra.
    cont : int, optional
       Continuum parameter:
         1   polynomial fitting  (ncont order, 0-constant, 1-linear)
         2   segmented normaleization  (ncont segments)
         3   running mean  (ncont pixels)
    ncont : int, optional
       Number for continuum normalization.  If cont=1, then ncont
         gives the polynomial order.  If cont=2, then ncont is the
         number of segements.  If cont=3, then ncont is the number
         of pixels for the running mean.
    loggrelation : bool, optional
       Use the logg-relation as a function of Teff/feh/alpha.

    Returns
    -------
    tab : table
       Output table of values.
    info : list
       List of dictionaries, one per spectrum, that includes spectra and arrays.

    Examples
    --------

    tab,info = cfit(files,vrel)


Default JWST resolution and wavelength spectrum.


    data : photometry for single star
    iso : isochrone data