view redelacxlsx2csv.py @ 2:3dfb066dcdab draft default tip

"planemo upload for repository https://forgemia.inra.fr/redelac/redelac-toolbox/-/tree/e8749ba309ff18daeaea5c4a9e7ee4b7448bd58d/tools/REDELACxlsx2csv commit e8749ba309ff18daeaea5c4a9e7ee4b7448bd58d-dirty"
author siwaa
date Fri, 05 Dec 2025 16:12:55 +0000
parents b91beff0963c
children
line wrap: on
line source

import sys
import pandas as pd

redelacXlsxInputFile = sys.argv[1]
redelacUSMsOutputFile = sys.argv[2]
redelacTecOutputFile = sys.argv[3]
redelacIniOutputFile = sys.argv[4]
redelacStationOutputFile = sys.argv[5]
redelacListe_plantesOutputFile = sys.argv[6]
redelacSuccessionsOutputFile = sys.argv[7]

# loading

USMsPdf = pd.read_excel(redelacXlsxInputFile, engine = 'openpyxl', sheet_name='USMs', keep_default_na=False, na_filter = False)
TecPdf = pd.read_excel(redelacXlsxInputFile, engine = 'openpyxl', sheet_name='Tec')
IniPdf = pd.read_excel(redelacXlsxInputFile, engine = 'openpyxl', sheet_name='Ini')
StationPdf = pd.read_excel(redelacXlsxInputFile, engine = 'openpyxl', sheet_name='Station')
Liste_plantesPdf = pd.read_excel(redelacXlsxInputFile, engine = 'openpyxl', sheet_name='Liste_plantes')
Successions = pd.read_excel(redelacXlsxInputFile, engine = 'openpyxl', sheet_name='liste_USMs') 

# sanityzing

julCol = [x for x in TecPdf.columns if x.startswith('jul')]

TecPdf[julCol] = TecPdf[julCol].astype('Int64')



USMsPdf['fclim1'] = USMsPdf['fclim1'].apply(lambda x: format(x, ".4f")).astype('string')
USMsPdf['fclim2'] = USMsPdf['fclim2'].apply(lambda x: format(x, ".4f")).astype('string')
USMsPdf['rcp'] = USMsPdf['rcp'].astype('string')

USMsPdf['Début'] = pd.to_datetime(USMsPdf['Début'], dayfirst = True)
USMsPdf['Fin'] = pd.to_datetime(USMsPdf['Fin'], dayfirst = True)

USMsPdf.loc[USMsPdf['culturean'] != 1, 'culturean'] = 0

# saving to csv

USMsPdf.to_csv(redelacUSMsOutputFile, sep=';', date_format='%d/%m/%Y', decimal = ',', index=False)
TecPdf.to_csv(redelacTecOutputFile, sep=';', date_format='%d/%m/%Y', decimal = ',', float_format='%.2f', index=False)
IniPdf.to_csv(redelacIniOutputFile, sep=';', date_format='%d/%m/%Y', decimal = ',', index=False)
StationPdf.to_csv(redelacStationOutputFile, sep=';', date_format='%d/%m/%Y', decimal = ',', index=False)
Liste_plantesPdf.to_csv(redelacListe_plantesOutputFile, sep=';', date_format='%d/%m/%Y', decimal = ',', index=False)
Successions.to_csv(redelacSuccessionsOutputFile, sep=';', index=False)