Skip to content

Commit

Permalink
Merge pull request #19 from asfadmin/sg/ml
Browse files Browse the repository at this point in the history
Sg/ml
  • Loading branch information
segallagher authored Oct 8, 2024
2 parents eecc413 + 39ab64d commit 634ffda
Show file tree
Hide file tree
Showing 38 changed files with 264 additions and 36 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ inputs:
name_of_input_1:
type: << Any, Bool, Binary, Set, Sequence, Str, Map, None, Number, !CustomClass your.type.here >>
default: << Value this variable should default to >>
user_input: << True, False >>
user_input: << None, Text, Dropdown, FileUpload >>
name_of_input_N:
type: << Any, Bool, Binary, Set, Sequence, Str, Map, None, Number, !CustomClass your.type.here >>
default: << Value this variable should default to >>
user_input: << True, False >>
user_input: << None, Text, Dropdown, FileUpload >>
outputs:
name_of_output:
type: << Any, Bool, Binary, Set, Sequence, Str, Map, None, Number, !CustomClass your.type.here >>
Expand Down Expand Up @@ -105,7 +105,7 @@ You can determine what system the code is currently running on using the platfor
import platform
system = platform.system()

if system() == "Emscripten":
if system == "Emscripten":
# import web packages
# Run web only code
else:
Expand Down
6 changes: 3 additions & 3 deletions flowblock_source_files/asf_utils/download_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
inputs:
grd_product:
type: !CustomClass asf_search.ASFProduct.ASFProduct
user_input: True
user_input: Text
edl_token:
type: Str
user_input: True
user_input: Text
download_path:
type: Str
user_input: True
user_input: Text
default: "/tmp/data_download"
outputs:
Expand Down
2 changes: 1 addition & 1 deletion flowblock_source_files/asf_utils/find_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
inputs:
scene_name:
type: Str
user_input: True
user_input: Text
outputs:
grd_product:
type: !CustomClass asf_search.ASFProduct.ASFProduct
Expand Down
Binary file modified flowblock_source_files/asf_utils/library.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions flowblock_source_files/base/concatenate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
string1:
type: Str
default: "Python"
user_input: True
user_input: Text
string2:
type: Str
default: " exists"
user_input: True
user_input: Text
outputs:
concatenated_string:
type: Str
Expand Down
4 changes: 2 additions & 2 deletions flowblock_source_files/base/download_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
URL:
type: Str
default: "/"
user_input: True
user_input: Text
directory:
type: Str
user_input: True
user_input: Text
outputs:
path:
type: Str
Expand Down
Binary file modified flowblock_source_files/base/library.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion flowblock_source_files/base/output_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
inputs:
image:
type: !CustomClass PIL.Image.Image
user_input: True
user_input: Text
description: "Writes the input PIL image to the \"Image Output\" field."
"""

Expand Down
2 changes: 1 addition & 1 deletion flowblock_source_files/base/output_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
inputs:
input_string:
type: Str
user_input: True
user_input: Text
description: "Displays the input_string based on platform"
"""

Expand Down
2 changes: 1 addition & 1 deletion flowblock_source_files/base/print_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
inputs:
path:
type: Str
user_input: True
user_input: Text
outputs:
success:
type: Bool
Expand Down
2 changes: 1 addition & 1 deletion flowblock_source_files/base/read_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
inputs:
input_string:
type: Str
user_input: True
user_input: Text
outputs:
output_string:
type: Str
Expand Down
6 changes: 3 additions & 3 deletions flowblock_source_files/base/write_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
inputs:
path:
type: Str
user_input: True
user_input: Text
write_mode:
type: Bool
user_input: True
user_input: Text
default: False
write_contents:
type: Str
user_input: True
user_input: Text
default: ""
outputs:
string:
Expand Down
Binary file modified flowblock_source_files/convert/library.zip
Binary file not shown.
Binary file modified flowblock_source_files/example/library.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion flowblock_source_files/example/open_image_and_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
type: Str
scale:
type: Number
user_input: True
user_input: Text
outputs:
image:
type: !CustomClass PIL.Image.Image
Expand Down
2 changes: 1 addition & 1 deletion flowblock_source_files/example/save_geotiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
type: Map
out_path:
type: Str
user_input: True
user_input: Text
outputs:
description: "Saves geotiff to a path"
"""
Expand Down
Binary file modified flowblock_source_files/image/library.zip
Binary file not shown.
1 change: 1 addition & 0 deletions flowblock_source_files/library_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ convert
example
image
math
ml
string
4 changes: 2 additions & 2 deletions flowblock_source_files/math/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
a:
type: Number
default: 0
user_input: True
user_input: Text
b:
type: Number
default: 0
user_input: True
user_input: Text
outputs:
sum:
type: Number
Expand Down
4 changes: 2 additions & 2 deletions flowblock_source_files/math/divide.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
a:
type: Number
default: 0
user_input: True
user_input: Text
b:
type: Number
default: 0
user_input: True
user_input: Text
outputs:
sum:
type: Number
Expand Down
Binary file modified flowblock_source_files/math/library.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions flowblock_source_files/math/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
a:
type: Number
default: 0
user_input: True
user_input: Text
b:
type: Number
default: 0
user_input: True
user_input: Text
outputs:
sum:
type: Number
Expand Down
4 changes: 2 additions & 2 deletions flowblock_source_files/math/multiply.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
a:
type: Number
default: 0
user_input: True
user_input: Text
b:
type: Number
default: 0
user_input: True
user_input: Text
outputs:
sum:
type: Number
Expand Down
4 changes: 2 additions & 2 deletions flowblock_source_files/math/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
a:
type: Number
default: 0
user_input: True
user_input: Text
b:
type: Number
default: 0
user_input: True
user_input: Text
outputs:
sum:
type: Number
Expand Down
2 changes: 1 addition & 1 deletion flowblock_source_files/math/roundup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
a:
type: Number
default: 0
user_input: True
user_input: Text
outputs:
sum:
type: Number
Expand Down
4 changes: 2 additions & 2 deletions flowblock_source_files/math/subtract.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
a:
type: Number
default: 0
user_input: True
user_input: Text
b:
type: Number
default: 0
user_input: True
user_input: Text
outputs:
sum:
type: Number
Expand Down
27 changes: 27 additions & 0 deletions flowblock_source_files/ml/cross-val-score.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
name: "Cross Validation Score"
requirements:
- numpy
- scikit-learn
inputs:
X:
type: !CustomClass numpy.ndarray
y:
type: !CustomClass numpy.ndarray
model:
type: !CustomClass sklearn.neural_network._multilayer_perceptron.MLPClassifier
outputs:
mean:
type: Number
standard_deviation:
type: Number
description: "Returns a trained sklearn MLP"
"""

import numpy as np
from sklearn.neural_network import MLPClassifier
from sklearn.model_selection import cross_val_score

def main(X:np.ndarray, y:np.ndarray, model:MLPClassifier):
scores = cross_val_score(model, X, y)
return scores.mean(), scores.std()
78 changes: 78 additions & 0 deletions flowblock_source_files/ml/import-sklearn-dataset.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
"""
name: "Import SKlearn Dataset"
requirements:
- numpy
- scikit-learn
inputs:
dataset_name:
type: Str
user_input: Dropdown
options:
- "breast_cancer"
- "diabetes"
- "digits"
- "iris"
- "linnerud"
- "wine"
n_class:
type: Number
default: None
user_input: Text
scaled:
type: Bool
default: None
user_input: Text
outputs:
X:
type: !CustomClass numpy.ndarray
y:
type: !CustomClass numpy.ndarray
description: "Returns a dataset loaded from sklearn"
"""

from sklearn import datasets
import logging
logging.basicConfig(format='%(asctime)s - %(message)s', level=logging.INFO)

def main(dataset_name:str, n_class:int=None, scaled:bool=None):
logging.info(f"Starting to import {dataset_name}")

## Temporary set "None" to None
## Remove after scipyflow issue #116 is completed
if n_class == "None":
n_class = None
if scaled == "None":
scaled = None
## End temporary code

dataset_name = dataset_name.lower()
kwargs = {
'return_X_y':True,
'as_frame':False,
}

if dataset_name == "breast_cancer":
return datasets.load_breast_cancer(**kwargs)

elif dataset_name == "diabetes":
if scaled:
kwargs[scaled] = scaled
return datasets.load_diabetes(**kwargs)

elif dataset_name == "digits":
if n_class:
kwargs[n_class] = n_class
return datasets.load_digits(**kwargs)

elif dataset_name == "iris":
return datasets.load_iris(**kwargs)

elif dataset_name == "linnerud":
return datasets.load_linnerud(**kwargs)

elif dataset_name == "wine":
return datasets.load_wine(**kwargs)

else:
logging.info(f"Cannot find dataset '{dataset_name}'")
return None, None
Binary file added flowblock_source_files/ml/library.zip
Binary file not shown.
23 changes: 23 additions & 0 deletions flowblock_source_files/ml/load-model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
name: "Load Model"
requirements:
- numpy
- scikit-learn
inputs:
X:
type: !CustomClass numpy.ndarray
y:
type: !CustomClass numpy.ndarray
model:
type: !CustomClass sklearn.neural_network._multilayer_perceptron.MLPClassifier
outputs:
score:
type: Number
description: "Returns a trained sklearn MLP"
"""

import numpy as np
from sklearn.neural_network import MLPClassifier

def main(X:np.ndarray, y: np.ndarray, model:MLPClassifier):
pass
Loading

0 comments on commit 634ffda

Please sign in to comment.