Core Data Interface (Detailed)
The legacy data interface module providing function-based API for climate data access.
Overview
climakitae.core.data_interface is the main entry point for the legacy interface. It provides:
- DataParameters class — Configuration object for data queries
- get_data() function — Execute data queries with validation
Warning
This is the legacy interface. For new code, use climakitae.new_core.user_interface.ClimateData instead.
DataParameters Class
Bases: Parameterized
Python param object to hold data parameters for use in panel GUI.
Call DataParameters when you want to select and retrieve data from the climakitae data catalog without using the ckg.Select GUI. ckg.Select uses this class to store selections and retrieve data.
DataParameters calls DataInterface, a singleton class that makes the connection to the intake-esm data store in S3 bucket.
Attributes
unit_options_dict : dict options dictionary for converting unit to other units area_subset : str dataset to use from Boundaries for sub area selection cached_area : list of strs one or more features from area_subset datasets to use for selection latitude : tuple latitude range of selection box longitude : tuple longitude range of selection box variable_type : str toggle raw or derived variable selection default_variable : str initial variable to have selected in widget time_slice : tuple year range to select resolution : str resolution of data to select ("3 km", "9 km", "45 km") timescale : str frequency of dataset ("hourly", "daily", "monthly") scenario_historical : list of strs historical scenario selections area_average : str whether to comput area average ("Yes", "No") downscaling_method : str whether to choose WRF or LOCA2 data or both ("Dynamical", "Statistical", "Dynamical+Statistical") data_type : str whether to choose gridded or station based data ("Gridded", "Stations") stations : list or strs list of stations that can be filtered by cached_area _station_data_info : str informational statement when station data selected with data_type scenario_ssp : list of strs list of future climate scenarios selected (availability depends on other params) simulation : list of strs list of simulations (models) selected (availability depends on other params) variable : str variable long display name units : str unit abbreviation currently of the data (native or converted) enable_hidden_vars : boolean enable selection of variables that are hidden from the GUI? extended_description : str extended description of the data variable variable_id : list of strs list of variable ids that match the variable (WRF and LOCA2 can have different codes for same type of variable) historical_climate_range_wrf : tuple time range of historical WRF data historical_climate_range_loca : tuple time range of historical LOCA2 data historical_climate_range_wrf_and_loca : tuple time range of historical WRF and LOCA2 data combined historical_reconstruction_range : tuple time range of historical reanalysis data ssp_range : tuple time range of future scenario SSP data _info_about_station_data : str warning message about station data _data_warning : str warning about selecting unavailable data combination data_interface : DataInterface data connection singleton class that provides data _data_catalog : intake_esm.source.ESMDataSource shorthand alias to DataInterface.data_catalog _variable_descriptions : pd.DataFrame shorthand alias to DataInterface.variable_descriptions _stations_gdf : gpd.GeoDataFrame shorthand alias to DataInterface.stations_gdf _geographies : Boundaries shorthand alias to DataInterface.geographies _geography_choose : dict shorthand alias to Boundaries.boundary_dict() _warming_level_times : pd.DataFrame shorthand alias to DataInterface.warming_level_times colormap : str default colormap to render the currently selected data scenario_options : list of strs list of available scenarios (historical and ssp) for selection variable_options_df : pd.DataFrame filtered variable descriptions for the downscaling_method and timescale warming_level : array global warming level(s) warming_level_window : integer years around Global Warming Level (+/-) (e.g. 15 means a 30yr window) approach : str, "Warming Level" or "Time" how do you want the data to be retrieved? warming_level_months : array months of year to use for computing warming levels default to entire calendar year: 1,2,3,4,5,6,7,8,9,10,11,12 all_touched : boolean spatial subset option for within or touching selection
Source code in climakitae/core/data_interface.py
751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 | |
retrieve(config=None, merge=True)
Retrieve data from catalog
By default, DataParameters determines the data retrieved. Grabs the data from the AWS S3 bucket, returns lazily loaded dask array. User-facing function that provides a wrapper for read_catalog_from_select.
Returns:
| Name | Type | Description |
|---|---|---|
data_return |
DataArray | Dataset | List[DataArray]
|
DataArray or Dataset object |
Source code in climakitae/core/data_interface.py
1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 | |
Get Data Function
Retrieve formatted data from the Analytics Engine data catalog.
Contrasts with DataParameters().retrieve(), which retrieves data from the user inputs in climakitaegui's selections GUI.
Parameters
variable : str
String name of climate variable
resolution : str, one of ["3 km", "9 km", "45 km"]
Resolution of data in kilometers
timescale : str, one of ["hourly", "daily", "monthly"]
Temporal frequency of dataset
downscaling_method : str, one of ["Dynamical", "Statistical", "Dynamical+Statistical"], optional
Downscaling method of the data:
WRF ("Dynamical"), LOCA2 ("Statistical"), or both "Dynamical+Statistical"
Default to "Dynamical"
data_type : str, one of ["Gridded", "Stations"], optional
Whether to choose gridded data or weather station data
Default to "Gridded"
approach : one of ["Time", "Warming Level"], optional
Default to "Time"
scenario : str or list of str, optional
SSP scenario ["SSP 3-7.0", "SSP 2-4.5","SSP 5-8.5"] and/or historical data selection ["Historical Climate", "Historical Reconstruction"]
If approach = "Time", you need to set a valid option
If approach = "Warming Level", scenario is ignored
units : str, optional
Variable units.
Defaults to native units of data
area_subset : str, optional
Area category: i.e "CA counties"
Defaults to entire domain ("none")
cached_area : list, optional
Area: i.e "Alameda county"
Defaults to entire domain (["entire domain"])
area_average : one of ["Yes","No"], optional
Take an average over spatial domain?
Default to "No".
latitude : None or tuple of float, optional
Tuple of valid latitude bounds
Default to entire domain
longitude : None or tuple of float, optional
Tuple of valid longitude bounds
Default to entire domain
time_slice : tuple, optional
Time range for retrieved data
Only valid for approach = "Time"
stations : list of str, optional
Which weather stations to retrieve data for
Only valid for data_type = "Stations"
Default to all stations
warming_level : list of float, optional
Must be one of the warming levels available in clmakitae.core.constants
Only valid for approach = "Warming Level" and data_type = "Stations"
warming_level_window : int in range (5,25), optional
Years around Global Warming Level (+/-)
(e.g. 15 means a 30yr window)
warming_level_months : list of int, optional
Months of year for which to perform warming level computation
Default to all months in a year: [1,2,3,4,5,6,7,8,9,10,11,12]
For example, you may want to set warming_level_months=[12,1,2] to perform the analysis for the winter season.
Only valid for approach = "Warming Level" and data_type = "Stations"
all_touched : boolean
spatial subset option for within or touching selection
enable_hidden_vars : boolean, optional
Return all variables, including the ones in which "show" is set to False?
Default to False
kwargs : dict
Additional keyword arguments to pass to DataParameters()
Returns
xr.DataArray The requested climate data, or None if an error occurred.
Notes
Errors aren't raised by the function. Rather, an appropriate informative message is printed, and the function returns None. This is due to the fact that the AE Jupyter Hub raises a strange Pieces Mismatch Error for some bad inputs; instead, that error is ignored and a more informative error message is printed instead.
Source code in climakitae/core/data_interface.py
1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 | |
Migration Note
For new code, use the modern climakitae.new_core interface. See the migration guide for detailed upgrade instructions.
Quick Example
Legacy (old):
from climakitae.core.data_interface import get_data, DataParameters
params = DataParameters()
params.variable = "Maximum air temperature at 2m"
params.time_slice = (2015, 2045) # year-range tuple
params.downscaling_method = "Statistical" # \u2248 LOCA2
params.resolution = "3 km" # \u2248 grid_label d03
params.timescale = "monthly" # \u2248 table_id "mon"
data = get_data(params)
Modern (new):