-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ef17148
committed
Oct 26, 2022
1 parent
8ca1778
commit 2482a62
Showing
5 changed files
with
57 additions
and
17 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,12 @@ | |
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%load_ext autoreload\n", | ||
"%autoreload 2" | ||
"Reproducible code for \"A machine learning emulator for Lagrangian particle dispersion model footprints: A case study using NAME\" by Elena Fillola, Raul Santos-Rodriguez, Alistair Manning, Simon O'Doherty and Matt Rigby (2022)\n", | ||
"\n", | ||
"Author: Elena Fillola ([email protected])" | ||
] | ||
}, | ||
{ | ||
|
@@ -57,7 +56,7 @@ | |
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
|
@@ -80,7 +79,7 @@ | |
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
|
@@ -96,7 +95,7 @@ | |
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
|
@@ -116,7 +115,7 @@ | |
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
|
@@ -129,11 +128,13 @@ | |
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"execution_count": 14, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Save the predictions\n", | ||
"# Save the predictions as a .nc file\n", | ||
"## Pass save_dir argument to specify path and filename format (year+month+.txt will be appended)\n", | ||
"## Otherwise default is used, saved in the data/emulated_fps folder\n", | ||
"predictions.save_predictions(info)" | ||
] | ||
}, | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,13 @@ | |
|
||
import argparse | ||
|
||
""" | ||
Reproducible code for "A machine learning emulator for Lagrangian particle dispersion model footprints: A case study using NAME" | ||
by Elena Fillola, Raul Santos-Rodriguez, Alistair Manning, Simon O'Doherty and Matt Rigby (2022) | ||
Author: Elena Fillola ([email protected]) | ||
""" | ||
|
||
parser = argparse.ArgumentParser(prog = "tree_emulator", description='Train footprint emulator') | ||
parser.add_argument('site', type=str, help='Site to train on, as string (eg "MHD")') | ||
parser.add_argument('year', help='Time period to train on. Can be int (2016) or str ("201[4-5]")') | ||
|
@@ -61,4 +68,3 @@ | |
|
||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,13 @@ | |
import glob | ||
import dask | ||
|
||
""" | ||
Reproducible code for "A machine learning emulator for Lagrangian particle dispersion model footprints: A case study using NAME" | ||
by Elena Fillola, Raul Santos-Rodriguez, Alistair Manning, Simon O'Doherty and Matt Rigby (2022) | ||
Author: Elena Fillola ([email protected]) | ||
""" | ||
|
||
class LoadData: | ||
""" | ||
Load data for training and testing, for a particular site | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,14 @@ | |
import sklearn.metrics as metrics | ||
import xarray as xr | ||
|
||
""" | ||
Reproducible code for "A machine learning emulator for Lagrangian particle dispersion model footprints: A case study using NAME" | ||
by Elena Fillola, Raul Santos-Rodriguez, Alistair Manning, Simon O'Doherty and Matt Rigby (2022) | ||
Author: Elena Fillola ([email protected]) | ||
""" | ||
|
||
|
||
class MakePredictions: | ||
""" | ||
Make footprint predictions | ||
|
@@ -99,9 +107,12 @@ def save_predictions(self, info, save_dir=None, year=None): | |
|
||
|
||
def predict_fluxes(self, flux, units_transform = "default"): | ||
## convolute predicted footprints and fluxes, returns two np arrays, one with the true flux and one with the emulated flux, of shape (n_footprints,) | ||
## flux is an array, regridded and cut to the same resolution and size of the footprints | ||
## units_transform can be None (use fluxes directly), "default" (performs flux*1e3 / CH4molarmass) or another function (which should return an array of the same shape as the original flux) | ||
""" | ||
convolute predicted footprints and fluxes. | ||
Returns two np arrays, one with the true flux and one with the emulated flux, both of shape (n_footprints,) | ||
input flux should be an array, regridded and cut to the same resolution and size of the footprints | ||
units_transform can be None (use fluxes directly), "default" (performs flux*1e3 / CH4molarmass) or another function (which should return an array of the same shape as the original flux) | ||
""" | ||
shape = self.size | ||
if units_transform != None: | ||
if units_transform == "default": | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,25 @@ | ||
import numpy as np | ||
from sklearn.ensemble import GradientBoostingRegressor | ||
|
||
""" | ||
Reproducible code for "A machine learning emulator for Lagrangian particle dispersion model footprints: A case study using NAME" | ||
by Elena Fillola, Raul Santos-Rodriguez, Alistair Manning, Simon O'Doherty and Matt Rigby (2022) | ||
Author: Elena Fillola ([email protected]) | ||
""" | ||
|
||
def train_tree(data, inputs, frequency, hours_back, tree): | ||
""" | ||
Train a GBRT (ie the regressor for a single cell) using parameters provided. Returns a trained sklearn regressor | ||
Train a GBRT (ie the regressor for a single cell) using parameters provided following method from paper. | ||
Returns a trained sklearn regressor | ||
Requires inputs: | ||
- data (LoadData object) | ||
- inputs (meteorological inputs) | ||
- frequency (freq to sample footprints) | ||
- hours_back (same parameter as used to produce inputs) | ||
- tree (int ID of cell to train, if all cells are flattened. tree is then unraveled into x,y coordinates within the domain, eg tree 0 is at loc 0,0) | ||
Parallel predicting function is predict_tree. Edit/replace both of these for custom training/predicting | ||
""" | ||
|
||
|