Skip to content

Commit

Permalink
Added function to find capacity column, replacing constant.
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamsTravis committed Jul 15, 2024
1 parent 753bcb0 commit 7d229d8
Show file tree
Hide file tree
Showing 13 changed files with 120 additions and 39 deletions.
4 changes: 4 additions & 0 deletions configs/offshore_fy22.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"project_name": "Testing Offshore- FY22",
"directory": "~/review_datasets/testing_offshore_fy22"
}
4 changes: 4 additions & 0 deletions configs/standard_scenarios_fy24.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"project_name": "Standard Scenarios - FY24",
"directory": "~/review_datasets/standard_scenarios_fy24"
}
4 changes: 4 additions & 0 deletions configs/temp_ice_test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"project_name": "Bespoke Temp/Icing Cutoff Test",
"directory": "~/review_datasets/temp_ice_test"
}
4 changes: 4 additions & 0 deletions configs/transport_tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"project_name": "Transport Tests- FY24",
"directory": "~/review_datasets/transport"
}
38 changes: 38 additions & 0 deletions environment_unpinned.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: review
channels:
- conda-forge
- nrel
dependencies:
- addfips
- colorama
- dash
- flask
- flask-caching
- cartopy
- geopandas
- h5py
- numpy
- pandas
- pandarallel
- pint
- plotly
- pyproj
- pytest
- python-dotenv
- requests
- scipy
- setuptools
- tqdm
- werkzeug
- shapely
- geoplot
- openpyxl
- xlrd
- pip
- pip:
- dash_bootstrap_components
- pygeopkg
- pyarrow
- scikit-learn
- us
- plotext
4 changes: 4 additions & 0 deletions reView/components/divs/toptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
TABLET_STYLE_CLOSED,
)
from reView.utils.config import Config
from reView.utils.functions import get_project_defaults


DEFAULT_PROJECT = get_project_defaults()["rev"]

TOP_TABS = html.Div(
id="options_tab",
children=[
Expand Down Expand Up @@ -154,6 +157,7 @@
html.H5("Project"),
dcc.Dropdown(
id="project",
value=DEFAULT_PROJECT,
options=[
# pylint: disable=not-an-iterable
{"label": project, "value": project}
Expand Down
56 changes: 28 additions & 28 deletions reView/components/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ def __repr__(self):

def figure(self, point_size, reverse_color=False):
"""Build scatter plot figure."""
self.df["text"] = self.hover_text
self.df.loc[:, "text"] = self.hover_text
if self.df.empty:
figure = go.Figure()
figure.update_layout(
Expand Down Expand Up @@ -410,7 +410,6 @@ def figure(self, point_size, reverse_color=False):

# Update the layout
layout = self.layout
# layout["mapbox"]["center"]
figure.update_layout(**layout)
figure.update_traces(
unselected={"marker": {"opacity": 1}},
Expand All @@ -423,25 +422,26 @@ def figure(self, point_size, reverse_color=False):
def hover_text(self):
"""Return hover text column."""
# Convert NaNs to strings for international projects
df = self.df.copy()
if "state" in self.df:
if self.df["state"].isnull().all():
self.df["state"] = ""
if df["state"].isnull().all():
df.loc[:, "state"] = ""
else:
self.df["state"][self.df["state"].isnull()] = "N/A"
self.df["state"][self.df["state"] != "nan"] = \
self.df["state"] + ":"
df.loc[df["state"].isnull(), "state"] = "N/A"
df.loc[df["state"] != "nan", "state"] = \
df["state"] + ":"
else:
self.df["state"] = ""
df.loc[:, "state"] = ""

if "county" in self.df:
if self.df["county"].isnull().all():
self.df["county"] = ""
if "county" in df:
if df["county"].isnull().all():
df.loc[:, "county"] = ""
else:
self.df["county"][self.df["county"].isnull()] = "N/A"
self.df["county"][self.df["county"] != "nan"] = \
self.df["county"] + " County, "
df.loc[df["county"].isnull(), "county"] = "N/A"
df.loc[df["county"] != "nan", "county"] = \
df["county"] + " County, "
else:
self.df["county"] = ""
df.loc[:, "county"] = ""

# Include demand data fro hydrogen runs
if self.demand_data is not None:
Expand All @@ -456,56 +456,56 @@ def hover_text(self):
elif self.units == "category":
try:
text = (
self.df["county"]
+ self.df["state"]
df["county"]
+ df["state"]
+ "<br> "
+ self.df[self.color_var].astype(str)
+ df[self.color_var].astype(str)
+ " "
+ self.units
)
except KeyError:
text = (
round(self.df[self.color_var], 2).astype(str)
round(df[self.color_var], 2).astype(str)
+ " "
+ self.units
)
else:
extra_str = ""
if "hydrogen_annual_kg" in self.df:
if "hydrogen_annual_kg" in df:
extra_str += (
"<br> H2 Supply: "
+ self.df["hydrogen_annual_kg"].apply(lambda x: f"{x:,}")
+ df["hydrogen_annual_kg"].apply(lambda x: f"{x:,}")
+ " kg "
)
if "dist_to_selected_load" in self.df:
if "dist_to_selected_load" in df:
extra_str += (
"<br> Dist to load: "
+ self.df["dist_to_selected_load"].apply(
+ df["dist_to_selected_load"].apply(
lambda x: f"{x:,.2f}"
)
+ " km "
)

try:
text = (
self.df["county"]
+ self.df["state"]
df["county"]
+ df["state"]
+ extra_str
+ f"<br> {convert_to_title(self.color_var)}: "
+ self.df[self.color_var].round(2).astype(str)
+ df[self.color_var].round(2).astype(str)
+ " "
+ self.units
)
except KeyError:
text = (
extra_str
+ f"<br> {convert_to_title(self.color_var)}: "
+ self.df[self.color_var].round(2).astype(str)
+ df[self.color_var].round(2).astype(str)
+ " "
+ self.units
)

return text
return text.values

@property
def layout(self):
Expand Down
1 change: 0 additions & 1 deletion reView/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def main():
host=APP_HOST,
port=APP_PORT,
debug=False,
dev_tools_hot_reload=True
)


Expand Down
34 changes: 27 additions & 7 deletions reView/pages/rev/controller/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,17 @@ def files_to_dropdown(files):
return scenario_options


def find_capacity(project):
"""Find a useable capacity string from a list of column names."""
config = Config(project)
file = config.files[next(iter(config.files))]
columns = read_file(file, nrows=0).columns
capcols = [col for col in columns if "capacity" in col]
if len(capcols) == 0:
raise KeyError("No capacity column found!")
return capcols[0]


@calls.log
def options_chart_type(project, y_var=None):
"""Add characterization plot option, if necessary."""
Expand Down Expand Up @@ -500,7 +511,10 @@ def dropdown_composite_plot_options(scenario_options, project):

logger.debug("Setting minimizing plot options")
config = Config(project)
path = choose_scenario(scenario_options, config)
try:
path = choose_scenario(scenario_options, config)
except KeyError:
raise PreventUpdate
plot_options = [{"label": "Scenario", "value": "scenario"}]

if path and os.path.exists(path):
Expand Down Expand Up @@ -571,7 +585,10 @@ def dropdown_composite_targets(scenario_options, project):

logger.debug("Setting minimizing target options")
config = Config(project)
path = choose_scenario(scenario_options, config)
try:
path = choose_scenario(scenario_options, config)
except KeyError:
raise PreventUpdate

target_options = []
if path and os.path.exists(path):
Expand Down Expand Up @@ -776,7 +793,7 @@ def dropdown_variables(
if old_variable in values:
value = old_variable
else:
value = "capacity"
value = find_capacity(project)

return (
variable_options,
Expand Down Expand Up @@ -815,7 +832,7 @@ def dropdown_x_variables(
variable_options = get_variable_options(
project, scenario_a, scenario_b, b_div
)
val = "capacity"
val = find_capacity(project)

if not variable_options:
variable_options = [{"label": "None", "value": "None"}]
Expand All @@ -837,6 +854,8 @@ def dropdown_time_variables(_, scenario_a, old_variable):
logger.debug("Setting timeseries variable options")

# Get the 2D (timeseries) datasets and create an option list
if not scenario_a.endswith(".h5"):
raise PreventUpdate
with h5py.File(scenario_a) as ds:
dsets = list(ds)
shapes = [len(ds[dset].shape) for dset in dsets]
Expand Down Expand Up @@ -1576,6 +1595,10 @@ def retrieve_signal(
config = Config(project)
trigger = callback_trigger()

# If no x is specified
if not x:
x = find_capacity(project)

# Set default scenario data set
if scenario_a == "placeholder":
files = list(config.files.values())
Expand Down Expand Up @@ -1613,9 +1636,6 @@ def retrieve_signal(
else:
y = composite_plot_value

if not x:
x = "capacity"

signal = {
"filters": [],
"mask": "off",
Expand Down
7 changes: 6 additions & 1 deletion reView/pages/rev/controller/element_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def binned(self, x_var, y_var, bins=100):
main_df,
x="xbin",
y="yagg", # Plot all y's so we can share selections with map
custom_data=["sc_point_gid", "capacity"],
custom_data=["sc_point_gid", self.capacity_col(main_df)],
labels={x_var: xtitle, y_var: ytitle},
color=self.GROUP,
color_discrete_sequence=px.colors.qualitative.Safe,
Expand Down Expand Up @@ -195,6 +195,11 @@ def fix_key(key):

return self._update_fig_layout(fig, y_var)

@property
def capacity(self):
"""Find the most appropriate cpacity column."""


def char_hist(self, x_var):
"""Make a histogram of the characterization column."""
main_df = list(self.datasets.values())[0]
Expand Down
Binary file removed review_disk.png
Binary file not shown.
1 change: 0 additions & 1 deletion runtime.txt

This file was deleted.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research",
"Natural Language :: English",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.9"
"Framework :: Dash",
],
test_suite="tests",
Expand Down

0 comments on commit 7d229d8

Please sign in to comment.