<commit_before>### Imports ###

# Package Imports
from hrl import HRL

# Qualified Imports
import numpy as np
import sys
import argparse as ap
import os

# Unqualified Imports
from random import shuffle


# Argument parser
prsr = ap.ArgumentParser(prog="hrl-util lut measure",
    description="""
    This script measures the relationship between the desired intensity (a
    normalized value between 0 and 1) given to the monitor, and the luminance
    produced by the monitor, and saves it to the file 'measure.csv'. This is
    the first step in generating a lookup table for normalizing a monitor's
    luminance.
    """)

prsr.add_argument('-sz',dest='sz',default=0.5,type=float,help='The size of the central patch, as a fraction of the total screen size. Default: 0.5')

prsr.add_argument('-s',dest='stps',default=65536,type=int,help='The number of unique intensity values to be sampled. Default: 65536')

prsr.add_argument('-mn',dest='mn',default=0.0,type=float,help='The minimum sampled intensity. Default: 0.0')

prsr.add_argument('-mx',dest='mx',default=1.0,type=float,help='The maximum sampled intensity. Default: 1.0')

prsr.add_argument('-n',dest='nsmps',default=5,type=int,help='The number of samples to be taken at each intensity. Default: 5')

prsr.add_argument('-sl',dest='slptm',default=200,type=int,help='The number of milliseconds to wait between each measurement. Default:200')

prsr.add_argument('-r',dest='rndm',action='store_true',help='Shall we randomize the order of intensity values? Default: False')

prsr.add_argument('-v',dest='rvs',action='store_true',help='Shall we reverse the order of intensity values (high to low rather than low to high)? Default: False')

# Settings (these can all be changed with system arguments)

def measure(args):
    
    args = prsr.parse_args(args)

    wdth = 1024
    hght = 768

    # Initializing HRL

    flnm = 'measure.csv'
    flds = ['Intensity'] + [ 'Luminance' + str(i) for i in range(args.nsmps) ]

    graphics = 'datapixx'
    inputs = 'keyboard'
    photometer = 'optical'

    fs = True

    hrl = HRL(graphics=graphics,inputs=inputs,photometer=photometer
            ,wdth=wdth,hght=hght,bg=0,rfl=flnm,rhds=flds,fs=fs,scrn=1)

    itss = np.linspace(args.mn,args.mx,args.stps)
    if args.rndm: shuffle(itss)
    if args.rvs: itss = itss[::-1]

    (pwdth,phght) = (wdth*args.sz,hght*args.sz)
    ppos = ((wdth - pwdth)/2,(hght - phght)/2)
    print pwdth
    print ppos
    print phght

    done = False

    for its in itss:

        hrl.results['Intensity'] = its

        ptch = hrl.graphics.newTexture(np.array([[its]]))
        ptch.draw(ppos,(pwdth,phght))
        hrl.graphics.flip()

        print 'Current Intensity:', its
        smps = []
        for i in range(args.nsmps):
            smps.append(hrl.photometer.readLuminance(5,args.slptm))

        for i in range(len(smps)):
            hrl.results['Luminance' + str(i)] = smps[i]

        hrl.writeResultLine()

        if hrl.inputs.checkEscape(): break

    # Experiment is over!
    hrl.close()


if __name__ == '__main__':
    main()
<commit_msg>added some options to hrl-util lut measure<commit_after>### Imports ###

# Package Imports
from hrl import HRL

# Qualified Imports
import numpy as np
import sys
import argparse as ap
import os

# Unqualified Imports
from random import shuffle


# Argument parser
prsr = ap.ArgumentParser(prog="hrl-util lut measure",
    description="""
    This script measures the relationship between the desired intensity (a
    normalized value between 0 and 1) given to the monitor, and the luminance
    produced by the monitor, and saves it to the file 'measure.csv'. This is
    the first step in generating a lookup table for normalizing a monitor's
    luminance.
    """)

prsr.add_argument('-sz',dest='sz',default=0.5,type=float,help='The size of the central patch, as a fraction of the total screen size. Default: 0.5')

prsr.add_argument('-s',dest='stps',default=65536,type=int,help='The number of unique intensity values to be sampled. Default: 65536')

prsr.add_argument('-mn',dest='mn',default=0.0,type=float,help='The minimum sampled intensity. Default: 0.0')

prsr.add_argument('-mx',dest='mx',default=1.0,type=float,help='The maximum sampled intensity. Default: 1.0')

prsr.add_argument('-n',dest='nsmps',default=5,type=int,help='The number of samples to be taken at each intensity. Default: 5')

prsr.add_argument('-sl',dest='slptm',default=200,type=int,help='The number of milliseconds to wait between each measurement. Default:200')

prsr.add_argument('-r',dest='rndm',action='store_true',help='Shall we randomize the order of intensity values? Default: False')

prsr.add_argument('-v',dest='rvs',action='store_true',help='Shall we reverse the order of intensity values (high to low rather than low to high)? Default: False')

prsr.add_argument('-p', dest='photometer', type=str, default='optical', help='The photometer to use. Default: optical')

prsr.add_argument('-o', dest='flnm', type=str, default='measure.csv', help='The output filename. Default: measure.csv')
# Settings (these can all be changed with system arguments)

def measure(args):

    args = prsr.parse_args(args)

    wdth = 1024
    hght = 768

    # Initializing HRL

    flnm = args.flnm
    flds = ['Intensity'] + [ 'Luminance' + str(i) for i in range(args.nsmps) ]

    graphics = 'datapixx'
    inputs = 'keyboard'
    photometer = args.photometer

    fs = True

    hrl = HRL(graphics=graphics,inputs=inputs,photometer=photometer
            ,wdth=wdth,hght=hght,bg=0,rfl=flnm,rhds=flds,fs=fs,scrn=1)

    itss = np.linspace(args.mn,args.mx,args.stps)
    if args.rndm: shuffle(itss)
    if args.rvs: itss = itss[::-1]

    (pwdth,phght) = (wdth*args.sz,hght*args.sz)
    ppos = ((wdth - pwdth)/2,(hght - phght)/2)
    print pwdth
    print ppos
    print phght

    done = False

    for its in itss:

        hrl.results['Intensity'] = its

        ptch = hrl.graphics.newTexture(np.array([[its]]))
        ptch.draw(ppos,(pwdth,phght))
        hrl.graphics.flip()

        print 'Current Intensity:', its
        smps = []
        for i in range(args.nsmps):
            smps.append(hrl.photometer.readLuminance(5,args.slptm))

        for i in range(len(smps)):
            hrl.results['Luminance' + str(i)] = smps[i]

        hrl.writeResultLine()

        if hrl.inputs.checkEscape(): break

    # Experiment is over!
    hrl.close()


if __name__ == '__main__':
    main()

{'fraction_non_alphanumeric': 0.13184772516248838, 'fraction_numerical': 0.013927576601671309, 'mean_word_length': 3.7909562638991847, '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': '3589496', 'n_tokens_mistral': 2282, 'n_tokens_neox': 2167, 'n_words': 575}