This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
modfile = 'https://gmao.gsfc.nasa.gov/gmaoftp/geoscf/COVID_NO2/examples/model.csv | |
model = cudf.read_csv(modfile,parse_dates=['ISO8601'],date_parser=lambda x: dt.datetime.strptime(x, '%Y-%m-%dT%H:%M:%SZ')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Xall = obsl.merge(model,how='inner',on='ISO8601') | |
Yall = Xall['value'] - Xall['NO2'] | |
... | |
train = xgb.DMatrix(data=Xtrain,label=Ytrain) | |
params = {'booster':'gbtree','tree_method':'gpu_hist'} | |
bst = xgb.train(params,train) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bst.set_param({"predictor": "gpu_predictor"}) | |
shap_array = np.abs(bst.predict(X,pred_contribs=True)) | |
shap_values = pd.DataFrame(data=shap_array[:,:-1],columns=list(bst.feature_names)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cudf | |
obsfile = 'https://gmao.gsfc.nasa.gov/gmaoftp/geoscf/COVID_NO2/examples/obs.csv' | |
obsdat = cudf.read_csv(obsfile,parse_dates=['ISO8601'],date_parser=lambda x: dt.datetime.strptime(x, '%Y-%m-%dT%H:%M:%SZ')) | |
allobs = obsdat.loc[(obsdat['obstype']=='no2')] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num_round = 20 | |
param = {'booster' : 'gbtree' } | |
param['tree_method'] = 'gpu_hist' | |
start_time = time.perf_counter() | |
bst = xgb.train(param,train,num_round) | |
end_time = time.perf_counter() | |
print('This took {0:.3f} seconds'.format(end_time-start_time)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import xgboost as xgb | |
import time | |
SVMURL = 'https://gmao.gsfc.nasa.gov/gmaoftp/geoscf/gc-xgb/svm' | |
ifile = 'gcxgb_example_train.svm' | |
urlfile = '/'.join([SVMURL,ifile]) | |
r = requests.get(urlfile) | |
open(ifile, 'wb').write(r.content) | |
train = xgb.DMatrix(ifile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cupy as cp | |
def get_dist_mat_gpu(coords): | |
# Calculate distance matrix for all elements in coords. | |
# ‘coords’ is a cupy array of [1D image coordinates, wavelengths] within a group of 7 files (7 wavelengths), in GPU memory. The 2D images coordinates are 1st converted from the 1D values “on the fly” and the Euclidian distance matrix is returned. | |
coords_x = coords % 4096 | |
coords_y = coords // 4096 | |
coords_xb = coords_x[:, cp.newaxis] | |
coords_yb = coords_y[:, cp.newaxis] |