Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include aec files in rat outputs #49

Merged
merged 3 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 0 additions & 66 deletions .github/workflows/run_tests.yaml

This file was deleted.

1 change: 1 addition & 0 deletions src/rat/ee_utils/ee_aec_file_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,5 @@ def aec_file_creator(reservoir_shpfile, shpfile_column_dict, aec_dir_path):
aec_df.to_csv(os.path.join(aec_dir_path,reservoir_name+'.csv'),index=False)
print(f"AEC file created succesfully for {reservoir_name}")
print("AEC file exists for all reservoirs in this basin")
return 1

15 changes: 12 additions & 3 deletions src/rat/rat_basin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import geopandas as gpd
import numpy as np
import xarray as xr
import shutil
from pathlib import Path

from rat.utils.utils import create_directory
Expand All @@ -29,7 +30,7 @@

from rat.core.run_postprocessing import run_postprocessing

from rat.utils.convert_to_final_outputs import convert_sarea, convert_inflow, convert_dels, convert_evaporation, convert_outflow, convert_altimeter
from rat.utils.convert_to_final_outputs import convert_sarea, convert_inflow, convert_dels, convert_evaporation, convert_outflow, convert_altimeter, copy_aec_files

# Step-(-1): Reading Configuration settings to run RAT
# Step-0: Creating required directory structure for RAT
Expand Down Expand Up @@ -161,6 +162,7 @@ def rat_basin(config, rat_logger):
DELS_STATUS = 0
EVAP_STATUS = 0
OUTFLOW_STATUS = 0
AEC_STATUS = 0
except:
no_errors = -1
rat_logger.exception("Error in Configuration parameters defined to run RAT.")
Expand Down Expand Up @@ -258,6 +260,7 @@ def rat_basin(config, rat_logger):
evap_savedir = create_directory(os.path.join(basin_data_dir,'rat_outputs', "Evaporation"), True)
dels_savedir = create_directory(os.path.join(basin_data_dir,'rat_outputs', "dels"), True)
outflow_savedir = create_directory(os.path.join(basin_data_dir,'rat_outputs', "rat_outflow"),True)
aec_savedir = Path(create_directory(os.path.join(basin_data_dir,'rat_outputs', "aec"),True))
final_output_path = create_directory(os.path.join(basin_data_dir,'final_outputs',''),True)
## End of defining paths for storing post-processed data and webformat data
#----------- Paths Necessary for running of Post-Processing-----------#
Expand Down Expand Up @@ -587,7 +590,7 @@ def rat_basin(config, rat_logger):
rat_logger.info("Starting Step-12: Generating Area Elevation Curves for reservoirs")
##--------------------------------Area Elevation Curves Extraction begins ------------------- ##
## Creating AEC files if not present for post-processing dels calculation
aec_file_creator(basin_reservoir_shpfile_path,reservoirs_gdf_column_dict,aec_dir_path)
AEC_STATUS = aec_file_creator(basin_reservoir_shpfile_path,reservoirs_gdf_column_dict,aec_dir_path)
except:
rat_logger.exception("Finished Step-12: Generating Area Elevation Curves for reservoirs")
else:
Expand All @@ -602,9 +605,10 @@ def rat_basin(config, rat_logger):
##---------- Mass-balance Approach begins and then post-processing ----------##
# Generate inflow files from RAT routing outputs
generate_inflow(routing_output_dir, inflow_dst_dir)
# Copying AEC files to RAT output directory
copy_aec_files(aec_dir_path, aec_savedir)
DELS_STATUS, EVAP_STATUS, OUTFLOW_STATUS = run_postprocessing(basin_name, basin_data_dir, basin_reservoir_shpfile_path, reservoirs_gdf_column_dict,
aec_dir_path, config['BASIN']['start'], config['BASIN']['end'], rout_init_state_save_file, use_state, evap_savedir, dels_savedir, outflow_savedir, VIC_STATUS, ROUTING_STATUS, GEE_STATUS)

except:
no_errors = no_errors+1
rat_logger.exception("Error Executing Step-13: Calculation of Outflow, Evaporation and Storage change")
Expand Down Expand Up @@ -660,6 +664,11 @@ def rat_basin(config, rat_logger):
else:
rat_logger.info("Could not convert Extracted Height from Altimeter to the Output Format as Altimeter Run failed.")

## AEC
if(AEC_STATUS):
shutil.copytree(aec_savedir, final_output_path)
rat_logger.info("Converted Area Elevation Curve to the Output Format.")

# Clearing out memory space as per user input
if(config['CLEAN_UP'].get('clean_metsim')):
rat_logger.info("Clearing up memory space: Removal of metsim output files")
Expand Down
14 changes: 14 additions & 0 deletions src/rat/utils/convert_to_final_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pandas as pd
import geopandas as gpd
import numpy as np
from pathlib import Path
from rat.utils.utils import create_directory

def convert_sarea(sarea_dir, website_v_dir):
Expand Down Expand Up @@ -123,6 +124,19 @@ def convert_altimeter(altimeter_ts_dir, website_v_dir):
print(f"Converting [Heights]: {res_name}")
df.to_csv(savepath, index=False)

def copy_aec_files(src_dir, dst_dir):
src_dir = Path(src_dir)
dst_dir = Path(dst_dir)

for src_path in src_dir.glob('*.csv'):
aec = pd.read_csv(src_path)
aec.rename({
'Elevation': 'elevation',
'CumArea': 'area'
}, axis=1, inplace=True)
aec.to_csv(dst_dir / src_path.name, index=False)


def convert_v2_frontend(basin_data_dir, res_name, inflow_src, sarea_src, dels_src, outflow_src):
"""Converts the files according to the newer version of the frontend (v2).

Expand Down