nctoolkit 1.1.3__tar.gz → 1.1.6__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.
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/PKG-INFO +3 -2
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/__init__.py +1 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/anomaly.py +10 -53
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/api.py +2 -16
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/plot.py +16 -1
- nctoolkit-1.1.3/nctoolkit/runthis.py → nctoolkit-1.1.6/nctoolkit/runners.py +45 -316
- nctoolkit-1.1.6/nctoolkit/runthis.py +346 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/verticals.py +25 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit.egg-info/SOURCES.txt +1 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/setup.py +3 -2
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/CITATION.cff +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/CODE_OF_CONDUCT.md +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/LICENSE +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/MANIFEST.in +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/README.md +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/benchmarks/benchmark_nctoolkit_versus_xarray.ipynb +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/cheatsheet/nctoolkit_cheatsheet.pdf +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/cheatsheet/nctoolkit_cheatsheet.pptx +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/checklists/api_checker.ipynb +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/data/geotiff.tif +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/data/pubplot_test.png +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/data/test1.html +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/data/test2.html +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/add_etc.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/append.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/assign.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/cdo_command.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/cellareas.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/centres.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/checks.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/cleanup.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/clear.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/compare.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/compare_data.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/corr.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/create_ensemble.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/crop.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/deprecated.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/distgrid.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/drop.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/ensembles.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/esoteric.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/experimental.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/fill.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/flatten.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/fldstat.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/format.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/generate_grid.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/inttime.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/invert.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/masking.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/matchpoint.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/mergers.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/meridonials.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/mp_adders.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/mp_matchers.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/mp_matchups.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/nco_command.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/phenology.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/reduce.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/reduce_grid.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/regrid.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/remove.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/rename.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/resample.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/rollstat.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/run.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/session.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/set.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/setters.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/shape.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/shift.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/show.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/split.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/static_plot.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/strip_vars.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/subset.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/sumall.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/temp_file.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/temporal_stat.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/temporals.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/thresholds.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/to_lonlat.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/to_nc.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/toxarray.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/tozlev.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/unify.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/utils.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/validator.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/validator_funs.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/zip.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/nctoolkit/zonals.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/requirements.txt +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/setup.cfg +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/testing/test_parallel.py +0 -0
- {nctoolkit-1.1.3 → nctoolkit-1.1.6}/testing/test_scripting.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: nctoolkit
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.6
|
|
4
4
|
Summary: A Python package for netCDF analysis and post-processing
|
|
5
5
|
Home-page: https://github.com/pmlmodelling/nctoolkit
|
|
6
6
|
Author: Robert Wilson
|
|
@@ -16,6 +16,7 @@ Classifier: Programming Language :: Python :: 3.8
|
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.9
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.10
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
20
|
Requires-Python: >=3.6.1
|
|
20
21
|
License-File: LICENSE
|
|
21
22
|
Requires-Dist: xarray
|
|
@@ -37,7 +38,7 @@ Requires-Dist: geopandas; extra == "complete"
|
|
|
37
38
|
|
|
38
39
|
|
|
39
40
|
|
|
40
|
-
**nctoolkit** is a comprehensive Python (3.
|
|
41
|
+
**nctoolkit** is a comprehensive Python (3.8 and above) package for analyzing netCDF data on Linux and macOS.
|
|
41
42
|
|
|
42
43
|
Core abilities of nctoolkit include:
|
|
43
44
|
|
|
@@ -8,7 +8,8 @@ from nctoolkit.runthis import run_cdo, tidy_command
|
|
|
8
8
|
from nctoolkit.show import nc_years
|
|
9
9
|
from nctoolkit.temp_file import temp_file
|
|
10
10
|
from nctoolkit.session import remove_safe, session_info, nc_safe_par, nc_safe
|
|
11
|
-
from nctoolkit.api import
|
|
11
|
+
from nctoolkit.api import options
|
|
12
|
+
from nctoolkit.runners import ann_anomaly
|
|
12
13
|
|
|
13
14
|
if platform.system() == "Linux":
|
|
14
15
|
import multiprocessing as mp
|
|
@@ -25,52 +26,6 @@ else:
|
|
|
25
26
|
manager = Manager()
|
|
26
27
|
|
|
27
28
|
|
|
28
|
-
def ann_anomaly(
|
|
29
|
-
ff, baseline, metric, window, align, precision, new_files, new_commands, nc_safe
|
|
30
|
-
):
|
|
31
|
-
"""
|
|
32
|
-
Function to calculate the anomaly for a single file
|
|
33
|
-
"""
|
|
34
|
-
# throw error if baseline is not valid
|
|
35
|
-
orig_safe = copy.deepcopy(nc_safe)
|
|
36
|
-
target = temp_file("nc")
|
|
37
|
-
nc_safe.append(target)
|
|
38
|
-
try:
|
|
39
|
-
|
|
40
|
-
# create the target file
|
|
41
|
-
# generate the cdo command
|
|
42
|
-
if metric == "absolute":
|
|
43
|
-
cdo_command = (
|
|
44
|
-
f"cdo -sub -runmean,{window} -yearmean {ff} -timmean "
|
|
45
|
-
f"-selyear,{baseline[0]}/{baseline[1]} {ff} {target}"
|
|
46
|
-
)
|
|
47
|
-
else:
|
|
48
|
-
cdo_command = (
|
|
49
|
-
f"cdo -div -runmean,{window} -yearmean {ff} -timmean "
|
|
50
|
-
f"-selyear,{baseline[0]}/{baseline[1]} {ff} {target}"
|
|
51
|
-
)
|
|
52
|
-
|
|
53
|
-
# run the command and save the temp file
|
|
54
|
-
|
|
55
|
-
cdo_command = tidy_command(cdo_command)
|
|
56
|
-
cdo_command = cdo_command.replace(
|
|
57
|
-
"cdo ", f"cdo --timestat_date {align} "
|
|
58
|
-
).replace(" ", " ")
|
|
59
|
-
|
|
60
|
-
target = run_cdo(cdo_command, target, precision=precision)
|
|
61
|
-
if target not in nc_safe:
|
|
62
|
-
nc_safe.append(target)
|
|
63
|
-
|
|
64
|
-
# update the new files and commands
|
|
65
|
-
new_files.append(target)
|
|
66
|
-
new_commands.append(cdo_command)
|
|
67
|
-
except BaseException as e:
|
|
68
|
-
try:
|
|
69
|
-
nc_safe.remove(target)
|
|
70
|
-
except:
|
|
71
|
-
pass
|
|
72
|
-
return e
|
|
73
|
-
|
|
74
29
|
|
|
75
30
|
def annual_anomaly(self, baseline=None, metric="absolute", window=1, align="right"):
|
|
76
31
|
"""
|
|
@@ -178,7 +133,7 @@ def annual_anomaly(self, baseline=None, metric="absolute", window=1, align="righ
|
|
|
178
133
|
start_parallel = session_info["parallel"]
|
|
179
134
|
|
|
180
135
|
if start_parallel is False:
|
|
181
|
-
|
|
136
|
+
options(parallel = True)
|
|
182
137
|
|
|
183
138
|
nc_safe_par_start = copy.deepcopy(nc_safe_par)
|
|
184
139
|
try:
|
|
@@ -188,7 +143,7 @@ def annual_anomaly(self, baseline=None, metric="absolute", window=1, align="righ
|
|
|
188
143
|
target_list = []
|
|
189
144
|
results = dict()
|
|
190
145
|
|
|
191
|
-
pool = mp.
|
|
146
|
+
pool = mp.get_context('fork').Pool(cores)
|
|
192
147
|
precision = copy.deepcopy(self._precision)
|
|
193
148
|
for ff in self:
|
|
194
149
|
results[ff] = pool.apply_async(
|
|
@@ -210,14 +165,15 @@ def annual_anomaly(self, baseline=None, metric="absolute", window=1, align="righ
|
|
|
210
165
|
if "Check that the years in baseline are in the dataset!" in str(out):
|
|
211
166
|
raise ValueError("Check that the years in baseline are in the dataset!")
|
|
212
167
|
|
|
213
|
-
pool.close()
|
|
214
|
-
pool.join()
|
|
168
|
+
#pool.close()
|
|
169
|
+
#pool.join()
|
|
215
170
|
|
|
216
171
|
self.history += list(new_commands)
|
|
217
172
|
self._hold_history = copy.deepcopy(self.history)
|
|
218
173
|
|
|
219
174
|
if start_parallel is False:
|
|
220
|
-
update_options({"parallel": False})
|
|
175
|
+
#update_options({"parallel": False})
|
|
176
|
+
options(parallel = False)
|
|
221
177
|
while True:
|
|
222
178
|
for ff in nc_safe_par:
|
|
223
179
|
if ff not in nc_safe:
|
|
@@ -254,7 +210,8 @@ def annual_anomaly(self, baseline=None, metric="absolute", window=1, align="righ
|
|
|
254
210
|
self.disk_clean()
|
|
255
211
|
except BaseException as e:
|
|
256
212
|
if start_parallel is False:
|
|
257
|
-
update_options({"parallel": False})
|
|
213
|
+
#update_options({"parallel": False})
|
|
214
|
+
options(parallel = False)
|
|
258
215
|
if start_parallel:
|
|
259
216
|
for ff in nc_safe_par:
|
|
260
217
|
if ff not in nc_safe_par_start:
|
|
@@ -137,21 +137,7 @@ cdo_methods.append("reduce_dim")
|
|
|
137
137
|
session_info["cdo_methods"] = cdo_methods
|
|
138
138
|
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
try:
|
|
142
|
-
import geoviews
|
|
143
|
-
import cartopy
|
|
144
|
-
from cartopy import crs
|
|
145
|
-
import cartopy.crs as ccrs
|
|
146
|
-
|
|
147
|
-
projection = ccrs.PlateCarree()
|
|
148
|
-
return True
|
|
149
|
-
except:
|
|
150
|
-
return False
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
session_info["coast"] = coast_check()
|
|
154
|
-
#session_info["coast"] = None
|
|
140
|
+
session_info["coast"] = None
|
|
155
141
|
|
|
156
142
|
|
|
157
143
|
session_info["interactive"] = sys.__stdin__.isatty()
|
|
@@ -1935,7 +1921,6 @@ class DataSet(object):
|
|
|
1935
1921
|
|
|
1936
1922
|
from nctoolkit.phenology import phenology
|
|
1937
1923
|
|
|
1938
|
-
# from nctoolkit.phenology import initiation
|
|
1939
1924
|
|
|
1940
1925
|
from nctoolkit.plot import plot
|
|
1941
1926
|
from nctoolkit.static_plot import pub_plot
|
|
@@ -2022,6 +2007,7 @@ class DataSet(object):
|
|
|
2022
2007
|
from nctoolkit.verticals import bottom
|
|
2023
2008
|
from nctoolkit.verticals import bottom_mask
|
|
2024
2009
|
from nctoolkit.verticals import surface_mask
|
|
2010
|
+
from nctoolkit.verticals import generate_level_bounds
|
|
2025
2011
|
|
|
2026
2012
|
from nctoolkit.zip import zip
|
|
2027
2013
|
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import signal
|
|
2
|
-
from ncplot import view
|
|
3
2
|
|
|
4
3
|
from contextlib import contextmanager
|
|
5
4
|
from nctoolkit.session import session_info
|
|
6
5
|
|
|
6
|
+
def coast_check():
|
|
7
|
+
try:
|
|
8
|
+
import geoviews
|
|
9
|
+
import cartopy
|
|
10
|
+
from cartopy import crs
|
|
11
|
+
import cartopy.crs as ccrs
|
|
12
|
+
|
|
13
|
+
projection = ccrs.PlateCarree()
|
|
14
|
+
return True
|
|
15
|
+
except:
|
|
16
|
+
return False
|
|
17
|
+
|
|
18
|
+
|
|
7
19
|
|
|
8
20
|
class TimeoutException(Exception):
|
|
9
21
|
pass
|
|
@@ -59,7 +71,10 @@ def plot(self, vars=None, autoscale=True, out=None, coast=None, **kwargs):
|
|
|
59
71
|
>>> ds.plot("var_of_choice")
|
|
60
72
|
|
|
61
73
|
"""
|
|
74
|
+
from ncplot import view
|
|
62
75
|
|
|
76
|
+
if session_info["coast"] is None:
|
|
77
|
+
session_info["coast"] = coast_check()
|
|
63
78
|
|
|
64
79
|
if "title" not in kwargs.keys():
|
|
65
80
|
kwargs["title"] = ""
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
|
|
1
2
|
import copy
|
|
2
3
|
import os
|
|
3
4
|
import re
|
|
@@ -5,15 +6,11 @@ import subprocess
|
|
|
5
6
|
import platform
|
|
6
7
|
import warnings
|
|
7
8
|
|
|
8
|
-
if platform.system() == "Linux":
|
|
9
|
-
import multiprocessing as mp
|
|
10
|
-
else:
|
|
11
|
-
import multiprocess as mp
|
|
12
|
-
|
|
13
9
|
import signal
|
|
14
10
|
|
|
15
11
|
from nctoolkit.cleanup import cleanup
|
|
16
12
|
from nctoolkit.flatten import str_flatten
|
|
13
|
+
|
|
17
14
|
from nctoolkit.session import (
|
|
18
15
|
session_info,
|
|
19
16
|
append_safe,
|
|
@@ -24,15 +21,50 @@ from nctoolkit.temp_file import temp_file
|
|
|
24
21
|
|
|
25
22
|
from nctoolkit.show import nc_variables
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
def ann_anomaly(
|
|
25
|
+
ff, baseline, metric, window, align, precision, new_files, new_commands, nc_safe):
|
|
29
26
|
"""
|
|
30
|
-
|
|
27
|
+
Function to calculate the anomaly for a single file
|
|
31
28
|
"""
|
|
32
|
-
if
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
# throw error if baseline is not valid
|
|
30
|
+
orig_safe = copy.deepcopy(nc_safe)
|
|
31
|
+
target = temp_file("nc")
|
|
32
|
+
nc_safe.append(target)
|
|
33
|
+
try:
|
|
34
|
+
|
|
35
|
+
# create the target file
|
|
36
|
+
# generate the cdo command
|
|
37
|
+
if metric == "absolute":
|
|
38
|
+
cdo_command = (
|
|
39
|
+
f"cdo -sub -runmean,{window} -yearmean {ff} -timmean "
|
|
40
|
+
f"-selyear,{baseline[0]}/{baseline[1]} {ff} {target}"
|
|
41
|
+
)
|
|
42
|
+
else:
|
|
43
|
+
cdo_command = (
|
|
44
|
+
f"cdo -div -runmean,{window} -yearmean {ff} -timmean "
|
|
45
|
+
f"-selyear,{baseline[0]}/{baseline[1]} {ff} {target}"
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
# run the command and save the temp file
|
|
35
49
|
|
|
50
|
+
cdo_command = tidy_command(cdo_command)
|
|
51
|
+
cdo_command = cdo_command.replace(
|
|
52
|
+
"cdo ", f"cdo --timestat_date {align} "
|
|
53
|
+
).replace(" ", " ")
|
|
54
|
+
|
|
55
|
+
target = run_cdo(cdo_command, target, precision=precision)
|
|
56
|
+
if target not in nc_safe:
|
|
57
|
+
nc_safe.append(target)
|
|
58
|
+
|
|
59
|
+
# update the new files and commands
|
|
60
|
+
new_files.append(target)
|
|
61
|
+
new_commands.append(cdo_command)
|
|
62
|
+
except BaseException as e:
|
|
63
|
+
try:
|
|
64
|
+
nc_safe.remove(target)
|
|
65
|
+
except:
|
|
66
|
+
pass
|
|
67
|
+
return e
|
|
36
68
|
|
|
37
69
|
def tidy_command(command):
|
|
38
70
|
if session_info["precision"] is not None:
|
|
@@ -145,6 +177,7 @@ def run_nco(command, target, out_file=None, overwrite=False):
|
|
|
145
177
|
def run_cdo(command=None, target=None, out_file=None, overwrite=False, precision=None):
|
|
146
178
|
warned = False
|
|
147
179
|
|
|
180
|
+
|
|
148
181
|
if not isinstance(precision, str):
|
|
149
182
|
raise TypeError("Precision must be str")
|
|
150
183
|
|
|
@@ -805,308 +838,4 @@ def run_cdo(command=None, target=None, out_file=None, overwrite=False, precision
|
|
|
805
838
|
message = f"The following month was missing in the dataset: {sel_month}"
|
|
806
839
|
warnings.warn(message=message)
|
|
807
840
|
|
|
808
|
-
return target
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
def run_this(os_command, self, output="one", out_file=None, suppress=False):
|
|
812
|
-
from tqdm import tqdm
|
|
813
|
-
|
|
814
|
-
if len(self) == 0:
|
|
815
|
-
raise ValueError("Failure do to empty dataset!")
|
|
816
|
-
|
|
817
|
-
self._ncommands += 1
|
|
818
|
-
|
|
819
|
-
cores = session_info["cores"]
|
|
820
|
-
|
|
821
|
-
if len(self) == 1:
|
|
822
|
-
output = "ensemble"
|
|
823
|
-
|
|
824
|
-
if self._execute is False:
|
|
825
|
-
if len(self._hold_history) == len(self.history):
|
|
826
|
-
self.history.append(os_command)
|
|
827
|
-
else:
|
|
828
|
-
self.history[-1] = os_command + " " + self.history[-1].replace("cdo ", " ")
|
|
829
|
-
self.history[-1] = self.history[-1].replace(" ", " ")
|
|
830
|
-
try:
|
|
831
|
-
if self._execute:
|
|
832
|
-
if ((output == "ensemble") and (len(self) > 1)) or (
|
|
833
|
-
(output == "ensemble") and (len(self) == 1)
|
|
834
|
-
):
|
|
835
|
-
new_history = copy.deepcopy(self._hold_history)
|
|
836
|
-
|
|
837
|
-
if len(self) == 1:
|
|
838
|
-
cores = 1
|
|
839
|
-
file_list = self.current
|
|
840
|
-
|
|
841
|
-
if len(self.history) > len(self._hold_history):
|
|
842
|
-
os_command = f'{os_command} {self.history[-1].replace("cdo ", " ")}'
|
|
843
|
-
os_command = os_command.replace(" ", " ")
|
|
844
|
-
|
|
845
|
-
if cores > 1:
|
|
846
|
-
original_sigint_handler = signal.signal(
|
|
847
|
-
signal.SIGTERM, signal.SIG_IGN
|
|
848
|
-
)
|
|
849
|
-
pool = mp.Pool(cores)
|
|
850
|
-
signal.signal(signal.SIGTERM, original_sigint_handler)
|
|
851
|
-
|
|
852
|
-
target_list = []
|
|
853
|
-
results = dict()
|
|
854
|
-
else:
|
|
855
|
-
target_list = []
|
|
856
|
-
|
|
857
|
-
progress_bar = False
|
|
858
|
-
|
|
859
|
-
if self._thredds is False:
|
|
860
|
-
if self.size["Number of files in ensemble"] >= 12:
|
|
861
|
-
if self.size["Ensemble size"].split(" ")[1] == "GB":
|
|
862
|
-
if float(self.size["Ensemble size"].split(" ")[0]) > 12:
|
|
863
|
-
progress_bar = True
|
|
864
|
-
|
|
865
|
-
if session_info["progress"] == "off":
|
|
866
|
-
progress_bar = False
|
|
867
|
-
|
|
868
|
-
if session_info["progress"] == "on" and len(self) > 1:
|
|
869
|
-
progress_bar = True
|
|
870
|
-
|
|
871
|
-
if cores == 1:
|
|
872
|
-
if progress_bar:
|
|
873
|
-
if session_info["progress"] == "on":
|
|
874
|
-
if not suppress:
|
|
875
|
-
print("Processing ensemble! In progress:")
|
|
876
|
-
else:
|
|
877
|
-
if not suppress:
|
|
878
|
-
print("Processing large ensemble! In progress")
|
|
879
|
-
if not suppress:
|
|
880
|
-
pbar = tqdm(total=len(file_list), position=0, leave=True)
|
|
881
|
-
|
|
882
|
-
for ff in file_list:
|
|
883
|
-
ff_command = os_command
|
|
884
|
-
|
|
885
|
-
ff_command = f"{ff_command} {ff} "
|
|
886
|
-
if "infile09178" in ff_command:
|
|
887
|
-
ff_command = " ".join(ff_command.split(" ")[:-2])
|
|
888
|
-
ff_command = ff_command.replace("infile09178", ff)
|
|
889
|
-
|
|
890
|
-
target = temp_file("nc")
|
|
891
|
-
|
|
892
|
-
if out_file is not None:
|
|
893
|
-
target = out_file
|
|
894
|
-
|
|
895
|
-
ff_command = f"{ff_command} {target}"
|
|
896
|
-
ff_command = ff_command.replace(" ", " ")
|
|
897
|
-
if " --sortname " in os_command:
|
|
898
|
-
os_command = os_command.replace(" --sortname ", " ")
|
|
899
|
-
os_command = os_command.replace("cdo ", "cdo --sortname ")
|
|
900
|
-
|
|
901
|
-
if "reduce_dim" in ff_command:
|
|
902
|
-
ff_command = (
|
|
903
|
-
ff_command.replace("reduce_dim", "")
|
|
904
|
-
.replace(" - ", " ")
|
|
905
|
-
.replace(" -- ", " ")
|
|
906
|
-
)
|
|
907
|
-
ff_command = ff_command.replace("cdo ", "cdo --reduce_dim ")
|
|
908
|
-
|
|
909
|
-
ff_command = tidy_command(ff_command)
|
|
910
|
-
|
|
911
|
-
zip_copy = False
|
|
912
|
-
if self._zip and self._ncommands == 1:
|
|
913
|
-
zip_copy = True
|
|
914
|
-
|
|
915
|
-
format_it = False
|
|
916
|
-
if self._format is not None:
|
|
917
|
-
format_it = True
|
|
918
|
-
if self._ncommands == 1:
|
|
919
|
-
ff_command = ff_command.replace(
|
|
920
|
-
"cdo ", f"cdo -f {self._format} copy "
|
|
921
|
-
)
|
|
922
|
-
else:
|
|
923
|
-
ff_command = ff_command.replace(
|
|
924
|
-
"cdo ", f"cdo -f {self._format} "
|
|
925
|
-
)
|
|
926
|
-
ff_command = ff_command.replace(
|
|
927
|
-
"cdo ", f"cdo {self._align} "
|
|
928
|
-
).replace(" ", " ")
|
|
929
|
-
|
|
930
|
-
if self._zip and zip_copy and format_it is False:
|
|
931
|
-
ff_command = ff_command.replace("cdo ", "cdo -z zip copy ")
|
|
932
|
-
else:
|
|
933
|
-
if self._zip:
|
|
934
|
-
ff_command = ff_command.replace("cdo ", "cdo -z zip ")
|
|
935
|
-
|
|
936
|
-
new_history.append(ff_command)
|
|
937
|
-
|
|
938
|
-
if cores > 1:
|
|
939
|
-
temp = pool.apply_async(
|
|
940
|
-
run_cdo,
|
|
941
|
-
[ff_command, target, out_file, False, self._precision],
|
|
942
|
-
)
|
|
943
|
-
results[ff] = temp
|
|
944
|
-
else:
|
|
945
|
-
target = run_cdo(
|
|
946
|
-
ff_command, target, out_file, precision=self._precision
|
|
947
|
-
)
|
|
948
|
-
target_list.append(target)
|
|
949
|
-
if progress_bar:
|
|
950
|
-
if not suppress:
|
|
951
|
-
pbar.update(1)
|
|
952
|
-
|
|
953
|
-
if cores > 1:
|
|
954
|
-
if progress_bar:
|
|
955
|
-
if session_info["progress"] == "on":
|
|
956
|
-
if not suppress:
|
|
957
|
-
print("Processing ensemble. In progress:")
|
|
958
|
-
else:
|
|
959
|
-
if not suppress:
|
|
960
|
-
print("Processing a large ensemble. In progress:")
|
|
961
|
-
if not suppress:
|
|
962
|
-
pbar = tqdm(total=len(file_list), position=0, leave=True)
|
|
963
|
-
for k, v in results.items():
|
|
964
|
-
target_list.append(v.get())
|
|
965
|
-
if progress_bar:
|
|
966
|
-
if not suppress:
|
|
967
|
-
pbar.update(1)
|
|
968
|
-
|
|
969
|
-
self.history = copy.deepcopy(new_history)
|
|
970
|
-
self.current = copy.deepcopy(target_list)
|
|
971
|
-
self.current = [x for x in self.current if x is not None]
|
|
972
|
-
|
|
973
|
-
if cores == 1 or session_info["parallel"]:
|
|
974
|
-
for ff in target_list:
|
|
975
|
-
remove_safe(ff)
|
|
976
|
-
|
|
977
|
-
self.disk_clean()
|
|
978
|
-
|
|
979
|
-
cleanup()
|
|
980
|
-
|
|
981
|
-
self._hold_history = copy.deepcopy(self.history)
|
|
982
|
-
|
|
983
|
-
self._zip = False
|
|
984
|
-
|
|
985
|
-
self._ncommands = 0
|
|
986
|
-
|
|
987
|
-
self._format = None
|
|
988
|
-
|
|
989
|
-
return None
|
|
990
|
-
|
|
991
|
-
if ((output == "one") and (len(self) > 1)) or self._zip is False:
|
|
992
|
-
new_history = copy.deepcopy(self._hold_history)
|
|
993
|
-
|
|
994
|
-
if len(self.history) > len(self._hold_history):
|
|
995
|
-
os_command = f'{os_command} {self.history[-1].replace("cdo ", " ")}'
|
|
996
|
-
os_command = os_command.replace(" ", " ")
|
|
997
|
-
|
|
998
|
-
# ensure there is sufficient space in /tmp if it is to be used
|
|
999
|
-
if platform.system() == "Linux":
|
|
1000
|
-
all_sizes = 0
|
|
1001
|
-
|
|
1002
|
-
for ff in self:
|
|
1003
|
-
if file_size(ff) is not None:
|
|
1004
|
-
all_sizes += file_size(ff)
|
|
1005
|
-
|
|
1006
|
-
result = os.statvfs("/tmp/")
|
|
1007
|
-
result = result.f_frsize * result.f_bavail
|
|
1008
|
-
|
|
1009
|
-
if result < (2 * all_sizes):
|
|
1010
|
-
session_info["temp_dir"] == "/var/tmp/"
|
|
1011
|
-
|
|
1012
|
-
target = temp_file("nc")
|
|
1013
|
-
|
|
1014
|
-
if out_file is not None:
|
|
1015
|
-
target = out_file
|
|
1016
|
-
|
|
1017
|
-
os_command = (
|
|
1018
|
-
os_command + " [ " + str_flatten(self.current, " ") + " ] " + target
|
|
1019
|
-
)
|
|
1020
|
-
|
|
1021
|
-
zip_copy = False
|
|
1022
|
-
if self._zip and self._ncommands == 1:
|
|
1023
|
-
zip_copy = True
|
|
1024
|
-
|
|
1025
|
-
format_it = False
|
|
1026
|
-
|
|
1027
|
-
if self._format is not None:
|
|
1028
|
-
format_it = True
|
|
1029
|
-
if self._ncommands == 1:
|
|
1030
|
-
os_command = os_command.replace(
|
|
1031
|
-
"cdo ", f"cdo -f {self._format} copy "
|
|
1032
|
-
)
|
|
1033
|
-
else:
|
|
1034
|
-
os_command = os_command.replace(
|
|
1035
|
-
"cdo ", f"cdo -f {self._format} "
|
|
1036
|
-
)
|
|
1037
|
-
|
|
1038
|
-
if self._zip and zip_copy and format_it is False:
|
|
1039
|
-
os_command = os_command.replace("cdo ", "cdo -z zip copy ")
|
|
1040
|
-
else:
|
|
1041
|
-
if self._zip:
|
|
1042
|
-
os_command = os_command.replace("cdo ", "cdo -z zip ")
|
|
1043
|
-
|
|
1044
|
-
if "infile09178" in os_command:
|
|
1045
|
-
os_command = os_command.replace(ff, "")
|
|
1046
|
-
os_command = os_command.replace("infile09178", ff)
|
|
1047
|
-
|
|
1048
|
-
os_command = tidy_command(os_command)
|
|
1049
|
-
|
|
1050
|
-
os_command = os_command.replace("cdo ", f"cdo {self._align} ").replace(
|
|
1051
|
-
" ", " "
|
|
1052
|
-
)
|
|
1053
|
-
|
|
1054
|
-
if "mergetime" in os_command:
|
|
1055
|
-
try:
|
|
1056
|
-
target = run_cdo(
|
|
1057
|
-
os_command, target, out_file, precision=self._precision
|
|
1058
|
-
)
|
|
1059
|
-
except:
|
|
1060
|
-
var_list = []
|
|
1061
|
-
var_com = []
|
|
1062
|
-
|
|
1063
|
-
for ff in self:
|
|
1064
|
-
var_list += nc_variables(ff)
|
|
1065
|
-
var_com.append(nc_variables(ff))
|
|
1066
|
-
new_list = []
|
|
1067
|
-
|
|
1068
|
-
for var in set(var_list):
|
|
1069
|
-
if len(var_com) == len([x for x in var_com if var in x]):
|
|
1070
|
-
new_list.append(var)
|
|
1071
|
-
if True:
|
|
1072
|
-
f_list = ",".join(new_list)
|
|
1073
|
-
os_command = os_command.replace(
|
|
1074
|
-
"-mergetime ", f'-mergetime -apply,"-selname,{f_list}" '
|
|
1075
|
-
)
|
|
1076
|
-
|
|
1077
|
-
removed = ",".join(
|
|
1078
|
-
[x for x in set(var_list) if x not in new_list]
|
|
1079
|
-
)
|
|
1080
|
-
if len([x for x in set(var_list) if x not in new_list]) > 0:
|
|
1081
|
-
warnings.warn(
|
|
1082
|
-
f"The following variables are not in all files, so were ignored when merging: {removed}"
|
|
1083
|
-
)
|
|
1084
|
-
|
|
1085
|
-
target = run_cdo(
|
|
1086
|
-
os_command, target, out_file, precision=self._precision
|
|
1087
|
-
)
|
|
1088
|
-
else:
|
|
1089
|
-
target = run_cdo(
|
|
1090
|
-
os_command, target, out_file, precision=self._precision
|
|
1091
|
-
)
|
|
1092
|
-
|
|
1093
|
-
remove_safe(target)
|
|
1094
|
-
|
|
1095
|
-
self.current = target
|
|
1096
|
-
|
|
1097
|
-
self.history = new_history
|
|
1098
|
-
self.history.append(os_command)
|
|
1099
|
-
|
|
1100
|
-
self.disk_clean()
|
|
1101
|
-
|
|
1102
|
-
cleanup()
|
|
1103
|
-
|
|
1104
|
-
self._hold_history = copy.deepcopy(self.history)
|
|
1105
|
-
|
|
1106
|
-
self._zip = False
|
|
1107
|
-
self._n_commands = 0
|
|
1108
|
-
|
|
1109
|
-
self._format = None
|
|
1110
|
-
except Exception as e:
|
|
1111
|
-
self.reset()
|
|
1112
|
-
raise ValueError(e)
|
|
841
|
+
return target
|