python_code
stringlengths
0
4.04M
repo_name
stringlengths
7
58
file_path
stringlengths
5
147
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import numpy as np class PerlinNoiseGenerator(object): def __init__(self, random_state=None): self.rand = np.random if random_sta...
augmentation-corruption-fbr_main
imagenet_c_bar/utils/perlin_noise.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import numpy as np #def smoothstep(low, high, x): # return np.clip(3 * (x ** 2) - 2 * (x ** 3), 0, 1) * (high - low) + low def smoothst...
augmentation-corruption-fbr_main
imagenet_c_bar/utils/image.py
# Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import math import torch import torch.nn as nn import torch.nn.functional as F import numpy as np def train_model(model, dataset, num_workers...
augmentation-corruption-fbr_main
notebook_utils/training_loop.py
# This source code is adapted from code licensed under the MIT license # found in third_party/wideresnet_license from the root directory of # this source tree. """WideResNet implementation (https://arxiv.org/abs/1605.07146).""" import math import torch import torch.nn as nn import torch.nn.functional as F import nump...
augmentation-corruption-fbr_main
notebook_utils/wideresnet.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from data_preprocessing import CLIMATE_VARS from data_preprocessing.sample_quadruplets import generate_training_for_coun...
Context-Aware-Representation-Crop-Yield-Prediction-main
generate_for_deep_gaussian.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from crop_yield_prediction.models.deep_gaussian_process import * from pathlib import Path import torch import argparse ...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_deep_gaussian.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os import numpy as np import pandas as pd import argparse import torch.optim as optim from pathlib import Path im...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_train_semi_transformer.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os import numpy as np import pandas as pd import argparse import torch.optim as optim from pathlib import Path im...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_train_cnn_lstm.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os import numpy as np import pandas as pd import argparse import torch.optim as optim from pathlib import Path im...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_train_c3d.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os import numpy as np import pandas as pd import argparse import torch.optim as optim from pathlib import Path im...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_train_cross_location.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from crop_yield_prediction import CLIMATE_VARS import os import numpy as np def generate_feature_importance_data_excl...
Context-Aware-Representation-Crop-Yield-Prediction-main
generate_feature_importance_data.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from data_preprocessing.sample_quadruplets import generate_training_for_counties from data_preprocessing.postprocess imp...
Context-Aware-Representation-Crop-Yield-Prediction-main
generate_experiment_data.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from crop_yield_prediction.utils import Logger from crop_yield_prediction.models import * import os import sys import a...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_no_spatial.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from crop_yield_prediction.dataloader import cross_location_dataloader import os import time from math import sqrt from...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/train_cross_location.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. __all__ = ['CLIMATE_VARS', 'STATIC_CLIMATE_VARS', 'DYNAMIC_CLIMATE_VARS'] CLIMATE_VARS = ['ppt', 'evi', 'ndvi', 'elevat...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from crop_yield_prediction.dataloader import c3d_dataloader import time from math import sqrt from sklearn.metrics impo...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/train_c3d.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from crop_yield_prediction.dataloader import semi_cropyield_dataloader import os import time from math import sqrt from...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/train_semi_transformer.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from crop_yield_prediction.dataloader import cnn_lstm_dataloader import time from math import sqrt from sklearn.metrics...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/train_cnn_lstm.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os import matplotlib.pyplot as plt from collections import defaultdict def plot_loss(params): out_dir = '.....
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/plot/plot_loss.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from bs4 import BeautifulSoup from pathlib import Path import matplotlib as mpl import matplotlib.pyplot as plt import p...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/plot/plot_crop_yield.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from .plot_crop_yield import crop_yield_plot from .plot_crop_yield_prediction_error import crop_yield_prediction_error_p...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/plot/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from bs4 import BeautifulSoup from pathlib import Path import matplotlib as mpl import matplotlib.pyplot as plt import p...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/plot/plot_crop_yield_prediction_error.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os from math import sqrt from sklearn.metrics import r2_score, mean_squared_error from scipy.stats.stats import p...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/utils/train_utils.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from .timing import timeit, timenow from .logger import Logger from .train_utils import get_statistics from .train_utils...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/utils/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import sys class Logger(object): def __init__(self, filename="Default.log"): self.terminal = sys.stdout ...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/utils/logger.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # https://stackoverflow.com/questions/1557571/how-do-i-get-time-of-a-python-programs-execution import atexit from time i...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/utils/timing.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from .no_spatial import predict_no_spatial __all__ = ['predict_no_spatial']
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import pandas as pd import numpy as np import os import sys from pathlib import Path from sklearn.ensemble import Random...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/no_spatial.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from crop_yield_prediction.models.semi_transformer.TileNet import make_tilenet import torch import torch.nn as nn cla...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/cnn_lstm/cnn_lstm.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # Based on transformer code from https://github.com/jadore801120/attention-is-all-you-need-pytorch from crop_yield_pred...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/cnn_lstm/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # Adapt code from https://github.com/gabrieltseng/pycrop-yield-prediction from crop_yield_prediction import CLIMATE_VAR...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/deep_gaussian_process/feature_engineering.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # Adapt code from https://github.com/gabrieltseng/pycrop-yield-prediction import torch from torch import nn import torch...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/deep_gaussian_process/convnet.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # Adapt code from https://github.com/gabrieltseng/pycrop-yield-prediction import numpy as np from scipy.spatial.distance...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/deep_gaussian_process/gp.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from .feature_engineering import get_features_for_deep_gaussian from .convnet import ConvModel from .rnn import RNNModel...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/deep_gaussian_process/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # Adapt code from https://github.com/gabrieltseng/pycrop-yield-prediction import torch.nn.functional as F def l1_l2_lo...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/deep_gaussian_process/loss.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # Adapt code from https://github.com/gabrieltseng/pycrop-yield-prediction from torch import nn import torch import math...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/deep_gaussian_process/rnn.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # Adapt code from https://github.com/gabrieltseng/pycrop-yield-prediction import torch from torch.utils.data import Ten...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/deep_gaussian_process/base.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # Based on transformer code from https://github.com/jadore801120/attention-is-all-you-need-pytorch from crop_yield_pred...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/c3d/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # Based on code from https://github.com/jfzhang95/pytorch-video-recognition/blob/master/network/C3D_model.py # Architectu...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/c3d/conv3d.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # Based on transformer code from https://github.com/jadore801120/attention-is-all-you-need-pytorch from crop_yield_predi...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/semi_transformer/AttentionModels.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree.# Based on transformer code from https://github.com/jadore801120/attention-is-all-you-need-pytorch from crop_yield_predic...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/semi_transformer/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # Based on transformer code from https://github.com/jadore801120/attention-is-all-you-need-pytorch ''' Define the sublay...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/semi_transformer/SubLayers.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # Based on transformer code from https://github.com/jadore801120/attention-is-all-you-need-pytorch import torch import t...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/semi_transformer/Modules.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # Based on transformer code from https://github.com/jadore801120/attention-is-all-you-need-pytorch from crop_yield_predi...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/semi_transformer/SemiTransformer.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # Based on transformer code from https://github.com/jadore801120/attention-is-all-you-need-pytorch from crop_yield_predi...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/semi_transformer/Layers.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # Based on transformer code from https://github.com/jadore801120/attention-is-all-you-need-pytorch '''A wrapper class fo...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/semi_transformer/Optim.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # Based on tile2vec code from https://github.com/ermongroup/tile2vec import torch import torch.nn as nn import torch.nn....
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/models/semi_transformer/TileNet.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from torch.utils.data import Dataset, DataLoader import torch import numpy as np class CnnLSTMDataset(Dataset): ""...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/dataloader/cnn_lstm_dataloader.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from torch.utils.data import Dataset, DataLoader import torch import numpy as np class C3DDataset(Dataset): """ ...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/dataloader/c3d_dataloader.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from crop_yield_prediction.dataloader.c3d_dataloader import c3d_dataloader from crop_yield_prediction.dataloader.semi_cr...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/dataloader/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from torch.utils.data import Dataset, DataLoader import torch import numpy as np class CrossLocationDataset(Dataset): ...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/dataloader/cross_location_dataloader.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from torch.utils.data import Dataset, DataLoader import torch import numpy as np class SemiCropYieldDataset(Dataset): ...
Context-Aware-Representation-Crop-Yield-Prediction-main
crop_yield_prediction/dataloader/semi_cropyield_dataloader.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. __all__ = ['cdl_values_to_crops', 'crops_to_cdl_values', 'CLIMATE_VARS', 'STATIC_CLIMATE_VARS', 'DYNAMIC_CLIM...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from .sample_for_counties import generate_training_for_counties from .sample_for_pretrained import generate_training_for...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/sample_quadruplets/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from netCDF4 import Dataset import numpy as np import os import pandas as pd import numpy.ma as ma import matplotlib.pyp...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/sample_quadruplets/sample_for_counties.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from netCDF4 import Dataset import numpy as np import os import pandas as pd import numpy.ma as ma import matplotlib.pyp...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/sample_quadruplets/sample_for_pretrained.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from .counties_plot import counties_plot, save_colorbar __all__ = ['counties_plot', 'save_colorbar']
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/plot/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from netCDF4 import Dataset import matplotlib.pyplot as plt import numpy as np # mean of lats: 40.614586, mean of lons...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/plot/plot_local.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from bs4 import BeautifulSoup from pathlib import Path import matplotlib as mpl import matplotlib.pyplot as plt import p...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/plot/counties_plot.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from .merge_various_days import merge_various_days __all__ = ['merge_various_days']
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/merge/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from ..utils import generate_doy import os import numpy as np import datetime as dt from datetime import datetime from ...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/merge/merge_various_days.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import pandas as pd from collections import defaultdict import numpy as np import numpy.ma as ma from pathlib import Pat...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/preprocess/crop_yield.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from netCDF4 import Dataset import numpy as np import numpy.ma as ma def combine_landsat(): fh_out = Dataset('../...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/preprocess/landsat.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os from netCDF4 import Dataset # gdal_translate -of netCDF PRISM_ppt_stable_4kmM3_201806_bil.bil PRISM_ppt_stabl...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/preprocess/prism.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os from netCDF4 import Dataset import numpy as np import numpy.ma as ma from pathlib import Path import pandas as...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/preprocess/county_locations.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from .cdl import cdl_convert_to_nc __all__ = ["cdl_convert_to_nc"]
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/preprocess/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from netCDF4 import Dataset import os from osgeo import gdal, osr import numpy as np from pyproj import Proj, transform...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/preprocess/cdl.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from netCDF4 import Dataset import numpy.ma as ma import datetime import sys sys.path.append("..") def extract_lai(nc...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/preprocess/lai.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from netCDF4 import Dataset import numpy as np import sys sys.path.append("..") from data_preprocessing.utils import ge...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/preprocess/subset.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from netCDF4 import Dataset import datetime import calendar from collections import defaultdict import numpy.ma as ma i...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/preprocess/lst.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os from netCDF4 import Dataset import numpy as np import numpy.ma as ma import sys sys.path.append("..") from da...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/preprocess/landcover.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from .get_lat_lon_bins import get_lat_lon_bins from .timing import timeit, timenow from .generate_doy import generate_do...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/utils/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os from datetime import date def get_closet_date(query_date, folder): doys = [x[:-3] for x in os.listdir(fo...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/utils/get_closest_date.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import numpy as np def get_lat_lon_bins(lats, lons): inter_lat = np.array([(x + y) / 2.0 for x, y in zip(lats[:-1]...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/utils/get_lat_lon_bins.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. # https://stackoverflow.com/questions/1557571/how-do-i-get-time-of-a-python-programs-execution import atexit from time i...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/utils/timing.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. def match_lat_lon(lats_from, lons_from, lats_to, lons_to, expand=0): i_lat_start = i_lat_end = i_lon_start = i_lon_...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/utils/match_lat_lon.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from datetime import date, timedelta def generate_doy(s_doy, e_doy, delimiter): s_doy = map(int, [s_doy[:4], s_doy...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/utils/generate_doy.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from netCDF4 import Dataset import numpy as np import numpy.ma as ma import fiona import sys sys.path.append("..") fro...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/rescaling/nws_precip.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from netCDF4 import Dataset import numpy as np import numpy.ma as ma import pandas as pd import csv import sys sys.pat...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/rescaling/soil_fraction.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import numpy as np import numpy.ma as ma from netCDF4 import Dataset import sys sys.path.append("..") from data_prepro...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/rescaling/us_counties.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import os from netCDF4 import Dataset import numpy as np def get_origi_lat_lon(): in_dir = '../../processed_data/p...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/rescaling/prism_upscale.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import numpy as np import numpy.ma as ma from netCDF4 import Dataset import sys sys.path.append("..") from data_prepro...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/rescaling/elevation.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from data_preprocessing.utils import get_lat_lon_bins from data_preprocessing import cdl_values_to_crops, crops_to_cdl_v...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/rescaling/cdl_upscale.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from .rescale_utils import search_kdtree from .rescale_utils import get_lat_lon_bins __all__ = ['search_kdtree', 'get_l...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/rescaling/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from netCDF4 import Dataset import numpy as np import numpy.ma as ma import sys sys.path.append("..") from data_prepr...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/rescaling/prism_downscale.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from netCDF4 import Dataset import numpy as np import numpy.ma as ma import datetime import os import sys sys.path.app...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/rescaling/lst.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from scipy.spatial import cKDTree import numpy as np def search_kdtree(lats, lons, points): mytree = cKDTree(np.ds...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/rescaling/rescale_utils.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from netCDF4 import Dataset import numpy as np import numpy.ma as ma import sys sys.path.append("..") from data_prepr...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/rescaling/soil_moisture.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. import pandas as pd import csv from netCDF4 import Dataset import numpy as np import numpy.ma as ma from collections im...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/postprocess/prism.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from .combine_multi_vars import mask_non_major_states from .combine_multi_vars import generate_no_spatial_for_counties f...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/postprocess/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. from netCDF4 import Dataset import numpy as np import os import pandas as pd import csv from collections import defaultd...
Context-Aware-Representation-Crop-Yield-Prediction-main
data_preprocessing/postprocess/combine_multi_vars.py
""" """ from __future__ import print_function from __future__ import division import matplotlib matplotlib.use('agg') import glob import os import torch import argparse import warnings import pandas from torch.utils.data import Dataset, DataLoader from utils import * from metrics import * from dataloaders import * fr...
ukb-cardiac-mri-master
ukb/predict.py
import argparse import pandas as pd from os import makedirs from os.path import isdir from ensemble import * def main(args): pd.set_option("display.width", 100) if args.pids_csv is not None: pids = list(pd.read_csv(args.pids_csv)[args.pids_key]) else: pids = None if args.output_dir i...
ukb-cardiac-mri-master
ukb/ensemble.py
""" """ from __future__ import print_function from __future__ import division import matplotlib matplotlib.use('agg') import os import torch import argparse import warnings import pandas from torch.utils.data import Dataset, DataLoader from utils import * from metrics import * from dataloaders import * from models im...
ukb-cardiac-mri-master
ukb/train.py
""" Phase Contrast Cardiac MRI Segmentation Prepare MRIs for training a CNN model. Given an input directory of numpy image tensors containing phase contrast cardiac MRIs: - Generate candidate value segmentations - Rank candidates in terms of the most likely atrial value - Write segmentation masks to numpy files - Exp...
ukb-cardiac-mri-master
ukb/segmentMultiple.py
""" Phase Contrast Cardiac MRI Segmentation Prepare MRIs for training a CNN model. Given an input directory of numpy image tensors containing phase contrast cardiac MRIs: - Generate candidate value segmentations - Rank candidates in terms of the most likely atrial value - Write segmentation masks to numpy files - Exp...
ukb-cardiac-mri-master
ukb/segment.py
""" Hacky script to generate synthetic data to debug model training. Default configuration generates sequences based on empirical attributes """ from __future__ import print_function import os import sys import math import argparse import numpy as np from skimage import draw import matplotlib.pyplot as plt import mat...
ukb-cardiac-mri-master
ukb/create_synthetic_data.py
from __future__ import print_function from __future__ import division from sklearn.metrics import fbeta_score as sk_fbeta from functools import wraps __all__ = ['f05_score', 'f04_score'] def fbeta_create(beta=1.0): def fbeta_wrapper(func): @wraps(func) def fbeta_score(*args, **kwargs)...
ukb-cardiac-mri-master
ukb/metrics/fbeta.py
from .base import * from .fbeta import *
ukb-cardiac-mri-master
ukb/metrics/__init__.py
from __future__ import print_function from __future__ import division import torch import torch.nn as nn from torch.autograd import Variable import numpy as np from sklearn.preprocessing import OneHotEncoder from sklearn.metrics import f1_score, precision_score, recall_score, \ accuracy_score, confusion_matrix, c...
ukb-cardiac-mri-master
ukb/metrics/base.py