<commit_before># coding: utf-8

""" Class for reading data from SCF simulations """

from __future__ import division, print_function

__author__ = "adrn <<EMAIL>>"

# Standard library
import os, sys
import logging
import re

# Third-party
import numpy as np
import astropy.units as u
from astropy.constants import G
from astropy.table import Table

# Project
from .core import NBodyReader

# Create logger
logger = logging.getLogger(__name__)

__all__ = ["SCFReader"]

class SCFReader(NBodyReader):

    # TODO: way to list snapshot files?

    def _read_units(self):
        """ Read and parse the SCFPAR file containing simulation parameters
            and initial conditions. Right now, only parse out the simulation
            units.
        """
        pars = dict()

        pattr = re.compile("^([0-9\.e\+]+)\s+satellite\s+((scale)|(mass))\s\(([A-Za-z]+)\)")
        parfile = os.path.join(self.path, "SCFPAR")
        with open(parfile) as f:
            for line in f:
                spl = line.split()

                # find what G is set to
                try:
                    if spl[1].strip() == 'G':
                        pars['G'] = float(spl[0])
                except IndexError:
                    pass

                # parse out length scale and mass scale
                m = pattr.search(line)
                try:
                    grp = m.groups()
                    if grp[1] == 'scale':
                        pars['length'] = float(grp[0])
                    elif grp[1] == 'mass':
                        pars['mass'] = float(grp[0])
                except:
                    pass

                # exit if have length, mass, and G
                if pars.has_key('G') and pars.has_key('length')\
                    and pars.has_key('mass'):
                    break

        _G = G.decompose(bases=[u.kpc,u.M_sun,u.Myr]).value
        X = (_G / pars['length']**3 * pars['mass'])**-0.5

        length_unit = u.Unit("{0} kpc".format(pars['length']))
        mass_unit = u.Unit("{0} M_sun".format(pars['mass']))
        time_unit = u.Unit("{:08f} Myr".format(X))

        units = dict(length=length_unit,
                     mass=mass_unit,
                     time=time_unit,
                     speed=length_unit/time_unit,
                     dimensionless=u.dimensionless_unscaled)<commit_msg>parse file line by line<commit_after># coding: utf-8

""" Class for reading data from SCF simulations """

from __future__ import division, print_function

__author__ = "adrn <<EMAIL>>"

# Standard library
import os, sys
import logging
import re

# Third-party
import numpy as np
import astropy.units as u
from astropy.constants import G
from astropy.table import Table

# Project
from .core import NBodyReader

# Create logger
logger = logging.getLogger(__name__)

__all__ = ["SCFReader"]

class SCFReader(NBodyReader):

    # TODO: way to list snapshot files?

    def _read_units(self):
        """ Read and parse the SCFPAR file containing simulation parameters
            and initial conditions. Right now, only parse out the simulation
            units.
        """
        pars = dict()

        parfile = os.path.join(self.path, "SCFPAR")
        with open(parfile) as f:
            lines = f.readlines()

            # find what G is set to
            pars['G'] = float(lines[7].split()[0])
            pars['length'] = float(lines[17].split()[0])
            pars['mass'] = float(lines[18].split()[0])

        _G = G.decompose(bases=[u.kpc,u.M_sun,u.Myr]).value
        X = (_G / pars['length']**3 * pars['mass'])**-0.5

        length_unit = u.Unit("{0} kpc".format(pars['length']))
        mass_unit = u.Unit("{0} M_sun".format(pars['mass']))
        time_unit = u.Unit("{:08f} Myr".format(X))

        units = dict(length=length_unit,
                     mass=mass_unit,
                     time=time_unit,
                     speed=length_unit/time_unit,
                     dimensionless=u.dimensionless_unscaled)
{'fraction_non_alphanumeric': 0.12462387161484453, 'fraction_numerical': 0.00802407221664995, 'mean_word_length': 1.9244868035190617, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4361628', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1158, 'n_words': 308}