TempEst-NEXT 0.2.1__tar.gz → 0.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {tempest_next-0.2.1 → tempest_next-0.2.3}/PKG-INFO +6 -2
- {tempest_next-0.2.1 → tempest_next-0.2.3}/README.md +5 -1
- {tempest_next-0.2.1 → tempest_next-0.2.3}/setup.cfg +3 -1
- tempest_next-0.2.3/src/NEXT/__init__.py +5 -0
- tempest_next-0.2.3/src/NEXT/__main__.py +15 -0
- {tempest_next-0.2.1 → tempest_next-0.2.3}/src/NEXT/data.py +232 -0
- tempest_next-0.2.3/src/NEXT/interactive.py +303 -0
- tempest_next-0.2.3/src/NEXT/model.pickle +0 -0
- {tempest_next-0.2.1 → tempest_next-0.2.3}/src/TempEst_NEXT.egg-info/PKG-INFO +6 -2
- {tempest_next-0.2.1 → tempest_next-0.2.3}/src/TempEst_NEXT.egg-info/SOURCES.txt +1 -0
- {tempest_next-0.2.1 → tempest_next-0.2.3}/src/TempEst_NEXT.egg-info/entry_points.txt +3 -0
- tempest_next-0.2.1/src/NEXT/__init__.py +0 -5
- tempest_next-0.2.1/src/NEXT/__main__.py +0 -10
- tempest_next-0.2.1/src/NEXT/interactive.py +0 -176
- {tempest_next-0.2.1 → tempest_next-0.2.3}/LICENSE +0 -0
- {tempest_next-0.2.1 → tempest_next-0.2.3}/pyproject.toml +0 -0
- {tempest_next-0.2.1 → tempest_next-0.2.3}/src/NEXT/coef_est.py +0 -0
- {tempest_next-0.2.1 → tempest_next-0.2.3}/src/NEXT/datatools.py +0 -0
- {tempest_next-0.2.1 → tempest_next-0.2.3}/src/NEXT/model_manager.py +0 -0
- {tempest_next-0.2.1 → tempest_next-0.2.3}/src/NEXT/reach_prep.py +0 -0
- {tempest_next-0.2.1 → tempest_next-0.2.3}/src/NEXT/wforecast.py +0 -0
- {tempest_next-0.2.1 → tempest_next-0.2.3}/src/TempEst_NEXT.egg-info/dependency_links.txt +0 -0
- {tempest_next-0.2.1 → tempest_next-0.2.3}/src/TempEst_NEXT.egg-info/requires.txt +0 -0
- {tempest_next-0.2.1 → tempest_next-0.2.3}/src/TempEst_NEXT.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: TempEst-NEXT
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: TempEst-NEXT, Stream Temperature Estimation - Near-term Expected Temperatures: a statistical stream temperature model with coefficient estimation for ungaged watersheds
|
|
5
5
|
Home-page: https://rivertempest.org/next/readme.html
|
|
6
6
|
Author: Daniel Philippus
|
|
@@ -52,6 +52,10 @@ Install from PyPI: `pip install tempest-next`. The installed module is called N
|
|
|
52
52
|
|
|
53
53
|
Dependencies: pandas, numpy>=2, TempEst-NEWT, pygam>=0.10, pydaymet>=0.19, pynldas2, dataretrieval, geopandas, pynhd>=0.19, pygeohydro, py3dep, xarray-spatial, s3fs, zarr, cartopy, metpy, getgfs, dask
|
|
54
54
|
|
|
55
|
+
### GUI
|
|
56
|
+
|
|
57
|
+
`NEXTapp` or `NEXT --gui` launches a graphical interface.
|
|
58
|
+
|
|
55
59
|
### Instant Command Line Use
|
|
56
60
|
|
|
57
61
|
All of the below requirements are automated under certain assumptions and can be used directly through the command line or interactive use. After installing TempEst-NEXT as above, just open a terminal/command line and run: `tempest-next` (or `NEXT`, or, if those aren't on your path, `python -m NEXT`). This will interactively request all required information to automatically run the model for a given site (currently, pour point coordinates or a USGS gage ID), including forecasts. (Note that forecast data retrieval is rather slow, and the model does need at least a few years of data to predict well. Future updates will include the option to combine forecast data with climatology-adjusted historical estimates, which are much faster to retrieve.)
|
|
@@ -126,4 +130,4 @@ NEXT will process an input dataset to estimate model coefficients and will then
|
|
|
126
130
|
|
|
127
131
|
If you use TempEst-NEXT in your research, please cite:
|
|
128
132
|
|
|
129
|
-
Philippus, Corona and Hogue.
|
|
133
|
+
Philippus, D., C. R. Corona, and T. S. Hogue. 2026. “Daily Stream Water Temperature Modeling and Forecasting for Ungaged Watersheds at the CONUS Scale.” Journal of Hydrology. https://doi.org/10.1016/j.jhydrol.2026.135620.
|
|
@@ -14,6 +14,10 @@ Install from PyPI: `pip install tempest-next`. The installed module is called N
|
|
|
14
14
|
|
|
15
15
|
Dependencies: pandas, numpy>=2, TempEst-NEWT, pygam>=0.10, pydaymet>=0.19, pynldas2, dataretrieval, geopandas, pynhd>=0.19, pygeohydro, py3dep, xarray-spatial, s3fs, zarr, cartopy, metpy, getgfs, dask
|
|
16
16
|
|
|
17
|
+
### GUI
|
|
18
|
+
|
|
19
|
+
`NEXTapp` or `NEXT --gui` launches a graphical interface.
|
|
20
|
+
|
|
17
21
|
### Instant Command Line Use
|
|
18
22
|
|
|
19
23
|
All of the below requirements are automated under certain assumptions and can be used directly through the command line or interactive use. After installing TempEst-NEXT as above, just open a terminal/command line and run: `tempest-next` (or `NEXT`, or, if those aren't on your path, `python -m NEXT`). This will interactively request all required information to automatically run the model for a given site (currently, pour point coordinates or a USGS gage ID), including forecasts. (Note that forecast data retrieval is rather slow, and the model does need at least a few years of data to predict well. Future updates will include the option to combine forecast data with climatology-adjusted historical estimates, which are much faster to retrieve.)
|
|
@@ -88,4 +92,4 @@ NEXT will process an input dataset to estimate model coefficients and will then
|
|
|
88
92
|
|
|
89
93
|
If you use TempEst-NEXT in your research, please cite:
|
|
90
94
|
|
|
91
|
-
Philippus, Corona and Hogue.
|
|
95
|
+
Philippus, D., C. R. Corona, and T. S. Hogue. 2026. “Daily Stream Water Temperature Modeling and Forecasting for Ungaged Watersheds at the CONUS Scale.” Journal of Hydrology. https://doi.org/10.1016/j.jhydrol.2026.135620.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[metadata]
|
|
2
2
|
name = TempEst-NEXT
|
|
3
|
-
version = 0.2.
|
|
3
|
+
version = 0.2.3
|
|
4
4
|
author = Daniel Philippus
|
|
5
5
|
author_email = daniel@dphilippus.com
|
|
6
6
|
description = TempEst-NEXT, Stream Temperature Estimation - Near-term Expected Temperatures: a statistical stream temperature model with coefficient estimation for ungaged watersheds
|
|
@@ -53,6 +53,8 @@ where = src
|
|
|
53
53
|
console_scripts =
|
|
54
54
|
tempest-next = NEXT:cmdrun
|
|
55
55
|
NEXT = NEXT:cmdrun
|
|
56
|
+
gui_scripts =
|
|
57
|
+
NEXTapp = NEXT:gui
|
|
56
58
|
|
|
57
59
|
[egg_info]
|
|
58
60
|
tag_build =
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
Created on Thu Jun 11 09:35:04 2026
|
|
5
|
+
|
|
6
|
+
@author: daniel
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from NEXT.interactive import cmdrun, gui
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
if len(sys.argv) > 1 and sys.argv[1] == "--gui":
|
|
13
|
+
gui()
|
|
14
|
+
else:
|
|
15
|
+
cmdrun()
|
|
@@ -39,6 +39,7 @@ import NEXT.wforecast as wfc
|
|
|
39
39
|
import warnings
|
|
40
40
|
import os
|
|
41
41
|
import rioxarray
|
|
42
|
+
from queue import SimpleQueue
|
|
42
43
|
|
|
43
44
|
tid = "10343500"
|
|
44
45
|
nldi_inst = [None]
|
|
@@ -392,6 +393,8 @@ def buffer(data, buffer):
|
|
|
392
393
|
def get_area(geom):
|
|
393
394
|
return geom.to_crs(projstr).area.rename("area").iloc[0]
|
|
394
395
|
|
|
396
|
+
|
|
397
|
+
|
|
395
398
|
def gage_geom(usgs_id: str):
|
|
396
399
|
"""Get geometry associated with USGS gage ID.
|
|
397
400
|
|
|
@@ -660,11 +663,13 @@ def geom_full_data(site, site_type, geom, lat, lon, area, start, end,
|
|
|
660
663
|
# just use watershed canopy as riparian canopy.
|
|
661
664
|
weather_fn = weather_fns[weather]
|
|
662
665
|
obs_fn = obs_fns[obs] if obs is not None else None
|
|
666
|
+
init_name = site
|
|
663
667
|
if site_type not in ["usgs", "comid", "coordinates"]:
|
|
664
668
|
# For weird stuff like geopackage, just switch it to the coordinates
|
|
665
669
|
site = f"{lon}:{lat}"
|
|
666
670
|
site_type = "coordinates"
|
|
667
671
|
statics = geom_static_data(site, site_type, geom, lat, lon, area)
|
|
672
|
+
statics['id'] = init_name
|
|
668
673
|
if len(start) > 4:
|
|
669
674
|
dynamics = weather_fn(geom, start, end)
|
|
670
675
|
fyr = pd.to_datetime(start).year
|
|
@@ -779,3 +784,230 @@ def all_data_gpkg(path, start, end, weather="gridmet", lc="nlcd",
|
|
|
779
784
|
yield (k, geom_full_data(k, "geopackage", v[0], v[1], v[2], v[3], start, end, weather=weather, lc=lc, topo=topo))
|
|
780
785
|
except Exception as e:
|
|
781
786
|
yield (k, handler(k, v[0], e))
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
# mapping=
|
|
790
|
+
# 1 -> 2, 3, 4, 5, 6, 7, 8, 9, 10
|
|
791
|
+
# 2 -> 3
|
|
792
|
+
# 3 -> []
|
|
793
|
+
# 4 -> []
|
|
794
|
+
# 5 -> 6, 7, 8, 9, 10
|
|
795
|
+
# 6 -> 7, 8, 9, 10
|
|
796
|
+
# 7 -> []
|
|
797
|
+
# 8 -> 9, 10
|
|
798
|
+
# 9 -> 10
|
|
799
|
+
# 10 -> []
|
|
800
|
+
testnet_pairs = [
|
|
801
|
+
(10, 9),
|
|
802
|
+
(9, 8),
|
|
803
|
+
(8, 6),
|
|
804
|
+
(7, 6),
|
|
805
|
+
(6, 5),
|
|
806
|
+
(5, 1),
|
|
807
|
+
(4, 1),
|
|
808
|
+
(3, 2),
|
|
809
|
+
(2, 1)
|
|
810
|
+
]
|
|
811
|
+
|
|
812
|
+
def recurse_network(start, pairs, toset=None, cache={}, rlist=True):
|
|
813
|
+
"""
|
|
814
|
+
Recursively build the network for a given outflow watershed, also storing
|
|
815
|
+
all subnetworks for further analysis.
|
|
816
|
+
|
|
817
|
+
Parameters
|
|
818
|
+
----------
|
|
819
|
+
start : Any
|
|
820
|
+
Starting point ID.
|
|
821
|
+
pairs : list of tuples of 2, same type as start
|
|
822
|
+
(from, to) pairs.
|
|
823
|
+
toset : set of the same type as start, optional
|
|
824
|
+
All "to" values. Will be built if unspecified.
|
|
825
|
+
cache : dictionary, optional
|
|
826
|
+
All previously-built return dictionaries, if such exist.
|
|
827
|
+
rlist : Boolean, optional
|
|
828
|
+
Return a list? Otherwise, just the dictionary.
|
|
829
|
+
|
|
830
|
+
Returns
|
|
831
|
+
-------
|
|
832
|
+
tuple of (list, dictionary)
|
|
833
|
+
The list is all upstream watersheds, including start.
|
|
834
|
+
The dictionary is equivalent sets for each upstream watershed,
|
|
835
|
+
used to cache previous results. This excludes the watershed itself.
|
|
836
|
+
|
|
837
|
+
Notes
|
|
838
|
+
-----
|
|
839
|
+
While the concept is recursive, this is iterative in order to avoid
|
|
840
|
+
maxing out recursion depth for very large watersheds.
|
|
841
|
+
"""
|
|
842
|
+
if start in cache:
|
|
843
|
+
return (cache[start].union([start]), cache) if rlist else cache
|
|
844
|
+
if toset is None:
|
|
845
|
+
toset = set([x[1] for x in pairs])
|
|
846
|
+
if not start in toset:
|
|
847
|
+
# base case: it's not downstream of anything
|
|
848
|
+
ncache = {start: set()} | cache
|
|
849
|
+
return (set([start]), ncache) if rlist else ncache
|
|
850
|
+
upstreams = [p[0] for p in pairs if p[1] == start]
|
|
851
|
+
allup = set(upstreams)
|
|
852
|
+
outset = set(upstreams)
|
|
853
|
+
outdict = cache
|
|
854
|
+
# initial
|
|
855
|
+
downdict = {p[1]: set() for p in pairs} | {p[0]: set([p[1]]) for p in pairs}
|
|
856
|
+
# Build the full dictionary. How do we do this iteratively?
|
|
857
|
+
# We repeatedly pass over the dictionary until we run out of recursions.
|
|
858
|
+
# How do we make sure everything gets updated? Also build a downstream
|
|
859
|
+
# dictionary.
|
|
860
|
+
added = True
|
|
861
|
+
checked = set(cache)
|
|
862
|
+
while added:
|
|
863
|
+
added = False
|
|
864
|
+
newup = allup.copy()
|
|
865
|
+
for k in allup:
|
|
866
|
+
if k in outdict:
|
|
867
|
+
dorun = outdict[k].union([k])
|
|
868
|
+
else:
|
|
869
|
+
dorun = [k]
|
|
870
|
+
for it in dorun:
|
|
871
|
+
if it != k:
|
|
872
|
+
downdict[it].add(k)
|
|
873
|
+
newup.add(it)
|
|
874
|
+
if not it in checked:
|
|
875
|
+
added = True
|
|
876
|
+
if not it in outdict:
|
|
877
|
+
outdict[it] = set()
|
|
878
|
+
for p in pairs:
|
|
879
|
+
if p[1] == it:
|
|
880
|
+
outdict[k].add(p[0])
|
|
881
|
+
outdict[it].add(p[0])
|
|
882
|
+
newup.add(p[0])
|
|
883
|
+
for ds in downdict[it]:
|
|
884
|
+
if not ds in outdict:
|
|
885
|
+
outdict[ds] = set()
|
|
886
|
+
outdict[ds].add(p[0])
|
|
887
|
+
else:
|
|
888
|
+
outdict[k] = outdict[k].union(outdict[it])
|
|
889
|
+
checked.add(k)
|
|
890
|
+
allup = newup
|
|
891
|
+
|
|
892
|
+
# now update the set
|
|
893
|
+
for k in upstreams:
|
|
894
|
+
for itm in outdict[k]:
|
|
895
|
+
outset.add(itm)
|
|
896
|
+
outlist = list(outset)
|
|
897
|
+
outdict[start] = outset
|
|
898
|
+
outlist = [start] + outlist
|
|
899
|
+
return (outlist, outdict) if rlist else outdict
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
def wsweights(start, data: pd.DataFrame, mapping: dict, identifier: str = 'id',
|
|
903
|
+
indexOn: str = 'date',
|
|
904
|
+
useCols: list = ["tmax", "prcp", "vp",
|
|
905
|
+
"elev", "slope",
|
|
906
|
+
"wetland", "developed", "ice_snow", "water",
|
|
907
|
+
"ws_canopy"],
|
|
908
|
+
usePour: dict = ['elev_min', 'canopy'],
|
|
909
|
+
keepContext: bool = True) -> pd.DataFrame:
|
|
910
|
+
"""
|
|
911
|
+
Compute weighted upstream conditions for a specific watershed and upstream watersheds.
|
|
912
|
+
|
|
913
|
+
Parameters
|
|
914
|
+
----------
|
|
915
|
+
start : Any
|
|
916
|
+
ID of the watershed being solved for.
|
|
917
|
+
data : pd.DataFrame
|
|
918
|
+
Watershed input data containing identifier and indexOn columns. All other
|
|
919
|
+
columns should be numeric. Must contain an area column.
|
|
920
|
+
mapping : dict
|
|
921
|
+
Dictionary of watershed identifier --> [upstream watersheds].
|
|
922
|
+
identifier : str, optional
|
|
923
|
+
Name of the identifier column. The default is 'id'.
|
|
924
|
+
indexOn : str, optional
|
|
925
|
+
Name of the column to align on. The default is 'date'.
|
|
926
|
+
useCols : list of str, optional
|
|
927
|
+
Columns to compute weighted outputs for, excluding usePour and 'area'.
|
|
928
|
+
usePour : list, optional
|
|
929
|
+
Columns for which to just use the outlet watershed value.
|
|
930
|
+
The default is ['elev_min', 'canopy'].
|
|
931
|
+
keepContext : bool, optional
|
|
932
|
+
If true, merge back in anything that wasn't included.
|
|
933
|
+
|
|
934
|
+
Returns
|
|
935
|
+
-------
|
|
936
|
+
pd.DataFrame
|
|
937
|
+
Weighted input DataFrame.
|
|
938
|
+
"""
|
|
939
|
+
usews = mapping[start]
|
|
940
|
+
relevant = data.loc[data[identifier].isin(usews)]
|
|
941
|
+
totArea = relevant.groupby(identifier)['area'].mean().sum()
|
|
942
|
+
pours = (relevant.loc[relevant[identifier] == start].
|
|
943
|
+
groupby(indexOn)[usePour].mean())
|
|
944
|
+
pours[identifier] = start
|
|
945
|
+
doweight = relevant[[indexOn, 'area'] + useCols].copy()
|
|
946
|
+
for col in useCols:
|
|
947
|
+
doweight[col] = doweight[col] * doweight['area']
|
|
948
|
+
weighted = doweight.groupby(indexOn)[useCols].mean() / totArea
|
|
949
|
+
result = pours.join(weighted).assign(area = totArea).reset_index()
|
|
950
|
+
if keepContext:
|
|
951
|
+
return (data.loc[data[identifier] == start].drop(
|
|
952
|
+
columns=['area'] + usePour + useCols).merge(
|
|
953
|
+
result, on=[identifier, indexOn]))
|
|
954
|
+
return result
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
|
|
958
|
+
def multiwatershed(data: pd.DataFrame, tofrom: pd.DataFrame,
|
|
959
|
+
identifier: str = 'id', tocol: str = 'to',
|
|
960
|
+
build_only: bool = False, mapping: dict = None,
|
|
961
|
+
return_map: bool = False) -> pd.DataFrame:
|
|
962
|
+
"""
|
|
963
|
+
Converts an input dataset with nested watersheds (individually) into
|
|
964
|
+
an input dataset where downstream watersheds use area-weighted upstream inputs.
|
|
965
|
+
This allows larger watershed models to be efficiently built from smaller
|
|
966
|
+
ones.
|
|
967
|
+
|
|
968
|
+
Parameters
|
|
969
|
+
----------
|
|
970
|
+
data : pd.DataFrame
|
|
971
|
+
Input dataset with required predictor columns, e.g., the output from
|
|
972
|
+
full_data, for multiple sites.
|
|
973
|
+
tofrom : pd.DataFrame
|
|
974
|
+
DataFrame containing flow information. Required columns are the identifier
|
|
975
|
+
column and the tocol column. Column names specified by argument, defaults
|
|
976
|
+
"id" and "to".
|
|
977
|
+
identifier : str, optional
|
|
978
|
+
Site identifier column in tofrom. Default: "id".
|
|
979
|
+
tocol : str, optional
|
|
980
|
+
Column specifying where a watershed flows to in tofrom. Default: "to".
|
|
981
|
+
build_only : bool, optional
|
|
982
|
+
If true, just build and return the network (data is ignored).
|
|
983
|
+
mapping : dict, optional
|
|
984
|
+
Provide a pre-built mapping to avoid redoing a rather involved process.
|
|
985
|
+
return_map : bool, optional
|
|
986
|
+
If True, return the mapping as well as the data.
|
|
987
|
+
|
|
988
|
+
Returns
|
|
989
|
+
-------
|
|
990
|
+
pd.DataFrame
|
|
991
|
+
Like data, but switched to area-weighted setup for nesting.
|
|
992
|
+
"""
|
|
993
|
+
# First, we build a mapping from tofrom to decide what is included. We do
|
|
994
|
+
# this recursively, but need to be smart about caching.
|
|
995
|
+
toset = set(tofrom[tocol])
|
|
996
|
+
if mapping is None:
|
|
997
|
+
mapping = {}
|
|
998
|
+
pairs = list(tofrom[[identifier, tocol]].itertuples(index=False))
|
|
999
|
+
for ident in tofrom[identifier]:
|
|
1000
|
+
mapping = recurse_network(ident, pairs, toset, mapping, rlist=False)
|
|
1001
|
+
for k in mapping:
|
|
1002
|
+
mapping[k].add(k)
|
|
1003
|
+
if build_only:
|
|
1004
|
+
return mapping
|
|
1005
|
+
# mapping is now a dictionary of site identifier --> [upstream identifiers]
|
|
1006
|
+
# Now we can use wsweights to combine everything.
|
|
1007
|
+
res = pd.concat([
|
|
1008
|
+
wsweights(start, data, mapping)
|
|
1009
|
+
for start in data['id'].unique()
|
|
1010
|
+
])
|
|
1011
|
+
if return_map:
|
|
1012
|
+
return (mapping, res)
|
|
1013
|
+
return res
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
"""
|
|
4
|
+
Created on Wed Jun 10 12:05:09 2026
|
|
5
|
+
|
|
6
|
+
@author: Daniel Philippus
|
|
7
|
+
|
|
8
|
+
This module supports interactive and command-line use.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import urllib.request as request
|
|
12
|
+
import os
|
|
13
|
+
from NEXT import NEXT
|
|
14
|
+
import pickle
|
|
15
|
+
from NEXT import data
|
|
16
|
+
import pandas as pd
|
|
17
|
+
import argparse
|
|
18
|
+
import sys
|
|
19
|
+
import tkinter as tk
|
|
20
|
+
from tkinter.filedialog import asksaveasfilename
|
|
21
|
+
import matplotlib.pyplot as plt
|
|
22
|
+
|
|
23
|
+
next_url = "https://github.com/mines-ciroh/TempEst-NEXT/raw/refs/heads/master/coefs.pickle"
|
|
24
|
+
|
|
25
|
+
def get_model(cache=None, url=next_url, overwrite=False):
|
|
26
|
+
"""
|
|
27
|
+
Retrieve and return a pre-trained model.
|
|
28
|
+
|
|
29
|
+
Parameters
|
|
30
|
+
----------
|
|
31
|
+
cache : str, optional
|
|
32
|
+
If provided, retrieve from or write to a local file. The default is None.
|
|
33
|
+
url : str, optional
|
|
34
|
+
URL from which to retrieve model file. The default is next_url.
|
|
35
|
+
overwrite : bool, optional
|
|
36
|
+
Overwrite cached model if it exists. The default is False.
|
|
37
|
+
|
|
38
|
+
Returns
|
|
39
|
+
-------
|
|
40
|
+
NEXT.NEXT
|
|
41
|
+
The pre-trained model.
|
|
42
|
+
"""
|
|
43
|
+
# Check if a stored model exists
|
|
44
|
+
if not overwrite and cache is not None:
|
|
45
|
+
if os.path.exists(cache):
|
|
46
|
+
return NEXT.from_pickle(cache)
|
|
47
|
+
# No stored model.
|
|
48
|
+
req = request.urlopen(url)
|
|
49
|
+
model = pickle.loads(req.read())
|
|
50
|
+
req.close()
|
|
51
|
+
if cache is not None:
|
|
52
|
+
if overwrite or not os.path.exists(cache):
|
|
53
|
+
model.to_pickle(cache)
|
|
54
|
+
return model
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def iget(arg, query, options=None, default=None):
|
|
58
|
+
"""
|
|
59
|
+
Interactively update parameter if needed.
|
|
60
|
+
|
|
61
|
+
Parameters
|
|
62
|
+
----------
|
|
63
|
+
arg : str
|
|
64
|
+
Pre-specified value. Will only ask if arg is None.
|
|
65
|
+
query : str
|
|
66
|
+
What to ask the user for.
|
|
67
|
+
options : [str], optional
|
|
68
|
+
List of options for categorical questions. The default is None. Will
|
|
69
|
+
be set to all lowercase.
|
|
70
|
+
default : str, optional
|
|
71
|
+
The default option if user enters nothing. The default is None. If
|
|
72
|
+
None, it will just complain and ask again.
|
|
73
|
+
|
|
74
|
+
Returns
|
|
75
|
+
-------
|
|
76
|
+
str
|
|
77
|
+
New argument value.
|
|
78
|
+
"""
|
|
79
|
+
oq = query
|
|
80
|
+
if arg is not None:
|
|
81
|
+
return arg
|
|
82
|
+
if options is not None:
|
|
83
|
+
options = [x.lower() for x in options]
|
|
84
|
+
query = query + f" ({', '.join(options)})"
|
|
85
|
+
if default is not None:
|
|
86
|
+
query = query + f" [default: {default}]"
|
|
87
|
+
arg = input(query + ': ')
|
|
88
|
+
if not arg.strip():
|
|
89
|
+
if default is not None:
|
|
90
|
+
return default
|
|
91
|
+
print("Error: a value must be provided.")
|
|
92
|
+
return iget(None, oq, options, default)
|
|
93
|
+
if options is not None:
|
|
94
|
+
if arg.lower() in options:
|
|
95
|
+
return arg
|
|
96
|
+
print(f"Error: invalid answer {arg}")
|
|
97
|
+
return iget(None, oq, options, default)
|
|
98
|
+
return arg.lower()
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# Query, options, default. We separate these out as a dict so they are usable
|
|
102
|
+
# for multiple interaction modes.
|
|
103
|
+
descs = {
|
|
104
|
+
"site_type": ("Site type", list(data.geom_fns), None),
|
|
105
|
+
"site": ("Numeric site ID (no prefix; e.g., 10343500)", None, None),
|
|
106
|
+
"lat": ("Pour point latitude (Decimal degrees North, e.g. 40.623)", None, None),
|
|
107
|
+
"lon": ("Pour point longitude (Decimal degrees East, e.g. -120.1)", None, None),
|
|
108
|
+
"start": ("Start date (yyyy-mm-dd)", None, None),
|
|
109
|
+
"end": ("End date (yyyy-mm-dd)", None, None),
|
|
110
|
+
"weather": ("Weather data source", list(data.weather_fns), "gridmet"),
|
|
111
|
+
"model": ("Pre-trained model URL (optional)", None,
|
|
112
|
+
next_url),
|
|
113
|
+
"modpath": ("Pre-trained model cache file (optional)", None, "./model.pickle"),
|
|
114
|
+
"datafile": ("Location to cache input data (optional)", None, ""),
|
|
115
|
+
"output": ("Output file location", None, None)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def run(site_type=None, site=None, lat=None, lon=None, start=None, end=None,
|
|
120
|
+
weather=None, model=None, modpath=None, datafile=None, output=None):
|
|
121
|
+
# Validate inputs
|
|
122
|
+
site_type = iget(site_type, *descs['site_type'])
|
|
123
|
+
if site_type == 'coordinates':
|
|
124
|
+
lat = iget(lat, *descs['lat'])
|
|
125
|
+
lon = iget(lon, *descs['lon'])
|
|
126
|
+
site = lon + ":" + lat
|
|
127
|
+
else:
|
|
128
|
+
site = iget(site, *descs['site'])
|
|
129
|
+
start = iget(start, *descs['start'])
|
|
130
|
+
end = iget(end, *descs['end'])
|
|
131
|
+
weather = iget(weather, *descs['weather'])
|
|
132
|
+
model = iget(model, *descs['model'])
|
|
133
|
+
modpath = iget(modpath, *descs['modpath'])
|
|
134
|
+
datafile = iget(datafile, *descs['datafile'])
|
|
135
|
+
output = iget(output, *descs['output'])
|
|
136
|
+
# Actually run the model, retrieve data, etc
|
|
137
|
+
print("Retrieving model")
|
|
138
|
+
nxt = get_model(modpath, model, False)
|
|
139
|
+
print("Downloading prediction data")
|
|
140
|
+
if datafile and os.path.exists(datafile):
|
|
141
|
+
inpdata = pd.read_csv(datafile, parse_dates=['date'])
|
|
142
|
+
else:
|
|
143
|
+
inpdata = data.full_data(site, start, end, site_type=site_type,
|
|
144
|
+
weather=weather)
|
|
145
|
+
if datafile:
|
|
146
|
+
inpdata.to_csv(datafile)
|
|
147
|
+
print("Running model")
|
|
148
|
+
predictions = nxt.run(inpdata, reset=True)
|
|
149
|
+
print("Results preview")
|
|
150
|
+
print(predictions)
|
|
151
|
+
predictions.to_csv(output)
|
|
152
|
+
print(f"Done; results are in {output}")
|
|
153
|
+
return predictions
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class GUI(tk.Frame):
|
|
159
|
+
browse = {k: None for k in ['modpath', 'datafile', 'output']}
|
|
160
|
+
def __init__(self, master):
|
|
161
|
+
super().__init__(master)
|
|
162
|
+
self.master = master
|
|
163
|
+
self.pack()
|
|
164
|
+
self.setup()
|
|
165
|
+
def setup(self):
|
|
166
|
+
self.entries = {}
|
|
167
|
+
self.values = {}
|
|
168
|
+
self.createEntries()
|
|
169
|
+
def createEntries(self):
|
|
170
|
+
self.entryFrame = tk.Frame(self)
|
|
171
|
+
tk.Label(self.entryFrame, text="Note: lat/lon are only needed if site_type=coordinates")
|
|
172
|
+
self.gridFrame = tk.Frame(self.entryFrame)
|
|
173
|
+
for (ix, (name, (desc, opts, default))) in enumerate(descs.items()):
|
|
174
|
+
tk.Label(self.gridFrame, text=f"[{name}] " + desc + ":").grid(row=ix)
|
|
175
|
+
if opts is None:
|
|
176
|
+
self.entries[name] = tk.StringVar(self.master)
|
|
177
|
+
entry = tk.Entry(self.gridFrame, width=30, textvariable=self.entries[name])
|
|
178
|
+
entry.grid(row=ix, column=1)
|
|
179
|
+
if name in self.values and self.values[name] is not None:
|
|
180
|
+
# Keep previous value
|
|
181
|
+
self.entries[name].set(self.values[name])
|
|
182
|
+
if name in self.browse:
|
|
183
|
+
self.browse[name] = ix
|
|
184
|
+
else:
|
|
185
|
+
self.entries[name] = tk.StringVar(self.master)
|
|
186
|
+
if name in self.values:
|
|
187
|
+
self.entries[name].set(self.values[name])
|
|
188
|
+
else:
|
|
189
|
+
self.entries[name].set(opts[0] if default is None else default)
|
|
190
|
+
tk.OptionMenu(self.gridFrame, self.entries[name], *opts).grid(row=ix, column=1)
|
|
191
|
+
# For some reason, building the browse buttons with a for loop messes
|
|
192
|
+
# up the targets. We have to hard-code them.
|
|
193
|
+
def browseButton(row, target):
|
|
194
|
+
(tk.Button(self.gridFrame, text="Browse",
|
|
195
|
+
command=lambda: target.set(asksaveasfilename(confirmoverwrite=False))).
|
|
196
|
+
grid(row=row, column=2))
|
|
197
|
+
for k in self.browse:
|
|
198
|
+
browseButton(self.browse[k], self.entries[k])
|
|
199
|
+
self.gridFrame.pack()
|
|
200
|
+
tk.Button(self.entryFrame, text="Run [Note: GUI will become unresponsive until model run is complete]",
|
|
201
|
+
command=self.run).pack(side="bottom")
|
|
202
|
+
self.entryFrame.pack()
|
|
203
|
+
def run(self):
|
|
204
|
+
for (k, v) in self.entries.items():
|
|
205
|
+
self.values[k] = res if (res := v.get()) else descs[k][2]
|
|
206
|
+
self.entryFrame.destroy()
|
|
207
|
+
self.validate()
|
|
208
|
+
if self.ok:
|
|
209
|
+
self.resultFrame = tk.Frame(self)
|
|
210
|
+
tk.Label(self.resultFrame,
|
|
211
|
+
text=f"Done. Results are in {self.values['output']}. Args:").pack()
|
|
212
|
+
varGrid = tk.Frame(self.resultFrame)
|
|
213
|
+
for (ix, (k, v)) in enumerate(self.values.items()):
|
|
214
|
+
tk.Label(varGrid, text=k + ": ").grid(row=ix, column=0)
|
|
215
|
+
tk.Label(varGrid, text=v).grid(row=ix, column=1)
|
|
216
|
+
varGrid.pack()
|
|
217
|
+
def reset():
|
|
218
|
+
self.resultFrame.destroy()
|
|
219
|
+
self.createEntries()
|
|
220
|
+
tk.Button(self.resultFrame, text="Return", command=reset).pack()
|
|
221
|
+
self.resultFrame.pack()
|
|
222
|
+
result = run(**self.values)
|
|
223
|
+
fig, axes = plt.subplots(1, 2, layout='compressed',
|
|
224
|
+
figsize=(8, 6))
|
|
225
|
+
result.plot(x='date', y='prediction', ax=axes[0])
|
|
226
|
+
axes[0].set_xlabel('Date')
|
|
227
|
+
axes[0].set_ylabel('Mean Stream Temperature [degC]')
|
|
228
|
+
axes[0].set_title('Full Predicted Timeseries')
|
|
229
|
+
result.iloc[-30:].plot(x='date', y='prediction', ax=axes[1])
|
|
230
|
+
axes[1].set_xlabel('Date')
|
|
231
|
+
axes[1].set_title('Last 30 Days')
|
|
232
|
+
plt.show()
|
|
233
|
+
def validate(self):
|
|
234
|
+
# Check that all required inputs are present.
|
|
235
|
+
bad = False
|
|
236
|
+
missing = []
|
|
237
|
+
# Things that are unconditionally required
|
|
238
|
+
simple_mandatory = ["output", "start", "end"]
|
|
239
|
+
for entry in simple_mandatory:
|
|
240
|
+
if self.values[entry] is None:
|
|
241
|
+
bad = True
|
|
242
|
+
missing.append(entry)
|
|
243
|
+
if (self.values['site_type'] != 'coordinates' and
|
|
244
|
+
self.values['site'] is None):
|
|
245
|
+
bad = True
|
|
246
|
+
missing.append('site')
|
|
247
|
+
if (self.values['site_type'] == 'coordinates' and
|
|
248
|
+
(self.values['lat'] is None or self.values['lon'] is None)):
|
|
249
|
+
bad = True
|
|
250
|
+
missing.append('lat')
|
|
251
|
+
missing.append('lon')
|
|
252
|
+
self.ok = not bad
|
|
253
|
+
if bad:
|
|
254
|
+
# If not bad, we don't do anything.
|
|
255
|
+
def reentry():
|
|
256
|
+
self.missingFrame.destroy()
|
|
257
|
+
self.createEntries()
|
|
258
|
+
self.missingFrame = tk.Frame(self)
|
|
259
|
+
tk.Label(self.missingFrame,
|
|
260
|
+
text="Error: the following values are missing. Please "
|
|
261
|
+
"fill in all required fields.").pack()
|
|
262
|
+
for entry in missing:
|
|
263
|
+
tk.Label(self.missingFrame, text=f"{entry} ({descs[entry][0]})").pack()
|
|
264
|
+
tk.Button(self.missingFrame, text="OK - Return", command=reentry).pack()
|
|
265
|
+
self.missingFrame.pack()
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def parser():
|
|
269
|
+
ap = argparse.ArgumentParser(
|
|
270
|
+
description="TempEst-NEXT Command Line\n"
|
|
271
|
+
"Carry out full TempEst-NEXT model runs from the "
|
|
272
|
+
"terminal/command prompt with no code. "
|
|
273
|
+
"All arguments are optional, with missing values requested "
|
|
274
|
+
"interactively. Site ID and lat/lon are mutually exclusive ("
|
|
275
|
+
"lat/lon will be ignored if site ID is provided).\n"
|
|
276
|
+
"To launch a GUI instead, run NEXT --gui or NEXTapp")
|
|
277
|
+
for (name, (desc, opts, default)) in descs.items():
|
|
278
|
+
name = "--" + name
|
|
279
|
+
ap.add_argument(name, choices=opts, required=False, default=default,
|
|
280
|
+
help=desc)
|
|
281
|
+
return ap
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
def cmdrun():
|
|
285
|
+
if len(sys.argv) > 1 and sys.argv[1] == "--gui":
|
|
286
|
+
gui()
|
|
287
|
+
else:
|
|
288
|
+
args = parser().parse_args()
|
|
289
|
+
run(**vars(args))
|
|
290
|
+
sys.exit()
|
|
291
|
+
|
|
292
|
+
def gui():
|
|
293
|
+
mainframe = tk.Frame(tk.Tk())
|
|
294
|
+
gui = GUI(mainframe)
|
|
295
|
+
mainframe.master.title("TempEst-NEXT GUI")
|
|
296
|
+
mainframe.pack()
|
|
297
|
+
gui.mainloop()
|
|
298
|
+
|
|
299
|
+
# if __name__ == "__main__":
|
|
300
|
+
# # Test args
|
|
301
|
+
# # --site_type usgs --site 10343500 --start 2024-01-01 --end 2025-12-31 --modpath cache.pickle --datafile sagehen.csv --output sagehen_pred.csv
|
|
302
|
+
# cmdrun()
|
|
303
|
+
|
|
Binary file
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: TempEst-NEXT
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: TempEst-NEXT, Stream Temperature Estimation - Near-term Expected Temperatures: a statistical stream temperature model with coefficient estimation for ungaged watersheds
|
|
5
5
|
Home-page: https://rivertempest.org/next/readme.html
|
|
6
6
|
Author: Daniel Philippus
|
|
@@ -52,6 +52,10 @@ Install from PyPI: `pip install tempest-next`. The installed module is called N
|
|
|
52
52
|
|
|
53
53
|
Dependencies: pandas, numpy>=2, TempEst-NEWT, pygam>=0.10, pydaymet>=0.19, pynldas2, dataretrieval, geopandas, pynhd>=0.19, pygeohydro, py3dep, xarray-spatial, s3fs, zarr, cartopy, metpy, getgfs, dask
|
|
54
54
|
|
|
55
|
+
### GUI
|
|
56
|
+
|
|
57
|
+
`NEXTapp` or `NEXT --gui` launches a graphical interface.
|
|
58
|
+
|
|
55
59
|
### Instant Command Line Use
|
|
56
60
|
|
|
57
61
|
All of the below requirements are automated under certain assumptions and can be used directly through the command line or interactive use. After installing TempEst-NEXT as above, just open a terminal/command line and run: `tempest-next` (or `NEXT`, or, if those aren't on your path, `python -m NEXT`). This will interactively request all required information to automatically run the model for a given site (currently, pour point coordinates or a USGS gage ID), including forecasts. (Note that forecast data retrieval is rather slow, and the model does need at least a few years of data to predict well. Future updates will include the option to combine forecast data with climatology-adjusted historical estimates, which are much faster to retrieve.)
|
|
@@ -126,4 +130,4 @@ NEXT will process an input dataset to estimate model coefficients and will then
|
|
|
126
130
|
|
|
127
131
|
If you use TempEst-NEXT in your research, please cite:
|
|
128
132
|
|
|
129
|
-
Philippus, Corona and Hogue.
|
|
133
|
+
Philippus, D., C. R. Corona, and T. S. Hogue. 2026. “Daily Stream Water Temperature Modeling and Forecasting for Ungaged Watersheds at the CONUS Scale.” Journal of Hydrology. https://doi.org/10.1016/j.jhydrol.2026.135620.
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
"""
|
|
4
|
-
Created on Wed Jun 10 12:05:09 2026
|
|
5
|
-
|
|
6
|
-
@author: Daniel Philippus
|
|
7
|
-
|
|
8
|
-
This module supports interactive and command-line use.
|
|
9
|
-
"""
|
|
10
|
-
|
|
11
|
-
import urllib.request as request
|
|
12
|
-
import os
|
|
13
|
-
from NEXT import NEXT
|
|
14
|
-
import pickle
|
|
15
|
-
from NEXT import data
|
|
16
|
-
import pandas as pd
|
|
17
|
-
import argparse
|
|
18
|
-
import sys
|
|
19
|
-
|
|
20
|
-
next_url = "https://github.com/mines-ciroh/TempEst-NEXT/raw/refs/heads/master/coefs.pickle"
|
|
21
|
-
|
|
22
|
-
def get_model(cache=None, url=next_url, overwrite=False):
|
|
23
|
-
"""
|
|
24
|
-
Retrieve and return a pre-trained model.
|
|
25
|
-
|
|
26
|
-
Parameters
|
|
27
|
-
----------
|
|
28
|
-
cache : str, optional
|
|
29
|
-
If provided, retrieve from or write to a local file. The default is None.
|
|
30
|
-
url : str, optional
|
|
31
|
-
URL from which to retrieve model file. The default is next_url.
|
|
32
|
-
overwrite : bool, optional
|
|
33
|
-
Overwrite cached model if it exists. The default is False.
|
|
34
|
-
|
|
35
|
-
Returns
|
|
36
|
-
-------
|
|
37
|
-
NEXT.NEXT
|
|
38
|
-
The pre-trained model.
|
|
39
|
-
"""
|
|
40
|
-
# Check if a stored model exists
|
|
41
|
-
if not overwrite and cache is not None:
|
|
42
|
-
if os.path.exists(cache):
|
|
43
|
-
return NEXT.from_pickle(cache)
|
|
44
|
-
# No stored model.
|
|
45
|
-
req = request.urlopen(url)
|
|
46
|
-
model = pickle.loads(req.read())
|
|
47
|
-
req.close()
|
|
48
|
-
if cache is not None:
|
|
49
|
-
if overwrite or os.path.exists(cache):
|
|
50
|
-
model.to_pickle(cache)
|
|
51
|
-
return model
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def iget(arg, query, options=None, default=None):
|
|
55
|
-
"""
|
|
56
|
-
Interactively update parameter if needed.
|
|
57
|
-
|
|
58
|
-
Parameters
|
|
59
|
-
----------
|
|
60
|
-
arg : str
|
|
61
|
-
Pre-specified value. Will only ask if arg is None.
|
|
62
|
-
query : str
|
|
63
|
-
What to ask the user for.
|
|
64
|
-
options : [str], optional
|
|
65
|
-
List of options for categorical questions. The default is None. Will
|
|
66
|
-
be set to all lowercase.
|
|
67
|
-
default : str, optional
|
|
68
|
-
The default option if user enters nothing. The default is None. If
|
|
69
|
-
None, it will just complain and ask again.
|
|
70
|
-
|
|
71
|
-
Returns
|
|
72
|
-
-------
|
|
73
|
-
str
|
|
74
|
-
New argument value.
|
|
75
|
-
"""
|
|
76
|
-
oq = query
|
|
77
|
-
if arg is not None:
|
|
78
|
-
return arg
|
|
79
|
-
if options is not None:
|
|
80
|
-
options = [x.lower() for x in options]
|
|
81
|
-
query = query + f" ({', '.join(options)})"
|
|
82
|
-
if default is not None:
|
|
83
|
-
query = query + f" [default: {default}]"
|
|
84
|
-
arg = input(query + ': ')
|
|
85
|
-
if not arg.strip():
|
|
86
|
-
if default is not None:
|
|
87
|
-
return default
|
|
88
|
-
print("Error: a value must be provided.")
|
|
89
|
-
return iget(None, oq, options, default)
|
|
90
|
-
if options is not None:
|
|
91
|
-
if arg.lower() in options:
|
|
92
|
-
return arg
|
|
93
|
-
print(f"Error: invalid answer {arg}")
|
|
94
|
-
return iget(None, oq, options, default)
|
|
95
|
-
return arg.lower()
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
# Query, options, default. We separate these out as a dict so they are usable
|
|
99
|
-
# for multiple interaction modes.
|
|
100
|
-
descs = {
|
|
101
|
-
"site_type": ("Site type", list(data.geom_fns), None),
|
|
102
|
-
"site": ("Numeric site ID (no prefix; e.g., 10343500)", None, None),
|
|
103
|
-
"lat": ("Pour point latitude (Decimal degrees North, e.g. 40.623)", None, None),
|
|
104
|
-
"lon": ("Pour point longitude (Decimal degrees East, e.g. -120.1)", None, None),
|
|
105
|
-
"start": ("Start date (yyyy-mm-dd)", None, "2001-01-01"),
|
|
106
|
-
"end": ("End date (yyyy-mm-dd)", None, "2020-12-31"),
|
|
107
|
-
"weather": ("Weather data source", list(data.weather_fns), "gridmet"),
|
|
108
|
-
"model": ("Pre-trained model URL (optional)", None,
|
|
109
|
-
next_url),
|
|
110
|
-
"modpath": ("Pre-trained model cache file (optional)", None, "./model.pickle"),
|
|
111
|
-
"datafile": ("Location to cache input data (optional)", None, ""),
|
|
112
|
-
"output": ("Output file location", None, None)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
def run(site_type=None, site=None, lat=None, lon=None, start=None, end=None,
|
|
117
|
-
weather=None, model=None, modpath=None, datafile=None, output=None):
|
|
118
|
-
# Validate inputs
|
|
119
|
-
site_type = iget(site_type, *descs['site_type'])
|
|
120
|
-
if site_type == 'coordinates':
|
|
121
|
-
lat = iget(lat, *descs['lat'])
|
|
122
|
-
lon = iget(lon, *descs['lon'])
|
|
123
|
-
site = lon + ":" + lat
|
|
124
|
-
else:
|
|
125
|
-
site = iget(site, *descs['site'])
|
|
126
|
-
start = iget(start, *descs['start'])
|
|
127
|
-
end = iget(end, *descs['end'])
|
|
128
|
-
weather = iget(weather, *descs['weather'])
|
|
129
|
-
model = iget(model, *descs['model'])
|
|
130
|
-
modpath = iget(modpath, *descs['modpath'])
|
|
131
|
-
datafile = iget(datafile, *descs['datafile'])
|
|
132
|
-
output = iget(output, *descs['output'])
|
|
133
|
-
# Actually run the model, retrieve data, etc
|
|
134
|
-
print("Retrieving model")
|
|
135
|
-
nxt = get_model(modpath, model, False)
|
|
136
|
-
print("Downloading prediction data")
|
|
137
|
-
if datafile and os.path.exists(datafile):
|
|
138
|
-
inpdata = pd.read_csv(datafile, parse_dates=['date'])
|
|
139
|
-
else:
|
|
140
|
-
inpdata = data.full_data(site, start, end, site_type=site_type,
|
|
141
|
-
weather=weather)
|
|
142
|
-
if datafile:
|
|
143
|
-
inpdata.to_csv(datafile)
|
|
144
|
-
print("Running model")
|
|
145
|
-
predictions = nxt.run(inpdata, reset=True)
|
|
146
|
-
print("Results preview")
|
|
147
|
-
print(predictions)
|
|
148
|
-
predictions.to_csv(output)
|
|
149
|
-
print(f"Done; results are in {output}")
|
|
150
|
-
sys.exit()
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
def parser():
|
|
154
|
-
ap = argparse.ArgumentParser(
|
|
155
|
-
description="TempEst-NEXT Command Line\n"
|
|
156
|
-
"Carry out full TempEst-NEXT model runs from the "
|
|
157
|
-
"terminal/command prompt with no code. "
|
|
158
|
-
"All arguments are optional, with missing values requested "
|
|
159
|
-
"interactively. Site ID and lat/lon are mutually exclusive ("
|
|
160
|
-
"lat/lon will be ignored if site ID is provided).")
|
|
161
|
-
for (name, (desc, opts, default)) in descs.items():
|
|
162
|
-
name = "--" + name
|
|
163
|
-
ap.add_argument(name, choices=opts, required=False, default=default,
|
|
164
|
-
help=desc)
|
|
165
|
-
return ap
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
def cmdrun():
|
|
169
|
-
args = parser().parse_args()
|
|
170
|
-
run(**vars(args))
|
|
171
|
-
|
|
172
|
-
if __name__ == "__main__":
|
|
173
|
-
# Test args
|
|
174
|
-
# --site_type usgs --site 10343500 --start 2024-01-01 --end 2025-12-31 --modpath cache.pickle --datafile sagehen.csv --output sagehen_pred.csv
|
|
175
|
-
cmdrun()
|
|
176
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|