Package: dispatches-synthetic-price-data
QuickstartStep 1: Install the data package in your DISPATCHES environment using pipcondaactivatedispatches-dev# or the name of your DISPATCHES dev environmentpipinstallgit+https://github.com/gmlc-dispatches/synthetic-price-dataStep 2: Access the contents of the data package in your code usingdispatches_data.apiUsingdispatches_data.api.path():fromdispatches_data.apiimportpath# path_to_data_package is a standard pathlib.Path objectpath_to_data_package=path("synthetic_price")# subdirectories and files can be accessed using the pathlib.Path APIpath_to_xml=path_to_data_package/"ARMA_train.xml"assertpath_to_xml.is_file()# alternatively, if the file is located directly under the data package directory (i.e. not in a subdirectory):# this will raise an exception if the file does not exist so we don't need to check explicitlypath_to_xml=path("synthetic_price","ARMA_train.xml")# if the path must be passed to a function that only accepts `str` objects, it can be converted using `str()`path_to_xml_as_str=str(path_to_xml)Usingdispatches_data.api.files():fromdispatches_data.apiimportfiles# `all_price_files` will be a list of pathlib.Path objects for each file matching the specified `pattern`all_price_files=files("synthetic_price",pattern="Price_20*.csv")# check that the list of found files is not emptyassertall_price_files# `dispatches_data.api.files()` always returns a list, even if only one file matchesprice_for_21=files("synthetic_price",pattern="Price_*21.csv")[0]Using the CLI interface:NOTEthis example uses UNIX shell syntax. It will not work on Windows unless adapted to the specific shell (e.g. Powershell) being used.# calling `dispatches-data-packages` on the command line with the name of the data package# will output the absolute path to the data package, which can then be saved as a shell variable# and used to generate paths to files in the data packagepath_to_data_package="$(dispatches-data-packagessynthetic_price)"path_to_xml_file="$path_to_data_package/ARMA_train.xml"ls-lh"$path_to_data_package"cp"$path_to_xml_file".# the entire contents of the data package can be copied to the current working directory# if this is required by the client applicationcp-r"$path_to_data_package"/*.
ls-lh.ExamplesUsing the data package with the RAVEN CLINOTEthis example uses UNIX shell syntax. It will not work on Windows unless adapted to the specific shell (e.g. Powershell) being used.TODO: must be testedpath_to_data_package="$(dispatches-data-packagessynthetic_price)"# copy contents to local directorycp-r"$path_to_data_package"/*.
raven_frameworkARMA_train.xmlUsing the data package with shell commands in IPython/Jupyter notebooksBoth the IPython shell and Jupyter notebooks allow running arbitrary shell commands within a Python code shell by prefixing the command with!.
Refer to theIPython documentationfor details.NOTEThe command (minus the!prefix) is passed verbatim to the system shell. Therefore, the exact syntax used in these examples may or may not work depending on the operating system (more specifically, on which shell is configured as the default).Within a!-prefixed line, the use of Python variables is supported by prefixing the variable name with$or wrapping it between{}.
Thevalueof the Python variable will be converted to a string automatically before the command is passed to the shell.Therefore, the following syntax can be used to use data packages within a IPython/Jupyter shell command:fromdispatches_data.apiimportpathxml_path=path("synthetic_price","ARMA_train.xml)# the $ syntax only supports simple variable names!raven_framework$xml_path# the {} syntax supports arbitrary Python expressions!raven_framework{path("synthetic_price","ARMA_train.xml")}