TempEst-NEXT 0.2.2__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.2 → tempest_next-0.2.3}/PKG-INFO +2 -2
- {tempest_next-0.2.2 → tempest_next-0.2.3}/README.md +1 -1
- {tempest_next-0.2.2 → tempest_next-0.2.3}/setup.cfg +1 -1
- tempest_next-0.2.3/src/NEXT/__init__.py +5 -0
- {tempest_next-0.2.2 → tempest_next-0.2.3}/src/NEXT/data.py +232 -0
- {tempest_next-0.2.2 → tempest_next-0.2.3}/src/TempEst_NEXT.egg-info/PKG-INFO +2 -2
- tempest_next-0.2.2/src/NEXT/__init__.py +0 -5
- {tempest_next-0.2.2 → tempest_next-0.2.3}/LICENSE +0 -0
- {tempest_next-0.2.2 → tempest_next-0.2.3}/pyproject.toml +0 -0
- {tempest_next-0.2.2 → tempest_next-0.2.3}/src/NEXT/__main__.py +0 -0
- {tempest_next-0.2.2 → tempest_next-0.2.3}/src/NEXT/coef_est.py +0 -0
- {tempest_next-0.2.2 → tempest_next-0.2.3}/src/NEXT/datatools.py +0 -0
- {tempest_next-0.2.2 → tempest_next-0.2.3}/src/NEXT/interactive.py +0 -0
- {tempest_next-0.2.2 → tempest_next-0.2.3}/src/NEXT/model.pickle +0 -0
- {tempest_next-0.2.2 → tempest_next-0.2.3}/src/NEXT/model_manager.py +0 -0
- {tempest_next-0.2.2 → tempest_next-0.2.3}/src/NEXT/reach_prep.py +0 -0
- {tempest_next-0.2.2 → tempest_next-0.2.3}/src/NEXT/wforecast.py +0 -0
- {tempest_next-0.2.2 → tempest_next-0.2.3}/src/TempEst_NEXT.egg-info/SOURCES.txt +0 -0
- {tempest_next-0.2.2 → tempest_next-0.2.3}/src/TempEst_NEXT.egg-info/dependency_links.txt +0 -0
- {tempest_next-0.2.2 → tempest_next-0.2.3}/src/TempEst_NEXT.egg-info/entry_points.txt +0 -0
- {tempest_next-0.2.2 → tempest_next-0.2.3}/src/TempEst_NEXT.egg-info/requires.txt +0 -0
- {tempest_next-0.2.2 → 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
|
|
@@ -130,4 +130,4 @@ NEXT will process an input dataset to estimate model coefficients and will then
|
|
|
130
130
|
|
|
131
131
|
If you use TempEst-NEXT in your research, please cite:
|
|
132
132
|
|
|
133
|
-
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.
|
|
@@ -92,4 +92,4 @@ NEXT will process an input dataset to estimate model coefficients and will then
|
|
|
92
92
|
|
|
93
93
|
If you use TempEst-NEXT in your research, please cite:
|
|
94
94
|
|
|
95
|
-
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
|
|
@@ -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
|
|
@@ -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
|
|
@@ -130,4 +130,4 @@ NEXT will process an input dataset to estimate model coefficients and will then
|
|
|
130
130
|
|
|
131
131
|
If you use TempEst-NEXT in your research, please cite:
|
|
132
132
|
|
|
133
|
-
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.
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|