Skip to content

Commit

Permalink
change append method
Browse files Browse the repository at this point in the history
  • Loading branch information
mariavictoriadiaz committed Sep 7, 2023
1 parent 6373e5a commit 0e56300
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/aclimate_resampling/resampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@ def forecast_station(self,station, prob, daily_data_root, output_root, year_fore

# Start the resampling process for every season of analysis in CPT probabilities file

base_years = [] # List to store years of sample for each season
seasons_range = [] # List to store climate data in the years of sample for each season
base_years = pd.DataFrame() # List to store years of sample for each season
seasons_range = pd.DataFrame() # List to store climate data in the years of sample for each season

for season in list(np.unique(cpt_prob['season'])):

Expand All @@ -299,7 +299,6 @@ def forecast_station(self,station, prob, daily_data_root, output_root, year_fore
#If not, select the months between the start and the end month of season
data_range = data.loc[(data['month'] >= x['Start'].iloc[0]) & (data['month'] <= x['End'].iloc[0])]

print(data_range.head(10))
predictand = cpt_prob['predictand'].iloc[0]

# Compute total precipitation for each year in the climate data range selected
Expand Down Expand Up @@ -385,7 +384,7 @@ def forecast_station(self,station, prob, daily_data_root, output_root, year_fore
merge_b.drop('plus', axis = 1,inplace = True)

# Merge filtered data
merge = merge_a.append(merge_b)
merge = pd.concat([merge_a, merge_b])

else:
# If season is another, filter climate data of the years in sample and get the sample id
Expand All @@ -395,36 +394,38 @@ def forecast_station(self,station, prob, daily_data_root, output_root, year_fore
merge = merge.drop(season, axis = 1)


# Append the 100 years in the sample for every season in the list
base_years.append(muestras_by_type[['index',season]])
# Join seasons samples by column by sample id
base_years = pd.concat([base_years, muestras_by_type[['index',season]]], axis = 1,ignore_index=True)

# Append the climate data filtered for every season in the list
seasons_range.append(merge)


# Join seasons samples by column by sample id and save DataFrame in the folder created
base_years = pd.concat(base_years, axis = 1).rename(columns={'index': 'id'})
# Join climate data filtered for the seasons
seasons_range = pd.concat([merge]).rename(columns={'index': 'id'})


if len(list(np.unique(cpt_prob['season']))) ==2:

s = list(np.unique(cpt_prob['season']))
base_years = base_years.iloc[:,[0,1,3] ]
base_years = base_years.rename(columns={0: 'id',1: s[0], 3: s[1]})
base_years['id'] = base_years['id'] + 1
seasons_range['id'] = seasons_range['id']+1
base_years.to_csv(os.path.join(val_root, f"{station}_Escenario_A.csv"), index = False)

# Join climate data filtered for the seasons and save DataFrame in the folder created
seasons_range = pd.concat(seasons_range).rename(columns={'index': 'id'})

#Return climate data filtered with sample id
return base_years, seasons_range

else:
print('Station just have one season available')
base_years = base_years.iloc[:,[0,1] ]
s = list(np.unique(cpt_prob['season']))
base_years = base_years.iloc[:,[0,1] ]
base_years = base_years.rename(columns={0: 'id',1: s[0]})
base_years['id'] = base_years['id'] + 1
seasons_range['id'] = seasons_range['id']+1
p = {'id': [station],'issue': ['Station just have one season available'], 'season': [base_years.columns[1]]}
problem = pd.DataFrame(p)
base_years.to_csv(os.path.join(val_root, f"{station}_Escenario_A.csv"), index = False)

# Join climate data filtered for the seasons and save DataFrame in the folder created
seasons_range = pd.concat(seasons_range).rename(columns={'index': 'id'})

#Return climate data filtered with sample id
return base_years, seasons_range, problem

Expand Down

0 comments on commit 0e56300

Please sign in to comment.