TempEst-NEXT 0.1.6__tar.gz → 0.2.1__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.1.6 → tempest_next-0.2.1}/PKG-INFO +7 -1
- {tempest_next-0.1.6 → tempest_next-0.2.1}/README.md +6 -0
- {tempest_next-0.1.6 → tempest_next-0.2.1}/setup.cfg +6 -1
- tempest_next-0.2.1/src/NEXT/__init__.py +5 -0
- tempest_next-0.2.1/src/NEXT/__main__.py +10 -0
- {tempest_next-0.1.6 → tempest_next-0.2.1}/src/NEXT/coef_est.py +38 -38
- {tempest_next-0.1.6 → tempest_next-0.2.1}/src/NEXT/data.py +3 -3
- tempest_next-0.2.1/src/NEXT/interactive.py +176 -0
- {tempest_next-0.1.6 → tempest_next-0.2.1}/src/TempEst_NEXT.egg-info/PKG-INFO +7 -1
- {tempest_next-0.1.6 → tempest_next-0.2.1}/src/TempEst_NEXT.egg-info/SOURCES.txt +3 -0
- tempest_next-0.2.1/src/TempEst_NEXT.egg-info/entry_points.txt +3 -0
- tempest_next-0.1.6/src/NEXT/__init__.py +0 -2
- {tempest_next-0.1.6 → tempest_next-0.2.1}/LICENSE +0 -0
- {tempest_next-0.1.6 → tempest_next-0.2.1}/pyproject.toml +0 -0
- {tempest_next-0.1.6 → tempest_next-0.2.1}/src/NEXT/datatools.py +0 -0
- {tempest_next-0.1.6 → tempest_next-0.2.1}/src/NEXT/model_manager.py +0 -0
- {tempest_next-0.1.6 → tempest_next-0.2.1}/src/NEXT/reach_prep.py +0 -0
- {tempest_next-0.1.6 → tempest_next-0.2.1}/src/NEXT/wforecast.py +0 -0
- {tempest_next-0.1.6 → tempest_next-0.2.1}/src/TempEst_NEXT.egg-info/dependency_links.txt +0 -0
- {tempest_next-0.1.6 → tempest_next-0.2.1}/src/TempEst_NEXT.egg-info/requires.txt +0 -0
- {tempest_next-0.1.6 → tempest_next-0.2.1}/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.1
|
|
3
|
+
Version: 0.2.1
|
|
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,12 @@ 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
|
+
### Instant Command Line Use
|
|
56
|
+
|
|
57
|
+
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.)
|
|
58
|
+
|
|
59
|
+
You can also pre-specify arguments instead of providing them interactively, which also means you can automate large-scale NEXT runs through the command line (or high-performance computing jobs, etc). To see all arguments, run `tempest-next --help`.
|
|
60
|
+
|
|
55
61
|
### Data Preparation
|
|
56
62
|
|
|
57
63
|
TempEst-NEXT provides automatic tools for data retrieval, for example: `NEXT.data.full_data("-105.1235:40.5723", start="2020", end="2024", site_type="coordinates")`. You can also provide an input data frame. Required columns are `["id", "tmax", "prcp", "vp", "area", "elev_min", "elev", "slope", "wetland", "developed", "ice_snow", "water", "canopy", "ws_canopy", "date", "day"]`, with the addition of a "temperature" column if you wish to train a model.
|
|
@@ -14,6 +14,12 @@ 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
|
+
### Instant Command Line Use
|
|
18
|
+
|
|
19
|
+
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.)
|
|
20
|
+
|
|
21
|
+
You can also pre-specify arguments instead of providing them interactively, which also means you can automate large-scale NEXT runs through the command line (or high-performance computing jobs, etc). To see all arguments, run `tempest-next --help`.
|
|
22
|
+
|
|
17
23
|
### Data Preparation
|
|
18
24
|
|
|
19
25
|
TempEst-NEXT provides automatic tools for data retrieval, for example: `NEXT.data.full_data("-105.1235:40.5723", start="2020", end="2024", site_type="coordinates")`. You can also provide an input data frame. Required columns are `["id", "tmax", "prcp", "vp", "area", "elev_min", "elev", "slope", "wetland", "developed", "ice_snow", "water", "canopy", "ws_canopy", "date", "day"]`, with the addition of a "temperature" column if you wish to train a model.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[metadata]
|
|
2
2
|
name = TempEst-NEXT
|
|
3
|
-
version = 0.1
|
|
3
|
+
version = 0.2.1
|
|
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
|
|
@@ -49,6 +49,11 @@ where = src
|
|
|
49
49
|
[options.package_data]
|
|
50
50
|
* = *.pickle
|
|
51
51
|
|
|
52
|
+
[options.entry_points]
|
|
53
|
+
console_scripts =
|
|
54
|
+
tempest-next = NEXT:cmdrun
|
|
55
|
+
NEXT = NEXT:cmdrun
|
|
56
|
+
|
|
52
57
|
[egg_info]
|
|
53
58
|
tag_build =
|
|
54
59
|
tag_date = 0
|
|
@@ -56,52 +56,52 @@ def preprocess(data, allow_no_id=True):
|
|
|
56
56
|
return predictors
|
|
57
57
|
|
|
58
58
|
var_sets = [
|
|
59
|
-
{"name": "PCA0", "vars": ['tmax', 'prcp', 'vp', '
|
|
60
|
-
{"name": "PCA1", "vars": ['tmax', '
|
|
61
|
-
{"name": "PCA2", "vars": ['tmax', '
|
|
62
|
-
{"name": "PCA3", "vars": ['tmax', '
|
|
63
|
-
{"name": "PCA4", "vars": ['tmax', '
|
|
64
|
-
{"name": "PCA5", "vars": ['tmax', '
|
|
59
|
+
{"name": "PCA0", "vars": ['tmax', 'prcp', 'vp', 'ice_snow', 'water', 'snowfrac', 'vp_sd', 'prcp_index', 'tmax_phi', 'elev', 'frozen', 'tmax_index', 'canopy', 'ws_canopy'], "eq": s(0) + s(1) + s(2) + s(3) + s(4) + s(5) + s(6) + s(7) + s(8) + s(9) + te(10, 11) + te(12, 13), "lam": 30, "noise": 0.818, "scale": 1.19},
|
|
60
|
+
{"name": "PCA1", "vars": ['tmax', 'prcp', 'vp', 'vp_sd', 'prcp_index', 'tmax_phi', 'elev_min', 'frozen', 'tmax_index'], "eq": s(0) + s(1) + s(2) + s(3) + s(4) + s(5) + s(6) + te(7, 8), "lam": 3, "noise": 0.501, "scale": 1.13},
|
|
61
|
+
{"name": "PCA2", "vars": ['tmax', 'prcp', 'wetland', 'water', 'snowfrac', 'vp_sd', 'prcp_index', 'tmax_phi', 'elev', 'ws_canopy', 'frozen', 'tmax_index'], "eq": s(0) + s(1) + s(2) + s(3) + s(4) + s(5) + s(6) + s(7) + s(8) + s(9) + te(10, 11), "lam": 21, "noise": 0.622, "scale": 1.45},
|
|
62
|
+
{"name": "PCA3", "vars": ['tmax', 'ice_snow', 'snowfrac', 'tmax_index', 'elev_min', 'canopy', 'ws_canopy'], "eq": s(0) + s(1) + s(2) + s(3) + s(4) + te(5, 6), "lam": 4, "noise": 0.555, "scale": 1.52},
|
|
63
|
+
{"name": "PCA4", "vars": ['tmax', 'prcp', 'vp', 'area', 'wetland', 'snowfrac', 'vp_sd', 'tmax_index', 'elev', 'elev_min'], "eq": s(0) + s(1) + s(2) + s(3) + s(4) + s(5) + s(6) + s(7) + te(8, 9), "lam": 30, "noise": 0.601, "scale": 1.86},
|
|
64
|
+
{"name": "PCA5", "vars": ['tmax', 'vp', 'area', 'vp_sd', 'prcp_phi', 'tmax_phi', 'elev_min', 'ws_canopy', 'frozen', 'tmax_index'], "eq": s(0) + s(1) + s(2) + s(3) + s(4) + s(5) + s(6) + s(7) + te(8, 9), "lam": 3, "noise": 0.248, "scale": 1.28},
|
|
65
65
|
]
|
|
66
66
|
|
|
67
67
|
coef_names = ["PCA" + str(i) for i in range(9)]
|
|
68
68
|
col_order = ['Intercept', 'Amplitude', 'FallDay', 'WinterDay', 'SpringDay',
|
|
69
69
|
'SummerDay', 'SpringSummer', 'FallWinter', 'at_coef']
|
|
70
|
-
offset = pd.Series([
|
|
71
|
-
|
|
72
|
-
0.
|
|
70
|
+
offset = pd.Series([ 13.0056967 , 8.20795656, 326.31318681, 74.14044198,
|
|
71
|
+
156.8 , 214.73186813, 0.58916219, 1.84876426,
|
|
72
|
+
0.72359814],
|
|
73
73
|
index=col_order)
|
|
74
|
-
scale = pd.Series([ 3.
|
|
75
|
-
1. ,
|
|
74
|
+
scale = pd.Series([ 3.99160561, 3.43586619, 1. , 25.38558154, 1. ,
|
|
75
|
+
1. , 1.20308955, 1.52486907, 0.50466527],
|
|
76
76
|
index=col_order)
|
|
77
77
|
|
|
78
|
-
pca_components = np.array([[
|
|
79
|
-
|
|
80
|
-
-
|
|
81
|
-
[
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
[-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
[
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
[
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
[-
|
|
94
|
-
-1.
|
|
95
|
-
-
|
|
96
|
-
[
|
|
97
|
-
-
|
|
98
|
-
|
|
99
|
-
[
|
|
100
|
-
-1.
|
|
101
|
-
|
|
102
|
-
[-
|
|
103
|
-
|
|
104
|
-
|
|
78
|
+
pca_components = np.array([[ 3.41756961e-01, -2.61355435e-01, -5.55111512e-17,
|
|
79
|
+
4.20259492e-01, 1.73472348e-18, 3.12560562e-30,
|
|
80
|
+
-3.63303205e-01, 4.70312769e-01, 5.33942091e-01],
|
|
81
|
+
[ 4.71762540e-01, 6.30409106e-01, 1.11022302e-16,
|
|
82
|
+
1.92012911e-01, -0.00000000e+00, 2.16840434e-19,
|
|
83
|
+
-4.64511826e-01, -1.61613840e-01, -3.18221994e-01],
|
|
84
|
+
[-3.87150503e-01, 3.94110963e-01, -1.11022302e-16,
|
|
85
|
+
-4.69134836e-01, 0.00000000e+00, -2.29213584e-29,
|
|
86
|
+
-3.07138668e-01, 6.13781957e-01, 6.03414407e-02],
|
|
87
|
+
[ 6.89037889e-01, 2.42842441e-02, -1.38777878e-16,
|
|
88
|
+
-6.16784244e-01, -5.55111512e-17, 6.93889390e-18,
|
|
89
|
+
3.14530607e-01, 8.58458389e-02, 1.94718384e-01],
|
|
90
|
+
[-3.22430482e-02, 5.40764079e-01, 1.73472348e-17,
|
|
91
|
+
4.14137910e-01, -0.00000000e+00, 1.11022302e-16,
|
|
92
|
+
6.59558509e-01, 2.61545280e-01, 1.77766779e-01],
|
|
93
|
+
[-1.86933003e-01, 2.93153083e-01, 1.66533454e-16,
|
|
94
|
+
-1.20384780e-01, 0.00000000e+00, -1.73472348e-18,
|
|
95
|
+
-1.54785186e-01, -5.47889709e-01, 7.35175653e-01],
|
|
96
|
+
[ 2.34342554e-18, -1.11613983e-16, 5.53604827e-02,
|
|
97
|
+
-7.70407156e-17, 1.84730811e-02, 9.98295529e-01,
|
|
98
|
+
-1.31345009e-16, -5.62176760e-17, -3.77791731e-17],
|
|
99
|
+
[ 4.39134634e-17, -6.00026241e-17, 9.97848118e-01,
|
|
100
|
+
-1.55562006e-16, 3.41576381e-02, -5.59677458e-02,
|
|
101
|
+
3.23505183e-17, 7.93158315e-17, 5.34770085e-17],
|
|
102
|
+
[-2.19955299e-18, -1.44874609e-17, -3.51333141e-02,
|
|
103
|
+
3.71401416e-17, 9.99245716e-01, -1.65423459e-02,
|
|
104
|
+
1.85164759e-17, -1.66091718e-17, -4.95729384e-18]])
|
|
105
105
|
|
|
106
106
|
|
|
107
107
|
def build_model_from_data(tr_data):
|
|
@@ -438,7 +438,7 @@ def merit_geom(merit_id):
|
|
|
438
438
|
# I don't know if this is straightforwardly doable, but useful for non-CONUS.
|
|
439
439
|
pass
|
|
440
440
|
|
|
441
|
-
geom_fns = {"usgs": gage_geom,
|
|
441
|
+
geom_fns = {"usgs": gage_geom,
|
|
442
442
|
"coordinates": watershed_geom}
|
|
443
443
|
|
|
444
444
|
# Weather requirements: date, tmax, prcp, vp
|
|
@@ -550,7 +550,7 @@ def weather_gfs(geom, start, end):
|
|
|
550
550
|
|
|
551
551
|
# HRRR can be used for prediction, but not to build coefficient estimation weather,
|
|
552
552
|
# as HRRR-Zarr doesn't have srad.
|
|
553
|
-
weather_fns = {"daymet": weather_daymet, "nldas": weather_nldas,
|
|
553
|
+
weather_fns = {#"daymet": weather_daymet, "nldas": weather_nldas,
|
|
554
554
|
"gfs": weather_gfs, "hrrr": weather_hrrr, "gridmet": weather_gridmet,
|
|
555
555
|
"gefs": weather_gefs}
|
|
556
556
|
|
|
@@ -629,7 +629,7 @@ def topo_3dep(geom, area):
|
|
|
629
629
|
def topo_merit(geom):
|
|
630
630
|
pass
|
|
631
631
|
|
|
632
|
-
topo_fns = {"3dep": topo_3dep
|
|
632
|
+
topo_fns = {"3dep": topo_3dep}
|
|
633
633
|
|
|
634
634
|
def obs_usgs(usgs_id, start, end):
|
|
635
635
|
# Observed temperature
|
|
@@ -0,0 +1,176 @@
|
|
|
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
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: TempEst-NEXT
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
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,12 @@ 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
|
+
### Instant Command Line Use
|
|
56
|
+
|
|
57
|
+
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.)
|
|
58
|
+
|
|
59
|
+
You can also pre-specify arguments instead of providing them interactively, which also means you can automate large-scale NEXT runs through the command line (or high-performance computing jobs, etc). To see all arguments, run `tempest-next --help`.
|
|
60
|
+
|
|
55
61
|
### Data Preparation
|
|
56
62
|
|
|
57
63
|
TempEst-NEXT provides automatic tools for data retrieval, for example: `NEXT.data.full_data("-105.1235:40.5723", start="2020", end="2024", site_type="coordinates")`. You can also provide an input data frame. Required columns are `["id", "tmax", "prcp", "vp", "area", "elev_min", "elev", "slope", "wetland", "developed", "ice_snow", "water", "canopy", "ws_canopy", "date", "day"]`, with the addition of a "temperature" column if you wish to train a model.
|
|
@@ -3,14 +3,17 @@ README.md
|
|
|
3
3
|
pyproject.toml
|
|
4
4
|
setup.cfg
|
|
5
5
|
src/NEXT/__init__.py
|
|
6
|
+
src/NEXT/__main__.py
|
|
6
7
|
src/NEXT/coef_est.py
|
|
7
8
|
src/NEXT/data.py
|
|
8
9
|
src/NEXT/datatools.py
|
|
10
|
+
src/NEXT/interactive.py
|
|
9
11
|
src/NEXT/model_manager.py
|
|
10
12
|
src/NEXT/reach_prep.py
|
|
11
13
|
src/NEXT/wforecast.py
|
|
12
14
|
src/TempEst_NEXT.egg-info/PKG-INFO
|
|
13
15
|
src/TempEst_NEXT.egg-info/SOURCES.txt
|
|
14
16
|
src/TempEst_NEXT.egg-info/dependency_links.txt
|
|
17
|
+
src/TempEst_NEXT.egg-info/entry_points.txt
|
|
15
18
|
src/TempEst_NEXT.egg-info/requires.txt
|
|
16
19
|
src/TempEst_NEXT.egg-info/top_level.txt
|
|
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
|