<commit_before>""" Module to faciliate scripting of EAZY analysis"""

import os
import warnings
from pkg_resources import resource_filename
from distutils import spawn
import subprocess

import numpy as np
import pandas

from astropy.table import Table
from astropy.cosmology import Planck15

from frb.surveys import catalog_utils

from IPython import embed

# Necessary because people might not execute eazy from src
# but might have a copy in bin or some other location.
try:
    _eazy_root = os.environ['EAZYDIR']
except KeyError:
    import pdb; pdb.set_trace()
    raise AssertionError('Please define the variable EAZYDIR in your environment pointing to the EAZY folder.')

_template_list = ['br07_default','br07_goods','cww+kin','eazy_v1.0','eazy_v1.1_lines','eazy_v1.2_dusty','eazy_v1.3','pegase','pegase13']
_acceptable_priors = ['prior_R_zmax7', 'prior_K_zmax7', 'prior_R_extend', 'prior_K_extend'] # F160W_TAO not included yet.
_default_prior = 'prior_R_zmax7'
_acceptable_combos = [1,2,99,-1,'a']

# This syncs to our custom FILTERS.RES.latest file
frb_to_eazy_filters = dict(GMOS_S_r=349,
                           LRISb_V=346,
                           LRISr_I=345,
                           NOT_z=348,
                           NIRI_J=257,
                           DECaL_g=294, # Turns out these are legacy transmission curves
                           DECaL_r=295,
                           DECaL_z=296,
                           DES_u=351, # Added DR1 filter curves
                           DES_g=352,
                           DES_r=353,
                           DES_i=354,
                           DES_z=355,
                           DES_y=356,
                           SDSS_u=156,
                           SDSS_g=157,
                           SDSS_r=158,
                           SDSS_i=159,
                           SDSS_z=160,
                           WISE_W1=244,
                           WISE_W2=245,
                           WISE_W3=246,
                           WISE_W4=247
                           )

def eazy_filenames(input_dir, name):
    """
    Generate names for EAZY files

    Args:
        input_dir (str):
            Path to eazy inputs/ folder  (can be relative)
            This is where eazy will be run
        name (str):
            Name of the source being analzyed

    Returns:
        tuple:  catalog_filename, parameter_filename, translate_file

    """
    if not os.path.isdir(input_dir):
        os.mkdir(input_dir)
    catfile = os.path.join(input_dir, '{}.cat'.format(name))
    param_file = os.path.join(input_dir, 'zphot.param.{}'.format(name))
    translate_file = os.path.join(input_dir, 'zphot.translate.{}'.format(name))
    #
    return catfile, param_file, translate_file


def eazy_setup(input_dir, template_dir=None):
    """
    Setup for EAZY

    Args:
        input_dir (str):
            Path to personal eazy inputs/ folder  (can be relative)
        template_dir(str, optional):
            Path to templates/ folder in EAZY software package.
            If not given, it looks for the folder of `eazy`,
            the executable and navigates from there.

    Returns:

    """
    if template_dir is None:
        template_dir = os.path.join(_eazy_root, "templates")
    if not os.path.isdir(input_dir):
        os.mkdir(input_dir)
    # Copy over templates
    os.system('cp -rp {:s} {:s}'.format(template_dir, os.path.join(input_dir, '..')))
    # And link
    os.system('ln -s {:s} {:s}'.format('../templates', os.path.join(input_dir, 'templates')))
    # And FILTER files
    filter_info = os.path.join(resource_filename('frb', 'data'), 'analysis', 'EAZY', 'FILTER.RES.latest.info')
    os.system('cp -rp {:s} {:s}'.format(filter_info, input_dir))
    filter_latest = os.path.join(resource_filename('frb', 'data'), 'analysis', 'EAZY', 'FILTER.RES.latest')
    os.system('cp -rp {:s} {:s}'.format(filter_latest, input_dir))
    return

def eazy_input_files(photom, input_dir, name, out_dir, prior_filter=None,
                     templates='eazy_v1.3', combo="a", cosmo=None,
                     magnitudes=False, prior=_default_prior,
                     zmin=0.050, zmax=7.000, zstep=0.0010, prior_ABZP=23.9,<commit_msg>no need to copy templates every single time.<commit_after>""" Module to faciliate scripting of EAZY analysis"""

import os
import warnings
from pkg_resources import resource_filename
from distutils import spawn
import subprocess

import numpy as np
import pandas

from astropy.table import Table
from astropy.cosmology import Planck15

from frb.surveys import catalog_utils

from IPython import embed

# Necessary because people might not execute eazy from src
# but might have a copy in bin or some other location.
try:
    _eazy_root = os.environ['EAZYDIR']
except KeyError:
    import pdb; pdb.set_trace()
    raise AssertionError('Please define the variable EAZYDIR in your environment pointing to the EAZY folder.')

_template_list = ['br07_default','br07_goods','cww+kin','eazy_v1.0','eazy_v1.1_lines','eazy_v1.2_dusty','eazy_v1.3','pegase','pegase13']
_acceptable_priors = ['prior_R_zmax7', 'prior_K_zmax7', 'prior_R_extend', 'prior_K_extend'] # F160W_TAO not included yet.
_default_prior = 'prior_R_zmax7'
_acceptable_combos = [1,2,99,-1,'a']

# This syncs to our custom FILTERS.RES.latest file
frb_to_eazy_filters = dict(GMOS_S_r=349,
                           LRISb_V=346,
                           LRISr_I=345,
                           NOT_z=348,
                           NIRI_J=257,
                           DECaL_g=294, # Turns out these are legacy transmission curves
                           DECaL_r=295,
                           DECaL_z=296,
                           DES_u=351, # Added DR1 filter curves
                           DES_g=352,
                           DES_r=353,
                           DES_i=354,
                           DES_z=355,
                           DES_y=356,
                           SDSS_u=156,
                           SDSS_g=157,
                           SDSS_r=158,
                           SDSS_i=159,
                           SDSS_z=160,
                           WISE_W1=244,
                           WISE_W2=245,
                           WISE_W3=246,
                           WISE_W4=247
                           )

def eazy_filenames(input_dir, name):
    """
    Generate names for EAZY files

    Args:
        input_dir (str):
            Path to eazy inputs/ folder  (can be relative)
            This is where eazy will be run
        name (str):
            Name of the source being analzyed

    Returns:
        tuple:  catalog_filename, parameter_filename, translate_file

    """
    if not os.path.isdir(input_dir):
        os.mkdir(input_dir)
    catfile = os.path.join(input_dir, '{}.cat'.format(name))
    param_file = os.path.join(input_dir, 'zphot.param.{}'.format(name))
    translate_file = os.path.join(input_dir, 'zphot.translate.{}'.format(name))
    #
    return catfile, param_file, translate_file


def eazy_setup(input_dir, template_dir=None):
    """
    Setup for EAZY

    Args:
        input_dir (str):
            Path to personal eazy inputs/ folder  (can be relative)
        template_dir(str, optional):
            Path to templates/ folder in EAZY software package.
            If not given, it looks for the folder of `eazy`,
            the executable and navigates from there.

    Returns:

    """
    if template_dir is None:
        template_dir = os.path.join(_eazy_root, "templates")
    if not os.path.isdir(input_dir):
        os.mkdir(input_dir)
    # And link
    os.system('ln -s {:s} {:s}'.format(template_dir, os.path.join(input_dir, 'templates')))
    # And FILTER files
    filter_info = os.path.join(resource_filename('frb', 'data'), 'analysis', 'EAZY', 'FILTER.RES.latest.info')
    os.system('cp -rp {:s} {:s}'.format(filter_info, input_dir))
    filter_latest = os.path.join(resource_filename('frb', 'data'), 'analysis', 'EAZY', 'FILTER.RES.latest')
    os.system('cp -rp {:s} {:s}'.format(filter_latest, input_dir))
    return

def eazy_input_files(photom, input_dir, name, out_dir, prior_filter=None,
                     templates='eazy_v1.3', combo="a", cosmo=None,
                     magnitudes=False, prior=_default_prior,
                     zmin=0.050, zmax=7.000, zstep=0.0010, prior_ABZP=23.9,
{'fraction_non_alphanumeric': 0.1019654556283502, 'fraction_numerical': 0.02835020845741513, 'mean_word_length': 2.0343332128659197, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5275597', 'n_tokens_mistral': 2861, 'n_tokens_neox': 2620, 'n_words': 622}