cal-adapt / climakitae

A Python toolkit for retrieving, visualizing, and performing scientific analyses with data from the Cal-Adapt Analytics Engine.
https://climakitae.readthedocs.io
BSD 3-Clause "New" or "Revised" License
21 stars 2 forks source link

handle list input for scenario #416

Closed nicolejkeeney closed 2 months ago

nicolejkeeney commented 2 months ago

Description of PR

See header below "How to test" for instructions on how to test this PR

When I wrote the new get_data function for the climatekitae_direct_data_download notebook (the functions that let you access/download data without the GUI), I wrote it such that you could only retrieve data for a single scenario (because it was way more simple programmatically).

In working on the warming levels code, I realized we really need to be able to pull multiple scenarios, like the selections GUI does. So, in this update, I allow you to use a list as an input for the scenario object.

How to test

In the climakitae_direct_data_download notebook, try retrieving and viewing different data options using the following two functions: get_data_options and get_data.

Type of change

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce.

Checklist:

nicolejkeeney commented 2 months ago

Add option to retrieve multiple scenarios in get_data function

vicford commented 2 months ago
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In [2], line 1
----> 1 get_data_options()

File ~/src/climakitae/climakitae/core/data_interface.py:1500, in get_data_options(variable, downscaling_method, resolution, timescale, scenario, tidy)
   1487         return None
   1488 d = {
   1489     "variable": variable if type(variable) == list else [variable],
   1490     "timescale": timescale if type(timescale) == list else [timescale],
   (...)
   1497     "resolution": resolution if type(resolution) == list else [resolution],
   1498 }
-> 1500 d = _check_if_good_input(d, cat_df)
   1502 # Subset the catalog with the user's inputs
   1503 cat_subset = cat_df[
   1504     (cat_df["variable"].isin(d["variable"]))
   1505     & (cat_df["downscaling_method"].isin(d["downscaling_method"]))
   (...)
   1508     & (cat_df["scenario"].isin(d["scenario"]))
   1509 ].reset_index(drop=True)

File ~/src/climakitae/climakitae/core/data_interface.py:1416, in _check_if_good_input(d, cat_df)
   1412         pass
   1414 if val_i not in valid_options:
-> 1416     print("Input " + key + "='" + val_i + "' is not a valid option.")
   1418     closest_options = _get_closest_options(val_i, valid_options)
   1420     # Sad! No closest options found. Just set the key to all valid options

TypeError: can only concatenate str (not "NoneType") to str

Error when running get_data_options()

nicolejkeeney commented 2 months ago
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In [2], line 1
----> 1 get_data_options()

File ~/src/climakitae/climakitae/core/data_interface.py:1500, in get_data_options(variable, downscaling_method, resolution, timescale, scenario, tidy)
   1487         return None
   1488 d = {
   1489     "variable": variable if type(variable) == list else [variable],
   1490     "timescale": timescale if type(timescale) == list else [timescale],
   (...)
   1497     "resolution": resolution if type(resolution) == list else [resolution],
   1498 }
-> 1500 d = _check_if_good_input(d, cat_df)
   1502 # Subset the catalog with the user's inputs
   1503 cat_subset = cat_df[
   1504     (cat_df["variable"].isin(d["variable"]))
   1505     & (cat_df["downscaling_method"].isin(d["downscaling_method"]))
   (...)
   1508     & (cat_df["scenario"].isin(d["scenario"]))
   1509 ].reset_index(drop=True)

File ~/src/climakitae/climakitae/core/data_interface.py:1416, in _check_if_good_input(d, cat_df)
   1412         pass
   1414 if val_i not in valid_options:
-> 1416     print("Input " + key + "='" + val_i + "' is not a valid option.")
   1418     closest_options = _get_closest_options(val_i, valid_options)
   1420     # Sad! No closest options found. Just set the key to all valid options

TypeError: can only concatenate str (not "NoneType") to str

Error when running get_data_options()

Good find!! I will investigate!! Do you remember your inputs by chance? @vicford

vicford commented 2 months ago

Good find!! I will investigate!! Do you remember your inputs by chance? @vicford

I didn't even get to the input stage :( it crapped out just on the call as is!

nicolejkeeney commented 2 months ago

Good find!! I will investigate!! Do you remember your inputs by chance? @vicford

I didn't even get to the input stage :( it crapped out just on the call as is!

Lol that's embarassing.... oops.