torchvic 0.4.9__py3-none-any.whl
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.
- torchvic/__init__.py +75 -0
- torchvic/__main__.py +6 -0
- torchvic/case.py +2077 -0
- torchvic/cli.py +421 -0
- torchvic/config.py +465 -0
- torchvic/core/__init__.py +5 -0
- torchvic/core/atmos.py +270 -0
- torchvic/core/blowing.py +444 -0
- torchvic/core/canopy.py +801 -0
- torchvic/core/carbon.py +719 -0
- torchvic/core/column.py +1394 -0
- torchvic/core/compact.py +523 -0
- torchvic/core/devconst.py +55 -0
- torchvic/core/diaglog.py +25 -0
- torchvic/core/energy.py +1017 -0
- torchvic/core/frozen.py +724 -0
- torchvic/core/fusion.py +876 -0
- torchvic/core/graphsafe.py +766 -0
- torchvic/core/implicit.py +624 -0
- torchvic/core/lake.py +3007 -0
- torchvic/core/newtc.py +1081 -0
- torchvic/core/ordered.py +105 -0
- torchvic/core/snow.py +1805 -0
- torchvic/core/snowbands.py +248 -0
- torchvic/core/soil.py +281 -0
- torchvic/core/soiltemp.py +1815 -0
- torchvic/core/tfallback.py +147 -0
- torchvic/core/treeline.py +173 -0
- torchvic/core/triton_stub.py +124 -0
- torchvic/core/vegetation.py +2124 -0
- torchvic/core/version.py +40 -0
- torchvic/core/xmath.py +162 -0
- torchvic/core/xscan.py +417 -0
- torchvic/core/xsum.py +136 -0
- torchvic/coupling/__init__.py +23 -0
- torchvic/coupling/connector.py +267 -0
- torchvic/coupling/connectors/__init__.py +13 -0
- torchvic/coupling/connectors/_combined.py +204 -0
- torchvic/coupling/connectors/common.py +75 -0
- torchvic/coupling/connectors/crop.py +831 -0
- torchvic/coupling/connectors/flood.py +1278 -0
- torchvic/coupling/connectors/groundwater.py +1304 -0
- torchvic/coupling/connectors/quality.py +324 -0
- torchvic/coupling/connectors/reservoir.py +336 -0
- torchvic/coupling/connectors/routing.py +463 -0
- torchvic/coupling/connectors/split.py +117 -0
- torchvic/coupling/connectors/vicwur_co2.py +128 -0
- torchvic/coupling/connectors/vicwur_common.py +561 -0
- torchvic/coupling/connectors/vicwur_crop.py +752 -0
- torchvic/coupling/connectors/vicwur_cropsyst.py +495 -0
- torchvic/coupling/connectors/vicwur_dams.py +419 -0
- torchvic/coupling/connectors/vicwur_efr.py +173 -0
- torchvic/coupling/connectors/vicwur_irrigation.py +566 -0
- torchvic/coupling/connectors/vicwur_landuse.py +476 -0
- torchvic/coupling/connectors/vicwur_nonrenew.py +159 -0
- torchvic/coupling/connectors/vicwur_routing.py +230 -0
- torchvic/coupling/connectors/vicwur_setup.py +448 -0
- torchvic/coupling/connectors/vicwur_wateruse_local.py +402 -0
- torchvic/coupling/connectors/vicwur_wateruse_remote.py +159 -0
- torchvic/coupling/connectors/wateruse.py +546 -0
- torchvic/coupling/graph.py +115 -0
- torchvic/coupling/hostfetch.py +77 -0
- torchvic/coupling/ledger.py +262 -0
- torchvic/coupling/managers.py +558 -0
- torchvic/coupling/registry.py +164 -0
- torchvic/coupling/runtime.py +1192 -0
- torchvic/coupling/schema.py +355 -0
- torchvic/coupling/spec.py +159 -0
- torchvic/coupling/toy.py +133 -0
- torchvic/coupling/vic.py +1621 -0
- torchvic/coupling/vic_session.py +171 -0
- torchvic/coupling/vic_stream.py +584 -0
- torchvic/crop/NOTICE_PCSE.txt +30 -0
- torchvic/crop/__init__.py +11 -0
- torchvic/crop/afgen.py +95 -0
- torchvic/crop/astro.py +60 -0
- torchvic/crop/bench.py +72 -0
- torchvic/crop/cropsyst/__init__.py +5 -0
- torchvic/crop/cropsyst/calendars.py +220 -0
- torchvic/crop/cropsyst/canopy.py +281 -0
- torchvic/crop/cropsyst/clip_kernel.py +102 -0
- torchvic/crop/cropsyst/clipping.py +946 -0
- torchvic/crop/cropsyst/daily.py +484 -0
- torchvic/crop/cropsyst/engine.py +775 -0
- torchvic/crop/cropsyst/fate_kernel.py +143 -0
- torchvic/crop/cropsyst/growth.py +225 -0
- torchvic/crop/cropsyst/irrigation.py +747 -0
- torchvic/crop/cropsyst/n_engine.py +787 -0
- torchvic/crop/cropsyst/n_management.py +233 -0
- torchvic/crop/cropsyst/nitrogen.py +631 -0
- torchvic/crop/cropsyst/om_kernels.py +902 -0
- torchvic/crop/cropsyst/orchard.py +666 -0
- torchvic/crop/cropsyst/orchard_arch.py +539 -0
- torchvic/crop/cropsyst/organic_matter.py +703 -0
- torchvic/crop/cropsyst/pet_short.py +42 -0
- torchvic/crop/cropsyst/phenology.py +705 -0
- torchvic/crop/cropsyst/ptf.py +71 -0
- torchvic/crop/cropsyst/readers.py +402 -0
- torchvic/crop/cropsyst/root.py +165 -0
- torchvic/crop/cropsyst/schema.py +701 -0
- torchvic/crop/cropsyst/sdr_field_ops.txt +489 -0
- torchvic/crop/cropsyst/soil_n.py +534 -0
- torchvic/crop/cropsyst/uptake.py +299 -0
- torchvic/crop/cropsyst/yield_.py +278 -0
- torchvic/crop/params.py +125 -0
- torchvic/crop/pcse_reference.py +230 -0
- torchvic/crop/run.py +48 -0
- torchvic/crop/waterbalance.py +201 -0
- torchvic/crop/wofost72.py +519 -0
- torchvic/crop/wofost_npk/__init__.py +14 -0
- torchvic/crop/wofost_npk/fuse.py +91 -0
- torchvic/crop/wofost_npk/kernel.py +2255 -0
- torchvic/crop/wofost_npk/leaf_kernels.py +363 -0
- torchvic/crop/wofost_npk/params.py +339 -0
- torchvic/data/vic42d_outvars.json +2006 -0
- torchvic/data/vic5_global_options.json +1471 -0
- torchvic/data/vic5_outvars.json +1493 -0
- torchvic/ensemble/__init__.py +7 -0
- torchvic/ensemble/assim.py +459 -0
- torchvic/ensemble/bench.py +96 -0
- torchvic/ensemble/members.py +95 -0
- torchvic/ensemble/perturb.py +154 -0
- torchvic/flood/__init__.py +27 -0
- torchvic/flood/dem.py +335 -0
- torchvic/flood/engine.py +870 -0
- torchvic/flood/multigpu.py +589 -0
- torchvic/flood/triton_step.py +2066 -0
- torchvic/forcing/__init__.py +3 -0
- torchvic/forcing/daily.py +519 -0
- torchvic/forcing/mtclim.py +631 -0
- torchvic/groundwater/__init__.py +7 -0
- torchvic/groundwater/grid.py +212 -0
- torchvic/groundwater/model.py +875 -0
- torchvic/groundwater/solver.py +97 -0
- torchvic/io/__init__.py +11 -0
- torchvic/io/async_history.py +115 -0
- torchvic/io/build.py +786 -0
- torchvic/io/classic.py +1326 -0
- torchvic/io/classic_to_image.py +691 -0
- torchvic/io/domain.py +225 -0
- torchvic/io/forcing.py +770 -0
- torchvic/io/global_param.py +388 -0
- torchvic/io/history.py +2716 -0
- torchvic/io/ncshare.py +92 -0
- torchvic/io/options.py +995 -0
- torchvic/io/params.py +383 -0
- torchvic/io/state_file.py +1134 -0
- torchvic/io/veghist.py +197 -0
- torchvic/metrics.py +177 -0
- torchvic/model/__init__.py +3 -0
- torchvic/model/basin.py +9580 -0
- torchvic/model/fastlaunch.py +63 -0
- torchvic/model/lakecell.py +654 -0
- torchvic/model/lanes.py +281 -0
- torchvic/model/outvars.py +403 -0
- torchvic/model/river_network.py +377 -0
- torchvic/model/routing.py +579 -0
- torchvic/model/routing_cascade.py +560 -0
- torchvic/model/routing_cascade_kernels.py +351 -0
- torchvic/model/routing_fast.py +114 -0
- torchvic/model/routing_kernels.py +395 -0
- torchvic/model/seqsum.py +165 -0
- torchvic/model/state.py +410 -0
- torchvic/model/tsum_kernel.py +161 -0
- torchvic/model/wbenergy.py +107 -0
- torchvic/parallel/__init__.py +6 -0
- torchvic/parallel/feed.py +198 -0
- torchvic/parallel/preread.py +120 -0
- torchvic/parallel/run.py +234 -0
- torchvic/parallel/shard.py +184 -0
- torchvic/progress.py +113 -0
- torchvic/quality/__init__.py +3 -0
- torchvic/quality/batch.py +98 -0
- torchvic/quality/heat.py +57 -0
- torchvic/quality/transport.py +420 -0
- torchvic/reservoir/__init__.py +6 -0
- torchvic/reservoir/data.py +136 -0
- torchvic/reservoir/system.py +473 -0
- torchvic/vicwur/__init__.py +1 -0
- torchvic/vicwur/balance.py +320 -0
- torchvic/vicwur/co2.py +174 -0
- torchvic/vicwur/core.py +558 -0
- torchvic/vicwur/crop_feedback.py +408 -0
- torchvic/vicwur/cs_core.py +123 -0
- torchvic/vicwur/cs_irrigation.py +167 -0
- torchvic/vicwur/dams.py +500 -0
- torchvic/vicwur/dams_kernels.py +232 -0
- torchvic/vicwur/efr.py +214 -0
- torchvic/vicwur/efr_kernels.py +103 -0
- torchvic/vicwur/forcing.py +342 -0
- torchvic/vicwur/fused.py +9 -0
- torchvic/vicwur/groundwater.py +337 -0
- torchvic/vicwur/irrigation.py +308 -0
- torchvic/vicwur/landuse.py +769 -0
- torchvic/vicwur/nonrenew.py +313 -0
- torchvic/vicwur/order.py +428 -0
- torchvic/vicwur/params.py +852 -0
- torchvic/vicwur/river_exchange.py +148 -0
- torchvic/vicwur/river_exchange_kernels.py +80 -0
- torchvic/vicwur/view.py +276 -0
- torchvic/vicwur/wateruse.py +341 -0
- torchvic/vicwur/wateruse_kernels.py +514 -0
- torchvic/vicwur/wateruse_remote.py +516 -0
- torchvic/wateruse/__init__.py +6 -0
- torchvic/wateruse/engine.py +362 -0
- torchvic-0.4.9.dist-info/METADATA +198 -0
- torchvic-0.4.9.dist-info/RECORD +214 -0
- torchvic-0.4.9.dist-info/WHEEL +5 -0
- torchvic-0.4.9.dist-info/entry_points.txt +2 -0
- torchvic-0.4.9.dist-info/licenses/LICENSE +674 -0
- torchvic-0.4.9.dist-info/licenses/NOTICE +33 -0
- torchvic-0.4.9.dist-info/licenses/THIRD_PARTY_NOTICES.md +247 -0
- torchvic-0.4.9.dist-info/licenses/torchvic/crop/NOTICE_PCSE.txt +30 -0
- torchvic-0.4.9.dist-info/top_level.txt +1 -0
torchvic/__init__.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"""TorchVIC: the VIC 5 land surface model (5.0.1 and 5.1.0 physics) in
|
|
2
|
+
PyTorch, run forward on a GPU or a CPU from native VIC 5 image-driver inputs.
|
|
3
|
+
|
|
4
|
+
import torchvic
|
|
5
|
+
case = torchvic.load_case('global_param.txt', device='cuda')
|
|
6
|
+
out = torchvic.run(case)
|
|
7
|
+
torchvic.write_history(out, case, result_dir='results')
|
|
8
|
+
|
|
9
|
+
`load_case` reads the global parameter file and everything it names (domain,
|
|
10
|
+
parameters, daily or sub-daily forcing), `run` executes the time loop
|
|
11
|
+
(torchvic.model.basin.simulate) without building an autograd graph, and
|
|
12
|
+
`write_history` writes the global file's OUTFILE streams as VIC 5's image
|
|
13
|
+
driver writes them. The command line does the same: `torchvic run`.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
__version__ = "0.4.9"
|
|
17
|
+
|
|
18
|
+
__all__ = ['__version__', 'default_device', 'load_case', 'load_study', 'run',
|
|
19
|
+
'write_history', 'set_core', 'TorchVIC']
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def __getattr__(name):
|
|
23
|
+
# the coupled runtime, imported on first use (torchvic.coupling)
|
|
24
|
+
if name == 'TorchVIC':
|
|
25
|
+
from .coupling import TorchVIC
|
|
26
|
+
return TorchVIC
|
|
27
|
+
raise AttributeError('module %r has no attribute %r' % (__name__, name))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def default_device():
|
|
31
|
+
"""'cuda' when a GPU is visible, else 'cpu'."""
|
|
32
|
+
import torch
|
|
33
|
+
return 'cuda' if torch.cuda.is_available() else 'cpu'
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def set_core(version):
|
|
37
|
+
"""Select the VIC core physics ('5.1.0', the default, '5.0.1' or 'vicwur3') for
|
|
38
|
+
later runs."""
|
|
39
|
+
from .core import version as core_version
|
|
40
|
+
return core_version.set_core(version)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def load_case(global_param, **kwargs):
|
|
44
|
+
"""A torchvic.case.Case from a VIC 5 image-driver global parameter file;
|
|
45
|
+
keyword arguments are torchvic.case.load's (device, dtype, core, steps,
|
|
46
|
+
first_step, daily, no_energy, log, ...)."""
|
|
47
|
+
from . import case
|
|
48
|
+
return case.load(global_param, **kwargs)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def load_study(path, **kwargs):
|
|
52
|
+
"""A torchvic.config.Study from a study file (YAML or JSON)."""
|
|
53
|
+
from . import config
|
|
54
|
+
return config.load(path, **kwargs)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def run(case, **kwargs):
|
|
58
|
+
"""Run `case` forward and return its outputs ({name: tensor}).
|
|
59
|
+
|
|
60
|
+
Runs under torch.inference_mode(): no graph is recorded, and tensors
|
|
61
|
+
created inside it cannot later enter an autograd computation. Keyword
|
|
62
|
+
arguments are passed to torchvic.model.basin.simulate."""
|
|
63
|
+
import torch
|
|
64
|
+
with torch.inference_mode():
|
|
65
|
+
return case.run(**kwargs)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def write_history(out, case, result_dir=None, **kwargs):
|
|
69
|
+
"""Write the global file's OUTFILE streams for the run `out` of `case`
|
|
70
|
+
(torchvic.io.history.write_history); returns the paths written."""
|
|
71
|
+
return case.write_history(out, result_dir=result_dir, **kwargs)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
# any CUDA graph capture first makes the generator state outside inference mode
|
|
75
|
+
from .core import graphsafe as _graphsafe # noqa: E402,F401
|