<commit_before>#!/usr/bin/env python3
import collections
import math
import os

# import numpy as np
import pandas as pd

pydir = os.path.dirname(os.path.abspath(__file__))

elsymbols = ['n'] + [line.split(',')[1]
                     for line in open(os.path.join(pydir, 'elements.csv'))]

roman_numerals = ('', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX',
                  'X', 'XI', 'XII', 'XIII', 'XIV', 'XV', 'XVI', 'XVII',
                  'XVIII', 'XIX', 'XX')

from astropy import constants as const

def showtimesteptimes(specfilename, numberofcolumns=5):
    specdata = pd.read_csv(specfilename, delim_whitespace=True)
    print('Time steps and times in days:\n')

    times = specdata.columns
    indexendofcolumnone = math.ceil((len(times) - 1) / numberofcolumns)
    for rownum in range(0, indexendofcolumnone):
        strline = ""
        for colnum in range(numberofcolumns):
            if colnum > 0:
                strline += '\t'
            newindex = rownum + colnum * indexendofcolumnone
            if newindex < len(times):
                strline += '{0:4d}: {1:.3f}'.format(
                    newindex, float(times[newindex + 1]))
        print(strline)


def get_elementlist(filename):
    elementtuple = collections.namedtuple(
        'elementtuple', 'Z,nions,lowermost_ionstage,uppermost_ionstage,nlevelsmax_readin,abundance,mass,startindex')

    elementlist = []
    with open(filename, 'r') as fcompdata:
        nelements = int(fcompdata.readline())
        fcompdata.readline()  # T_preset
        fcompdata.readline()  # homogeneous_abundances
        startindex = 0
        for _ in range(nelements):
            line = fcompdata.readline()
            linesplit = line.split()
            elementlist.append(elementtuple._make(
                list(map(int, linesplit[:5])) + list(map(float, linesplit[5:])) + [startindex]))
            startindex += elementlist[-1].nions
            print(elementlist[-1])

    return elementlist


def getmodeldata(filename):
    modeldata = []
    gridcelltuple = collections.namedtuple(
        'gridcell', 'cellid velocity logrho ffe fni fco f52fe f48cr')
    modeldata.append(gridcelltuple._make([-1, 0., 0., 0., 0., 0., 0., 0.]))
    with open(filename, 'r') as fmodel:
        # gridcellcount = int(fmodel.readline())
        # t_model_init = float(fmodel.readline())
        for line in fmodel:
            row = line.split()
            modeldata.append(gridcelltuple._make(
                [int(row[0])] + list(map(float, row[1:]))))

    return modeldata


def getinitialabundances1d(filename):
    abundancedata = []
    abundancedata.append([])
    with open(filename, 'r') as fabund:
        for line in fabund:
            row = line.split()
            abundancedata.append([int(row[0])] + list(map(float, row[1:])))

    return abundancedata


def get_spectrum(specfilename, timesteplow, timestephigh=-1, normalised=False,
                 fnufilterfunc=None):
    """
        returns a tuple of (wavelgnth in Angstroms, flux over d lambda [lambda in meters])<commit_msg>Document functions in readartisfiles.py<commit_after>#!/usr/bin/env python3
import collections
import math
import os

import pandas as pd
from astropy import constants as const

pydir = os.path.dirname(os.path.abspath(__file__))

elsymbols = ['n'] + [line.split(',')[1]
                     for line in open(os.path.join(pydir, 'elements.csv'))]

roman_numerals = ('', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX',
                  'X', 'XI', 'XII', 'XIII', 'XIV', 'XV', 'XVI', 'XVII',
                  'XVIII', 'XIX', 'XX')



def showtimesteptimes(specfilename, numberofcolumns=5):
    """
        Print a table showing the timeteps and their corresponding times
    """
    specdata = pd.read_csv(specfilename, delim_whitespace=True)
    print('Time steps and times in days:\n')

    times = specdata.columns
    indexendofcolumnone = math.ceil((len(times) - 1) / numberofcolumns)
    for rownum in range(0, indexendofcolumnone):
        strline = ""
        for colnum in range(numberofcolumns):
            if colnum > 0:
                strline += '\t'
            newindex = rownum + colnum * indexendofcolumnone
            if newindex < len(times):
                strline += '{0:4d}: {1:.3f}'.format(
                    newindex, float(times[newindex + 1]))
        print(strline)


def get_elementlist(filename):
    """
        Return a list containing named tuples for all included ions
    """
    elementtuple = collections.namedtuple(
        'elementtuple', 'Z,nions,lowermost_ionstage,uppermost_ionstage,nlevelsmax_readin,abundance,mass,startindex')

    elementlist = []
    with open(filename, 'r') as fcompdata:
        nelements = int(fcompdata.readline())
        fcompdata.readline()  # T_preset
        fcompdata.readline()  # homogeneous_abundances
        startindex = 0
        for _ in range(nelements):
            line = fcompdata.readline()
            linesplit = line.split()
            elementlist.append(elementtuple._make(
                list(map(int, linesplit[:5])) + list(map(float, linesplit[5:])) + [startindex]))
            startindex += elementlist[-1].nions
            print(elementlist[-1])

    return elementlist


def getmodeldata(filename):
    """
        Return a list containing named tuples for all model grid cells
    """
    modeldata = []
    gridcelltuple = collections.namedtuple(
        'gridcell', 'cellid velocity logrho ffe fni fco f52fe f48cr')
    modeldata.append(gridcelltuple._make([-1, 0., 0., 0., 0., 0., 0., 0.]))
    with open(filename, 'r') as fmodel:
        # gridcellcount = int(fmodel.readline())
        # t_model_init = float(fmodel.readline())
        for line in fmodel:
            row = line.split()
            modeldata.append(gridcelltuple._make(
                [int(row[0])] + list(map(float, row[1:]))))

    return modeldata


def getinitialabundances1d(filename):
    abundancedata = []
    abundancedata.append([])
    with open(filename, 'r') as fabund:
        for line in fabund:
            row = line.split()
            abundancedata.append([int(row[0])] + list(map(float, row[1:])))

    return abundancedata


def get_spectrum(specfilename, timesteplow, timestephigh=-1, normalised=False,
                 fnufilterfunc=None):
    """
        returns a tuple of (wavelgnth in Angstroms, flux over d lambda [lambda in meters])
{'fraction_non_alphanumeric': 0.13329180940516974, 'fraction_numerical': 0.01058860168171909, 'mean_word_length': 2.645289443813848, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2710484', 'n_tokens_mistral': 2096, 'n_tokens_neox': 2004, 'n_words': 471}