TypeError: float() argument must be a string or a number, not 'NoneType'

What are you trying to achieve?
I want to make an Serial Reaction Time Task for Motor in Psychopy Builder 2023.2.3, the orientation_degrees will be [0, 90, 180, 270] and the direction will be [0, 1, 2, 3], The participant will press the corresponding button to answer and the information all will be save in csv file with summary .

What is the problem?
After the learning block, it will be the motor block. The participant will answer the sequence which I set in the motor block by respond box, Now’s problem is after the learning block it just close and return this to me:

Files\PsychoPy\lib\site-packages\psychopy\visual\basevisual.py", line 1809, in ori
self.dict[‘ori’] = float(value)
TypeError: float() argument must be a string or a number, not ‘NoneType’

In general it should continue the motor block,but I have no idea about what happen on this?

Here is the code if any person need:

import numpy as np
import pandas as pd

Experiment setup: gather participant ID and learning condition type

participant_id = expInfo[‘participant’]
#learning_condition_id = expInfo[‘learning_type’]

Define experiment parameters

repetitions_per_block = 10
number_of_practice_blocks = 5
number_of_learning_blocks = 20
number_of_motortesting_blocks = 5
answer_directions = np.array([‘4’, ‘3’, ‘2’, ‘1’])

Define longer fixed sequence

fixed_sequence = [1, 0, 3, 0, 1, 2, 0, 2, 1, 3] # Longer fixed sequence

Function to rotate answer direction by 90 degrees clockwise

def rotate_clockwise_90(orientation):
return (orientation + 1) % 4

Function to generate alternating sequence without more than two consecutive same condition

def generate_alternating_sequence(random_part, fixed_part, rule_toggle, random_sequences):
sequence =
trial_types = # Record each trila are regular or random
regular_count = 0
random_count = 0

for rule in rule_toggle:
    if rule ==1:
        sequence.append(fixed_part[:10])
        fixed_part  = fixed_part[10:] # Shift the fixed part
        trial_types.extend(['regular'] * 10) # Add 'Regular' for each trial
        regular_count += 10
    else:
        sequence.append(random_sequences[0])
        random_sequences = random_sequences[1:]
        trial_types.extend(['random'] * 10) # Add 'random' for each trial
        random_count += 10
        
return np.concatenate(sequence), trial_types, regular_count, random_count          

List to store filenames of generated sequence files

practice_sequences_files =
learning_sequences_files =
motortesting_sequences_files =

Generate learning sequences with 90 degrees clockwise rotation

for block_index in range(number_of_learning_blocks):
random_part = np.random.randint(0, 4, 5)

fixed_part = np.tile(fixed_sequence, repetitions_per_block)[:40]
random_sequences = np.random.randint(0, 4, 40).reshape(4, 10)

rule_toggle = [1, 1, 2, 1, 2, 2, 1, 2] #Example rule sequence
    
learning_sequence, trial_types, regular_count, random_count = generate_alternating_sequence(random_part, fixed_part, rule_toggle, random_sequences)

# Insert the first 5 random pratice trials at the beginning
learning_sequence = np.concatenate((random_part, learning_sequence))
trial_types = ['random'] * 5 + trial_types
random_count += 5

# Map sequence indices to answer directions
learning_sequence_answers = rotate_clockwise_90(learning_sequence)
learning_sequence_answers_str = answer_directions[learning_sequence_answers]

# Save the learning sequence to a CSV file 
learning_sequence_df = pd.DataFrame({
    'block': block_index + 1,
    'trial_index': np.arange(1, len(learning_sequence) + 1), # Trial index
    'orientation_degrees': learning_sequence * 90,
    'orientation_index': learning_sequence,
    'correct_answer_index': learning_sequence_answers,
    'correct_answer_direction': learning_sequence_answers_str,
    'trial_types': trial_types, # Add trial type to each trial
    'block_type': 'learning',
    'regular_count': regular_count,
    'random_count': random_count
})

 # Append summary row
summary_row = pd.DataFrame({
    'block': [block_index +1],
    'trial_index': ['Summary'],
    'orientation_degrees': [''],
    'orientation_index': [''],
    'correct_answer_index': [''],
    'correct_answer_direction': [''],
    'trial_types': ['Summary'],
    'block_type': ['learning'],
    'regular_count': [regular_count],
    'random_count': [random_count]
})

learning_sequence_df = pd.concat([learning_sequence_df, summary_row], ignore_index=True)

learning_filename = f'sequences/{participant_id}_learning_sequence_{block_index:03}.csv'
learning_sequence_df.to_csv(learning_filename, index=False)
learning_sequences_files.append(learning_filename)

Save filenames of learning sequences to an Excel file

df_learning_files = pd.DataFrame({‘learning_seq_files’: learning_sequences_files})
df_learning_files.to_excel(f’sequences/learning_sequence_file_list.xlsx’, index=False)

Generate motor testing sequences without rotation but following learning block sequences

fixed_sequence_2 = [2, 1, 0, 1, 2, 3, 1, 3, 2, 0] # Rotate the new sequence 90 degrees clockwise

for block_index in range(number_of_motortesting_blocks):
random_part = np.random.randint(0, 4, 5) # First 5 trials are random
fixed_part = np.tile(fixed_sequence_2, repetitions_per_block)[:40] # Fixed the sequence for the block
random_sequences = np.random.randint(0, 4, 40).reshape(4, 10) # Create random sequences, each with 10 trials

rule_toggle = [1, 1, 2, 1, 2, 2, 1, 2] #Example rule sequence ensuring no more than two consecutive same conditions

motortesting_sequence, trial_types, regular_count, random_count = generate_alternating_sequence(random_part, fixed_part, rule_toggle, random_sequences)

# Insert the first 5 random pratice trials at the beginning
motortesting_sequence = np.concatenate((random_part, motortesting_sequence))
trial_types = ['ramdom'] * 5 + trial_types
random_count += 5

#Map sequence indices to answer directions
motortesting_sequence_answers = motortesting_sequence
motortesting_sequence_answers_str = answer_directions[motortesting_sequence_answers]

#Save the learning sequence to a CSV file
motortesting_sequence_df = pd.DataFrame({
    'block': block_index + 1,
    'trial_index': np.arange(1, len(motortesting_sequence) + 1), #Trial index 
    'orientation_degrees': motortesting_sequence * 90,
    'orientation_index': motortesting_sequence,
    'correct_answer_index': motortesting_sequence_answers,
    'correct_answer_direction': motortesting_sequence_answers_str,
    'trial_types': trial_types, # Add trial type to each trial
    'block_type': 'perceptual',
    'regular_count': [regular_count] * len(motortesting_sequence),
    'random_count': [random_count] * len(motortesting_sequence)
})

#Append summary row
summary_row = pd.DataFrame({
    'block': [block_index + 1],
    'trial_index': ['Summary'],
    'orientation_degrees': [''],
    'orientation_index': [''],
    'correct_answer_index': [''],
    'correct_answer_direction': [''],
    'trial_types': ['Summary'],
    'block_type': ['motor'],
    'regular_count': [regular_count],
    'random_count': [random_count]
})

motortesting_sequence_df = pd.concat([motortesting_sequence_df, summary_row], ignore_index=True)

motortesting_filename = f'sequences/{participant_id}_motortesting_sequence_{block_index:04}.csv'
motortesting_sequence_df.to_csv(motortesting_filename, index=False)
motortesting_sequences_files.append(motortesting_filename)

Save filenames of motor testing sequences to an Excel file

df_motortesting_files = pd.DataFrame({‘motor_testing_seq_files’: motortesting_sequences_files})
df_motortesting_files.to_excel(f’sequences/motor_testing_sequence_file_list.xlsx’, index=False)

I will be appreciate if anyone can save me!!

OS(Win11)
PsychoPy version (2023.2.3)
**Standard Standalone? (yes)

Is there more of that error message before what you’ve shared? If you can figure out where .ori is being set to None it’ll make it clearer where the error is coming from.

Hello, thank you for your reply, I guess there is something wrong when the code summary and save orientation_degrees.

Here is the error message return from Psychopy-2023.2.3 Runner :

ioHub Server Process Completed With Code: 0
File “C:\Experiment\ssrt_builder-main-button_motor_v1\SSRT_motor_v1_lastrun.py”, line 3567, in run(
File “C:\Experiment\ssrt_builder-main-button_motor_v1\SSRT_motor_v1_lastrun.py”, line 2360, in run arrowhead.set0ri(orientation_degrees)
File “C:\Program Files\PsyoPy\lib\site-packages\psychopy\visual\basevisual.py”, line 1922, in set0ri setAttribute(self, ‘ori’, new0ri, log, operation)
File “C:\Program Files\PsychoPy\lib\site-packages\tools\attributetools.py”, line 134, in setAttribute setattr(self, attrib, value)
File “C:\Program Files\PsychoPy\lib\site-packages\paychopy\tools\attributetools.py”, line 27, in set newValue = self.func(obj, value)
File “C:\Program Files\PsychoPy\lib\site-packages\psychopy\visual\basevisual.py”, line 1809, in ori self.dict[ ‘ori’ ] = float(value)
TypeError: float() argument must be a string or a number, not ‘NoneType’
############ Experiment ended with exit code 1 [pid:24384] ###############

The error has been fixed, the problem which in the issue is the sequence psychopy create will add summary in last in line on sequence csv file. So, just remove the summary part on the code then runner won’t return the error anymore.

Out of interest, how did you save the csv file? I’m guessing you created it by clicking the “View table” button in the relevant loop, which opens an Excel Template (.xltx) file in your default table editor. Those summaries are added as “notes” in Excel, but my hunch here is that either a specific option when saving or a specific table editor reads these from the template file and inserts them as values at the end of each column. If we can figure out potential problem cases we may be able to catch them and open the template without notes in those cases.

1 Like