Skip to content

Commit

Permalink
Lint code with black
Browse files Browse the repository at this point in the history
  • Loading branch information
Bachibouzouk committed Nov 8, 2023
1 parent b92ef3d commit 9629d5d
Show file tree
Hide file tree
Showing 23 changed files with 1,093 additions and 828 deletions.
24 changes: 11 additions & 13 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@

# -- Project information -----------------------------------------------------

project = 'RAMP'
copyright = '2022, Author List'
author = 'Author List'

project = "RAMP"
copyright = "2022, Author List"
author = "Author List"


# -- General configuration ---------------------------------------------------
Expand All @@ -40,14 +39,14 @@
"sphinx.ext.coverage",
"sphinx.ext.autosummary",
"sphinx.ext.napoleon",
'sphinx.ext.duration',
'sphinx.ext.doctest',
'sphinx_copybutton',
'sphinx.ext.autosectionlabel'
"sphinx.ext.duration",
"sphinx.ext.doctest",
"sphinx_copybutton",
"sphinx.ext.autosectionlabel",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -61,13 +60,12 @@
# a list of builtin themes.
#
extensions.append("sphinxjp.themes.basicstrap")
html_theme = 'basicstrap'
#html_theme_path = [sphinx_pdj_theme.get_html_theme_path()]
html_theme = "basicstrap"
# html_theme_path = [sphinx_pdj_theme.get_html_theme_path()]
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# copy btn settings
copybutton_prompt_text = "<AxesSubplot:>"

12 changes: 6 additions & 6 deletions ramp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@


from ramp._version import __version__
from ramp.core.core import UseCase,User,Appliance
from ramp.core.core import UseCase, User, Appliance
from ramp.core.stochastic_process import calc_peak_time_range
from ramp.core.utils import yearly_pattern
from ramp.example.examples import load_data,download_example
from ramp.post_process.post_process import Run,Plot
from ramp.example.examples import load_data, download_example
from ramp.post_process.post_process import Run, Plot

__authors__ = "Listed in AUTHORS"
__copyright__ = "Licensed under the European Union Public Licence (EUPL), Version 1.2-or-later"


__copyright__ = (
"Licensed under the European Union Public Licence (EUPL), Version 1.2-or-later"
)
1 change: 0 additions & 1 deletion ramp/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

__version__ = "0.4.1"
69 changes: 45 additions & 24 deletions ramp/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@
)

parser.add_argument(
"--ext",
dest="extension",
type=str,
help="Format of input files",
default="xlsx"
"--ext", dest="extension", type=str, help="Format of input files", default="xlsx"
)

parser.add_argument(
Expand All @@ -76,7 +72,6 @@


def main():

args = vars(parser.parse_args())
fnames = args["fname_path"]
ofnames = args["ofname_path"]
Expand All @@ -100,7 +95,9 @@ def main():

if years is not None:
if date_start is not None or date_end is not None:
raise ValueError("You cannot use the option -y in combinaison with --date-start and/or --date-end")
raise ValueError(
"You cannot use the option -y in combinaison with --date-start and/or --date-end"
)
else:
date_start = datetime.date(years[0], 1, 1)
date_end = datetime.date(years[-1], 12, 31)
Expand All @@ -109,20 +106,27 @@ def main():
# Triggers the special mode "one input file per month"
if os.path.isdir(fnames[0]):
dir_path = fnames[0]
fnames = [os.path.join(dir_path, f) for f in os.listdir(fnames[0]) if f.endswith(ext)]
fnames.sort(key=lambda f: int(''.join(filter(str.isdigit, f))))
fnames = [
os.path.join(dir_path, f)
for f in os.listdir(fnames[0])
if f.endswith(ext)
]
fnames.sort(key=lambda f: int("".join(filter(str.isdigit, f))))

if len(fnames) == 12:
print("The following input files were found and will be used in this exact order for month inputs")
print(
"The following input files were found and will be used in this exact order for month inputs"
)
print("\n".join(fnames))
month_files = True
year = years[0]
else:
raise ValueError(f"You want to simulate a whole year, yet the folder {dir_path} only contains {len(fnames)} out of the 12 monthes required")
raise ValueError(
f"You want to simulate a whole year, yet the folder {dir_path} only contains {len(fnames)} out of the 12 monthes required"
)
else:
print("You selected a single year but the input path is not a folder.")


if date_start is not None and date_end is not None:
days = pd.date_range(start=date_start, end=date_end)
else:
Expand All @@ -132,7 +136,9 @@ def main():
ofnames = [None]

if fnames is None:
print("Please provide path to input file with option -i, \n\nDefault to old version of RAMP input files\n")
print(
"Please provide path to input file with option -i, \n\nDefault to old version of RAMP input files\n"
)
# Files are specified as numbers in a list (e.g. [1,2] will consider input_file_1.py and input_file_2.py)
from ramp.ramp_run import input_files_to_run

Expand All @@ -142,7 +148,8 @@ def main():
else:
if len(num_profiles) != len(input_files_to_run):
raise ValueError(
"The number of profiles parameters should match the number of input files provided")
"The number of profiles parameters should match the number of input files provided"
)
else:
num_profiles = [None] * len(input_files_to_run)

Expand All @@ -167,34 +174,49 @@ def main():
else:
if len(num_profiles) != len(fnames):
raise ValueError(
"The number of profiles parameters should match the number of input files provided")
"The number of profiles parameters should match the number of input files provided"
)
else:
num_profiles = [None] * len(fnames)
if month_files is True:
year_profile = []
for i, fname in enumerate(fnames):
month_start = datetime.date(year, i+1, 1)
month_end = datetime.date(year, i+1, pd.Period(month_start, freq="D").days_in_month)
days = pd.date_range(start=month_start, end=month_end, freq='D')
monthly_profiles = run_usecase(fname=fname, num_profiles=num_profiles[i], days=days, plot=False, parallel=parallel_processing)
month_start = datetime.date(year, i + 1, 1)
month_end = datetime.date(
year, i + 1, pd.Period(month_start, freq="D").days_in_month
)
days = pd.date_range(start=month_start, end=month_end, freq="D")
monthly_profiles = run_usecase(
fname=fname,
num_profiles=num_profiles[i],
days=days,
plot=False,
parallel=parallel_processing,
)
year_profile.append(np.hstack(monthly_profiles))

# Create a dataFrame to save the year profile with timestamps every minutes
series_frame = pd.DataFrame(
np.hstack(year_profile),
index=pd.date_range(start=f"{year}-1-1", end=f"{year}-12-31 23:59", freq="T")
index=pd.date_range(
start=f"{year}-1-1", end=f"{year}-12-31 23:59", freq="T"
),
)
# Save to minute and hour resolution
# TODO let the user choose where to save the files/file_name, make sure the user wants to overwrite the file
# if it already exists
series_frame.to_csv(os.path.join(BASE_PATH, 'yearly_profile_min_resolution.csv'))
series_frame.to_csv(
os.path.join(BASE_PATH, "yearly_profile_min_resolution.csv")
)
resampled = pd.DataFrame()

resampled["mean"] = series_frame.resample("H").mean()
resampled["max"] = series_frame.resample("H").max()
resampled["min"] = series_frame.resample("H").min()
#TODO add more columns with other resampled functions (do this in Jupyter)
resampled.to_csv(os.path.join(BASE_PATH, 'yearly_profile_hourly_resolution.csv'))
# TODO add more columns with other resampled functions (do this in Jupyter)
resampled.to_csv(
os.path.join(BASE_PATH, "yearly_profile_hourly_resolution.csv")
)
else:
if len(ofnames) == 1:
ofnames = ofnames * len(fnames)
Expand All @@ -214,5 +236,4 @@ def main():


if __name__ == "__main__":

main()
114 changes: 57 additions & 57 deletions ramp/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,69 +64,69 @@ def switch_on_parameters():


APPLIANCE_ATTRIBUTES = (
"name",
"number",
"power",
"num_windows",
"func_time",
"time_fraction_random_variability",
"func_cycle",
"fixed",
"fixed_cycle",
"occasional_use",
"flat",
"thermal_p_var",
"pref_index",
"wd_we_type",
"p_11",
"t_11",
"cw11",
"p_12",
"t_12",
"cw12",
"r_c1",
"p_21",
"t_21",
"cw21",
"p_22",
"t_22",
"cw22",
"r_c2",
"p_31",
"t_31",
"cw31",
"p_32",
"t_32",
"cw32",
"r_c3",
"window_1",
"window_2",
"window_3",
"random_var_w",
)
"name",
"number",
"power",
"num_windows",
"func_time",
"time_fraction_random_variability",
"func_cycle",
"fixed",
"fixed_cycle",
"occasional_use",
"flat",
"thermal_p_var",
"pref_index",
"wd_we_type",
"p_11",
"t_11",
"cw11",
"p_12",
"t_12",
"cw12",
"r_c1",
"p_21",
"t_21",
"cw21",
"p_22",
"t_22",
"cw22",
"r_c2",
"p_31",
"t_31",
"cw31",
"p_32",
"t_32",
"cw32",
"r_c3",
"window_1",
"window_2",
"window_3",
"random_var_w",
)

APPLIANCE_ARGS = (
"number",
"power",
#"p_series",
"num_windows",
"func_time",
"time_fraction_random_variability",
"func_cycle",
"fixed",
"fixed_cycle",
"occasional_use",
"flat",
"thermal_p_var",
"pref_index",
"wd_we_type",
"name",
)
"number",
"power",
# "p_series",
"num_windows",
"func_time",
"time_fraction_random_variability",
"func_cycle",
"fixed",
"fixed_cycle",
"occasional_use",
"flat",
"thermal_p_var",
"pref_index",
"wd_we_type",
"name",
)

MAX_WINDOWS = 3
WINDOWS_PARAMETERS = ("window_1", "window_2", "window_3", "random_var_w")
DUTY_CYCLE_PARAMETERS = (
("p_11", "t_11", "cw11", "p_12", "t_12", "cw12", "r_c1"),
("p_21", "t_21", "cw21", "p_22", "t_22", "cw22", "r_c2"),
("p_31", "t_31", "cw31", "p_32", "t_32", "cw32", "r_c3"),
)
)
Loading

0 comments on commit 9629d5d

Please sign in to comment.