diff --git a/docs/nodes/AI_ML/ANOMALY_DETECTION/ISOLATION_FOREST/ISOLATION_FOREST.md b/docs/nodes/AI_ML/ANOMALY_DETECTION/ISOLATION_FOREST/ISOLATION_FOREST.md new file mode 100644 index 000000000..84602ae8c --- /dev/null +++ b/docs/nodes/AI_ML/ANOMALY_DETECTION/ISOLATION_FOREST/ISOLATION_FOREST.md @@ -0,0 +1,47 @@ + +[//]: # (Custom component imports) + +import DocString from '@site/src/components/DocString'; +import PythonCode from '@site/src/components/PythonCode'; +import AppDisplay from '@site/src/components/AppDisplay'; +import SectionBreak from '@site/src/components/SectionBreak'; +import AppendixSection from '@site/src/components/AppendixSection'; + +[//]: # (Docstring) + +import DocstringSource from '!!raw-loader!./a1-[autogen]/docstring.txt'; +import PythonSource from '!!raw-loader!./a1-[autogen]/python_code.txt'; + +{DocstringSource} +{PythonSource} + + + + + +[//]: # (Examples) + +## Examples + + + + + + + + +[//]: # (Appendix) + +import Notes from '!!raw-loader!./appendix/notes.md'; +import Hardware from '!!raw-loader!./appendix/hardware.md'; +import Media from '!!raw-loader!./appendix/media.md'; + +## Appendix + +{Notes} +{Hardware} +{Media} + + diff --git a/docs/nodes/AI_ML/ANOMALY_DETECTION/ISOLATION_FOREST/a1-[autogen]/docstring.txt b/docs/nodes/AI_ML/ANOMALY_DETECTION/ISOLATION_FOREST/a1-[autogen]/docstring.txt new file mode 100644 index 000000000..51da70cb9 --- /dev/null +++ b/docs/nodes/AI_ML/ANOMALY_DETECTION/ISOLATION_FOREST/a1-[autogen]/docstring.txt @@ -0,0 +1,13 @@ + +The ISOLATION_FOREST node uses the Isolation Forest algorithm to detect anomalous points in a tabular dataset. +Reference: https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.IsolationForest.html + +Parameters +---------- +contamination: float, default=0 (auto) + The estimated proportion of outliers in the data set. + +Returns +------- +dataframe + The original dataframe for the input data including two columns: 'anomaly_scores' and 'anomaly'. diff --git a/docs/nodes/AI_ML/ANOMALY_DETECTION/ISOLATION_FOREST/a1-[autogen]/python_code.txt b/docs/nodes/AI_ML/ANOMALY_DETECTION/ISOLATION_FOREST/a1-[autogen]/python_code.txt new file mode 100644 index 000000000..80de46d53 --- /dev/null +++ b/docs/nodes/AI_ML/ANOMALY_DETECTION/ISOLATION_FOREST/a1-[autogen]/python_code.txt @@ -0,0 +1,21 @@ +from flojoy import flojoy, DataFrame as FlojoyDataFrame +from sklearn.ensemble import IsolationForest + + +@flojoy +def ISOLATION_FOREST( + default: FlojoyDataFrame, + contamination: float = 0 +) -> FlojoyDataFrame: + + + df = default.m + if contamination == 0: + contamination = "auto" + model = IsolationForest(contamination=contamination) + model.fit(df) + results = model.decision_function(df) + df['anomaly'] = model.predict(df) + df['anomaly_scores'] = results + + return FlojoyDataFrame(df=df) \ No newline at end of file diff --git a/docs/nodes/AI_ML/ANOMALY_DETECTION/ISOLATION_FOREST/appendix/hardware.md b/docs/nodes/AI_ML/ANOMALY_DETECTION/ISOLATION_FOREST/appendix/hardware.md new file mode 100644 index 000000000..e69de29bb diff --git a/docs/nodes/AI_ML/ANOMALY_DETECTION/ISOLATION_FOREST/appendix/media.md b/docs/nodes/AI_ML/ANOMALY_DETECTION/ISOLATION_FOREST/appendix/media.md new file mode 100644 index 000000000..e69de29bb diff --git a/docs/nodes/AI_ML/ANOMALY_DETECTION/ISOLATION_FOREST/appendix/notes.md b/docs/nodes/AI_ML/ANOMALY_DETECTION/ISOLATION_FOREST/appendix/notes.md new file mode 100644 index 000000000..e69de29bb diff --git a/docs/nodes/AI_ML/IMAGE_CAPTIONING/NLP_CONNECT_VIT_GPT2/a1-[autogen]/python_code.txt b/docs/nodes/AI_ML/IMAGE_CAPTIONING/NLP_CONNECT_VIT_GPT2/a1-[autogen]/python_code.txt index b5f134f7c..251a462b6 100644 --- a/docs/nodes/AI_ML/IMAGE_CAPTIONING/NLP_CONNECT_VIT_GPT2/a1-[autogen]/python_code.txt +++ b/docs/nodes/AI_ML/IMAGE_CAPTIONING/NLP_CONNECT_VIT_GPT2/a1-[autogen]/python_code.txt @@ -16,6 +16,7 @@ def NLP_CONNECT_VIT_GPT2(default: Image) -> DataFrame: import pandas as pd import transformers + import torch import torchvision.transforms.functional as TF from flojoy import snapshot_download @@ -36,10 +37,11 @@ def NLP_CONNECT_VIT_GPT2(default: Image) -> DataFrame: feature_extractor = transformers.ViTImageProcessor.from_pretrained(local_repo_path) tokenizer = transformers.AutoTokenizer.from_pretrained(local_repo_path) - pixel_values = feature_extractor(images=[image], return_tensors="pt").pixel_values # type: ignore - output_ids = model.generate(pixel_values, max_length=16, num_beams=4) # type: ignore - preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True) # type: ignore - pred = preds[0].strip() + with torch.inference_mode(): + pixel_values = feature_extractor(images=[image], return_tensors="pt").pixel_values # type: ignore + output_ids = model.generate(pixel_values, max_length=16, num_beams=4) # type: ignore + preds = tokenizer.batch_decode(output_ids, skip_special_tokens=True) # type: ignore + pred = preds[0].strip() df_pred = pd.DataFrame.from_records([(pred,)], columns=["caption"]) diff --git a/docs/nodes/AI_ML/NLP/COUNT_VECTORIZER/a1-[autogen]/python_code.txt b/docs/nodes/AI_ML/NLP/COUNT_VECTORIZER/a1-[autogen]/python_code.txt index 1ed814884..311e2c6d0 100644 --- a/docs/nodes/AI_ML/NLP/COUNT_VECTORIZER/a1-[autogen]/python_code.txt +++ b/docs/nodes/AI_ML/NLP/COUNT_VECTORIZER/a1-[autogen]/python_code.txt @@ -1,6 +1,7 @@ from typing import TypedDict from sklearn.feature_extraction.text import CountVectorizer from flojoy import flojoy, DataFrame, Matrix, Vector +import numpy as np import pandas as pd @@ -24,6 +25,6 @@ def COUNT_VECTORIZER(default: DataFrame | Matrix | Vector) -> CountVectorizerOut X = vectorizer.fit_transform(data.flatten()) x = pd.DataFrame({"tokens": vectorizer.get_feature_names_out()}) - y = X.toarray() + y = X.toarray() # type: ignore return CountVectorizerOutput(tokens=DataFrame(df=x), word_count_vector=Vector(v=y)) diff --git a/docs/nodes/AI_ML/PREDICT_TIME_SERIES/PROPHET_PREDICT/a1-[autogen]/python_code.txt b/docs/nodes/AI_ML/PREDICT_TIME_SERIES/PROPHET_PREDICT/a1-[autogen]/python_code.txt index 8676291b5..460406c3c 100644 --- a/docs/nodes/AI_ML/PREDICT_TIME_SERIES/PROPHET_PREDICT/a1-[autogen]/python_code.txt +++ b/docs/nodes/AI_ML/PREDICT_TIME_SERIES/PROPHET_PREDICT/a1-[autogen]/python_code.txt @@ -1,8 +1,5 @@ -import pandas as pd -from flojoy import flojoy, DataFrame, DataContainer -from prophet import Prophet +from flojoy import flojoy, run_in_venv, DataFrame, DataContainer from typing import TypedDict -from prophet.serialize import model_to_json class ProphetPredictOutput(TypedDict): @@ -11,11 +8,70 @@ class ProphetPredictOutput(TypedDict): @flojoy(deps={"prophet": "1.1.4", "holidays": "0.26", "pystan": "2.19.1.1"}) +@run_in_venv( + pip_dependencies=[ + "prophet==1.1.4", + ] +) def PROPHET_PREDICT( default: DataFrame, run_forecast: bool = True, periods: int = 365 ) -> ProphetPredictOutput: + import os + import sys + import pandas as pd + import numpy as np + + import prophet + from prophet.serialize import model_to_json + + def _make_dummy_dataframe_for_prophet(): + Generate random time series data to test if prophet works + start_date = pd.Timestamp("2023-01-01") + end_date = pd.Timestamp("2023-07-20") + num_days = (end_date - start_date).days + 1 + timestamps = pd.date_range(start=start_date, end=end_date, freq="D") + data = np.random.randn(num_days) # Random data points + df = pd.DataFrame({"ds": timestamps, "ys": data}) + df.rename( + columns={df.columns[0]: "ds", df.columns[1]: "y"}, inplace=True + ) # PROPHET model expects first column to be `ds` and second to be `y` + return df + + def _apply_macos_prophet_hotfix(): + This is a hotfix for MacOS. See https://github.com/facebook/prophet/issues/2250#issuecomment-1559516328 for more detail + + if not sys.platform == "darwin": + return + + # Test if prophet works (i.e. if the hotfix had already been applied) + try: + _dummy_df = _make_dummy_dataframe_for_prophet() + prophet.Prophet().fit(_dummy_df) + except RuntimeError as e: + print(f"Could not run prophet, applying hotfix...") + else: + return + + prophet_dir = prophet.__path__[0] # type: ignore + # Get stan dir + stan_dir = os.path.join(prophet_dir, "stan_model") + # Find cmdstan-xxxxx dir + cmdstan_basename = [x for x in os.listdir(stan_dir) if x.startswith("cmdstan")] + assert len(cmdstan_basename) == 1, "Could not find cmdstan dir" + cmdstan_basename = cmdstan_basename[0] + # Run (from stan_dir) : install_name_tool -add_rpath @executable_path//stan/lib/stan_math/lib/tbb prophet_model.bin + cmd = f"install_name_tool -add_rpath @executable_path/{cmdstan_basename}/stan/lib/stan_math/lib/tbb prophet_model.bin" + cwd = os.getcwd() + os.chdir(stan_dir) + return_code = os.system(cmd) + os.chdir(cwd) + if return_code != 0: + raise RuntimeError("Could not apply hotfix") + + _apply_macos_prophet_hotfix() + df = default.m first_col = df.iloc[:, 0] if not pd.api.types.is_datetime64_any_dtype(first_col): @@ -25,7 +81,7 @@ def PROPHET_PREDICT( df.rename( columns={df.columns[0]: "ds", df.columns[1]: "y"}, inplace=True ) # PROPHET model expects first column to be `ds` and second to be `y` - model = Prophet() + model = prophet.Prophet() model.fit(df) extra = {"prophet": model_to_json(model), "run_forecast": run_forecast} # If run_forecast, the return df is the forecast, otherwise the original diff --git a/docs/nodes/AI_ML/SEGMENTATION/DEEPLAB_V3/a1-[autogen]/python_code.txt b/docs/nodes/AI_ML/SEGMENTATION/DEEPLAB_V3/a1-[autogen]/python_code.txt index b34a6db8f..d2a4718f0 100644 --- a/docs/nodes/AI_ML/SEGMENTATION/DEEPLAB_V3/a1-[autogen]/python_code.txt +++ b/docs/nodes/AI_ML/SEGMENTATION/DEEPLAB_V3/a1-[autogen]/python_code.txt @@ -1,55 +1,64 @@ -from flojoy import flojoy, Image - -import torch -from torchvision import transforms -import torchvision.transforms.functional as TF - -from PIL import Image as PIL_Image -import numpy as np +from flojoy import flojoy, run_in_venv, Image @flojoy +@run_in_venv( + pip_dependencies=[ + "torch==2.0.1", + "torchvision==0.15.2", + "Pillow==9.5.0", + "numpy==1.24.3", + ] +) def DEEPLAB_V3(default: Image) -> Image: - input_image = default + import os + import numpy as np + from PIL import Image as PIL_Image + import torch + from torchvision import transforms + import torchvision.transforms.functional as TF + from flojoy.utils import FLOJOY_CACHE_DIR + + # Parse input image + input_image = default r, g, b, a = input_image.r, input_image.g, input_image.b, input_image.a nparray = ( np.stack((r, g, b, a), axis=2) if a is not None else np.stack((r, g, b), axis=2) ) - + # Convert input image input_image = TF.to_pil_image(nparray).convert("RGB") - + # Set torch hub cache directory + torch.hub.set_dir(os.path.join(FLOJOY_CACHE_DIR, "torch_hub")) model = torch.hub.load( "pytorch/vision:v0.10.0", "deeplabv3_resnet50", pretrained=True ) model.eval() - + # Preprocessing preprocess_transform = transforms.Compose( [ transforms.ToTensor(), transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), ] ) - + # Feed the input image to the model input_tensor = preprocess_transform(input_image) input_batch = input_tensor.unsqueeze(0) - - with torch.no_grad(): + with torch.inference_mode(): output = model(input_batch)["out"][0] - + # Fetch the output output_predictions = output.argmax(0) palette = torch.tensor([2**25 - 1, 2**15 - 1, 2**21 - 1]) colors = torch.as_tensor([i for i in range(21)])[:, None] * palette colors = (colors % 255).numpy().astype("uint8") - # plot the semantic segmentation predictions of 21 classes in each color r = PIL_Image.fromarray(output_predictions.byte().cpu().numpy()).resize( input_image.size ) r.putpalette(colors) out_img = np.array(r.convert("RGB")) - + # Build the output image return Image( r=out_img[:, :, 0], g=out_img[:, :, 1], diff --git a/docs/nodes/AI_ML/TEXT_SUMMARIZATION/BART_LARGE_CNN/a1-[autogen]/docstring.txt b/docs/nodes/AI_ML/TEXT_SUMMARIZATION/BART_LARGE_CNN/a1-[autogen]/docstring.txt index ba4fcf4a2..c4a1ff643 100644 --- a/docs/nodes/AI_ML/TEXT_SUMMARIZATION/BART_LARGE_CNN/a1-[autogen]/docstring.txt +++ b/docs/nodes/AI_ML/TEXT_SUMMARIZATION/BART_LARGE_CNN/a1-[autogen]/docstring.txt @@ -1,5 +1,5 @@ -The BART_LARGE_CNN node takes an input dataframe with multiple rows and a single "text" column, - and produces a dataframe with a single "summary_text" column. The "summary_text" column contains a summary +The BART_LARGE_CNN node takes an input dataframe with multiple rows and a single column, + and produces a dataframe with a single "summary_text" column. The "summary_text" column contains a summary of the text in the corresponding row of the input dataframe. Parameters diff --git a/docs/nodes/AI_ML/TEXT_SUMMARIZATION/BART_LARGE_CNN/a1-[autogen]/python_code.txt b/docs/nodes/AI_ML/TEXT_SUMMARIZATION/BART_LARGE_CNN/a1-[autogen]/python_code.txt index 9e23f3a58..cec0319c7 100644 --- a/docs/nodes/AI_ML/TEXT_SUMMARIZATION/BART_LARGE_CNN/a1-[autogen]/python_code.txt +++ b/docs/nodes/AI_ML/TEXT_SUMMARIZATION/BART_LARGE_CNN/a1-[autogen]/python_code.txt @@ -1,35 +1,47 @@ -from flojoy import flojoy, DataFrame -import torch -from transformers import BartTokenizer, BartForConditionalGeneration -import pandas as pd +from flojoy import flojoy, run_in_venv, DataFrame @flojoy +@run_in_venv( + pip_dependencies=[ + "transformers==4.30.2", + "torch==2.0.1", + "torchvision==0.15.2", + "pandas==1.5.3", + ] +) def BART_LARGE_CNN(default: DataFrame) -> DataFrame: + + import torch + from flojoy import snapshot_download + from transformers import BartTokenizer, BartForConditionalGeneration + import pandas as pd + input_df = default.m assert ( len(input_df.columns.tolist()) == 1 ), "Can only take a single-column dataframe as input" - # Load the pre-trained BART model - model = BartForConditionalGeneration.from_pretrained( - "facebook/bart-large-cnn", revision="3d22493" - ) - tokenizer = BartTokenizer.from_pretrained( - "facebook/bart-large-cnn", revision="3d22493" + # Load the repo from either the local cache or from the web, and get the local path + local_path = snapshot_download( + repo_id="facebook/bart-large-cnn", revision="3d22493" ) + # Load the pre-trained BART model + model = BartForConditionalGeneration.from_pretrained(local_path) + tokenizer = BartTokenizer.from_pretrained(local_path) + def _chunk_text(text): inputs_no_trunc = tokenizer( text, max_length=None, return_tensors="pt", truncation=False ) chunks = [] - for i in range( - 0, len(inputs_no_trunc["input_ids"][0]), tokenizer.model_max_length - ): - chunk = inputs_no_trunc["input_ids"][0][i : i + tokenizer.model_max_length] + step = 1024 + # step = tokenizer.model_max_length - 1 + for i in range(0, len(inputs_no_trunc["input_ids"][0]), step): + chunk = inputs_no_trunc["input_ids"][0][i : i + step] chunks.append(torch.unsqueeze(chunk, 0)) return chunks @@ -39,7 +51,7 @@ def BART_LARGE_CNN(default: DataFrame) -> DataFrame: model.generate( chunk, num_beams=4, - max_length=tokenizer.model_max_length // 2, + max_length=1024 // 2, early_stopping=True, ) for chunk in chunks @@ -59,7 +71,8 @@ def BART_LARGE_CNN(default: DataFrame) -> DataFrame: column = input_df.columns[0] - output_df = pd.DataFrame( - input_df[column].apply(_summarize_text).rename("summary_text") - ) + with torch.inference_mode(): + output_df = pd.DataFrame( + input_df[column].apply(_summarize_text).rename("summary_text") + ) return DataFrame(df=output_df) diff --git a/docs/nodes/EXTRACTORS/FILE/READ_S3/READ_S3.md b/docs/nodes/EXTRACTORS/FILE/READ_S3/READ_S3.md index e085c5775..4250d5dd1 100644 --- a/docs/nodes/EXTRACTORS/FILE/READ_S3/READ_S3.md +++ b/docs/nodes/EXTRACTORS/FILE/READ_S3/READ_S3.md @@ -25,13 +25,13 @@ import PythonSource from '!!raw-loader!./a1-[autogen]/python_code.txt'; import Example1 from './examples/EX1/example.md'; import App1 from '!!raw-loader!./examples/EX1/app.txt'; - - +import appImg from './examples/EX1/app.jpeg' +import outputImg from './examples/EX1/output.jpeg' {App1} diff --git a/docs/nodes/EXTRACTORS/FILE/READ_S3/a1-[autogen]/docstring.txt b/docs/nodes/EXTRACTORS/FILE/READ_S3/a1-[autogen]/docstring.txt index fcf637de4..03f37178a 100644 --- a/docs/nodes/EXTRACTORS/FILE/READ_S3/a1-[autogen]/docstring.txt +++ b/docs/nodes/EXTRACTORS/FILE/READ_S3/a1-[autogen]/docstring.txt @@ -14,4 +14,4 @@ file_name: Returns ------ DataContainer: - type 'dataframe', m + type 'dataframe', df diff --git a/docs/nodes/EXTRACTORS/FILE/READ_S3/a1-[autogen]/python_code.txt b/docs/nodes/EXTRACTORS/FILE/READ_S3/a1-[autogen]/python_code.txt index c894847d0..fbf67bd05 100644 --- a/docs/nodes/EXTRACTORS/FILE/READ_S3/a1-[autogen]/python_code.txt +++ b/docs/nodes/EXTRACTORS/FILE/READ_S3/a1-[autogen]/python_code.txt @@ -1,7 +1,4 @@ -from pathlib import Path -import os import pandas as pd -import yaml import io import boto3 import keyring @@ -20,9 +17,8 @@ def READ_S3( raise ValueError("Provide a name that was used to set AWS S3 key") try: - accessKey = keyring.get_password(f"{s3_name}accessKey") - secretKey = keyring.get_password(f"{s3_name}secretKey") - + accessKey = keyring.get_password("system", f"{s3_name}_ACCESSKEY") + secretKey = keyring.get_password("system", f"{s3_name}_SECRETKEY") s3 = boto3.resource( "s3", aws_access_key_id=accessKey, aws_secret_access_key=secretKey ) @@ -31,7 +27,7 @@ def READ_S3( object.download_fileobj(buffer) df = pd.read_parquet(buffer) - return DataFrame(m=df) + return DataFrame(df=df) except Exception as e: print(e) diff --git a/docs/nodes/EXTRACTORS/FILE/READ_S3/examples/EX1/app.txt b/docs/nodes/EXTRACTORS/FILE/READ_S3/examples/EX1/app.txt index 2c100bca7..eac6e228b 100644 --- a/docs/nodes/EXTRACTORS/FILE/READ_S3/examples/EX1/app.txt +++ b/docs/nodes/EXTRACTORS/FILE/READ_S3/examples/EX1/app.txt @@ -3,113 +3,159 @@ "nodes": [ { "width": 150, - "height": 150, - "id": "READ_S3-4e5e8dec-036d-4bc2-b4cf-2165c66a8923", + "height": 180, + "id": "READ_S3-a7ae5adf-3873-46e1-b0f1-89abfb885ae6", "type": "FILE", "data": { - "id": "READ_S3-4e5e8dec-036d-4bc2-b4cf-2165c66a8923", + "id": "READ_S3-a7ae5adf-3873-46e1-b0f1-89abfb885ae6", "label": "READ S3", "func": "READ_S3", "type": "FILE", "ctrls": { "s3_name": { + "type": "str", + "default": "", + "desc": "name of the key that the user used to save access and secret access key", "functionName": "READ_S3", "param": "s3_name", - "value": "flojoy-testing" + "value": "FLOJOY" }, "bucket_name": { + "type": "str", + "default": "", + "desc": "AWS S3 bucket name that they are trying to access", "functionName": "READ_S3", "param": "bucket_name", - "value": "read-s3-node-testing" + "value": "flojoy-test" }, "file_name": { + "type": "str", + "default": "", + "desc": "name of the file that they want to extract", "functionName": "READ_S3", "param": "file_name", "value": "userdata1.parquet" } }, + "outputs": [ + { + "name": "default", + "id": "default", + "type": "DataFrame", + "desc": null + } + ], + "path": "PYTHON/nodes/EXTRACTORS/FILE/READ_S3/READ_S3.py", "selected": false }, "position": { - "x": 238.01114122664217, - "y": 667.3907700195157 + "x": -30.844856544489318, + "y": -70.41830920648297 }, "selected": false, "positionAbsolute": { - "x": 238.01114122664217, - "y": 667.3907700195157 + "x": -30.844856544489318, + "y": -70.41830920648297 }, "dragging": true }, { - "width": 210, - "height": 130, - "id": "END-ec894b0d-cc13-4dcc-9ee6-f66dfdb38ed0", - "type": "TERMINATOR", + "width": 96, + "height": 96, + "id": "END-94f1b44f-4496-4d32-a145-95750f055100", + "type": "TERMINATORS", "data": { - "id": "END-ec894b0d-cc13-4dcc-9ee6-f66dfdb38ed0", + "id": "END-94f1b44f-4496-4d32-a145-95750f055100", "label": "END", "func": "END", - "type": "TERMINATOR", + "type": "TERMINATORS", "ctrls": {}, + "inputs": [ + { + "name": "default", + "id": "default", + "type": "Any", + "multiple": false, + "desc": null + } + ], + "path": "PYTHON/nodes/LOGIC_GATES/TERMINATORS/END/END.py", "selected": false }, "position": { - "x": 1379.4397126552135, - "y": 665.9621985909441 + "x": 897.1988653150759, + "y": -38.08358889850612 }, "selected": false, "positionAbsolute": { - "x": 1379.4397126552135, - "y": 665.9621985909441 + "x": 897.1988653150759, + "y": -38.08358889850612 }, "dragging": true }, { - "width": 380, - "height": 293, - "id": "TABLE-d71cf926-0c67-443d-9f6e-a3f6649c9c22", - "type": "PLOTLY_VISOR", + "width": 225, + "height": 226, + "id": "TABLE-0f7daf14-fbf4-46c1-8d75-124ce212b38e", + "type": "PLOTLY", "data": { - "id": "TABLE-d71cf926-0c67-443d-9f6e-a3f6649c9c22", + "id": "TABLE-0f7daf14-fbf4-46c1-8d75-124ce212b38e", "label": "TABLE", "func": "TABLE", - "type": "PLOTLY_VISOR", + "type": "PLOTLY", "ctrls": {}, + "inputs": [ + { + "name": "default", + "id": "default", + "type": "OrderedTriple|OrderedPair|DataFrame|Matrix|Vector", + "multiple": false, + "desc": null + } + ], + "outputs": [ + { + "name": "default", + "id": "default", + "type": "Plotly", + "desc": null + } + ], + "path": "PYTHON/nodes/VISUALIZERS/PLOTLY/TABLE/TABLE.py", "selected": false }, "position": { - "x": 705.1539983694992, - "y": 574.5336271623727 + "x": 325.5749490958755, + "y": -89.02125782914803 }, "selected": false, "positionAbsolute": { - "x": 705.1539983694992, - "y": 574.5336271623727 + "x": 325.5749490958755, + "y": -89.02125782914803 }, "dragging": true } ], "edges": [ { - "source": "READ_S3-4e5e8dec-036d-4bc2-b4cf-2165c66a8923", - "sourceHandle": "main", - "target": "TABLE-d71cf926-0c67-443d-9f6e-a3f6649c9c22", - "targetHandle": "TABLE", - "id": "reactflow__edge-READ_S3-4e5e8dec-036d-4bc2-b4cf-2165c66a8923main-TABLE-d71cf926-0c67-443d-9f6e-a3f6649c9c22TABLE" + "source": "READ_S3-a7ae5adf-3873-46e1-b0f1-89abfb885ae6", + "sourceHandle": "default", + "target": "TABLE-0f7daf14-fbf4-46c1-8d75-124ce212b38e", + "targetHandle": "default", + "id": "reactflow__edge-READ_S3-a7ae5adf-3873-46e1-b0f1-89abfb885ae6default-TABLE-0f7daf14-fbf4-46c1-8d75-124ce212b38edefault" }, { - "source": "TABLE-d71cf926-0c67-443d-9f6e-a3f6649c9c22", - "sourceHandle": "main", - "target": "END-ec894b0d-cc13-4dcc-9ee6-f66dfdb38ed0", - "targetHandle": "END", - "id": "reactflow__edge-TABLE-d71cf926-0c67-443d-9f6e-a3f6649c9c22main-END-ec894b0d-cc13-4dcc-9ee6-f66dfdb38ed0END" + "source": "TABLE-0f7daf14-fbf4-46c1-8d75-124ce212b38e", + "sourceHandle": "default", + "target": "END-94f1b44f-4496-4d32-a145-95750f055100", + "targetHandle": "default", + "id": "reactflow__edge-TABLE-0f7daf14-fbf4-46c1-8d75-124ce212b38edefault-END-94f1b44f-4496-4d32-a145-95750f055100default" } ], "viewport": { - "x": 383.94248946966945, - "y": 98.35910915060867, - "zoom": 1.1608238532718647 + "x": 510.21439896404956, + "y": 541.3693344933569, + "zoom": 0.8648007408335578 } }, "ctrlsManifest": [ diff --git a/docs/nodes/GENERATORS/SAMPLE_DATASETS/TABULAR_DATASETS/TABULAR_DATASETS.md b/docs/nodes/GENERATORS/SAMPLE_DATASETS/TABULAR_DATASETS/TABULAR_DATASETS.md new file mode 100644 index 000000000..0593d9b32 --- /dev/null +++ b/docs/nodes/GENERATORS/SAMPLE_DATASETS/TABULAR_DATASETS/TABULAR_DATASETS.md @@ -0,0 +1,47 @@ + +[//]: # (Custom component imports) + +import DocString from '@site/src/components/DocString'; +import PythonCode from '@site/src/components/PythonCode'; +import AppDisplay from '@site/src/components/AppDisplay'; +import SectionBreak from '@site/src/components/SectionBreak'; +import AppendixSection from '@site/src/components/AppendixSection'; + +[//]: # (Docstring) + +import DocstringSource from '!!raw-loader!./a1-[autogen]/docstring.txt'; +import PythonSource from '!!raw-loader!./a1-[autogen]/python_code.txt'; + +{DocstringSource} +{PythonSource} + + + + + +[//]: # (Examples) + +## Examples + + + + + + + + +[//]: # (Appendix) + +import Notes from '!!raw-loader!./appendix/notes.md'; +import Hardware from '!!raw-loader!./appendix/hardware.md'; +import Media from '!!raw-loader!./appendix/media.md'; + +## Appendix + +{Notes} +{Hardware} +{Media} + + diff --git a/docs/nodes/GENERATORS/SAMPLE_DATASETS/TABULAR_DATASETS/a1-[autogen]/docstring.txt b/docs/nodes/GENERATORS/SAMPLE_DATASETS/TABULAR_DATASETS/a1-[autogen]/docstring.txt new file mode 100644 index 000000000..71fc7b464 --- /dev/null +++ b/docs/nodes/GENERATORS/SAMPLE_DATASETS/TABULAR_DATASETS/a1-[autogen]/docstring.txt @@ -0,0 +1,12 @@ + +The TABULAR_DATASETS node loads a tabular dataset from sklearn.datasets. + +Parameters +---------- +dataset: str, default="Iris" + The name of the dataset to load. Options are: "Iris", "Diabetes", "Digits", "Wine", "Linnerud", "Breast Cancer". + +Returns +------- +dataframe: FlojoyDataframe + The original dataframe for the input data. diff --git a/docs/nodes/GENERATORS/SAMPLE_DATASETS/TABULAR_DATASETS/a1-[autogen]/python_code.txt b/docs/nodes/GENERATORS/SAMPLE_DATASETS/TABULAR_DATASETS/a1-[autogen]/python_code.txt new file mode 100644 index 000000000..9ced39ee9 --- /dev/null +++ b/docs/nodes/GENERATORS/SAMPLE_DATASETS/TABULAR_DATASETS/a1-[autogen]/python_code.txt @@ -0,0 +1,27 @@ +from flojoy import flojoy, DataFrame as FlojoyDataframe +from typing import Literal +from sklearn import datasets + + +DATASETS_MAP = { + "Iris": datasets.load_iris, + "Diabetes": datasets.load_diabetes, + "Digits": datasets.load_digits, + "Wine": datasets.load_wine, + "Linnerud": datasets.load_linnerud, + "Breast Cancer": datasets.load_breast_cancer +} + + +@flojoy +def TABULAR_DATASETS( + dataset: Literal["Iris", "Diabetes", "Digits", "Wine", "Linnerud", "Breast Cancer"] = "Iris" +) -> FlojoyDataframe: + + + load_method = DATASETS_MAP[dataset] + data = load_method(as_frame=True).frame + + return FlojoyDataframe(df=data) + + diff --git a/docs/nodes/GENERATORS/SAMPLE_DATASETS/TABULAR_DATASETS/appendix/hardware.md b/docs/nodes/GENERATORS/SAMPLE_DATASETS/TABULAR_DATASETS/appendix/hardware.md new file mode 100644 index 000000000..e69de29bb diff --git a/docs/nodes/GENERATORS/SAMPLE_DATASETS/TABULAR_DATASETS/appendix/media.md b/docs/nodes/GENERATORS/SAMPLE_DATASETS/TABULAR_DATASETS/appendix/media.md new file mode 100644 index 000000000..e69de29bb diff --git a/docs/nodes/GENERATORS/SAMPLE_DATASETS/TABULAR_DATASETS/appendix/notes.md b/docs/nodes/GENERATORS/SAMPLE_DATASETS/TABULAR_DATASETS/appendix/notes.md new file mode 100644 index 000000000..e69de29bb diff --git a/docs/nodes/LOADERS/LOCAL_FILE_SYSTEM/LOCAL_FILE/LOCAL_FILE.md b/docs/nodes/LOADERS/LOCAL_FILE_SYSTEM/LOCAL_FILE/LOCAL_FILE.md index 0cd1dfcbf..9a4078144 100644 --- a/docs/nodes/LOADERS/LOCAL_FILE_SYSTEM/LOCAL_FILE/LOCAL_FILE.md +++ b/docs/nodes/LOADERS/LOCAL_FILE_SYSTEM/LOCAL_FILE/LOCAL_FILE.md @@ -25,13 +25,13 @@ import PythonSource from '!!raw-loader!./a1-[autogen]/python_code.txt'; import Example1 from './examples/EX1/example.md'; import App1 from '!!raw-loader!./examples/EX1/app.txt'; - - +import appImg from './examples/EX1/app.jpeg' +import outputImg from './examples/EX1/output.jpeg' {App1} diff --git a/docs/nodes/NUMPY/LINALG/CHOLESKY/a1-[autogen]/python_code.txt b/docs/nodes/NUMPY/LINALG/CHOLESKY/a1-[autogen]/python_code.txt index 34adc4d81..8983cb184 100644 --- a/docs/nodes/NUMPY/LINALG/CHOLESKY/a1-[autogen]/python_code.txt +++ b/docs/nodes/NUMPY/LINALG/CHOLESKY/a1-[autogen]/python_code.txt @@ -1,4 +1,4 @@ -from flojoy import OrderedPair, flojoy, Matrix, Scalar +from flojoy import flojoy, Matrix, Scalar import numpy as np from collections import namedtuple from typing import Literal @@ -18,7 +18,7 @@ def CHOLESKY( if isinstance(result, np.ndarray): result = Matrix(m=result) - elif isinstance(result, np.float64): - result = Scalar(c=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) return result diff --git a/docs/nodes/NUMPY/LINALG/DET/a1-[autogen]/python_code.txt b/docs/nodes/NUMPY/LINALG/DET/a1-[autogen]/python_code.txt index f77d9fd89..bc3e4bcdb 100644 --- a/docs/nodes/NUMPY/LINALG/DET/a1-[autogen]/python_code.txt +++ b/docs/nodes/NUMPY/LINALG/DET/a1-[autogen]/python_code.txt @@ -1,4 +1,4 @@ -from flojoy import OrderedPair, flojoy, Matrix, Scalar +from flojoy import flojoy, Matrix, Scalar import numpy as np from collections import namedtuple from typing import Literal @@ -18,7 +18,7 @@ def DET( if isinstance(result, np.ndarray): result = Matrix(m=result) - elif isinstance(result, np.float64): - result = Scalar(c=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) return result diff --git a/docs/nodes/NUMPY/LINALG/EIG/a1-[autogen]/docstring.txt b/docs/nodes/NUMPY/LINALG/EIG/a1-[autogen]/docstring.txt index ebbd0d4c0..bae299492 100644 --- a/docs/nodes/NUMPY/LINALG/EIG/a1-[autogen]/docstring.txt +++ b/docs/nodes/NUMPY/LINALG/EIG/a1-[autogen]/docstring.txt @@ -6,7 +6,7 @@ The EIG node is based on a numpy or scipy function. Parameters ---------- - select_return : This function has returns multiple Objects: + select_return : This function has returns multiple objects: ['w', 'v']. Select the desired one to return. See the respective function docs for descriptors. a : (..., M, M) array diff --git a/docs/nodes/NUMPY/LINALG/EIG/a1-[autogen]/python_code.txt b/docs/nodes/NUMPY/LINALG/EIG/a1-[autogen]/python_code.txt index dfba47c49..effac147d 100644 --- a/docs/nodes/NUMPY/LINALG/EIG/a1-[autogen]/python_code.txt +++ b/docs/nodes/NUMPY/LINALG/EIG/a1-[autogen]/python_code.txt @@ -1,4 +1,4 @@ -from flojoy import OrderedPair, flojoy, Matrix, Scalar +from flojoy import flojoy, Matrix, Scalar import numpy as np from collections import namedtuple from typing import Literal @@ -17,13 +17,20 @@ def EIG( a=default.m, ) - if isinstance(result, namedtuple): + return_list = ["w", "v"] + if isinstance(result, tuple): + res_dict = {} + num = min(len(result), len(return_list)) + for i in range(num): + res_dict[return_list[i]] = result[i] + result = res_dict[select_return] + else: result = result._asdict() result = result[select_return] if isinstance(result, np.ndarray): result = Matrix(m=result) - elif isinstance(result, np.float64): - result = Scalar(c=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) return result diff --git a/docs/nodes/NUMPY/LINALG/EIGH/a1-[autogen]/python_code.txt b/docs/nodes/NUMPY/LINALG/EIGH/a1-[autogen]/python_code.txt index 255161669..022bc59ce 100644 --- a/docs/nodes/NUMPY/LINALG/EIGH/a1-[autogen]/python_code.txt +++ b/docs/nodes/NUMPY/LINALG/EIGH/a1-[autogen]/python_code.txt @@ -1,4 +1,4 @@ -from flojoy import OrderedPair, flojoy, Matrix, Scalar +from flojoy import flojoy, Matrix, Scalar import numpy as np from collections import namedtuple from typing import Literal @@ -19,13 +19,20 @@ def EIGH( UPLO=UPLO, ) - if isinstance(result, namedtuple): + return_list = ["w", "v"] + if isinstance(result, tuple): + res_dict = {} + num = min(len(result), len(return_list)) + for i in range(num): + res_dict[return_list[i]] = result[i] + result = res_dict[select_return] + else: result = result._asdict() result = result[select_return] if isinstance(result, np.ndarray): result = Matrix(m=result) - elif isinstance(result, np.float64): - result = Scalar(c=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) return result diff --git a/docs/nodes/NUMPY/LINALG/EIGVALS/a1-[autogen]/python_code.txt b/docs/nodes/NUMPY/LINALG/EIGVALS/a1-[autogen]/python_code.txt index 40ad225d4..de07ba18e 100644 --- a/docs/nodes/NUMPY/LINALG/EIGVALS/a1-[autogen]/python_code.txt +++ b/docs/nodes/NUMPY/LINALG/EIGVALS/a1-[autogen]/python_code.txt @@ -1,4 +1,4 @@ -from flojoy import OrderedPair, flojoy, Matrix, Scalar +from flojoy import flojoy, Matrix, Scalar import numpy as np from collections import namedtuple from typing import Literal @@ -18,7 +18,7 @@ def EIGVALS( if isinstance(result, np.ndarray): result = Matrix(m=result) - elif isinstance(result, np.float64): - result = Scalar(c=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) return result diff --git a/docs/nodes/NUMPY/LINALG/EIGVALSH/a1-[autogen]/python_code.txt b/docs/nodes/NUMPY/LINALG/EIGVALSH/a1-[autogen]/python_code.txt index 2b31fe9ef..7dee01378 100644 --- a/docs/nodes/NUMPY/LINALG/EIGVALSH/a1-[autogen]/python_code.txt +++ b/docs/nodes/NUMPY/LINALG/EIGVALSH/a1-[autogen]/python_code.txt @@ -1,4 +1,4 @@ -from flojoy import OrderedPair, flojoy, Matrix, Scalar +from flojoy import flojoy, Matrix, Scalar import numpy as np from collections import namedtuple from typing import Literal @@ -20,7 +20,7 @@ def EIGVALSH( if isinstance(result, np.ndarray): result = Matrix(m=result) - elif isinstance(result, np.float64): - result = Scalar(c=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) return result diff --git a/docs/nodes/NUMPY/LINALG/INV/a1-[autogen]/python_code.txt b/docs/nodes/NUMPY/LINALG/INV/a1-[autogen]/python_code.txt index 8f534d3b4..6c9c257bb 100644 --- a/docs/nodes/NUMPY/LINALG/INV/a1-[autogen]/python_code.txt +++ b/docs/nodes/NUMPY/LINALG/INV/a1-[autogen]/python_code.txt @@ -1,4 +1,4 @@ -from flojoy import OrderedPair, flojoy, Matrix, Scalar +from flojoy import flojoy, Matrix, Scalar import numpy as np from collections import namedtuple from typing import Literal @@ -18,7 +18,7 @@ def INV( if isinstance(result, np.ndarray): result = Matrix(m=result) - elif isinstance(result, np.float64): - result = Scalar(c=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) return result diff --git a/docs/nodes/NUMPY/LINALG/MATRIX_POWER/a1-[autogen]/python_code.txt b/docs/nodes/NUMPY/LINALG/MATRIX_POWER/a1-[autogen]/python_code.txt index 2c8c149e1..a42dabb4f 100644 --- a/docs/nodes/NUMPY/LINALG/MATRIX_POWER/a1-[autogen]/python_code.txt +++ b/docs/nodes/NUMPY/LINALG/MATRIX_POWER/a1-[autogen]/python_code.txt @@ -1,4 +1,4 @@ -from flojoy import OrderedPair, flojoy, Matrix, Scalar +from flojoy import flojoy, Matrix, Scalar import numpy as np from collections import namedtuple from typing import Literal @@ -9,7 +9,7 @@ import numpy.linalg @flojoy(node_type="default") def MATRIX_POWER( default: Matrix, - n: int, + n: int = 2, ) -> Matrix | Scalar: @@ -20,7 +20,7 @@ def MATRIX_POWER( if isinstance(result, np.ndarray): result = Matrix(m=result) - elif isinstance(result, np.float64): - result = Scalar(c=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) return result diff --git a/docs/nodes/NUMPY/LINALG/PINV/a1-[autogen]/python_code.txt b/docs/nodes/NUMPY/LINALG/PINV/a1-[autogen]/python_code.txt index 9a73b2fcf..b2029190b 100644 --- a/docs/nodes/NUMPY/LINALG/PINV/a1-[autogen]/python_code.txt +++ b/docs/nodes/NUMPY/LINALG/PINV/a1-[autogen]/python_code.txt @@ -1,4 +1,4 @@ -from flojoy import OrderedPair, flojoy, Matrix, Scalar +from flojoy import flojoy, Matrix, Scalar import numpy as np from collections import namedtuple from typing import Literal @@ -22,7 +22,7 @@ def PINV( if isinstance(result, np.ndarray): result = Matrix(m=result) - elif isinstance(result, np.float64): - result = Scalar(c=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) return result diff --git a/docs/nodes/NUMPY/LINALG/QR/a1-[autogen]/docstring.txt b/docs/nodes/NUMPY/LINALG/QR/a1-[autogen]/docstring.txt index 0f66122eb..ba28cae97 100644 --- a/docs/nodes/NUMPY/LINALG/QR/a1-[autogen]/docstring.txt +++ b/docs/nodes/NUMPY/LINALG/QR/a1-[autogen]/docstring.txt @@ -9,7 +9,7 @@ The QR node is based on a numpy or scipy function. Parameters ---------- - select_return : This function has returns multiple Objects: + select_return : This function has returns multiple objects: ['q', 'r', '(h, tau)']. Select the desired one to return. See the respective function docs for descriptors. a : array_like, shape (..., M, N) diff --git a/docs/nodes/NUMPY/LINALG/QR/a1-[autogen]/python_code.txt b/docs/nodes/NUMPY/LINALG/QR/a1-[autogen]/python_code.txt index 398e9ebc9..4ced9457d 100644 --- a/docs/nodes/NUMPY/LINALG/QR/a1-[autogen]/python_code.txt +++ b/docs/nodes/NUMPY/LINALG/QR/a1-[autogen]/python_code.txt @@ -1,4 +1,4 @@ -from flojoy import OrderedPair, flojoy, Matrix, Scalar +from flojoy import flojoy, Matrix, Scalar import numpy as np from collections import namedtuple from typing import Literal @@ -19,13 +19,20 @@ def QR( mode=mode, ) - if isinstance(result, namedtuple): + return_list = ["q", "r", "(h, tau)"] + if isinstance(result, tuple): + res_dict = {} + num = min(len(result), len(return_list)) + for i in range(num): + res_dict[return_list[i]] = result[i] + result = res_dict[select_return] + else: result = result._asdict() result = result[select_return] if isinstance(result, np.ndarray): result = Matrix(m=result) - elif isinstance(result, np.float64): - result = Scalar(c=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) return result diff --git a/docs/nodes/NUMPY/LINALG/SLOGDET/a1-[autogen]/docstring.txt b/docs/nodes/NUMPY/LINALG/SLOGDET/a1-[autogen]/docstring.txt index aba848cd8..fc9bb6c12 100644 --- a/docs/nodes/NUMPY/LINALG/SLOGDET/a1-[autogen]/docstring.txt +++ b/docs/nodes/NUMPY/LINALG/SLOGDET/a1-[autogen]/docstring.txt @@ -11,7 +11,7 @@ The SLOGDET node is based on a numpy or scipy function. Parameters ---------- - select_return : This function has returns multiple Objects: + select_return : This function has returns multiple objects: ['sign', 'logdet']. Select the desired one to return. See the respective function docs for descriptors. a : (..., M, M) array_like diff --git a/docs/nodes/NUMPY/LINALG/SLOGDET/a1-[autogen]/python_code.txt b/docs/nodes/NUMPY/LINALG/SLOGDET/a1-[autogen]/python_code.txt index 8acea38ea..4a86c5bb5 100644 --- a/docs/nodes/NUMPY/LINALG/SLOGDET/a1-[autogen]/python_code.txt +++ b/docs/nodes/NUMPY/LINALG/SLOGDET/a1-[autogen]/python_code.txt @@ -1,4 +1,4 @@ -from flojoy import OrderedPair, flojoy, Matrix, Scalar +from flojoy import flojoy, Matrix, Scalar import numpy as np from collections import namedtuple from typing import Literal @@ -17,13 +17,20 @@ def SLOGDET( a=default.m, ) - if isinstance(result, namedtuple): + return_list = ["sign", "logdet"] + if isinstance(result, tuple): + res_dict = {} + num = min(len(result), len(return_list)) + for i in range(num): + res_dict[return_list[i]] = result[i] + result = res_dict[select_return] + else: result = result._asdict() result = result[select_return] if isinstance(result, np.ndarray): result = Matrix(m=result) - elif isinstance(result, np.float64): - result = Scalar(c=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) return result diff --git a/docs/nodes/NUMPY/LINALG/SVD/a1-[autogen]/docstring.txt b/docs/nodes/NUMPY/LINALG/SVD/a1-[autogen]/docstring.txt index 62354f400..e217cfd15 100644 --- a/docs/nodes/NUMPY/LINALG/SVD/a1-[autogen]/docstring.txt +++ b/docs/nodes/NUMPY/LINALG/SVD/a1-[autogen]/docstring.txt @@ -13,7 +13,7 @@ The SVD node is based on a numpy or scipy function. Parameters ---------- - select_return : This function has returns multiple Objects: + select_return : This function has returns multiple objects: ['u', 's', 'vh']. Select the desired one to return. See the respective function docs for descriptors. a : (..., M, N) array_like diff --git a/docs/nodes/NUMPY/LINALG/SVD/a1-[autogen]/python_code.txt b/docs/nodes/NUMPY/LINALG/SVD/a1-[autogen]/python_code.txt index 1abc8f8bd..eb80e002f 100644 --- a/docs/nodes/NUMPY/LINALG/SVD/a1-[autogen]/python_code.txt +++ b/docs/nodes/NUMPY/LINALG/SVD/a1-[autogen]/python_code.txt @@ -1,4 +1,4 @@ -from flojoy import OrderedPair, flojoy, Matrix, Scalar +from flojoy import flojoy, Matrix, Scalar import numpy as np from collections import namedtuple from typing import Literal @@ -23,13 +23,20 @@ def SVD( hermitian=hermitian, ) - if isinstance(result, namedtuple): + return_list = ["u", "s", "vh"] + if isinstance(result, tuple): + res_dict = {} + num = min(len(result), len(return_list)) + for i in range(num): + res_dict[return_list[i]] = result[i] + result = res_dict[select_return] + else: result = result._asdict() result = result[select_return] if isinstance(result, np.ndarray): result = Matrix(m=result) - elif isinstance(result, np.float64): - result = Scalar(c=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) return result diff --git a/docs/nodes/NUMPY/LINALG/TENSORINV/a1-[autogen]/python_code.txt b/docs/nodes/NUMPY/LINALG/TENSORINV/a1-[autogen]/python_code.txt index 8e3a934bb..3836e9a3b 100644 --- a/docs/nodes/NUMPY/LINALG/TENSORINV/a1-[autogen]/python_code.txt +++ b/docs/nodes/NUMPY/LINALG/TENSORINV/a1-[autogen]/python_code.txt @@ -1,4 +1,4 @@ -from flojoy import OrderedPair, flojoy, Matrix, Scalar +from flojoy import flojoy, Matrix, Scalar import numpy as np from collections import namedtuple from typing import Literal @@ -20,7 +20,7 @@ def TENSORINV( if isinstance(result, np.ndarray): result = Matrix(m=result) - elif isinstance(result, np.float64): - result = Scalar(c=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) return result diff --git a/docs/nodes/SCIPY/SIGNAL/BSPLINE/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/SIGNAL/BSPLINE/a1-[autogen]/python_code.txt index fa929737f..215e61f24 100644 --- a/docs/nodes/SCIPY/SIGNAL/BSPLINE/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/SIGNAL/BSPLINE/a1-[autogen]/python_code.txt @@ -9,16 +9,18 @@ import scipy.signal @flojoy(node_type="default") def BSPLINE( default: OrderedPair | Matrix, - n: int, + n: int = 2, ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.signal.bspline( - x=default.y, - n=n, - ), + result = scipy.signal.bspline( + x=default.y, + n=n, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/SIGNAL/CUBIC/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/SIGNAL/CUBIC/a1-[autogen]/python_code.txt index 231fea90b..1894099ad 100644 --- a/docs/nodes/SCIPY/SIGNAL/CUBIC/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/SIGNAL/CUBIC/a1-[autogen]/python_code.txt @@ -12,11 +12,13 @@ def CUBIC( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.signal.cubic( - x=default.y, - ), + result = scipy.signal.cubic( + x=default.y, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/SIGNAL/DECIMATE/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/SIGNAL/DECIMATE/a1-[autogen]/python_code.txt index 9ae41dd4a..b4296317e 100644 --- a/docs/nodes/SCIPY/SIGNAL/DECIMATE/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/SIGNAL/DECIMATE/a1-[autogen]/python_code.txt @@ -9,24 +9,26 @@ import scipy.signal @flojoy(node_type="default") def DECIMATE( default: OrderedPair | Matrix, - q: int, - n: int, + q: int = 2, + n: int = 2, ftype: str = "iir", axis: int = -1, zero_phase: bool = True, ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.signal.decimate( - x=default.y, - q=q, - n=n, - ftype=ftype, - axis=axis, - zero_phase=zero_phase, - ), + result = scipy.signal.decimate( + x=default.y, + q=q, + n=n, + ftype=ftype, + axis=axis, + zero_phase=zero_phase, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/SIGNAL/DETREND/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/SIGNAL/DETREND/a1-[autogen]/python_code.txt index 6704e2a1b..7afa767a1 100644 --- a/docs/nodes/SCIPY/SIGNAL/DETREND/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/SIGNAL/DETREND/a1-[autogen]/python_code.txt @@ -16,15 +16,17 @@ def DETREND( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.signal.detrend( - data=default.y, - axis=axis, - type=type, - bp=bp, - overwrite_data=overwrite_data, - ), + result = scipy.signal.detrend( + data=default.y, + axis=axis, + type=type, + bp=bp, + overwrite_data=overwrite_data, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/SIGNAL/GAUSS_SPLINE/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/SIGNAL/GAUSS_SPLINE/a1-[autogen]/python_code.txt index f17bb191c..3a33dd70c 100644 --- a/docs/nodes/SCIPY/SIGNAL/GAUSS_SPLINE/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/SIGNAL/GAUSS_SPLINE/a1-[autogen]/python_code.txt @@ -9,16 +9,18 @@ import scipy.signal @flojoy(node_type="default") def GAUSS_SPLINE( default: OrderedPair | Matrix, - n: int, + n: int = 2, ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.signal.gauss_spline( - x=default.y, - n=n, - ), + result = scipy.signal.gauss_spline( + x=default.y, + n=n, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/SIGNAL/HILBERT/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/SIGNAL/HILBERT/a1-[autogen]/python_code.txt index 29328380d..16d8e69b0 100644 --- a/docs/nodes/SCIPY/SIGNAL/HILBERT/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/SIGNAL/HILBERT/a1-[autogen]/python_code.txt @@ -9,18 +9,20 @@ import scipy.signal @flojoy(node_type="default") def HILBERT( default: OrderedPair | Matrix, - N: int, + N: int = 2, axis: int = -1, ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.signal.hilbert( - x=default.y, - N=N, - axis=axis, - ), + result = scipy.signal.hilbert( + x=default.y, + N=N, + axis=axis, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/SIGNAL/KAISER_BETA/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/SIGNAL/KAISER_BETA/a1-[autogen]/python_code.txt index d9a5a493e..09e36c7e7 100644 --- a/docs/nodes/SCIPY/SIGNAL/KAISER_BETA/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/SIGNAL/KAISER_BETA/a1-[autogen]/python_code.txt @@ -12,11 +12,13 @@ def KAISER_BETA( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.signal.kaiser_beta( - a=default.y, - ), + result = scipy.signal.kaiser_beta( + a=default.y, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/SIGNAL/PERIODOGRAM/a1-[autogen]/docstring.txt b/docs/nodes/SCIPY/SIGNAL/PERIODOGRAM/a1-[autogen]/docstring.txt index cc2da51d8..2706b161d 100644 --- a/docs/nodes/SCIPY/SIGNAL/PERIODOGRAM/a1-[autogen]/docstring.txt +++ b/docs/nodes/SCIPY/SIGNAL/PERIODOGRAM/a1-[autogen]/docstring.txt @@ -1,43 +1,49 @@ +The PERIODOGRAM node is based on a numpy or scipy function. + The description of that function is as follows: - Estimate power spectral density using a periodogram. + Estimate power spectral density using a periodogram. --.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -The parameters of the function in this Flojoy wrapper are given below. --.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. + Parameters + ---------- + select_return : This function has returns multiple objects: + ['f', 'Pxx']. Select the desired one to return. + See the respective function docs for descriptors. + x : array_like + Time series of measurement values + fs : float, optional + Sampling frequency of the `x` time series. Defaults to 1.0. + window : str or tuple or array_like, optional + Desired window to use. If `window` is a string or tuple, it is + passed to `get_window` to generate the window values, which are + DFT-even by default. See `get_window` for a list of windows and + required parameters. If `window` is array_like it will be used + directly as the window and its length must be nperseg. Defaults + to 'boxcar'. + nfft : int, optional + Length of the FFT used. If `None` the length of `x` will be + used. + detrend : str or function or `False`, optional + Specifies how to detrend each segment. If `detrend` is a + string, it is passed as the `type` argument to the `detrend` + function. If it is a function, it takes a segment and returns a + detrended segment. If `detrend` is `False`, no detrending is + done. Defaults to 'constant'. + return_onesided : bool, optional + If `True`, return a one-sided spectrum for real data. If + `False` return a two-sided spectrum. Defaults to `True`, but for + complex data, a two-sided spectrum is always returned. + scaling : { 'density', 'spectrum' }, optional + Selects between computing the power spectral density ('density') + where `Pxx` has units of V**2/Hz and computing the power + spectrum ('spectrum') where `Pxx` has units of V**2, if `x` + is measured in V and `fs` is measured in Hz. Defaults to + 'density' + axis : int, optional + Axis along which the periodogram is computed; the default is + over the last axis (i.e. ``axis=-1``). -Parameters ----------- -x : array_like - Time series of measurement values -fs : float, optional - Sampling frequency of the `x` time series. Defaults to 1.0. -window : str or tuple or array_like, optional - Desired window to use. If `window` is a string or tuple, it is - passed to `get_window` to generate the window values, which are - DFT-even by default. See `get_window` for a list of windows and - required parameters. If `window` is array_like it will be used - directly as the window and its length must be nperseg. Defaults - to 'boxcar'. -nfft : int, optional - Length of the FFT used. If `None` the length of `x` will be - used. -detrend : str or function or `False`, optional - Specifies how to detrend each segment. If `detrend` is a - string, it is passed as the `type` argument to the `detrend` - function. If it is a function, it takes a segment and returns a - detrended segment. If `detrend` is `False`, no detrending is - done. Defaults to 'constant'. -return_onesided : bool, optional - If `True`, return a one-sided spectrum for real data. If - `False` return a two-sided spectrum. Defaults to `True`, but for - complex data, a two-sided spectrum is always returned. -scaling : { 'density', 'spectrum' }, optional - Selects between computing the power spectral density ('density') - where `Pxx` has units of V**2/Hz and computing the power - spectrum ('spectrum') where `Pxx` has units of V**2, if `x` - is measured in V and `fs` is measured in Hz. Defaults to - 'density' -axis : int, optional - Axis along which the periodogram is computed; the default is - over the last axis (i.e. ``axis=-1``). + Returns + ---------- + DataContainer: + type 'ordered pair', 'scalar', or 'matrix' diff --git a/docs/nodes/SCIPY/SIGNAL/PERIODOGRAM/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/SIGNAL/PERIODOGRAM/a1-[autogen]/python_code.txt index 36c27a47e..2aa3681b5 100644 --- a/docs/nodes/SCIPY/SIGNAL/PERIODOGRAM/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/SIGNAL/PERIODOGRAM/a1-[autogen]/python_code.txt @@ -1,24 +1,50 @@ -from flojoy import DataContainer, flojoy +from flojoy import OrderedPair, flojoy, Matrix, Scalar +import numpy as np +from collections import namedtuple +from typing import Literal + import scipy.signal -@flojoy -def PERIODOGRAM(dc, params): +@flojoy(node_type="default") +def PERIODOGRAM( + default: OrderedPair | Matrix, + fs: float = 1.0, + window: str = "boxcar", + nfft: int = 2, + detrend: str = "constant", + return_onesided: bool = True, + scaling: str = "density", + axis: int = -1, + select_return: Literal["f", "Pxx"] = "f", +) -> OrderedPair | Matrix | Scalar: - return DataContainer( - x=dc[0].y, - y=scipy.signal.periodogram( - x=dc[0].y, - fs=(float(params["fs"]) if params["fs"] != "" else None), - window=(str(params["window"]) if params["window"] != "" else None), - nfft=(int(params["nfft"]) if params["nfft"] != "" else None), - detrend=(str(params["detrend"]) if params["detrend"] != "" else None), - return_onesided=( - bool(params["return_onesided"]) - if params["return_onesided"] != "" - else None - ), - scaling=(str(params["scaling"]) if params["scaling"] != "" else None), - axis=(int(params["axis"]) if params["axis"] != "" else None), - ), + + result = scipy.signal.periodogram( + x=default.y, + fs=fs, + window=window, + nfft=nfft, + detrend=detrend, + return_onesided=return_onesided, + scaling=scaling, + axis=axis, ) + + return_list = ["f", "Pxx"] + if isinstance(result, tuple): + res_dict = {} + num = min(len(result), len(return_list)) + for i in range(num): + res_dict[return_list[i]] = result[i] + result = res_dict[select_return] + else: + result = result._asdict() + result = result[select_return] + + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + + return result diff --git a/docs/nodes/SCIPY/SIGNAL/QUADRATIC/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/SIGNAL/QUADRATIC/a1-[autogen]/python_code.txt index 03f23417a..5ba815bd6 100644 --- a/docs/nodes/SCIPY/SIGNAL/QUADRATIC/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/SIGNAL/QUADRATIC/a1-[autogen]/python_code.txt @@ -12,11 +12,13 @@ def QUADRATIC( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.signal.quadratic( - x=default.y, - ), + result = scipy.signal.quadratic( + x=default.y, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/SIGNAL/SAVGOL_FILTER/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/SIGNAL/SAVGOL_FILTER/a1-[autogen]/python_code.txt index 232e9220e..3e82301b0 100644 --- a/docs/nodes/SCIPY/SIGNAL/SAVGOL_FILTER/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/SIGNAL/SAVGOL_FILTER/a1-[autogen]/python_code.txt @@ -9,8 +9,8 @@ import scipy.signal @flojoy(node_type="default") def SAVGOL_FILTER( default: OrderedPair | Matrix, - window_length: int, - polyorder: int, + window_length: int = 2, + polyorder: int = 1, deriv: int = 0, delta: float = 1.0, axis: int = -1, @@ -19,18 +19,20 @@ def SAVGOL_FILTER( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.signal.savgol_filter( - x=default.y, - window_length=window_length, - polyorder=polyorder, - deriv=deriv, - delta=delta, - axis=axis, - mode=mode, - cval=cval, - ), + result = scipy.signal.savgol_filter( + x=default.y, + window_length=window_length, + polyorder=polyorder, + deriv=deriv, + delta=delta, + axis=axis, + mode=mode, + cval=cval, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/SIGNAL/STFT/a1-[autogen]/docstring.txt b/docs/nodes/SCIPY/SIGNAL/STFT/a1-[autogen]/docstring.txt index f9cc88c12..1e2a19d9b 100644 --- a/docs/nodes/SCIPY/SIGNAL/STFT/a1-[autogen]/docstring.txt +++ b/docs/nodes/SCIPY/SIGNAL/STFT/a1-[autogen]/docstring.txt @@ -1,68 +1,74 @@ +The STFT node is based on a numpy or scipy function. + The description of that function is as follows: - Compute the Short Time Fourier Transform (STFT). + Compute the Short Time Fourier Transform (STFT). - STFTs can be used as a way of quantifying the change of a - nonstationary signal's frequency and phase content over time. + STFTs can be used as a way of quantifying the change of a + nonstationary signal's frequency and phase content over time. --.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -The parameters of the function in this Flojoy wrapper are given below. --.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. + Parameters + ---------- + select_return : This function has returns multiple objects: + ['f', 't', 'Zxx']. Select the desired one to return. + See the respective function docs for descriptors. + x : array_like + Time series of measurement values + fs : float, optional + Sampling frequency of the `x` time series. Defaults to 1.0. + window : str or tuple or array_like, optional + Desired window to use. If `window` is a string or tuple, it is + passed to `get_window` to generate the window values, which are + DFT-even by default. See `get_window` for a list of windows and + required parameters. If `window` is array_like it will be used + directly as the window and its length must be nperseg. Defaults + to a Hann window. + nperseg : int, optional + Length of each segment. Defaults to 256. + noverlap : int, optional + Number of points to overlap between segments. If `None`, + ``noverlap = nperseg // 2``. Defaults to `None`. When + specified, the COLA constraint must be met (see Notes below). + nfft : int, optional + Length of the FFT used, if a zero padded FFT is desired. If + `None`, the FFT length is `nperseg`. Defaults to `None`. + detrend : str or function or `False`, optional + Specifies how to detrend each segment. If `detrend` is a + string, it is passed as the `type` argument to the `detrend` + function. If it is a function, it takes a segment and returns a + detrended segment. If `detrend` is `False`, no detrending is + done. Defaults to `False`. + return_onesided : bool, optional + If `True`, return a one-sided spectrum for real data. If + `False` return a two-sided spectrum. Defaults to `True`, but for + complex data, a two-sided spectrum is always returned. + boundary : str or None, optional + Specifies whether the input signal is extended at both ends, and + how to generate the new values, in order to center the first + windowed segment on the first input point. This has the benefit + of enabling reconstruction of the first input point when the + employed window function starts at zero. Valid options are + ``['even', 'odd', 'constant', 'zeros', None]``. Defaults to + 'zeros', for zero padding extension. I.e. ``[1, 2, 3, 4]`` is + extended to ``[0, 1, 2, 3, 4, 0]`` for ``nperseg=3``. + padded : bool, optional + Specifies whether the input signal is zero-padded at the end to + make the signal fit exactly into an integer number of window + segments, so that all of the signal is included in the output. + Defaults to `True`. Padding occurs after boundary extension, if + `boundary` is not `None`, and `padded` is `True`, as is the + default. + axis : int, optional + Axis along which the STFT is computed; the default is over the + last axis (i.e. ``axis=-1``). + scaling: {'spectrum', 'psd'} + The default 'spectrum' scaling allows each frequency line of `Zxx` to + be interpreted as a magnitude spectrum. The 'psd' option scales each + line to a power spectral density - it allows to calculate the signal's + energy by numerically integrating over ``abs(Zxx)**2``. -Parameters ----------- -x : array_like - Time series of measurement values -fs : float, optional - Sampling frequency of the `x` time series. Defaults to 1.0. -window : str or tuple or array_like, optional - Desired window to use. If `window` is a string or tuple, it is - passed to `get_window` to generate the window values, which are - DFT-even by default. See `get_window` for a list of windows and - required parameters. If `window` is array_like it will be used - directly as the window and its length must be nperseg. Defaults - to a Hann window. -nperseg : int, optional - Length of each segment. Defaults to 256. -noverlap : int, optional - Number of points to overlap between segments. If `None`, - ``noverlap = nperseg // 2``. Defaults to `None`. When - specified, the COLA constraint must be met (see Notes below). -nfft : int, optional - Length of the FFT used, if a zero padded FFT is desired. If - `None`, the FFT length is `nperseg`. Defaults to `None`. -detrend : str or function or `False`, optional - Specifies how to detrend each segment. If `detrend` is a - string, it is passed as the `type` argument to the `detrend` - function. If it is a function, it takes a segment and returns a - detrended segment. If `detrend` is `False`, no detrending is - done. Defaults to `False`. -return_onesided : bool, optional - If `True`, return a one-sided spectrum for real data. If - `False` return a two-sided spectrum. Defaults to `True`, but for - complex data, a two-sided spectrum is always returned. -boundary : str or None, optional - Specifies whether the input signal is extended at both ends, and - how to generate the new values, in order to center the first - windowed segment on the first input point. This has the benefit - of enabling reconstruction of the first input point when the - employed window function starts at zero. Valid options are - ``['even', 'odd', 'constant', 'zeros', None]``. Defaults to - 'zeros', for zero padding extension. I.e. ``[1, 2, 3, 4]`` is - extended to ``[0, 1, 2, 3, 4, 0]`` for ``nperseg=3``. -padded : bool, optional - Specifies whether the input signal is zero-padded at the end to - make the signal fit exactly into an integer number of window - segments, so that all of the signal is included in the output. - Defaults to `True`. Padding occurs after boundary extension, if - `boundary` is not `None`, and `padded` is `True`, as is the - default. -axis : int, optional - Axis along which the STFT is computed; the default is over the - last axis (i.e. ``axis=-1``). -scaling: {'spectrum', 'psd'} - The default 'spectrum' scaling allows each frequency line of `Zxx` to - be interpreted as a magnitude spectrum. The 'psd' option scales each - line to a power spectral density - it allows to calculate the signal's - energy by numerically integrating over ``abs(Zxx)**2``. + .. versionadded:: 1.9.0 -.. versionadded:: 1.9.0 + Returns + ---------- + DataContainer: + type 'ordered pair', 'scalar', or 'matrix' diff --git a/docs/nodes/SCIPY/SIGNAL/STFT/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/SIGNAL/STFT/a1-[autogen]/python_code.txt index cfda81024..cdf50741d 100644 --- a/docs/nodes/SCIPY/SIGNAL/STFT/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/SIGNAL/STFT/a1-[autogen]/python_code.txt @@ -1,28 +1,58 @@ -from flojoy import DataContainer, flojoy +from flojoy import OrderedPair, flojoy, Matrix, Scalar +import numpy as np +from collections import namedtuple +from typing import Literal + import scipy.signal -@flojoy -def STFT(dc, params): +@flojoy(node_type="default") +def STFT( + default: OrderedPair | Matrix, + fs: float = 1.0, + window: str = "hann", + nperseg: int = 2, + noverlap: int = 1, + nfft: int = 2, + detrend: bool = False, + return_onesided: bool = True, + boundary: str = "zeros", + padded: bool = True, + axis: int = -1, + scaling: str = "spectrum", + select_return: Literal["f", "t", "Zxx"] = "f", +) -> OrderedPair | Matrix | Scalar: - return DataContainer( - x=dc[0].y, - y=scipy.signal.stft( - x=dc[0].y, - fs=(float(params["fs"]) if params["fs"] != "" else None), - window=(str(params["window"]) if params["window"] != "" else None), - nperseg=(int(params["nperseg"]) if params["nperseg"] != "" else None), - noverlap=(int(params["noverlap"]) if params["noverlap"] != "" else None), - nfft=(int(params["nfft"]) if params["nfft"] != "" else None), - detrend=(bool(params["detrend"]) if params["detrend"] != "" else None), - return_onesided=( - bool(params["return_onesided"]) - if params["return_onesided"] != "" - else None - ), - boundary=(str(params["boundary"]) if params["boundary"] != "" else None), - padded=(bool(params["padded"]) if params["padded"] != "" else None), - axis=(int(params["axis"]) if params["axis"] != "" else None), - scaling=(str(params["scaling"]) if params["scaling"] != "" else None), - ), + + result = scipy.signal.stft( + x=default.y, + fs=fs, + window=window, + nperseg=nperseg, + noverlap=noverlap, + nfft=nfft, + detrend=detrend, + return_onesided=return_onesided, + boundary=boundary, + padded=padded, + axis=axis, + scaling=scaling, ) + + return_list = ["f", "t", "Zxx"] + if isinstance(result, tuple): + res_dict = {} + num = min(len(result), len(return_list)) + for i in range(num): + res_dict[return_list[i]] = result[i] + result = res_dict[select_return] + else: + result = result._asdict() + result = result[select_return] + + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + + return result diff --git a/docs/nodes/SCIPY/SIGNAL/WELCH/a1-[autogen]/docstring.txt b/docs/nodes/SCIPY/SIGNAL/WELCH/a1-[autogen]/docstring.txt index 97f1a012c..11f3c47d4 100644 --- a/docs/nodes/SCIPY/SIGNAL/WELCH/a1-[autogen]/docstring.txt +++ b/docs/nodes/SCIPY/SIGNAL/WELCH/a1-[autogen]/docstring.txt @@ -1,59 +1,65 @@ +The WELCH node is based on a numpy or scipy function. + The description of that function is as follows: - Estimate power spectral density using Welch's method. + Estimate power spectral density using Welch's method. - Welch's method [1]_ computes an estimate of the power spectral - density by dividing the data into overlapping segments, computing a - modified periodogram for each segment and averaging the - periodograms. + Welch's method [1]_ computes an estimate of the power spectral + density by dividing the data into overlapping segments, computing a + modified periodogram for each segment and averaging the + periodograms. --.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -The parameters of the function in this Flojoy wrapper are given below. --.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. + Parameters + ---------- + select_return : This function has returns multiple objects: + ['f', 'Pxx']. Select the desired one to return. + See the respective function docs for descriptors. + x : array_like + Time series of measurement values + fs : float, optional + Sampling frequency of the `x` time series. Defaults to 1.0. + window : str or tuple or array_like, optional + Desired window to use. If `window` is a string or tuple, it is + passed to `get_window` to generate the window values, which are + DFT-even by default. See `get_window` for a list of windows and + required parameters. If `window` is array_like it will be used + directly as the window and its length must be nperseg. Defaults + to a Hann window. + nperseg : int, optional + Length of each segment. Defaults to None, but if window is str or + tuple, is set to 256, and if window is array_like, is set to the + length of the window. + noverlap : int, optional + Number of points to overlap between segments. If `None`, + ``noverlap = nperseg // 2``. Defaults to `None`. + nfft : int, optional + Length of the FFT used, if a zero padded FFT is desired. If + `None`, the FFT length is `nperseg`. Defaults to `None`. + detrend : str or function or `False`, optional + Specifies how to detrend each segment. If `detrend` is a + string, it is passed as the `type` argument to the `detrend` + function. If it is a function, it takes a segment and returns a + detrended segment. If `detrend` is `False`, no detrending is + done. Defaults to 'constant'. + return_onesided : bool, optional + If `True`, return a one-sided spectrum for real data. If + `False` return a two-sided spectrum. Defaults to `True`, but for + complex data, a two-sided spectrum is always returned. + scaling : { 'density', 'spectrum' }, optional + Selects between computing the power spectral density ('density') + where `Pxx` has units of V**2/Hz and computing the power + spectrum ('spectrum') where `Pxx` has units of V**2, if `x` + is measured in V and `fs` is measured in Hz. Defaults to + 'density' + axis : int, optional + Axis along which the periodogram is computed; the default is + over the last axis (i.e. ``axis=-1``). + average : { 'mean', 'median' }, optional + Method to use when averaging periodograms. Defaults to 'mean'. -Parameters ----------- -x : array_like - Time series of measurement values -fs : float, optional - Sampling frequency of the `x` time series. Defaults to 1.0. -window : str or tuple or array_like, optional - Desired window to use. If `window` is a string or tuple, it is - passed to `get_window` to generate the window values, which are - DFT-even by default. See `get_window` for a list of windows and - required parameters. If `window` is array_like it will be used - directly as the window and its length must be nperseg. Defaults - to a Hann window. -nperseg : int, optional - Length of each segment. Defaults to None, but if window is str or - tuple, is set to 256, and if window is array_like, is set to the - length of the window. -noverlap : int, optional - Number of points to overlap between segments. If `None`, - ``noverlap = nperseg // 2``. Defaults to `None`. -nfft : int, optional - Length of the FFT used, if a zero padded FFT is desired. If - `None`, the FFT length is `nperseg`. Defaults to `None`. -detrend : str or function or `False`, optional - Specifies how to detrend each segment. If `detrend` is a - string, it is passed as the `type` argument to the `detrend` - function. If it is a function, it takes a segment and returns a - detrended segment. If `detrend` is `False`, no detrending is - done. Defaults to 'constant'. -return_onesided : bool, optional - If `True`, return a one-sided spectrum for real data. If - `False` return a two-sided spectrum. Defaults to `True`, but for - complex data, a two-sided spectrum is always returned. -scaling : { 'density', 'spectrum' }, optional - Selects between computing the power spectral density ('density') - where `Pxx` has units of V**2/Hz and computing the power - spectrum ('spectrum') where `Pxx` has units of V**2, if `x` - is measured in V and `fs` is measured in Hz. Defaults to - 'density' -axis : int, optional - Axis along which the periodogram is computed; the default is - over the last axis (i.e. ``axis=-1``). -average : { 'mean', 'median' }, optional - Method to use when averaging periodograms. Defaults to 'mean'. + .. versionadded:: 1.2.0 -.. versionadded:: 1.2.0 + Returns + ---------- + DataContainer: + type 'ordered pair', 'scalar', or 'matrix' diff --git a/docs/nodes/SCIPY/SIGNAL/WELCH/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/SIGNAL/WELCH/a1-[autogen]/python_code.txt index 78378b4af..909a68df8 100644 --- a/docs/nodes/SCIPY/SIGNAL/WELCH/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/SIGNAL/WELCH/a1-[autogen]/python_code.txt @@ -1,27 +1,56 @@ -from flojoy import DataContainer, flojoy +from flojoy import OrderedPair, flojoy, Matrix, Scalar +import numpy as np +from collections import namedtuple +from typing import Literal + import scipy.signal -@flojoy -def WELCH(dc, params): +@flojoy(node_type="default") +def WELCH( + default: OrderedPair | Matrix, + fs: float = 1.0, + window: str = "hann", + nperseg: int = 2, + noverlap: int = 1, + nfft: int = 2, + detrend: str = "constant", + return_onesided: bool = True, + scaling: str = "density", + axis: int = -1, + average: str = "mean", + select_return: Literal["f", "Pxx"] = "f", +) -> OrderedPair | Matrix | Scalar: - return DataContainer( - x=dc[0].y, - y=scipy.signal.welch( - x=dc[0].y, - fs=(float(params["fs"]) if params["fs"] != "" else None), - window=(str(params["window"]) if params["window"] != "" else None), - nperseg=(int(params["nperseg"]) if params["nperseg"] != "" else None), - noverlap=(int(params["noverlap"]) if params["noverlap"] != "" else None), - nfft=(int(params["nfft"]) if params["nfft"] != "" else None), - detrend=(str(params["detrend"]) if params["detrend"] != "" else None), - return_onesided=( - bool(params["return_onesided"]) - if params["return_onesided"] != "" - else None - ), - scaling=(str(params["scaling"]) if params["scaling"] != "" else None), - axis=(int(params["axis"]) if params["axis"] != "" else None), - average=(str(params["average"]) if params["average"] != "" else None), - ), + + result = scipy.signal.welch( + x=default.y, + fs=fs, + window=window, + nperseg=nperseg, + noverlap=noverlap, + nfft=nfft, + detrend=detrend, + return_onesided=return_onesided, + scaling=scaling, + axis=axis, + average=average, ) + + return_list = ["f", "Pxx"] + if isinstance(result, tuple): + res_dict = {} + num = min(len(result), len(return_list)) + for i in range(num): + res_dict[return_list[i]] = result[i] + result = res_dict[select_return] + else: + result = result._asdict() + result = result[select_return] + + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + + return result diff --git a/docs/nodes/SCIPY/STATS/ANDERSON/a1-[autogen]/docstring.txt b/docs/nodes/SCIPY/STATS/ANDERSON/a1-[autogen]/docstring.txt index 782c1a6b8..0ac058bc4 100644 --- a/docs/nodes/SCIPY/STATS/ANDERSON/a1-[autogen]/docstring.txt +++ b/docs/nodes/SCIPY/STATS/ANDERSON/a1-[autogen]/docstring.txt @@ -12,7 +12,7 @@ The ANDERSON node is based on a numpy or scipy function. Parameters ---------- - select_return : This function has returns multiple Objects: + select_return : This function has returns multiple objects: ['statistic', 'critical_values', 'significance_level']. Select the desired one to return. See the respective function docs for descriptors. x : array_like diff --git a/docs/nodes/SCIPY/STATS/ANDERSON/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/ANDERSON/a1-[autogen]/python_code.txt index 27cf5a11e..817e368bc 100644 --- a/docs/nodes/SCIPY/STATS/ANDERSON/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/ANDERSON/a1-[autogen]/python_code.txt @@ -16,12 +16,25 @@ def ANDERSON( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.anderson( - x=default.y, - dist=dist, - ), + result = scipy.stats.anderson( + x=default.y, + dist=dist, ) + return_list = ["statistic", "critical_values", "significance_level"] + if isinstance(result, tuple): + res_dict = {} + num = min(len(result), len(return_list)) + for i in range(num): + res_dict[return_list[i]] = result[i] + result = res_dict[select_return] + else: + result = result._asdict() + result = result[select_return] + + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/BINOM_TEST/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/BINOM_TEST/a1-[autogen]/python_code.txt index 6bb33f6f2..69dee07b8 100644 --- a/docs/nodes/SCIPY/STATS/BINOM_TEST/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/BINOM_TEST/a1-[autogen]/python_code.txt @@ -9,20 +9,22 @@ import scipy.stats @flojoy(node_type="default") def BINOM_TEST( default: OrderedPair | Matrix, - n: int, + n: int = 2, p: float = 0.5, alternative: str = "two-sided", ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.binom_test( - x=default.y, - n=n, - p=p, - alternative=alternative, - ), + result = scipy.stats.binom_test( + x=default.y, + n=n, + p=p, + alternative=alternative, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/DESCRIBE/a1-[autogen]/docstring.txt b/docs/nodes/SCIPY/STATS/DESCRIBE/a1-[autogen]/docstring.txt index 37f5656aa..8cd2d74df 100644 --- a/docs/nodes/SCIPY/STATS/DESCRIBE/a1-[autogen]/docstring.txt +++ b/docs/nodes/SCIPY/STATS/DESCRIBE/a1-[autogen]/docstring.txt @@ -5,7 +5,7 @@ The DESCRIBE node is based on a numpy or scipy function. Parameters ---------- - select_return : This function has returns multiple Objects: + select_return : This function has returns multiple objects: ['nobs', 'mean', 'variance', 'skewness', 'kurtosis']. Select the desired one to return. See the respective function docs for descriptors. a : array_like diff --git a/docs/nodes/SCIPY/STATS/DESCRIBE/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/DESCRIBE/a1-[autogen]/python_code.txt index 5618462d7..9b09ce0c3 100644 --- a/docs/nodes/SCIPY/STATS/DESCRIBE/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/DESCRIBE/a1-[autogen]/python_code.txt @@ -17,15 +17,28 @@ def DESCRIBE( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.describe( - a=default.y, - axis=axis, - ddof=ddof, - bias=bias, - nan_policy=nan_policy, - ), + result = scipy.stats.describe( + a=default.y, + axis=axis, + ddof=ddof, + bias=bias, + nan_policy=nan_policy, ) + return_list = ["nobs", "mean", "variance", "skewness", "kurtosis"] + if isinstance(result, tuple): + res_dict = {} + num = min(len(result), len(return_list)) + for i in range(num): + res_dict[return_list[i]] = result[i] + result = res_dict[select_return] + else: + result = result._asdict() + result = result[select_return] + + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/GSTD/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/GSTD/a1-[autogen]/python_code.txt index 1d24cdc94..fefdba02b 100644 --- a/docs/nodes/SCIPY/STATS/GSTD/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/GSTD/a1-[autogen]/python_code.txt @@ -14,13 +14,15 @@ def GSTD( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.gstd( - a=default.y, - axis=axis, - ddof=ddof, - ), + result = scipy.stats.gstd( + a=default.y, + axis=axis, + ddof=ddof, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/GZSCORE/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/GZSCORE/a1-[autogen]/python_code.txt index 7c3a7e6d9..90c7d0672 100644 --- a/docs/nodes/SCIPY/STATS/GZSCORE/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/GZSCORE/a1-[autogen]/python_code.txt @@ -15,14 +15,16 @@ def GZSCORE( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.gzscore( - a=default.y, - axis=axis, - ddof=ddof, - nan_policy=nan_policy, - ), + result = scipy.stats.gzscore( + a=default.y, + axis=axis, + ddof=ddof, + nan_policy=nan_policy, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/JARQUE_BERA/a1-[autogen]/docstring.txt b/docs/nodes/SCIPY/STATS/JARQUE_BERA/a1-[autogen]/docstring.txt index 72f3de469..f5e3875a9 100644 --- a/docs/nodes/SCIPY/STATS/JARQUE_BERA/a1-[autogen]/docstring.txt +++ b/docs/nodes/SCIPY/STATS/JARQUE_BERA/a1-[autogen]/docstring.txt @@ -12,7 +12,7 @@ The JARQUE_BERA node is based on a numpy or scipy function. Parameters ---------- - select_return : This function has returns multiple Objects: + select_return : This function has returns multiple objects: ['jb_value', 'p']. Select the desired one to return. See the respective function docs for descriptors. x : array_like diff --git a/docs/nodes/SCIPY/STATS/JARQUE_BERA/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/JARQUE_BERA/a1-[autogen]/python_code.txt index 2f4deb7b8..7eacfd6da 100644 --- a/docs/nodes/SCIPY/STATS/JARQUE_BERA/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/JARQUE_BERA/a1-[autogen]/python_code.txt @@ -13,11 +13,24 @@ def JARQUE_BERA( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.jarque_bera( - x=default.y, - ), + result = scipy.stats.jarque_bera( + x=default.y, ) + return_list = ["jb_value", "p"] + if isinstance(result, tuple): + res_dict = {} + num = min(len(result), len(return_list)) + for i in range(num): + res_dict[return_list[i]] = result[i] + result = res_dict[select_return] + else: + result = result._asdict() + result = result[select_return] + + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/KURTOSIS/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/KURTOSIS/a1-[autogen]/python_code.txt index e704c39eb..73b1393d2 100644 --- a/docs/nodes/SCIPY/STATS/KURTOSIS/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/KURTOSIS/a1-[autogen]/python_code.txt @@ -17,16 +17,18 @@ def KURTOSIS( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.kurtosis( - a=default.y, - axis=axis, - fisher=fisher, - bias=bias, - nan_policy=nan_policy, - keepdims=keepdims, - ), + result = scipy.stats.kurtosis( + a=default.y, + axis=axis, + fisher=fisher, + bias=bias, + nan_policy=nan_policy, + keepdims=keepdims, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/KURTOSISTEST/a1-[autogen]/docstring.txt b/docs/nodes/SCIPY/STATS/KURTOSISTEST/a1-[autogen]/docstring.txt index bec0b5e33..42ac1182c 100644 --- a/docs/nodes/SCIPY/STATS/KURTOSISTEST/a1-[autogen]/docstring.txt +++ b/docs/nodes/SCIPY/STATS/KURTOSISTEST/a1-[autogen]/docstring.txt @@ -9,7 +9,7 @@ The KURTOSISTEST node is based on a numpy or scipy function. Parameters ---------- - select_return : This function has returns multiple Objects: + select_return : This function has returns multiple objects: ['statistic', 'pvalue']. Select the desired one to return. See the respective function docs for descriptors. a : array diff --git a/docs/nodes/SCIPY/STATS/KURTOSISTEST/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/KURTOSISTEST/a1-[autogen]/python_code.txt index e36fc6ec4..cec62e325 100644 --- a/docs/nodes/SCIPY/STATS/KURTOSISTEST/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/KURTOSISTEST/a1-[autogen]/python_code.txt @@ -16,14 +16,27 @@ def KURTOSISTEST( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.kurtosistest( - a=default.y, - axis=axis, - nan_policy=nan_policy, - alternative=alternative, - ), + result = scipy.stats.kurtosistest( + a=default.y, + axis=axis, + nan_policy=nan_policy, + alternative=alternative, ) + return_list = ["statistic", "pvalue"] + if isinstance(result, tuple): + res_dict = {} + num = min(len(result), len(return_list)) + for i in range(num): + res_dict[return_list[i]] = result[i] + result = res_dict[select_return] + else: + result = result._asdict() + result = result[select_return] + + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/MOMENT/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/MOMENT/a1-[autogen]/python_code.txt index 5367655e6..f50e0a700 100644 --- a/docs/nodes/SCIPY/STATS/MOMENT/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/MOMENT/a1-[autogen]/python_code.txt @@ -16,15 +16,17 @@ def MOMENT( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.moment( - a=default.y, - moment=moment, - axis=axis, - nan_policy=nan_policy, - keepdims=keepdims, - ), + result = scipy.stats.moment( + a=default.y, + moment=moment, + axis=axis, + nan_policy=nan_policy, + keepdims=keepdims, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/NORMALTEST/a1-[autogen]/docstring.txt b/docs/nodes/SCIPY/STATS/NORMALTEST/a1-[autogen]/docstring.txt index 0334155be..54050f63f 100644 --- a/docs/nodes/SCIPY/STATS/NORMALTEST/a1-[autogen]/docstring.txt +++ b/docs/nodes/SCIPY/STATS/NORMALTEST/a1-[autogen]/docstring.txt @@ -10,7 +10,7 @@ The NORMALTEST node is based on a numpy or scipy function. Parameters ---------- - select_return : This function has returns multiple Objects: + select_return : This function has returns multiple objects: ['statistic', 'pvalue']. Select the desired one to return. See the respective function docs for descriptors. a : array_like diff --git a/docs/nodes/SCIPY/STATS/NORMALTEST/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/NORMALTEST/a1-[autogen]/python_code.txt index ccd61e548..3fa79ebcd 100644 --- a/docs/nodes/SCIPY/STATS/NORMALTEST/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/NORMALTEST/a1-[autogen]/python_code.txt @@ -15,13 +15,26 @@ def NORMALTEST( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.normaltest( - a=default.y, - axis=axis, - nan_policy=nan_policy, - ), + result = scipy.stats.normaltest( + a=default.y, + axis=axis, + nan_policy=nan_policy, ) + return_list = ["statistic", "pvalue"] + if isinstance(result, tuple): + res_dict = {} + num = min(len(result), len(return_list)) + for i in range(num): + res_dict[return_list[i]] = result[i] + result = res_dict[select_return] + else: + result = result._asdict() + result = result[select_return] + + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/SEM/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/SEM/a1-[autogen]/python_code.txt index 93402c122..5b6a1c352 100644 --- a/docs/nodes/SCIPY/STATS/SEM/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/SEM/a1-[autogen]/python_code.txt @@ -15,14 +15,16 @@ def SEM( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.sem( - a=default.y, - axis=axis, - ddof=ddof, - nan_policy=nan_policy, - ), + result = scipy.stats.sem( + a=default.y, + axis=axis, + ddof=ddof, + nan_policy=nan_policy, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/SHAPIRO/a1-[autogen]/docstring.txt b/docs/nodes/SCIPY/STATS/SHAPIRO/a1-[autogen]/docstring.txt index dda6cbca5..9af4f50c2 100644 --- a/docs/nodes/SCIPY/STATS/SHAPIRO/a1-[autogen]/docstring.txt +++ b/docs/nodes/SCIPY/STATS/SHAPIRO/a1-[autogen]/docstring.txt @@ -8,7 +8,7 @@ The SHAPIRO node is based on a numpy or scipy function. Parameters ---------- - select_return : This function has returns multiple Objects: + select_return : This function has returns multiple objects: ['statistic', 'p-value']. Select the desired one to return. See the respective function docs for descriptors. x : array_like diff --git a/docs/nodes/SCIPY/STATS/SHAPIRO/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/SHAPIRO/a1-[autogen]/python_code.txt index 27d1b77fe..bbc747923 100644 --- a/docs/nodes/SCIPY/STATS/SHAPIRO/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/SHAPIRO/a1-[autogen]/python_code.txt @@ -13,11 +13,24 @@ def SHAPIRO( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.shapiro( - x=default.y, - ), + result = scipy.stats.shapiro( + x=default.y, ) + return_list = ["statistic", "p-value"] + if isinstance(result, tuple): + res_dict = {} + num = min(len(result), len(return_list)) + for i in range(num): + res_dict[return_list[i]] = result[i] + result = res_dict[select_return] + else: + result = result._asdict() + result = result[select_return] + + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/SIGMACLIP/a1-[autogen]/docstring.txt b/docs/nodes/SCIPY/STATS/SIGMACLIP/a1-[autogen]/docstring.txt index 2d8df6c7d..613f1d9f5 100644 --- a/docs/nodes/SCIPY/STATS/SIGMACLIP/a1-[autogen]/docstring.txt +++ b/docs/nodes/SCIPY/STATS/SIGMACLIP/a1-[autogen]/docstring.txt @@ -15,7 +15,7 @@ The SIGMACLIP node is based on a numpy or scipy function. Parameters ---------- - select_return : This function has returns multiple Objects: + select_return : This function has returns multiple objects: ['clipped', 'lower', 'upper']. Select the desired one to return. See the respective function docs for descriptors. a : array_like diff --git a/docs/nodes/SCIPY/STATS/SIGMACLIP/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/SIGMACLIP/a1-[autogen]/python_code.txt index 0dff3c777..7dd27ee77 100644 --- a/docs/nodes/SCIPY/STATS/SIGMACLIP/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/SIGMACLIP/a1-[autogen]/python_code.txt @@ -15,13 +15,26 @@ def SIGMACLIP( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.sigmaclip( - a=default.y, - low=low, - high=high, - ), + result = scipy.stats.sigmaclip( + a=default.y, + low=low, + high=high, ) + return_list = ["clipped", "lower", "upper"] + if isinstance(result, tuple): + res_dict = {} + num = min(len(result), len(return_list)) + for i in range(num): + res_dict[return_list[i]] = result[i] + result = res_dict[select_return] + else: + result = result._asdict() + result = result[select_return] + + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/SKEW/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/SKEW/a1-[autogen]/python_code.txt index 5243aca13..017ddc132 100644 --- a/docs/nodes/SCIPY/STATS/SKEW/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/SKEW/a1-[autogen]/python_code.txt @@ -16,15 +16,17 @@ def SKEW( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.skew( - a=default.y, - axis=axis, - bias=bias, - nan_policy=nan_policy, - keepdims=keepdims, - ), + result = scipy.stats.skew( + a=default.y, + axis=axis, + bias=bias, + nan_policy=nan_policy, + keepdims=keepdims, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/SKEWTEST/a1-[autogen]/docstring.txt b/docs/nodes/SCIPY/STATS/SKEWTEST/a1-[autogen]/docstring.txt index ad93b48fa..97500364f 100644 --- a/docs/nodes/SCIPY/STATS/SKEWTEST/a1-[autogen]/docstring.txt +++ b/docs/nodes/SCIPY/STATS/SKEWTEST/a1-[autogen]/docstring.txt @@ -9,7 +9,7 @@ The SKEWTEST node is based on a numpy or scipy function. Parameters ---------- - select_return : This function has returns multiple Objects: + select_return : This function has returns multiple objects: ['statistic', 'pvalue']. Select the desired one to return. See the respective function docs for descriptors. a : array diff --git a/docs/nodes/SCIPY/STATS/SKEWTEST/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/SKEWTEST/a1-[autogen]/python_code.txt index c21047769..e1e27d2bc 100644 --- a/docs/nodes/SCIPY/STATS/SKEWTEST/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/SKEWTEST/a1-[autogen]/python_code.txt @@ -16,14 +16,27 @@ def SKEWTEST( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.skewtest( - a=default.y, - axis=axis, - nan_policy=nan_policy, - alternative=alternative, - ), + result = scipy.stats.skewtest( + a=default.y, + axis=axis, + nan_policy=nan_policy, + alternative=alternative, ) + return_list = ["statistic", "pvalue"] + if isinstance(result, tuple): + res_dict = {} + num = min(len(result), len(return_list)) + for i in range(num): + res_dict[return_list[i]] = result[i] + result = res_dict[select_return] + else: + result = result._asdict() + result = result[select_return] + + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/TMAX/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/TMAX/a1-[autogen]/python_code.txt index 00cfc836a..a719a3fdc 100644 --- a/docs/nodes/SCIPY/STATS/TMAX/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/TMAX/a1-[autogen]/python_code.txt @@ -9,22 +9,24 @@ import scipy.stats @flojoy(node_type="default") def TMAX( default: OrderedPair | Matrix, - upperlimit: None or float, + upperlimit: float = 0.1, axis: int = 0, inclusive: bool = True, nan_policy: str = "propagate", ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.tmax( - a=default.y, - upperlimit=upperlimit, - axis=axis, - inclusive=inclusive, - nan_policy=nan_policy, - ), + result = scipy.stats.tmax( + a=default.y, + upperlimit=upperlimit, + axis=axis, + inclusive=inclusive, + nan_policy=nan_policy, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/TMIN/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/TMIN/a1-[autogen]/python_code.txt index d15275a1b..0dc2ef9a9 100644 --- a/docs/nodes/SCIPY/STATS/TMIN/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/TMIN/a1-[autogen]/python_code.txt @@ -9,22 +9,24 @@ import scipy.stats @flojoy(node_type="default") def TMIN( default: OrderedPair | Matrix, - lowerlimit: None or float, + lowerlimit: float = 0.1, axis: int = 0, inclusive: bool = True, nan_policy: str = "propagate", ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.tmin( - a=default.y, - lowerlimit=lowerlimit, - axis=axis, - inclusive=inclusive, - nan_policy=nan_policy, - ), + result = scipy.stats.tmin( + a=default.y, + lowerlimit=lowerlimit, + axis=axis, + inclusive=inclusive, + nan_policy=nan_policy, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/TRIM1/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/TRIM1/a1-[autogen]/python_code.txt index 39ec110db..260c6b700 100644 --- a/docs/nodes/SCIPY/STATS/TRIM1/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/TRIM1/a1-[autogen]/python_code.txt @@ -9,20 +9,22 @@ import scipy.stats @flojoy(node_type="default") def TRIM1( default: OrderedPair | Matrix, - proportiontocut: float, + proportiontocut: float = 0.1, tail: str = "right", axis: int = 0, ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.trim1( - a=default.y, - proportiontocut=proportiontocut, - tail=tail, - axis=axis, - ), + result = scipy.stats.trim1( + a=default.y, + proportiontocut=proportiontocut, + tail=tail, + axis=axis, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/TRIMBOTH/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/TRIMBOTH/a1-[autogen]/python_code.txt index 9e524617b..a1196e0ba 100644 --- a/docs/nodes/SCIPY/STATS/TRIMBOTH/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/TRIMBOTH/a1-[autogen]/python_code.txt @@ -9,18 +9,20 @@ import scipy.stats @flojoy(node_type="default") def TRIMBOTH( default: OrderedPair | Matrix, - proportiontocut: float, + proportiontocut: float = 0.1, axis: int = 0, ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.trimboth( - a=default.y, - proportiontocut=proportiontocut, - axis=axis, - ), + result = scipy.stats.trimboth( + a=default.y, + proportiontocut=proportiontocut, + axis=axis, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/TRIM_MEAN/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/TRIM_MEAN/a1-[autogen]/python_code.txt index 8dc8865a8..440cf513a 100644 --- a/docs/nodes/SCIPY/STATS/TRIM_MEAN/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/TRIM_MEAN/a1-[autogen]/python_code.txt @@ -9,18 +9,20 @@ import scipy.stats @flojoy(node_type="default") def TRIM_MEAN( default: OrderedPair | Matrix, - proportiontocut: float, + proportiontocut: float = 0.1, axis: int = 0, ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.trim_mean( - a=default.y, - proportiontocut=proportiontocut, - axis=axis, - ), + result = scipy.stats.trim_mean( + a=default.y, + proportiontocut=proportiontocut, + axis=axis, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/TTEST_1SAMP/a1-[autogen]/docstring.txt b/docs/nodes/SCIPY/STATS/TTEST_1SAMP/a1-[autogen]/docstring.txt index b9b55de02..c9f58152c 100644 --- a/docs/nodes/SCIPY/STATS/TTEST_1SAMP/a1-[autogen]/docstring.txt +++ b/docs/nodes/SCIPY/STATS/TTEST_1SAMP/a1-[autogen]/docstring.txt @@ -9,7 +9,7 @@ The TTEST_1SAMP node is based on a numpy or scipy function. Parameters ---------- - select_return : This function has returns multiple Objects: + select_return : This function has returns multiple objects: ['statistic', 'pvalue']. Select the desired one to return. See the respective function docs for descriptors. a : array_like diff --git a/docs/nodes/SCIPY/STATS/TTEST_1SAMP/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/TTEST_1SAMP/a1-[autogen]/python_code.txt index 87040c650..38222c953 100644 --- a/docs/nodes/SCIPY/STATS/TTEST_1SAMP/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/TTEST_1SAMP/a1-[autogen]/python_code.txt @@ -9,7 +9,7 @@ import scipy.stats @flojoy(node_type="default") def TTEST_1SAMP( default: OrderedPair | Matrix, - popmean: float or array_like, + popmean: float = 0.1, axis: int = 0, nan_policy: str = "propagate", alternative: str = "two-sided", @@ -17,15 +17,28 @@ def TTEST_1SAMP( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.ttest_1samp( - a=default.y, - popmean=popmean, - axis=axis, - nan_policy=nan_policy, - alternative=alternative, - ), + result = scipy.stats.ttest_1samp( + a=default.y, + popmean=popmean, + axis=axis, + nan_policy=nan_policy, + alternative=alternative, ) + return_list = ["statistic", "pvalue"] + if isinstance(result, tuple): + res_dict = {} + num = min(len(result), len(return_list)) + for i in range(num): + res_dict[return_list[i]] = result[i] + result = res_dict[select_return] + else: + result = result._asdict() + result = result[select_return] + + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/VARIATION/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/VARIATION/a1-[autogen]/python_code.txt index 9b201fd8a..0d548e015 100644 --- a/docs/nodes/SCIPY/STATS/VARIATION/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/VARIATION/a1-[autogen]/python_code.txt @@ -16,15 +16,17 @@ def VARIATION( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.variation( - a=default.y, - axis=axis, - nan_policy=nan_policy, - ddof=ddof, - keepdims=keepdims, - ), + result = scipy.stats.variation( + a=default.y, + axis=axis, + nan_policy=nan_policy, + ddof=ddof, + keepdims=keepdims, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/YEOJOHNSON/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/YEOJOHNSON/a1-[autogen]/python_code.txt index 0377cbea1..a92ef3e58 100644 --- a/docs/nodes/SCIPY/STATS/YEOJOHNSON/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/YEOJOHNSON/a1-[autogen]/python_code.txt @@ -9,16 +9,18 @@ import scipy.stats @flojoy(node_type="default") def YEOJOHNSON( default: OrderedPair | Matrix, - lmbda: float, + lmbda: float = 0.1, ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.yeojohnson( - x=default.y, - lmbda=lmbda, - ), + result = scipy.stats.yeojohnson( + x=default.y, + lmbda=lmbda, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/SCIPY/STATS/ZSCORE/a1-[autogen]/python_code.txt b/docs/nodes/SCIPY/STATS/ZSCORE/a1-[autogen]/python_code.txt index d56fd04c1..bd3e61a2f 100644 --- a/docs/nodes/SCIPY/STATS/ZSCORE/a1-[autogen]/python_code.txt +++ b/docs/nodes/SCIPY/STATS/ZSCORE/a1-[autogen]/python_code.txt @@ -15,14 +15,16 @@ def ZSCORE( ) -> OrderedPair | Matrix | Scalar: - result = OrderedPair( - x=default.x, - y=scipy.stats.zscore( - a=default.y, - axis=axis, - ddof=ddof, - nan_policy=nan_policy, - ), + result = scipy.stats.zscore( + a=default.y, + axis=axis, + ddof=ddof, + nan_policy=nan_policy, ) + if isinstance(result, np.ndarray): + result = OrderedPair(x=default.x, y=result) + elif isinstance(result, np.float64 | float | np.int64 | int): + result = Scalar(c=float(result)) + return result diff --git a/docs/nodes/TRANSFORMERS/IMAGE_PROCESSING/EDGE_DETECTION/examples/EX1/example.md b/docs/nodes/TRANSFORMERS/IMAGE_PROCESSING/EDGE_DETECTION/examples/EX1/example.md index 3fed86f23..c1ea75901 100644 --- a/docs/nodes/TRANSFORMERS/IMAGE_PROCESSING/EDGE_DETECTION/examples/EX1/example.md +++ b/docs/nodes/TRANSFORMERS/IMAGE_PROCESSING/EDGE_DETECTION/examples/EX1/example.md @@ -1 +1 @@ -ITS AN EDGE DETECTION APP WHICH USES AN EDGE DETECTION FILTER NODE TO DETECT EDGES ON AN IMAGE. \ No newline at end of file +It's an edge detection app which uses an edge detection filter node to detect edges on an image. \ No newline at end of file diff --git a/docs/nodes/TRANSFORMERS/SIGNAL_PROCESSING/FFT/a1-[autogen]/python_code.txt b/docs/nodes/TRANSFORMERS/SIGNAL_PROCESSING/FFT/a1-[autogen]/python_code.txt index 9b6e92dbf..5f5e19ddd 100644 --- a/docs/nodes/TRANSFORMERS/SIGNAL_PROCESSING/FFT/a1-[autogen]/python_code.txt +++ b/docs/nodes/TRANSFORMERS/SIGNAL_PROCESSING/FFT/a1-[autogen]/python_code.txt @@ -9,6 +9,7 @@ from pandas import DataFrame as df def FFT( default: OrderedPair, window: Literal[ + "none", "boxcar", "triang", "blackman", diff --git a/docs/nodes/VISUALIZERS/PLOTLY/PROPHET_COMPONENTS/a1-[autogen]/python_code.txt b/docs/nodes/VISUALIZERS/PLOTLY/PROPHET_COMPONENTS/a1-[autogen]/python_code.txt index 595ae0c54..ef1d1e271 100644 --- a/docs/nodes/VISUALIZERS/PLOTLY/PROPHET_COMPONENTS/a1-[autogen]/python_code.txt +++ b/docs/nodes/VISUALIZERS/PLOTLY/PROPHET_COMPONENTS/a1-[autogen]/python_code.txt @@ -1,14 +1,73 @@ -from flojoy import flojoy, DataFrame, Plotly, DataContainer -from prophet.plot import plot_components_plotly -from prophet.serialize import model_from_json +from flojoy import flojoy, run_in_venv, DataFrame, Plotly, DataContainer @flojoy(deps={"prophet": "1.1.4", "holidays": "0.26", "pystan": "2.19.1.1"}) +@run_in_venv( + pip_dependencies=[ + "prophet==1.1.4", + ] +) def PROPHET_COMPONENTS( default: DataFrame, data: DataContainer, periods: int = 365 ) -> Plotly: + import os + import sys + import prophet + + import pandas as pd + import numpy as np + + from prophet.plot import plot_components_plotly + from prophet.serialize import model_from_json + + def _make_dummy_dataframe_for_prophet(): + Generate random time series data to test if prophet works + start_date = pd.Timestamp("2023-01-01") + end_date = pd.Timestamp("2023-07-20") + num_days = (end_date - start_date).days + 1 + timestamps = pd.date_range(start=start_date, end=end_date, freq="D") + data = np.random.randn(num_days) # Random data points + df = pd.DataFrame({"ds": timestamps, "ys": data}) + df.rename( + columns={df.columns[0]: "ds", df.columns[1]: "y"}, inplace=True + ) # PROPHET model expects first column to be `ds` and second to be `y` + return df + + def _apply_macos_prophet_hotfix(): + This is a hotfix for MacOS. See https://github.com/facebook/prophet/issues/2250#issuecomment-1559516328 for more detail + + if not sys.platform == "darwin": + return + + # Test if prophet works (i.e. if the hotfix had already been applied) + try: + _dummy_df = _make_dummy_dataframe_for_prophet() + prophet.Prophet().fit(_dummy_df) + except RuntimeError as e: + print(f"Could not run prophet, applying hotfix...") + else: + return + + prophet_dir = prophet.__path__[0] # type: ignore + # Get stan dir + stan_dir = os.path.join(prophet_dir, "stan_model") + # Find cmdstan-xxxxx dir + cmdstan_basename = [x for x in os.listdir(stan_dir) if x.startswith("cmdstan")] + assert len(cmdstan_basename) == 1, "Could not find cmdstan dir" + cmdstan_basename = cmdstan_basename[0] + # Run (from stan_dir) : install_name_tool -add_rpath @executable_path//stan/lib/stan_math/lib/tbb prophet_model.bin + cmd = f"install_name_tool -add_rpath @executable_path/{cmdstan_basename}/stan/lib/stan_math/lib/tbb prophet_model.bin" + cwd = os.getcwd() + os.chdir(stan_dir) + return_code = os.system(cmd) + os.chdir(cwd) + if return_code != 0: + raise RuntimeError("Could not apply hotfix") + + _apply_macos_prophet_hotfix() + extra = data.extra if not extra or "prophet" not in extra: raise ValueError( diff --git a/docs/nodes/VISUALIZERS/PLOTLY/PROPHET_PLOT/a1-[autogen]/python_code.txt b/docs/nodes/VISUALIZERS/PLOTLY/PROPHET_PLOT/a1-[autogen]/python_code.txt index c6e41a5e1..29ff0a80a 100644 --- a/docs/nodes/VISUALIZERS/PLOTLY/PROPHET_PLOT/a1-[autogen]/python_code.txt +++ b/docs/nodes/VISUALIZERS/PLOTLY/PROPHET_PLOT/a1-[autogen]/python_code.txt @@ -1,11 +1,71 @@ -from flojoy import flojoy, DataFrame, Plotly, DataContainer -from prophet.plot import plot_plotly -from prophet.serialize import model_from_json +from flojoy import flojoy, run_in_venv, DataFrame, Plotly, DataContainer @flojoy(deps={"prophet": "1.1.4", "holidays": "0.26", "pystan": "2.19.1.1"}) +@run_in_venv( + pip_dependencies=[ + "prophet==1.1.4", + ] +) def PROPHET_PLOT(default: DataFrame, data: DataContainer, periods: int = 365) -> Plotly: + + import os + import sys + import prophet + + import pandas as pd + import numpy as np + + from prophet.plot import plot_plotly + from prophet.serialize import model_from_json + + def _make_dummy_dataframe_for_prophet(): + Generate random time series data to test if prophet works + start_date = pd.Timestamp("2023-01-01") + end_date = pd.Timestamp("2023-07-20") + num_days = (end_date - start_date).days + 1 + timestamps = pd.date_range(start=start_date, end=end_date, freq="D") + data = np.random.randn(num_days) # Random data points + df = pd.DataFrame({"ds": timestamps, "ys": data}) + df.rename( + columns={df.columns[0]: "ds", df.columns[1]: "y"}, inplace=True + ) # PROPHET model expects first column to be `ds` and second to be `y` + return df + + def _apply_macos_prophet_hotfix(): + This is a hotfix for MacOS. See https://github.com/facebook/prophet/issues/2250#issuecomment-1559516328 for more detail + + if not sys.platform == "darwin": + return + + # Test if prophet works (i.e. if the hotfix had already been applied) + try: + _dummy_df = _make_dummy_dataframe_for_prophet() + prophet.Prophet().fit(_dummy_df) + except RuntimeError as e: + print(f"Could not run prophet, applying hotfix...") + else: + return + + prophet_dir = prophet.__path__[0] # type: ignore + # Get stan dir + stan_dir = os.path.join(prophet_dir, "stan_model") + # Find cmdstan-xxxxx dir + cmdstan_basename = [x for x in os.listdir(stan_dir) if x.startswith("cmdstan")] + assert len(cmdstan_basename) == 1, "Could not find cmdstan dir" + cmdstan_basename = cmdstan_basename[0] + # Run (from stan_dir) : install_name_tool -add_rpath @executable_path//stan/lib/stan_math/lib/tbb prophet_model.bin + cmd = f"install_name_tool -add_rpath @executable_path/{cmdstan_basename}/stan/lib/stan_math/lib/tbb prophet_model.bin" + cwd = os.getcwd() + os.chdir(stan_dir) + return_code = os.system(cmd) + os.chdir(cwd) + if return_code != 0: + raise RuntimeError("Could not apply hotfix") + + _apply_macos_prophet_hotfix() + extra = data.extra if not extra or "prophet" not in extra: raise ValueError( diff --git a/nodeSidebar.json b/nodeSidebar.json index 9809ea591..1deeabef9 100644 --- a/nodeSidebar.json +++ b/nodeSidebar.json @@ -42,6 +42,7 @@ "Data > Generate > Synthetic Data > DATAFRAMES": [ "nodes/GENERATORS/SAMPLE_DATASETS/PLOTLY_DATASET/PLOTLY_DATASET", "nodes/GENERATORS/SAMPLE_DATASETS/R_DATASET/R_DATASET", + "nodes/GENERATORS/SAMPLE_DATASETS/TABULAR_DATASETS/TABULAR_DATASETS", "nodes/GENERATORS/SAMPLE_DATASETS/TEXT_DATASET/TEXT_DATASET" ], "Data > Generate > Synthetic Data > IMAGES": [