|
| 1 | +import os |
| 2 | +from tqdm import tqdm |
| 3 | +import MLP_Model |
| 4 | +import sys |
| 5 | +sys.path.insert(0, '..') |
| 6 | +from shared_scripts import DataProcess, Hindcast_Initialization, NSM_SCA |
| 7 | +import warnings |
| 8 | + |
| 9 | +warnings.filterwarnings('ignore') |
| 10 | + |
| 11 | +# Set working directories |
| 12 | +cwd = os.getcwd() |
| 13 | +datapath = f"{os.path.expanduser('~')}/SWEML" |
| 14 | + |
| 15 | + |
| 16 | +def sweml_hindcast(new_year, threshold, Region_list, fSCA, frequency, NewSim): |
| 17 | + model = 'Neural_Network' |
| 18 | + |
| 19 | + datelist = Hindcast_Initialization.Hindcast_Initialization(cwd, datapath, new_year, threshold, Region_list, |
| 20 | + frequency, fSCA=fSCA) |
| 21 | + |
| 22 | + # Run data processing script to partition key regional dataframes |
| 23 | + # note, need to load RegionTrain_SCA.h5, |
| 24 | + if datelist[0][-5:] == '10-01': |
| 25 | + RegionTrain, RegionTest, RegionObs_Train, RegionObs_Test, RegionTest_notScaled = DataProcess.DataProcess( |
| 26 | + new_year, frequency, model, Region_list, fSCA=fSCA) |
| 27 | + |
| 28 | + """ |
| 29 | + # model training, each participants model will be different but should follow the prescribed input feature |
| 30 | + template epochs= 30 |
| 31 | + batchsize = 60 |
| 32 | + MLP_Model.Model_train(epochs, batchsize, RegionTrain, RegionTest, RegionObs_Train, RegionObs_Test, Region_list, |
| 33 | + fSCA = fSCA) |
| 34 | + """ |
| 35 | + |
| 36 | + # Need to create Predictions folder if running for the first time |
| 37 | + Predictions = MLP_Model.Model_predict(RegionTest, RegionObs_Test, RegionTest_notScaled, Region_list, fSCA=fSCA) |
| 38 | + |
| 39 | + for day in tqdm(datelist): |
| 40 | + # connect interactive script to Wasatch Snow module |
| 41 | + snow = NSM_SCA.NSM_SCA(day, threshold=threshold, Regions=Region_list, modelname=model, frequency=frequency, |
| 42 | + fSCA=fSCA, NewSim=NewSim) |
| 43 | + |
| 44 | + # Go get SNOTEL observations - all data currently loaded, set to True to download |
| 45 | + snow.Get_Monitoring_Data_Threaded(getdata=True) |
| 46 | + |
| 47 | + # Initialize/Download the granules, all data preprocessed for the SSM activRegion_listhange to True to use |
| 48 | + # the functions. |
| 49 | + snow.initializeGranules(getdata=True) |
| 50 | + |
| 51 | + # Process observations into Model prediction ready format, |
| 52 | + snow.Data_Processing(SCA=True) |
| 53 | + |
| 54 | + # Agument with SCA |
| 55 | + snow.augmentPredictionDFs() |
| 56 | + |
| 57 | + # Make predictions, set NewSim to False Look to multiprocess, each region can do a prediction to speed things |
| 58 | + # up. set NewSim to true for New simulation, turn to false once all data has been proces and saved. |
| 59 | + snow.SWE_Predict(NewSim=NewSim, Corrections=False, fSCA=fSCA) |
| 60 | + |
| 61 | + modelname = 'Neural_Network' |
| 62 | + folderpath = 'Predictions/Hold_Out_Year/Daily/fSCA_True/' |
| 63 | + AWSpath = f"Hold_Out_Year/Daily/" |
| 64 | + file_type = '.h5' |
| 65 | + Hindcast_Initialization.Hindcast_to_AWS(modelname, folderpath, AWSpath, file_type) |
| 66 | + |
| 67 | + |
| 68 | +if __name__ == "__main__": |
| 69 | + new_year = 2023 |
| 70 | + threshold = 10 |
| 71 | + Region_list = ['N_Sierras', 'S_Sierras_High', 'S_Sierras_Low', 'Greater_Yellowstone', |
| 72 | + 'N_Co_Rockies', 'SW_Mont', 'SW_Co_Rockies', 'GBasin', 'N_Wasatch', 'N_Cascade', |
| 73 | + 'S_Wasatch', 'SW_Mtns', 'E_WA_N_Id_W_Mont', 'S_Wyoming', 'SE_Co_Rockies', |
| 74 | + 'Sawtooth', 'Ca_Coast', 'E_Or', 'N_Yellowstone', 'S_Cascade', 'Wa_Coast', |
| 75 | + 'Greater_Glacier', 'Or_Coast' |
| 76 | + ] |
| 77 | + fSCA = True |
| 78 | + frequency = 'Daily' |
| 79 | + NewSim = True |
| 80 | + |
| 81 | + sweml_hindcast(new_year, threshold, Region_list, fSCA, frequency, NewSim) |
0 commit comments