Skip to content

invalid literal for int() with base 10 issue #27

@guilherber

Description

@guilherber

After I changed my weather database, the algorithm finds problems to continue the simulation. I just changed it from csv to a json API, the data is the same and the Weather function works normally. I'm using version 2.1.3. I encounter errors during the DSSAT run.

Traceback (most recent call last):
File "fortranformat_output.py", line 595, in _compose_i_string
val = int(val)
ValueError: invalid literal for int() with base 10: '375.18'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "main.py", line 39, in
thread = int(future.result()['Profile'].str.extract('(\d+)').iloc[0].iloc[0]) - 1
File "lib\concurrent\futures_base.py", line 437, in result
return self.__get_result()
File "lib\concurrent\futures_base.py", line 389, in __get_result
raise self._exception
File "ib\concurrent\futures\thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "\main.py", line 15, in run_dssat
dssat_env.run(crop=crop, weather=dados_clima(), management=man, soil=soil_profile)
File "\run.py", line 216, in run
management.write(filename=management_filename)
File "management.py", line 325, in write
outstr += section_obj.write() + '\n'
File "sections.py", line 544, in write
outstr += rowbased_write(
File "\sections.py", line 351, in rowbased_write
return writer.write(fields)
File "FortranRecordWriter.py", line 42, in write
return _output(self._eds, self._rev_eds, values)
File "output.py", line 98, in output
sub_string = _compose_i_string(
File "fortranformat_output.py", line 597, in _compose_i_string
raise ValueError("cannot convert '%s' to a integer" % str(val))
ValueError: cannot convert '375.18' to a integer

Maybe the problem is during the formation of topics, even changing the condition, the error follows...

def run_dssat(thread, crop, man, soil_profile, dssat_envs):
dssat_env = DSSAT()
dssat_env.setup()
dssat_env.run(crop=crop, weather=dados_clima(), management=man, soil=soil_profile)

plant_gro_results = dssat_env.output.get('PlantGro', {})
df = pd.DataFrame(plant_gro_results)
df['Profile'] = f'Soil Profile {thread + 1}'
df['GWAD'] = df['GWAD'].round().astype(int)

# Add DSSAT instance to a list
dssat_envs[thread] = dssat_env

return df

Number of threads equal to soil_profiles number

threads = len(soil_profiles)

List to store results

output_dataframes = [None] * threads # Initialize with None for each thread

List to store DSSAT instances

dssat_envs = [None] * threads

with concurrent.futures.ThreadPoolExecutor(max_workers=threads) as executor:
futures = [executor.submit(run_dssat, thread, crop, deepcopy(man), soil_profile, dssat_envs) for thread, soil_profile in enumerate(soil_profiles)]

for future in concurrent.futures.as_completed(futures):
    # Extract the thread index from the 'Profile' column
    thread = int(future.result()['Profile'].str.extract('(\d+)').iloc[0].iloc[0]) - 1
    output_dataframes[thread] = future.result()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions