No project description provided
Project description
Quickstart
Step 1: Install the data package in your DISPATCHES environment using pip
conda activate dispatches-dev # or the name of your DISPATCHES dev environment
pip install git+https://github.com/gmlc-dispatches/dynamic-sweep-data
Step 2: Access the contents of the data package in your code using dispatches_data.api
Using dispatches_data.api.path()
:
from dispatches_data.api import path
# path_to_data_package is a standard pathlib.Path object
path_to_data_package = path("dynamic_sweep")
# subdirectories and files can be accessed using the pathlib.Path API
path_to_NE_results = path_to_data_package / "NE" / "sweep_parameters_results_NE_whole.h5"
assert path_to_NE_results.is_file()
# if the path must be passed to a function that only accepts `str` objects, it can be converted using `str()`
path_to_NE_results_as_str = str(path_to_NE_results)
Using dispatches_data.api.files()
:
from dispatches_data.api import files
# paths_to_all_results_files will be a list of pathlib.Path objects for each file matching the specified `pattern`
paths_to_all_results_files = files("dynamic_sweep", pattern="**/sweep_parameters_results_*_whole.h5")
# check that the list of found files is not empty
assert paths_to_all_results_files
# `dispatches_data.api.files()` always returns a list, even if only one file matches
path_to_NE_results = files("dynamic_sweep", pattern="NE/*result_*_whole.h5")[0]
Examples
Loading multiple CSV files into a pandas DataFrame
import pandas as pd
from dispatches_data.api import files
def load_data(case_study: str = "NE") -> pd.DataFrame:
results_file_pattern = f"{case_study}/results_*_sweep_*/*.csv"
csv_files_to_load = files("dynamic_sweep", pattern=results_files_pattern)
if not csv_files_to_load:
raise LookupError("No files found with pattern {results_file_pattern!r}")
df = pd.concat(
[pd.read_csv(csv_path) for csv_path in csv_files_to_load],
axis="index"
)
# process df as needed
return df
def main():
df_NE = load_data("NE")
df_RE = load_data("RE")
...
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for dispatches-dynamic-sweep-data-23.4.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd3bf8da4a0252097f4f14242b8f2c5982ce60fa5fd300a3caa81eb937203b29 |
|
MD5 | 57b2a2f03ef87f574aeb1bbb9a79caa0 |
|
BLAKE2b-256 | 1c28dbad57f9accc00b259016e682774264c0c8e7eaa7ecec00d5855bd1639b0 |
Close
Hashes for dispatches_dynamic_sweep_data-23.4.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d694366affc8d4d96d5913301876ffb11b90c26c8c69190cc4957645b21842a |
|
MD5 | c796f0ffabc216846199c77659caf0d4 |
|
BLAKE2b-256 | 71059a90ad02be1aac7c05c685fd27b67e609faa32e4751ba08aa40ac5b597be |