Ejemplo n.º 1
0
 def test_DataLoader(self):
     smb = Glacier_dmdt("JAKOBSHAVN_ISBRAE",
                        1980,
                        2002,
                        path="../glaicer_dmdt.csv")
     data = ERA5Datasets("JAKOBSHAVN_ISBRAE",
                         1980,
                         2002,
                         path="../ECMWF_reanalysis_data")
     dataset = GlacierDataset([data, data], [smb, smb])
     loader = DataLoader(dataset, batch_size=1)
     for feature, s in loader:
         self.assertEqual(feature.shape, (1, 5, 289, 12))
         self.assertEqual(s.shape, (1, ))
Ejemplo n.º 2
0
 def setUpClass(cls):
     smb = Glacier_dmdt("JAKOBSHAVN_ISBRAE",
                        1980,
                        2002,
                        path="../glaicer_dmdt.csv")
     data = ERA5Datasets("JAKOBSHAVN_ISBRAE",
                         1980,
                         2002,
                         path="../ECMWF_reanalysis_data")
     dataset = GlacierDataset([data], [smb])
     cls.loader = DataLoader(dataset, batch_size=16)
     cls.device = torch.device(
         "cuda" if torch.cuda.is_available() else "cpu")
     cls.train_loader = cls.loader
     cls.test_loader = cls.loader
Ejemplo n.º 3
0
 def test_DMDTLoader(self):
     smb = Glacier_dmdt("JAKOBSHAVN_ISBRAE",
                        1980,
                        2002,
                        path="../glaicer_dmdt.csv")
     self.assertEqual(len(smb), 2002 - 1980)
Ejemplo n.º 4
0
                   show=False,
                   device=cuda, epochs=150, lr=0.002, reg=0.001, save_every=20, eval_every=1, test_split_at=split_at,
                   critic=loss_function, optimizer=torch.optim.Adam, save_path="saved_models")


glaicer_selected = pd.read_csv("Glacier_select.csv")

glaciers = list(glaicer_selected["NAME"])
end_year = 2018
for name in glaciers:
    cond_1 = glaicer_selected["NAME"] == name
    years = int(list(glaicer_selected[cond_1]["Years"])[0])
    cal_start_year = lambda years: (2018 - years) if ((2018 - years) > 1979) else 1979
    start_year = cal_start_year(years)
    test_years = int(years * 0.2)
    train_smb = Glacier_dmdt(name, start_year, end_year - test_years, path="glacier_dmdt.csv")
    train_data = ERA5Datasets(name, start_year, end_year - test_years, path="ECMWF_reanalysis_data")
    train_dataset = GlacierDataset([train_data], [train_smb])
    train_loader = DataLoader(train_dataset, batch_size=1, shuffle=False)
    second = train_data[1].shape[1]

    if second <48:
        continue
    test_smb = Glacier_dmdt(name, end_year - test_years, end_year, path="glacier_dmdt.csv")
    test_data = ERA5Datasets(name, end_year - test_years, end_year, path="ECMWF_reanalysis_data")
    test_dataset = GlacierDataset([test_data], [test_smb])
    test_loader = DataLoader(test_dataset, batch_size=1, shuffle=False)

    train(name, train_loader, test_data, test_smb,int(years * 0.8))

# print(glaciers)
Ejemplo n.º 5
0
 for name in glaciers:
     try:
         new_df = glacier_info[glacier_info["NAME"] == name]
         start_year = 2018 - int(new_df["Years"])
         if start_year < 1980:
             start_year = 1980
         last_year_smb = True
         dataset = GlacierDataset3D(name,
                                    start_year,
                                    2018,
                                    last_year=last_year_smb,
                                    path="glacier_dmdt.csv")
         # dataset = GlacierDatasetNoPadding3D(name, start_year, 2018, last_year=last_year_smb, path="glacier_dmdt.csv")
         datasets = train_val_dataset(dataset, val_split=0.3, shuffle=False)
         last_year_dmdt = Glacier_dmdt(name,
                                       start_year - 1,
                                       2017,
                                       path="glacier_dmdt.csv")
         test_last_year_dmdt = train_val_dataset(last_year_dmdt,
                                                 val_split=0.3)['val']
         train_loader = DataLoader(datasets['train'], batch_size=1)
         test_dataset = datasets['val']
         extractor = SeparateFeatureExtractor3D(output_dim=256,
                                                layers=[
                                                    TWCNN2D(),
                                                    TWCNN2D(),
                                                    TWCNN2D(),
                                                    TWCNN2D(),
                                                    TWCNN2D(),
                                                    TWCNN2D(),
                                                    TWCNN2D()
                                                ])
Ejemplo n.º 6
0

if __name__ == '__main__':
    # set dataset
    glacier_name = "STORSTROMMEN"
    start, mid, end = 1980, 2008, 2018
    last_year_smb = True
    hidden_dim = 256
    reg = 0
    save_every = 1
    eval_every = 1
    epochs = 50
    run_hcnn = True
    from datasets import Glacier_dmdt, ERA5Datasets, GlacierDataset
    from models import GlacierModel, LSTMPredictor, HCNN, VCNN, SeparateFeatureExtractor
    train_smb = Glacier_dmdt(glacier_name, start, mid, path="glacier_dmdt.csv")
    train_data = ERA5Datasets(glacier_name,
                              start,
                              mid,
                              path="ECMWF_reanalysis_data")
    test_smb = Glacier_dmdt(glacier_name, start, end, path="glacier_dmdt.csv")
    test_last_year_dmdt = Glacier_dmdt(glacier_name,
                                       start - 1,
                                       end - 1,
                                       path="glacier_dmdt.csv")
    test_data = ERA5Datasets(glacier_name,
                             start,
                             end,
                             path="ECMWF_reanalysis_data")
    glacier_dataset = GlacierDataset([train_data], [train_smb],
                                     last_year=last_year_smb)
Ejemplo n.º 7
0
import os
import torch
import argparse
from datasets import ERA5Datasets, Glacier_dmdt

parser = argparse.ArgumentParser(description='Glacier SMB prediction')
parser.add_argument('-model', type=str, help='Path to the saved_model')
parser.add_argument('-data', type=str, help='Path to the dataset', default="ECMWF_reanalysis_data")
parser.add_argument('-glacier', type=str, help='Glacier name')
parser.add_argument('-year', type=int, help='Glacier name')
args = parser.parse_args()

if args.year < 1980 or args.year > 2018:
    print("[ERROR] Year not within the available range")
if not os.path.exists(args.model):
    print("[ERROR] Model file not exist")
model = torch.load(args.model)
dataset = ERA5Datasets(args.glacier, 1980, 2018, path=args.data)
smb = Glacier_dmdt(args.glacier, 1980, 2018, path="glacier_dmdt.csv")
result = model(dataset[args.year - 1980].unsqueeze(0))
print("[INFO] Predicted SMB for {} in {} is: {}".format(args.glacier, args.year, result.item()))
print("[INFO]    Actual SMB for {} in {} is: {}".format(args.glacier, args.year, smb[args.year - 1980]))