Mercurial > repos > siwaa > redelac_stics_e
comparison redelacPlanExpander.py @ 4:a7463ad6a389 draft default tip
"planemo upload for repository https://forgemia.inra.fr/redelac/redelac-toolbox/-/tree/179e64aac208ae8af4d7416a7d5ff4b9da572850/tools/REDELACplanExpander commit 179e64aac208ae8af4d7416a7d5ff4b9da572850-dirty"
| author | siwaa |
|---|---|
| date | Mon, 16 Feb 2026 11:45:40 +0000 |
| parents | ecbd096ba43b |
| children |
comparison
equal
deleted
inserted
replaced
| 3:ecbd096ba43b | 4:a7463ad6a389 |
|---|---|
| 11 successiveFileName = sys.argv[6] | 11 successiveFileName = sys.argv[6] |
| 12 StationsFileName = sys.argv[7] | 12 StationsFileName = sys.argv[7] |
| 13 aclimParHorizonFileName = sys.argv[8] | 13 aclimParHorizonFileName = sys.argv[8] |
| 14 latitudeMailleDriasDFileName= sys.argv[9] | 14 latitudeMailleDriasDFileName= sys.argv[9] |
| 15 expandedStationsFileName = sys.argv[10] | 15 expandedStationsFileName = sys.argv[10] |
| 16 SafranOrDrias = sys.argv[11] == "SAFRAN" | |
| 17 | |
| 18 print( sys.argv[11]) | |
| 19 | |
| 20 print( sys.argv[11] == "SAFRAN") | |
| 21 | |
| 16 | 22 |
| 17 # 1) reading the base list of USMs | 23 # 1) reading the base list of USMs |
| 18 | 24 |
| 19 #USMsDf = pd.read_excel(basePlanFileName, sheet_name='USMs') | 25 #USMsDf = pd.read_excel(basePlanFileName, sheet_name='USMs') |
| 20 USMsDf = pd.read_csv(USMsFileName, sep=";", keep_default_na=False, na_filter = False) | 26 USMsDf = pd.read_csv(USMsFileName, sep=";", keep_default_na=False, na_filter = False) |
| 40 | 46 |
| 41 # a new dataframe to hosts the stations in expansion | 47 # a new dataframe to hosts the stations in expansion |
| 42 expandedStationsDf = pd.DataFrame() | 48 expandedStationsDf = pd.DataFrame() |
| 43 | 49 |
| 44 for i, row in planDf.iterrows(): | 50 for i, row in planDf.iterrows(): |
| 51 | |
| 52 print("I") | |
| 53 print(i) | |
| 54 | |
| 45 tmpDf = StationsDf | 55 tmpDf = StationsDf |
| 46 | 56 |
| 47 safran = int(row['upc'].split('_')[1]) | 57 safran = int(row['upc'].split('_')[1]) |
| 58 | |
| 59 print("safran:") | |
| 60 print(safran) | |
| 61 | |
| 48 drias = maillesDf[maillesDf["maille_safran"] == safran].reset_index(drop=True)["maille_drias"][0] | 62 drias = maillesDf[maillesDf["maille_safran"] == safran].reset_index(drop=True)["maille_drias"][0] |
| 63 | |
| 64 print("drias:") | |
| 65 print(drias) | |
| 49 | 66 |
| 50 tmpDfBis = tmpDf; | 67 tmpDfBis = tmpDf; |
| 51 | 68 |
| 52 for j, rowS in tmpDf.iterrows(): | 69 for j, rowS in tmpDf.iterrows(): |
| 53 horizon = rowS['Sta_name'].split('_')[1] | 70 horizon = rowS['Sta_name'].split('_')[1] |
| 54 tmpDfBis.at[j, 'Sta_name'] = str(drias) + '_' + horizon + '_sta.xml' | 71 if SafranOrDrias : |
| 55 tmpDfBis.at[j, 'aclim'] = aclimParHorizonDf[(aclimParHorizonDf['maille_DRIAS'] == drias) & (aclimParHorizonDf['horizon'] == horizon)].reset_index(drop=True)["aclim"][0] | 72 tmpDfBis.at[j, 'Sta_name'] = str(safran) + '_' + horizon + '_sta.xml' |
| 56 tmpDfBis.at[j, 'latitude'] = latitudeMailleDriasDf[(latitudeMailleDriasDf['maille_DRIAS'] == drias)].reset_index(drop=True)["latitude"][0] | 73 |
| 74 tmpDfBis.at[j, 'aclim'] = aclimParHorizonDf[(aclimParHorizonDf['maille_SAFRAN'] == safran) & (aclimParHorizonDf['horizon'] == horizon)].reset_index(drop=True)["aclim"][0] | |
| 75 tmpDfBis.at[j, 'latitude'] = latitudeMailleDriasDf[(latitudeMailleDriasDf['maille_DRIAS'] == drias)].reset_index(drop=True)["latitude"][0] | |
| 76 else : | |
| 77 tmpDfBis.at[j, 'Sta_name'] = str(drias) + '_' + horizon + '_sta.xml' | |
| 78 | |
| 79 tmpDfBis.at[j, 'aclim'] = aclimParHorizonDf[(aclimParHorizonDf['maille_DRIAS'] == drias) & (aclimParHorizonDf['horizon'] == horizon)].reset_index(drop=True)["aclim"][0] | |
| 80 tmpDfBis.at[j, 'latitude'] = latitudeMailleDriasDf[(latitudeMailleDriasDf['maille_DRIAS'] == drias)].reset_index(drop=True)["latitude"][0] | |
| 57 | 81 |
| 58 expandedStationsDf = pd.concat([expandedStationsDf, tmpDfBis]) | 82 expandedStationsDf = pd.concat([expandedStationsDf, tmpDfBis]) |
| 59 | 83 |
| 60 expandedStationsDf.to_csv(expandedStationsFileName, index = False, sep = ';') | 84 expandedStationsDf.to_csv(expandedStationsFileName, index = False, sep = ';') |
| 61 | 85 |
| 69 typeOfRotation = 'PP' | 93 typeOfRotation = 'PP' |
| 70 else : | 94 else : |
| 71 typeOfRotation = 'GC' | 95 typeOfRotation = 'GC' |
| 72 | 96 |
| 73 for i, row in planDf.iterrows(): | 97 for i, row in planDf.iterrows(): |
| 98 | |
| 99 print("I") | |
| 100 print(i) | |
| 101 | |
| 74 tmpDf = USMsDf | 102 tmpDf = USMsDf |
| 75 | 103 |
| 76 safran = int(row['upc'].split('_')[1]) | 104 safran = int(row['upc'].split('_')[1]) |
| 77 drias = maillesDf[maillesDf["maille_safran"] == safran].reset_index(drop=True)["maille_drias"][0] | 105 drias = maillesDf[maillesDf["maille_safran"] == safran].reset_index(drop=True)["maille_drias"][0] |
| 78 | 106 |
| 107 print("safran:") | |
| 108 print(safran) | |
| 109 | |
| 110 print("drias:") | |
| 111 print(drias) | |
| 112 | |
| 79 tmpDf['upc'] = row['upc'] | 113 tmpDf['upc'] = row['upc'] |
| 80 tmpDf['ucs'] = row['ucs'] | 114 tmpDf['ucs'] = row['ucs'] |
| 81 tmpDf['num_sol'] = row['num_sol'] | 115 tmpDf['num_sol'] = row['num_sol'] |
| 82 | 116 |
| 83 if typeOfRotation == 'GC' : | 117 if typeOfRotation == 'GC' : |
| 86 else : | 120 else : |
| 87 tmpDf['Norg_sols'] = row['Norg_sols_PP'] | 121 tmpDf['Norg_sols'] = row['Norg_sols_PP'] |
| 88 tmpDf['nom_sol_sans_point'] = row['nom_sols_PP_dans_USM'] | 122 tmpDf['nom_sol_sans_point'] = row['nom_sols_PP_dans_USM'] |
| 89 | 123 |
| 90 tmpDf['maille_drias'] = drias | 124 tmpDf['maille_drias'] = drias |
| 125 tmpDf['maille_safran'] = safran | |
| 91 | 126 |
| 92 # Updating the id_simu column | 127 # Updating the id_simu column |
| 93 # alias =CONCATENATE(F2;"-";G2;"_";H2;"-";I2;"-";K2;"-";L2;"-";M2) | 128 # alias =CONCATENATE(F2;"-";G2;"_";H2;"-";I2;"-";K2;"-";L2;"-";M2) |
| 94 # new alias = =CONCATENATE(F2;"-";I2;"-";J2;"-";L2;"-";M2;"-";N2) | 129 # new alias = =CONCATENATE(F2;"-";I2;"-";J2;"-";L2;"-";M2;"-";N2) |
| 95 | 130 |
| 98 tmpDf['nom_sol_sans_point'].astype(str) + '-' + \ | 133 tmpDf['nom_sol_sans_point'].astype(str) + '-' + \ |
| 99 tmpDf['systeme'].astype(str) + '-' + \ | 134 tmpDf['systeme'].astype(str) + '-' + \ |
| 100 tmpDf['code_rotation'].astype(str) + '-' + \ | 135 tmpDf['code_rotation'].astype(str) + '-' + \ |
| 101 tmpDf['tete_rotation'].astype(str) + '-' + \ | 136 tmpDf['tete_rotation'].astype(str) + '-' + \ |
| 102 tmpDf['horizon '].astype(str) | 137 tmpDf['horizon '].astype(str) |
| 138 | |
| 139 | |
| 140 print(tmpDf['id_simu']) | |
| 103 | 141 |
| 104 # Merging 2 sheets in order to solve the VLOOKUP | 142 # Merging 2 sheets in order to solve the VLOOKUP |
| 105 plantsDf.rename(columns = {'Nom_plante':'culture'}, inplace = True) | 143 plantsDf.rename(columns = {'Nom_plante':'culture'}, inplace = True) |
| 106 tmpDf = pd.merge(tmpDf,plantsDf, how='left', on='culture', sort=False) | 144 tmpDf = pd.merge(tmpDf,plantsDf, how='left', on='culture', sort=False) |
| 107 | 145 |
| 117 tmpDf['tete_rotation'].astype(str) + '-' + \ | 155 tmpDf['tete_rotation'].astype(str) + '-' + \ |
| 118 tmpDf['horizon '].astype(str) + '-' + \ | 156 tmpDf['horizon '].astype(str) + '-' + \ |
| 119 tmpDf['annee_fin'].astype(str) + '-' + \ | 157 tmpDf['annee_fin'].astype(str) + '-' + \ |
| 120 tmpDf['Code_plante'] | 158 tmpDf['Code_plante'] |
| 121 | 159 |
| 160 print(tmpDf['usm_name']) | |
| 122 | 161 |
| 123 # Updating the nomsol column | 162 # Updating the nomsol column |
| 124 # alias =CONCATENATE(G2;"_";H2) | 163 # alias =CONCATENATE(G2;"_";H2) |
| 125 | 164 |
| 126 tmpDf['nomsol'] = \ | 165 tmpDf['nomsol'] = \ |
| 127 tmpDf['num_sol'].astype(str) + '_' + \ | 166 tmpDf['num_sol'].astype(str) + '_' + \ |
| 128 tmpDf['Norg_sols'].astype(str) | 167 tmpDf['Norg_sols'].astype(str) |
| 129 | 168 |
| 130 | 169 if SafranOrDrias : |
| 131 # Updating the fstation column | 170 # Updating the fstation column |
| 132 # alias =CONCATENATE($E2;"_";M2;"_sta.xml") | 171 # alias =CONCATENATE($E2;"_";M2;"_sta.xml") |
| 133 | 172 |
| 134 tmpDf['fstation'] = \ | 173 tmpDf['fstation'] = \ |
| 135 tmpDf['maille_drias'].astype(str) + '_' + \ | 174 tmpDf['maille_safran'].astype(str) + '_' + \ |
| 136 tmpDf['horizon '].astype(str) + '_sta.xml' | 175 tmpDf['horizon '].astype(str) + '_sta.xml' |
| 137 | 176 |
| 138 # Updating the fclim1 column | 177 # Updating the fclim1 column |
| 139 # alias =CONCATENATE($E2;".";YEAR(R2)) | 178 # alias =CONCATENATE($E2;".";YEAR(R2)) |
| 140 | 179 |
| 141 tmpDf['fclim1'] = \ | 180 tmpDf['fclim1'] = \ |
| 142 tmpDf['maille_drias'].astype(str) + '.' + \ | 181 tmpDf['maille_safran'].astype(str) + '.' + \ |
| 143 pd.to_datetime(tmpDf['Début'], dayfirst = True).dt.year.astype(str) | 182 pd.to_datetime(tmpDf['Début'], dayfirst = True).dt.year.astype(str) |
| 144 | 183 |
| 145 # Updating the fclim2 column | 184 # Updating the fclim2 column |
| 146 # alias =CONCATENATE($E2;".";YEAR(S2)) | 185 # alias =CONCATENATE($E2;".";YEAR(S2)) |
| 147 | 186 |
| 148 tmpDf['fclim2'] = \ | 187 tmpDf['fclim2'] = \ |
| 149 tmpDf['maille_drias'].astype(str) + '.' + \ | 188 tmpDf['maille_safran'].astype(str) + '.' + \ |
| 150 pd.to_datetime(tmpDf['Fin'], dayfirst = True).dt.year.astype(str) | 189 pd.to_datetime(tmpDf['Fin'], dayfirst = True).dt.year.astype(str) |
| 190 | |
| 191 else : | |
| 192 # Updating the fstation column | |
| 193 # alias =CONCATENATE($E2;"_";M2;"_sta.xml") | |
| 194 | |
| 195 tmpDf['fstation'] = \ | |
| 196 tmpDf['maille_drias'].astype(str) + '_' + \ | |
| 197 tmpDf['horizon '].astype(str) + '_sta.xml' | |
| 198 | |
| 199 # Updating the fclim1 column | |
| 200 # alias =CONCATENATE($E2;".";YEAR(R2)) | |
| 201 | |
| 202 tmpDf['fclim1'] = \ | |
| 203 tmpDf['maille_drias'].astype(str) + '.' + \ | |
| 204 pd.to_datetime(tmpDf['Début'], dayfirst = True).dt.year.astype(str) | |
| 205 | |
| 206 # Updating the fclim2 column | |
| 207 # alias =CONCATENATE($E2;".";YEAR(S2)) | |
| 208 | |
| 209 tmpDf['fclim2'] = \ | |
| 210 tmpDf['maille_drias'].astype(str) + '.' + \ | |
| 211 pd.to_datetime(tmpDf['Fin'], dayfirst = True).dt.year.astype(str) | |
| 151 | 212 |
| 152 expandedDf = pd.concat([expandedDf, tmpDf]) | 213 expandedDf = pd.concat([expandedDf, tmpDf]) |
| 153 | 214 |
| 154 # now getting the list of simu | 215 # now getting the list of simu |
| 155 | 216 |
