<commit_before>#include <phypp.hpp>

// Structure to define a line group to be fitted simultaneously
struct line_t {
    line_t() = default;
    line_t(std::string n, vec1d lam, vec1d ra) : name(n), lambda(lam), ratio(ra) {
        ratio /= ratio[0];
    }

    std::string name; // identifier of the line
    vec1d lambda;     // wavelengths of the lines
    vec1d ratio;      // flux ratios of the lines relative to the first
};

// Local functions (defined at the end of the file)
vec2u segment(vec2u map, uint_t first_id, uint_t& nsrc);
vec2u grow_within(vec2u map, vec2b mask);
void print_help(const std::map<std::string,line_t>& db);
void print_available_lines(const std::map<std::string,line_t>& db);

int main(int argc, char* argv[]) {
    // Build the line data base (you can add your own there!)
    // NB: the line grouping and theoretical ratios are not used here
    // the whole data base will be "flattended" later on. This format
    // is just used for consistency with clinefit and slinefit.
    std::map<std::string,line_t> linedb = {
        {"lyalpha", line_t("lyalpha", {0.12157},        {1.0})},
        {"c4",      line_t("c4",      {0.15495},        {1.0})},
        {"c3",      line_t("c3",      {0.19087},        {1.0})},
        {"mg2",     line_t("mg2",     {0.2799},         {1.0})},
        {"o2",      line_t("o2",      {0.3727},         {1.0})},
        {"ne3",     line_t("ne3",     {0.3869},         {1.0})},
        {"o3",      line_t("o3",      {0.5007, 0.4959}, {1.0, 0.3})},
        {"hdelta",  line_t("hdelta",  {0.4103},         {1.0})},
        {"hgamma",  line_t("hgamma",  {0.4342},         {1.0})},
        {"hbeta",   line_t("hbeta",   {0.4861},         {1.0})},
        {"halpha",  line_t("halpha",  {0.6563},         {1.0})},
        {"n2",      line_t("n2",      {0.6584},         {1.0})},
        {"s2",      line_t("s2",      {0.6718, 0.6733}, {1.0, 0.75})},
        {"palpha",  line_t("palpha",  {1.875},          {1.0})}
    };

    if (argc < 2) {
        print_help(linedb);
        return 0;
    }

    std::string expmap;
    double minexp = 1;
    double spatial_smooth = 1.2; // radius of the smoothing kernel
    uint_t spectral_bin = 1; // number of spectral pixels to sum
    bool save_cubes = false;
    double snr_det = 5.0; // SNR threshold for detections
    double snr_source = 3.0; // lower SNR threshold for the extents of the source
    bool verbose = false;
    double error_scale = 1.0;
    uint_t lambda_pad = 5;
    vec1d zhint;
    double maxdv = 200.0;
    double maxdist = 5;
    double qflag2_snr_threshold = 5.0;
    bool disable_zsearch = false;
    uint_t minqflag = 0;
    bool single_source = false;
    std::string outdir;
    bool ascii = false;
    std::string semethod = "stddevneg";

    read_args(argc-1, argv+1, arg_list(expmap, minexp, spatial_smooth, save_cubes,
        snr_det, snr_source, verbose, spectral_bin, zhint, maxdv, maxdist, single_source,
        qflag2_snr_threshold, minqflag, error_scale, outdir, ascii, disable_zsearch,
        lambda_pad, name(semethod, "emethod")));

    if (!outdir.empty()) {
        outdir = file::directorize(outdir);
        file::mkdir(outdir);
    }

    if (zhint.size() != 0 && zhint.size() != 2) {
        error("'zhint' must contain two values: the minimum and maximum allowed redshift");
        return 1;
    }

    // Find out which method to use to compute the uncertainties
    enum class error_method {
        pipeline,
        mad,
        stddev,
        madneg,
        stddevneg
    } emethod = error_method::stddevneg;

    vec<1,std::pair<std::string,error_method>> semethod_dict = {
        {"pipeline",  error_method::pipeline},
        {"mad",       error_method::mad},
        {"stddev",    error_method::stddev},
        {"madneg",    error_method::madneg},
        {"stddevneg", error_method::stddevneg},
    };

    bool found_method = false;<commit_msg>Added the missing lines parameter<commit_after>#include <phypp.hpp>

// Structure to define a line group to be fitted simultaneously
struct line_t {
    line_t() = default;
    line_t(std::string n, vec1d lam, vec1d ra) : name(n), lambda(lam), ratio(ra) {
        ratio /= ratio[0];
    }

    std::string name; // identifier of the line
    vec1d lambda;     // wavelengths of the lines
    vec1d ratio;      // flux ratios of the lines relative to the first
};

// Local functions (defined at the end of the file)
vec2u segment(vec2u map, uint_t first_id, uint_t& nsrc);
vec2u grow_within(vec2u map, vec2b mask);
void print_help(const std::map<std::string,line_t>& db);
void print_available_lines(const std::map<std::string,line_t>& db);

int main(int argc, char* argv[]) {
    // Build the line data base (you can add your own there!)
    // NB: the line grouping and theoretical ratios are not used here
    // the whole data base will be "flattended" later on. This format
    // is just used for consistency with clinefit and slinefit.
    std::map<std::string,line_t> linedb = {
        {"lyalpha", line_t("lyalpha", {0.12157},        {1.0})},
        {"c4",      line_t("c4",      {0.15495},        {1.0})},
        {"c3",      line_t("c3",      {0.19087},        {1.0})},
        {"mg2",     line_t("mg2",     {0.2799},         {1.0})},
        {"o2",      line_t("o2",      {0.3727},         {1.0})},
        {"ne3",     line_t("ne3",     {0.3869},         {1.0})},
        {"o3",      line_t("o3",      {0.5007, 0.4959}, {1.0, 0.3})},
        {"hdelta",  line_t("hdelta",  {0.4103},         {1.0})},
        {"hgamma",  line_t("hgamma",  {0.4342},         {1.0})},
        {"hbeta",   line_t("hbeta",   {0.4861},         {1.0})},
        {"halpha",  line_t("halpha",  {0.6563},         {1.0})},
        {"n2",      line_t("n2",      {0.6584},         {1.0})},
        {"s2",      line_t("s2",      {0.6718, 0.6733}, {1.0, 0.75})},
        {"palpha",  line_t("palpha",  {1.875},          {1.0})}
    };

    if (argc < 2) {
        print_help(linedb);
        return 0;
    }

    std::string expmap;
    double minexp = 1;
    double spatial_smooth = 1.2; // radius of the smoothing kernel
    uint_t spectral_bin = 1; // number of spectral pixels to sum
    bool save_cubes = false;
    double snr_det = 5.0; // SNR threshold for detections
    double snr_source = 3.0; // lower SNR threshold for the extents of the source
    bool verbose = false;
    double error_scale = 1.0;
    uint_t lambda_pad = 5;
    vec1d zhint;
    double maxdv = 200.0;
    double maxdist = 5;
    double qflag2_snr_threshold = 5.0;
    bool disable_zsearch = false;
    uint_t minqflag = 0;
    bool single_source = false;
    std::string outdir;
    bool ascii = false;
    vec1s lines;
    std::string semethod = "stddevneg";

    read_args(argc-1, argv+1, arg_list(expmap, minexp, spatial_smooth, save_cubes,
        snr_det, snr_source, verbose, spectral_bin, zhint, maxdv, maxdist, single_source,
        qflag2_snr_threshold, minqflag, error_scale, outdir, ascii, disable_zsearch,
        lambda_pad, lines, name(semethod, "emethod")));

    if (!outdir.empty()) {
        outdir = file::directorize(outdir);
        file::mkdir(outdir);
    }

    if (zhint.size() != 0 && zhint.size() != 2) {
        error("'zhint' must contain two values: the minimum and maximum allowed redshift");
        return 1;
    }

    if (!lines.empty()) {
        bool bad = false;
        std::map<std::string, line_t> tdb;
        for (auto& l : lines) {
            auto iter = linedb.find(l);
            if (iter == linedb.end()) {
                error("unknown line '", l, "'");
                bad = true;
            } else {
                tdb.insert(*iter);
            }
        }

        if (bad) {
            print_available_lines(linedb);
            return 1;
        }

        std::swap(linedb, tdb);
    }

    // Find out which method to use to compute the uncertainties
    enum class error_method {
        pipeline,
        mad,
        stddev,
        madneg,
        stddevneg
    } emethod = error_method::stddevneg;

    vec<1,std::pair<std::string,error_method>> semethod_dict = {
        {"pipeline",  error_method::pipeline},
        {"mad",       error_method::mad},
        {"stddev",    error_method::stddev},
        {"madneg",    error_method::madneg},
        {"stddevneg", error_method::stddevneg},
    };

    bool found_method = false;
{'fraction_non_alphanumeric': 0.15004181101421574, 'fraction_numerical': 0.04109425397204635, 'mean_word_length': 2.2626656274356978, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1241209', 'n_tokens_mistral': 3066, 'n_tokens_neox': 2881, 'n_words': 750}