windmapper 2.2.3__tar.gz → 2.2.4__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.
Files changed (26) hide show
  1. windmapper-2.2.4/.gitignore +21 -0
  2. windmapper-2.2.4/MANIFEST.in +10 -0
  3. {windmapper-2.2.3 → windmapper-2.2.4}/PKG-INFO +17 -3
  4. {windmapper-2.2.3 → windmapper-2.2.4}/README.md +15 -1
  5. windmapper-2.2.4/implementation/implimentation.ipynb +308 -0
  6. windmapper-2.2.4/implementation/spack.yaml +20 -0
  7. windmapper-2.2.4/implementation/windmapper_config.py +22 -0
  8. {windmapper-2.2.3 → windmapper-2.2.4}/publish.sh +5 -5
  9. {windmapper-2.2.3 → windmapper-2.2.4}/pyproject.toml +2 -2
  10. windmapper-2.2.4/spack-deploy.yaml +6 -0
  11. {windmapper-2.2.3 → windmapper-2.2.4}/src/windmapper/windmapper_cli.py +18 -15
  12. {windmapper-2.2.3 → windmapper-2.2.4}/src/windmapper/windmapper_utls/MPI_call_WN_1dir.py +1 -1
  13. windmapper-2.2.3/.gitignore +0 -26
  14. windmapper-2.2.3/proj.ipynb +0 -49
  15. windmapper-2.2.3/spack-deploy.yaml +0 -6
  16. windmapper-2.2.3/spack.yaml +0 -3
  17. windmapper-2.2.3/write_WN_config.py +0 -55
  18. {windmapper-2.2.3 → windmapper-2.2.4}/.github/workflows/main.yml +0 -0
  19. {windmapper-2.2.3 → windmapper-2.2.4}/.readthedocs.yml +0 -0
  20. {windmapper-2.2.3 → windmapper-2.2.4}/CMakeLists.txt +0 -0
  21. {windmapper-2.2.3 → windmapper-2.2.4}/LICENSE +0 -0
  22. {windmapper-2.2.3 → windmapper-2.2.4}/build.rst +0 -0
  23. {windmapper-2.2.3 → windmapper-2.2.4}/cfg/cli_massSolver.cfg +0 -0
  24. {windmapper-2.2.3 → windmapper-2.2.4}/src/windmapper/__init__.py +0 -0
  25. {windmapper-2.2.3 → windmapper-2.2.4}/src/windmapper/windmapper_utls/__init__.py +0 -0
  26. {windmapper-2.2.3 → windmapper-2.2.4}/src/windmapper/windmapper_utls/rio_merge.py +0 -0
@@ -0,0 +1,21 @@
1
+ __pycache__
2
+ *.tif
3
+ *.vrt
4
+ *.asc
5
+ *.prj
6
+ WindNinja_cli
7
+ .python-version
8
+ .idea/
9
+ docs/_build/
10
+ build/
11
+ MANIFEST
12
+ dist/
13
+ *.egg-info
14
+ _skbuild/
15
+ /spack-deploy/*
16
+ /dist/*
17
+ /implementation/._view
18
+ /implementation/.spack-env
19
+ /implementation/view
20
+ /implementation/windmapper_config
21
+ /implementation/spack.lock
@@ -0,0 +1,10 @@
1
+ graft pysrc
2
+ graft scripts
3
+
4
+ include .gitignore
5
+ include CMakeLists.txt
6
+ include LICENSE
7
+ include README.md
8
+ include windmapper.py
9
+ include pyproject.toml
10
+ include setup.py
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: windmapper
3
- Version: 2.2.3
3
+ Version: 2.2.4
4
4
  Summary: Windfield library generation
5
5
  Author: Chris Marsh
6
6
  Project-URL: Homepage, https://github.com/Chrismarsh/Windmapper
@@ -20,10 +20,24 @@ Description-Content-Type: text/markdown
20
20
 
21
21
  Windmapper is a python tool and a set of algorithms for producing and using pre-computed libraries of wind field used for wind downscaling.
22
22
 
23
+ ## Paper
24
+ Marsh, C. B., Vionnet, V. & Pomeroy, J. W. Windmapper: An Efficient Wind Downscaling Method for Hydrological Models. [Water Resour Res 59, (2023).](https://agupubs.onlinelibrary.wiley.com/doi/10.1029/2022WR032683)
25
+
26
+
23
27
  ![](docs/images/WM-main.png)
24
28
 
25
29
  # Installation
26
30
 
31
+ Because Windmapper depends on WindNinja, it is easiest to use [Spack](https://spack.readthedocs.io/) to install Windmapper:
32
+
33
+ ```
34
+ spack repo add https://github.com/Chrismarsh/spack-repo.git
35
+ spack install py-windmapper
36
+ ```
37
+
38
+ ## Pip
39
+ This is a harder way to get Windmapper.
40
+
27
41
  The default ``pip install windmapper`` will build windmapper without Windninja. However Windninja is required to run.
28
42
 
29
43
  To build Windninja, ensure gdal, boost, and mpi system libraries are installed and then
@@ -38,4 +52,4 @@ Documentation and full instructions on use can be found [here](https://windmappe
38
52
  # Implimentation
39
53
 
40
54
  The directory `implementation/` contains a jupyter notebook with an example implimentation of the code. It is not
41
- vectorized to aid in readability. However, this makes it very very slow!
55
+ vectorized to aid in readability. However, this makes it very, very slow!
@@ -2,10 +2,24 @@
2
2
 
3
3
  Windmapper is a python tool and a set of algorithms for producing and using pre-computed libraries of wind field used for wind downscaling.
4
4
 
5
+ ## Paper
6
+ Marsh, C. B., Vionnet, V. & Pomeroy, J. W. Windmapper: An Efficient Wind Downscaling Method for Hydrological Models. [Water Resour Res 59, (2023).](https://agupubs.onlinelibrary.wiley.com/doi/10.1029/2022WR032683)
7
+
8
+
5
9
  ![](docs/images/WM-main.png)
6
10
 
7
11
  # Installation
8
12
 
13
+ Because Windmapper depends on WindNinja, it is easiest to use [Spack](https://spack.readthedocs.io/) to install Windmapper:
14
+
15
+ ```
16
+ spack repo add https://github.com/Chrismarsh/spack-repo.git
17
+ spack install py-windmapper
18
+ ```
19
+
20
+ ## Pip
21
+ This is a harder way to get Windmapper.
22
+
9
23
  The default ``pip install windmapper`` will build windmapper without Windninja. However Windninja is required to run.
10
24
 
11
25
  To build Windninja, ensure gdal, boost, and mpi system libraries are installed and then
@@ -20,4 +34,4 @@ Documentation and full instructions on use can be found [here](https://windmappe
20
34
  # Implimentation
21
35
 
22
36
  The directory `implementation/` contains a jupyter notebook with an example implimentation of the code. It is not
23
- vectorized to aid in readability. However, this makes it very very slow!
37
+ vectorized to aid in readability. However, this makes it very, very slow!
@@ -0,0 +1,308 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "import xarray as xr\n",
10
+ "import rioxarray as rio\n",
11
+ "import glob\n",
12
+ "from pathlib import Path\n",
13
+ "import natsort\n",
14
+ "import subprocess\n",
15
+ "import numpy as np\n"
16
+ ]
17
+ },
18
+ {
19
+ "cell_type": "code",
20
+ "execution_count": null,
21
+ "metadata": {},
22
+ "outputs": [],
23
+ "source": [
24
+ "# get all the speedup \n",
25
+ "files = natsort.natsorted(glob.glob('windmapper_config/*.tif'))\n",
26
+ "\n",
27
+ "# the shortest name is the the base DEM. Remove this basename from the variable name used in the dataset\n",
28
+ "basename = Path(min(files, key=len)).stem\n",
29
+ "\n",
30
+ "variables = []\n",
31
+ "dem = None\n",
32
+ "for tif_file in files:\n",
33
+ " # Use the file name (without extension) as the variable name\n",
34
+ " variable_name = Path(tif_file).stem\n",
35
+ "\n",
36
+ " if variable_name == basename:\n",
37
+ "\n",
38
+ " # The WM area is smaller than the input DEM due to the strict alignment requirements\n",
39
+ " # cut down the input DEM to match the output WM extent\n",
40
+ " variable_name = variable_name.replace(basename,'DEM')\n",
41
+ " shp = Path(tif_file).parent / 'shp' / 'user_bbox.shp'\n",
42
+ " new_dem = 'DEM-WM-clip.tif'\n",
43
+ "\n",
44
+ " command = [\n",
45
+ " \"gdalwarp\", # Replace with actual path to gdalwarp\n",
46
+ " \"-cutline\", shp,\n",
47
+ " \"-crop_to_cutline\",\n",
48
+ " \"-dstalpha\",\n",
49
+ " \"-overwrite\",\n",
50
+ " 'FABDEM-clip.tif',\n",
51
+ " new_dem\n",
52
+ " ]\n",
53
+ " result = subprocess.run(command, capture_output=True, text=True)\n",
54
+ " dem = xr.open_mfdataset(new_dem).isel(band=0).drop_vars('band')\n",
55
+ " dem = dem.rename({'band_data': 'DEM','x':'lon','y':'lat'})\n",
56
+ " continue\n",
57
+ " \n",
58
+ " else:\n",
59
+ " variable_name = variable_name.replace(basename,'dir')\n",
60
+ " \n",
61
+ " ds = xr.open_mfdataset(tif_file).isel(band=0).drop_vars('band')\n",
62
+ " ds = ds.rename({'band_data': variable_name,'x':'lon','y':'lat'})\n",
63
+ " variables.append(ds)\n",
64
+ "\n",
65
+ "# Combine all variables into a single xarray.Dataset\n",
66
+ "# Enforce them to all /exactly/ match the same x,y and compensate for any tiny floating point differences in the lat lon coords \n",
67
+ "ds = xr.merge( xr.align(*variables, join=\"override\"), compat='no_conflicts', join='exact')\n",
68
+ "ds\n"
69
+ ]
70
+ },
71
+ {
72
+ "cell_type": "code",
73
+ "execution_count": 3,
74
+ "metadata": {},
75
+ "outputs": [],
76
+ "source": [
77
+ "# Create a new dataset with the same coordinates as the existing dem\n",
78
+ "wind = xr.Dataset(coords=dem.coords)\n",
79
+ "\n",
80
+ "# Add a new variable to the new dataset (optional)\n",
81
+ "wind[\"speed\"] = ((\"lon\", \"lat\"), np.zeros((557,406))+10) # a constant 10m/s wind\n",
82
+ "wind[\"dir\"] = ((\"lon\", \"lat\"), np.zeros((557,406)) + 45) # a 45 degree wind\n",
83
+ "\n",
84
+ "# where the output will go\n",
85
+ "wind[\"u\"] = ((\"lon\", \"lat\"), np.zeros((557,406))) \n",
86
+ "wind[\"v\"] = ((\"lon\", \"lat\"), np.zeros((557,406))) "
87
+ ]
88
+ },
89
+ {
90
+ "cell_type": "code",
91
+ "execution_count": null,
92
+ "metadata": {},
93
+ "outputs": [],
94
+ "source": [
95
+ "# example usage. The tight loop + lookup is very very slow\n",
96
+ "\n",
97
+ "# this would be run for each timestep of the using model\n",
98
+ "N_windfield = len(ds.data_vars) // 3\n",
99
+ "delta_angle = 360. / N_windfield\n",
100
+ "\n",
101
+ "# Iterate over intput wind field\n",
102
+ "for i in range(wind.sizes['lon']): \n",
103
+ " print(i, wind.sizes['lon'])\n",
104
+ " lon = wind['lon'][i]\n",
105
+ " for j in range(wind.sizes['lat']):\n",
106
+ " \n",
107
+ " lat = wind['lat'][j]\n",
108
+ "\n",
109
+ " # find the nearest point in the windmapper output because the using DEM and WM output don't have to be 1:1 exactly\n",
110
+ " nearest_point = ds.sel(lat=lat, \n",
111
+ " lon=lon, \n",
112
+ " method=\"nearest\")\n",
113
+ " nearest_lat = nearest_point[\"lat\"].values\n",
114
+ " nearest_lon = nearest_point[\"lon\"].values\n",
115
+ "\n",
116
+ " lon_i, lat_j = np.where((ds.lat == nearest_point.lat) & (ds.lon == nearest_point.lon))\n",
117
+ "\n",
118
+ " # get the input wind dir\n",
119
+ " theta = wind.dir[i,j].values.flatten()[0]\n",
120
+ "\n",
121
+ " # compute the two two nearest wind maps to this input direction\n",
122
+ " d1 = int(theta / delta_angle)\n",
123
+ " theta1 = d1 * delta_angle \n",
124
+ " if d1 == 0:\n",
125
+ " d1 = N_windfield\n",
126
+ "\n",
127
+ " d2 = int((theta + delta_angle) / delta_angle)\n",
128
+ " theta2 = d2 * delta_angle \n",
129
+ " if d2 == 0:\n",
130
+ " d2 = N_windfield\n",
131
+ "\n",
132
+ " d1 = int(d1 * delta_angle)\n",
133
+ " d2 = int(d2 * delta_angle)\n",
134
+ "\n",
135
+ " if d1 == 360:\n",
136
+ " d1 = 0\n",
137
+ " if d2 == 360:\n",
138
+ " d2 = 0\n",
139
+ "\n",
140
+ " U_d1 = ds[f'dir_{d1}_U'][lon_i,lat_j].values.flatten()[0]\n",
141
+ " U_d2 = ds[f'dir_{d2}_U'][lon_i,lat_j].values.flatten()[0]\n",
142
+ "\n",
143
+ " V_d1 = ds[f'dir_{d1}_V'][lon_i,lat_j].values.flatten()[0]\n",
144
+ " V_d2 = ds[f'dir_{d2}_V'][lon_i,lat_j].values.flatten()[0]\n",
145
+ "\n",
146
+ " W_d1 = ds[f'dir_{d1}_spd_up_1000'][lon_i,lat_j].values.flatten()[0]\n",
147
+ " W_d2 = ds[f'dir_{d2}_spd_up_1000'][lon_i,lat_j].values.flatten()[0]\n",
148
+ "\n",
149
+ " # interpolate between them\n",
150
+ " U = U_d1*(theta2-theta)/(theta2-theta1)+U_d2*(theta-theta1)/(theta2-theta1)\n",
151
+ " V = V_d1*(theta2-theta)/(theta2-theta1)+V_d2*(theta-theta1)/(theta2-theta1)\n",
152
+ " W_transf = W_d1*(theta2-theta)/(theta2-theta1)+W_d2*(theta-theta1)/(theta2-theta1)\n",
153
+ "\n",
154
+ " # update the direction\n",
155
+ " wind.u[i,j] = U\n",
156
+ " wind.v[i,j] = V\n",
157
+ "\n",
158
+ " # update the speed\n",
159
+ " wind.speed[i,j] = wind.speed[i,j] * W_transf\n",
160
+ "\n",
161
+ " # TODO: fix degree / radian \n",
162
+ " # sign convention \n",
163
+ " # http://mst.nerc.ac.uk/wind_vect_convs.html\n",
164
+ " # new_dir = np.arctan2(-U, -V)\n",
165
+ "\n",
166
+ " # if new_dir < 0:\n",
167
+ " # new_dir = new_dir + 360.\n",
168
+ "\n",
169
+ " # wind.dir[i,j] = new_dir\n"
170
+ ]
171
+ },
172
+ {
173
+ "cell_type": "code",
174
+ "execution_count": null,
175
+ "metadata": {},
176
+ "outputs": [],
177
+ "source": [
178
+ "# same as previous cell but a bit more pre computed & vectorized\n",
179
+ "# still comically slow\n",
180
+ "\n",
181
+ "# precompute static fields\n",
182
+ "N_windfield = len(ds.data_vars) // 3\n",
183
+ "delta_angle = 360. / N_windfield\n",
184
+ "\n",
185
+ "lon_grid, lat_grid = np.meshgrid(wind['lon'], wind['lat'], indexing='ij')\n",
186
+ "nearest_points = ds.sel(lat=xr.DataArray(lat_grid, dims=[\"lon\", \"lat\"]),\n",
187
+ " lon=xr.DataArray(lon_grid, dims=[\"lon\", \"lat\"]),\n",
188
+ " method=\"nearest\")\n",
189
+ "\n",
190
+ "theta_grid = wind['dir']\n",
191
+ "# Compute angle bins (d1, d2) and their corresponding angles (theta1, theta2)\n",
192
+ "d1 = np.floor(theta_grid / delta_angle).astype(int)\n",
193
+ "d2 = (d1 + 1) % N_windfield\n",
194
+ "theta1_grid = d1 * delta_angle\n",
195
+ "theta2_grid = d2 * delta_angle\n",
196
+ "\n",
197
+ "# Handle edge cases where d1 or d2 wrap around to 0 or 360 degrees\n",
198
+ "d1 = xr.where(d1 == 0, N_windfield, d1)\n",
199
+ "d2 = xr.where(d2 == 0, N_windfield, d2)\n",
200
+ "\n",
201
+ "# Convert angle bins to dataset variable names\n",
202
+ "d1_angles = (d1 * delta_angle).astype(int)\n",
203
+ "d2_angles = (d2 * delta_angle).astype(int)\n",
204
+ "\n",
205
+ "d1_angles = xr.where(d1_angles == 360, 0, d1_angles)\n",
206
+ "d2_angles = xr.where(d2_angles == 0, 0, d2_angles)\n",
207
+ "\n",
208
+ "\n",
209
+ "for i in range(wind.sizes['lon']): # Iterate over the first dimension (x)\n",
210
+ " print(i, wind.sizes['lon'])\n",
211
+ " for j in range(wind.sizes['lat']):\n",
212
+ " \n",
213
+ " U_d1 = nearest_points[f'dir_{d1_angles[i,j].values.flatten()[0]}_U'][i,j].values.flatten()[0]\n",
214
+ " U_d2 = nearest_points[f'dir_{d2_angles[i,j].values.flatten()[0]}_U'][i,j].values.flatten()[0]\n",
215
+ "\n",
216
+ " V_d1 = nearest_points[f'dir_{d1_angles[i,j].values.flatten()[0]}_V'][i,j].values.flatten()[0]\n",
217
+ " V_d2 = nearest_points[f'dir_{d2_angles[i,j].values.flatten()[0]}_V'][i,j].values.flatten()[0]\n",
218
+ "\n",
219
+ " W_d1 = nearest_points[f'dir_{d1_angles[i,j].values.flatten()[0]}_spd_up_1000'][i,j].values.flatten()[0]\n",
220
+ " W_d2 = nearest_points[f'dir_{d2_angles[i,j].values.flatten()[0]}_spd_up_1000'][i,j].values.flatten()[0]\n",
221
+ "\n",
222
+ " theta = theta_grid[i,j].values.flatten()[0]\n",
223
+ " theta1 = theta1_grid[i,j].values.flatten()[0]\n",
224
+ " theta2 = theta2_grid[i,j].values.flatten()[0]\n",
225
+ "\n",
226
+ " U = U_d1*(theta2-theta)/(theta2-theta1)+U_d2*(theta-theta1)/(theta2-theta1)\n",
227
+ " V = V_d1*(theta2-theta)/(theta2-theta1)+V_d2*(theta-theta1)/(theta2-theta1)\n",
228
+ " W_transf = W_d1*(theta2-theta)/(theta2-theta1)+W_d2*(theta-theta1)/(theta2-theta1)\n",
229
+ "\n",
230
+ " wind.u[i,j] = U\n",
231
+ " wind.v[i,j] = V\n",
232
+ "\n",
233
+ " wind.speed[i,j] = wind.speed[i,j] * W_transf\n"
234
+ ]
235
+ },
236
+ {
237
+ "cell_type": "code",
238
+ "execution_count": null,
239
+ "metadata": {},
240
+ "outputs": [],
241
+ "source": [
242
+ "# WIP vectorized approach, ignore\n",
243
+ "# Precompute constants\n",
244
+ "N_windfield = len(ds.data_vars) // 3\n",
245
+ "delta_angle = 360.0 / N_windfield\n",
246
+ "\n",
247
+ "# Precompute nearest neighbors for all lat/lon combinations\n",
248
+ "lon_grid, lat_grid = np.meshgrid(wind['lon'], wind['lat'], indexing='xy')\n",
249
+ "nearest_points = ds.sel(lat=xr.DataArray(lat_grid, dims=[\"lon\", \"lat\"]),\n",
250
+ " lon=xr.DataArray(lon_grid, dims=[\"lon\", \"lat\"]),\n",
251
+ " method=\"nearest\")\n",
252
+ "\n",
253
+ "nearest_lats = nearest_points[\"lat\"].values\n",
254
+ "nearest_lons = nearest_points[\"lon\"].values\n",
255
+ "\n",
256
+ "# Precompute indices for nearest neighbors\n",
257
+ "lon_indices = np.searchsorted(ds['lon'], nearest_lons)\n",
258
+ "lat_indices = np.searchsorted(ds['lat'], nearest_lats)\n",
259
+ "\n",
260
+ "# Vectorized computation over the entire grid\n",
261
+ "theta = wind['dir'].values # Shape (lon, lat)\n",
262
+ "\n",
263
+ "\n",
264
+ "\n",
265
+ "# Extract U, V, and W components for d1 and d2 using precomputed indices\n",
266
+ "U_d1 = ds[f'dir_{d1_angles}_U'].values[lon_indices, lat_indices]\n",
267
+ "U_d2 = ds[f'dir_{d2_angles}_U'].values[lon_indices, lat_indices]\n",
268
+ "\n",
269
+ "V_d1 = ds[f'dir_{d1_angles}_V'].values[lon_indices, lat_indices]\n",
270
+ "V_d2 = ds[f'dir_{d2_angles}_V'].values[lon_indices, lat_indices]\n",
271
+ "\n",
272
+ "W_d1 = ds[f'dir_{d1_angles}_spd_up_1000'].values[lon_indices, lat_indices]\n",
273
+ "W_d2 = ds[f'dir_{d2_angles}_spd_up_1000'].values[lon_indices, lat_indices]\n",
274
+ "\n",
275
+ "# Interpolate U, V, and W components based on theta\n",
276
+ "U = U_d1 * (theta2 - theta) / (theta2 - theta1) + U_d2 * (theta - theta1) / (theta2 - theta1)\n",
277
+ "V = V_d1 * (theta2 - theta) / (theta2 - theta1) + V_d2 * (theta - theta1) / (theta2 - theta1)\n",
278
+ "W_transf = W_d1 * (theta2 - theta) / (theta2 - theta1) + W_d2 * (theta - theta1) / (theta2 - theta1)\n",
279
+ "\n",
280
+ "# Update wind dataset with computed values\n",
281
+ "wind['u'].values[:, :] = U\n",
282
+ "wind['v'].values[:, :] = V\n",
283
+ "wind['speed'].values[:, :] *= W_transf"
284
+ ]
285
+ }
286
+ ],
287
+ "metadata": {
288
+ "kernelspec": {
289
+ "display_name": "Python 3 (ipykernel)",
290
+ "language": "python",
291
+ "name": "python3"
292
+ },
293
+ "language_info": {
294
+ "codemirror_mode": {
295
+ "name": "ipython",
296
+ "version": 3
297
+ },
298
+ "file_extension": ".py",
299
+ "mimetype": "text/x-python",
300
+ "name": "python",
301
+ "nbconvert_exporter": "python",
302
+ "pygments_lexer": "ipython3",
303
+ "version": "3.11.9"
304
+ }
305
+ },
306
+ "nbformat": 4,
307
+ "nbformat_minor": 2
308
+ }
@@ -0,0 +1,20 @@
1
+ spack:
2
+ specs:
3
+ - "py-numpy"
4
+ - "py-importlib-metadata"
5
+ - 'py-xarray +io +viz +parallel'
6
+ - "py-netcdf4"
7
+ - "py-pandas"
8
+ - "gdal@3.5: +python +hdf5 +netcdf"
9
+ - "py-dask"
10
+ - "py-pyproj"
11
+ - "py-matplotlib"
12
+ - "py-jupyterlab"
13
+ - "py-natsort"
14
+ - "py-rioxarray"
15
+ - "py-rasterio"
16
+ - "py-tdqm"
17
+ - "py-windmapper"
18
+ - "windninja"
19
+ view: ./view
20
+
@@ -0,0 +1,22 @@
1
+ # Configuration file for windmapper when a DEM is downloaded from the SRTM 30m archive
2
+
3
+ # Resolution of WindNinja simulations (in m)
4
+ res_wind = 50
5
+
6
+ # Number of wind speed categories (every 360/ncat degrees)
7
+ ncat = 8
8
+
9
+ # Flag to use existing DEM (DEM must be in UTM for WindNinja)
10
+ use_existing_dem = True
11
+ dem_filename = 'FABDEM-clip.tif'
12
+
13
+ # Averaging method to compute the transfer function in the downscaling method
14
+ # "mean_tile": the wind speed is average over the whole domain for each WN simulation (as in marsh et al, 2020)
15
+ # "grid": the wind speed is averaged over a squared area of size targer_res (as in Vionnet et al., 2020)
16
+ wind_average = 'grid'
17
+
18
+ # Target resolution for avegaging (in m)
19
+ targ_res = 1000
20
+
21
+
22
+ MPI_workers=8
@@ -1,9 +1,10 @@
1
1
  set -e
2
- . ~/Documents/science/code/spack/share/spack/setup-env.sh
2
+ # . ~/Documents/science/code/spack/share/spack/setup-env.sh
3
3
  #setup build env
4
- #spack env create -d spack-deploy spack-deploy.yaml
4
+ rm -rf spack-deploy dist
5
+ spack env create -d spack-deploy spack-deploy.yaml
5
6
  spack env activate spack-deploy
6
- #spack install
7
+ spack install
7
8
 
8
9
 
9
10
  #build current version
@@ -14,5 +15,4 @@ twine upload dist/* --skip-existing
14
15
  #clean up
15
16
  spack env deactivate
16
17
  rm -rf spack-deploy
17
- rm -rf dist
18
-
18
+ rm -rf dist
@@ -4,7 +4,7 @@ build-backend = "scikit_build_core.build"
4
4
 
5
5
  [project]
6
6
  name = "windmapper"
7
- version = "2.2.3"
7
+ version = "2.2.4"
8
8
  authors = [
9
9
  {name="Chris Marsh"}
10
10
  ]
@@ -27,7 +27,7 @@ dependencies = [
27
27
  Homepage = "https://github.com/Chrismarsh/Windmapper"
28
28
 
29
29
  [tool.scikit-build]
30
- sdist.exclude = ["examples", "docs", "_config.yml", "dist", "spack-deploy", "venv", "implementation"]
30
+ sdist.exclude = ["examples", "docs", "_config.yml", "dist"]
31
31
 
32
32
  [project.scripts]
33
33
  windmapper = "windmapper:main"
@@ -0,0 +1,6 @@
1
+ spack:
2
+ specs:
3
+ - py-pip
4
+ - py-build
5
+ - py-twine@6
6
+ view: ./venv-deploy
@@ -60,20 +60,24 @@ def main():
60
60
 
61
61
  # path to Wind Ninja executable
62
62
 
63
- # default path assumes that WN is on $PATH
64
- wn_exe = shutil.which('WindNinja_cli')
65
-
66
- if hasattr(X, 'wn_exe'):
67
- wn_exe = X.wn_exe
68
-
69
- if not os.path.exists(wn_exe):
70
- if hasattr(X, 'wn_exe'):
71
- print('ERROR: Path to WindNinja_cli not found. Confirm `wn_exe` config option is correct.')
72
- print(f'Path = {wn_exe}')
73
- else:
74
- print(
75
- 'ERROR: WindNinja_cli not found on $PATH. Ensure it is is or Consider specifying a `wn_exe` config option')
76
- exit(-1)
63
+ # Priority: explicit configuration, environment, then PATH.
64
+ requested = (
65
+ getattr(X, "wn_exe", None)
66
+ or os.environ.get("WINDNINJA_EXE")
67
+ or "WindNinja_cli"
68
+ )
69
+
70
+ wn_exe = shutil.which(os.path.expanduser(os.fspath(requested)))
71
+
72
+ if wn_exe is None:
73
+ raise FileNotFoundError(
74
+ f"WindNinja executable not found or not executable: {requested!r}. "
75
+ "Set wn_exe in the configuration, set WINDNINJA_EXE, "
76
+ "or put WindNinja_cli on PATH."
77
+ )
78
+
79
+ # Resolve Spack view symlinks before deriving the data directory.
80
+ wn_exe = os.path.realpath(wn_exe)
77
81
 
78
82
  MPI_exec_str = None
79
83
  if hasattr(X, 'MPI_exec_str'):
@@ -550,7 +554,6 @@ write_farsite_atm = false """
550
554
  # absolutely make sure there are no missing data. From the cut above can sometimes be missing 1px along the edge
551
555
  exec_str = '%sgdal_fillnodata.py %s %s'
552
556
  com_string = exec_str % (gdal_prefix, fic_tmp+'.tmp.tif', fic_tmp)
553
- print(com_string)
554
557
  subprocess.check_call([com_string], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
555
558
 
556
559
  os.remove(fic_tmp+'.tmp.tif')
@@ -66,7 +66,7 @@ def call_WN_1dir(WINDNINJA_DATA, gdal_prefix, user_output_dir, fic_config_WN, li
66
66
  exec_cmd = wn_exe + ' ' + \
67
67
  fic_config_WN + ' --elevation_file ' + fic_dem_in + ' --mesh_resolution ' + str(
68
68
  res_wind) + ' --input_direction ' + str(int(wdir)) + ' --output_path ' + dir_tmp
69
- print(exec_cmd)
69
+
70
70
  try:
71
71
  os.environ["WINDNINJA_DATA"] = WINDNINJA_DATA
72
72
  out = subprocess.check_output([exec_cmd],
@@ -1,26 +0,0 @@
1
- __pycache__
2
- *.tif
3
- *.vrt
4
- *.asc
5
- *.prj
6
- WindNinja_cli
7
- .python-version
8
- .idea/
9
- docs/_build/
10
-
11
- *.egg-info
12
-
13
- spack-deploy/*
14
- .spack-env/*
15
- ._venv/*
16
- venv
17
-
18
-
19
- dist/*
20
-
21
- spack.lock
22
- /implementation/._view/*
23
- /implementation/.spack-env/*
24
- /implementation/view/*
25
- /implementation/windmapper_config
26
- /implementation/spack.lock
@@ -1,49 +0,0 @@
1
- {
2
- "cells": [
3
- {
4
- "cell_type": "code",
5
- "execution_count": 1,
6
- "metadata": {
7
- "collapsed": true,
8
- "pycharm": {
9
- "name": "#%%\n"
10
- }
11
- },
12
- "outputs": [
13
- {
14
- "name": "stdout",
15
- "output_type": "stream",
16
- "text": [
17
- "Warning: ecCodes 2.22.0 or higher is recommended. You are running version 2.20.0\n"
18
- ]
19
- }
20
- ],
21
- "source": [
22
- "import xarray as xr\n",
23
- "import numpy as np\n",
24
- "import rasterio as rio"
25
- ]
26
- }
27
- ],
28
- "metadata": {
29
- "kernelspec": {
30
- "name": "snowcast",
31
- "language": "python",
32
- "display_name": "snowcast"
33
- },
34
- "language_info": {
35
- "codemirror_mode": {
36
- "name": "ipython",
37
- "version": 2
38
- },
39
- "file_extension": ".py",
40
- "mimetype": "text/x-python",
41
- "name": "python",
42
- "nbconvert_exporter": "python",
43
- "pygments_lexer": "ipython2",
44
- "version": "2.7.6"
45
- }
46
- },
47
- "nbformat": 4,
48
- "nbformat_minor": 0
49
- }
@@ -1,6 +0,0 @@
1
- spack:
2
- specs:
3
- - py-pip
4
- - py-build
5
- - py-twine
6
- view: ./venv-mesher-deploy
@@ -1,3 +0,0 @@
1
- spack:
2
- specs: [py-windmapper]
3
- view: venv
@@ -1,55 +0,0 @@
1
- #!/usr/bin/env python
2
- import numpy as np
3
- import os
4
-
5
- # Write a text file containing information on the WN maps used as input to mesher
6
-
7
- # Directory where are stored to WN maps
8
- dir_wind = '/home/vvionnet/data3/Run_WindNinja/WN_Lajoie/param_lajoie'
9
-
10
- # Direcrtory where are stored mesher command
11
- dir_mesh = '/home/vvionnet/snow_models/mesher/lajoie_srtm'
12
-
13
- # Name of the wind maps:
14
- name_run_WN = 'ref-DEM-utm'
15
-
16
- # Number of wind maps to be used
17
- ncat = 12
18
-
19
- ############################
20
- #No change after these lines
21
- ############################
22
-
23
- # Angle between each wind maps
24
- delta_wind = 360/ncat
25
-
26
- list_wind = np.arange(0,360,delta_wind)
27
-
28
- # List of variables to be inclused in mesher
29
- list_var = ['U','V','spd_up']
30
-
31
- dic_suffix = {'U':'_U','V':'_V','spd_up':''}
32
-
33
- # File containing results
34
- fic_res = dir_mesh+"/config_WN.txt"
35
-
36
- if(os.path.isfile(fic_res)):
37
- os.remove(fic_res)
38
-
39
- file1 = open(fic_res,"w")
40
-
41
- for ii,ww in enumerate(list_wind):
42
-
43
- if(ii==0):
44
- ii=ncat
45
-
46
- for var in list_var:
47
- ll = "'Ninja"+str(ii)+dic_suffix[var]+"' : {'file':'"+dir_wind+"/"+name_run_WN+"_"+str(int(ww))+"_"+var+".vrt','method':'mean'}, \n"
48
- file1.write(ll)
49
-
50
- file1.write("\n")
51
-
52
-
53
-
54
-
55
-
File without changes
File without changes
File without changes
File without changes