|
| 1 | +TopoPyScale Optimization Session Summary |
| 2 | +======================================== |
| 3 | + |
| 4 | +Session objective: Improve performance of TopoPyScale downscaling and terrain processing pipelines. |
| 5 | + |
| 6 | +Files modified and committed: |
| 7 | +------------------------------ |
| 8 | + |
| 9 | +1. TopoPyScale/topo_scale_zarr.py |
| 10 | + - Added module-level MONTHLY_COEFFS constant to avoid per-call Dataset creation. |
| 11 | + - Fixed a stray '{}' bug in precip_lapse_rate formula. |
| 12 | + - Vectorized horizon lookup (azimuth indexing) to remove per-timestep xarray .sel() calls. |
| 13 | + - Added _preload_worker_data() to load da_horizon and ds_solar before forking for copy-on-write sharing. |
| 14 | + - Pre-extracted unique ERA5 subsets in the parent process to reduce redundant zarr I/O. |
| 15 | + - Added _downscale_atmo_optimized() with vectorized vertical interpolation and reduced allocations. |
| 16 | + - Implemented optimized zarr output store creation with explicit regions to avoid lock contention, |
| 17 | + zstd compression, float32 precision, and consolidated metadata. |
| 18 | + - Added per-section wall-clock timing in downscale_atmo and profile_atmo() serial profiler |
| 19 | + using cProfile + tracemalloc. |
| 20 | + - Made zarr the recommended default output format via downscale_parallel(..., output_format='zarr'). |
| 21 | + - Added chunked processing (chunk_size parameter) for memory management with large point counts. |
| 22 | + |
| 23 | +2. TopoPyScale/topo_param.py |
| 24 | + - Added conditional HORAYZON backend support with fallback to topocalc. |
| 25 | + - Implemented _compute_slope_aspect_horayzon(), _compute_svf_horayzon(), _compute_horizon_horayzon(). |
| 26 | + - Added automatic aspect convention conversion: |
| 27 | + HORAYZON: 0° = North, clockwise (meteorological) |
| 28 | + topocalc gradient_d8: 0° = East, counter-clockwise (mathematical) |
| 29 | + Conversion used: topocalc_aspect = (90 - horayzon_aspect) mod 360 |
| 30 | + - Added check_terrain_backend() and get_terrain_performance_info() helper functions. |
| 31 | + - Stored backend name in output horizon DataArray attrs for traceability. |
| 32 | + |
| 33 | +3. pyproject.toml |
| 34 | + - Added optional [project.optional-dependencies] "horayzon" and "performance" extras |
| 35 | + with cython, scipy, geographiclib, tqdm, requests. |
| 36 | + |
| 37 | +4. CLAUDE.md |
| 38 | + - Documented HORAYZON installation and performance options. |
| 39 | + - Documented aspect convention conversion note. |
| 40 | + |
| 41 | +5. TopoPyScale/solar_geom.py |
| 42 | + - Replaced ThreadPool per-element calls with vectorized pvlib solarposition calls. |
| 43 | + - Added tqdm progress bar, pre-allocated output arrays, and improved metadata. |
| 44 | + - Deprecated num_threads parameter (vectorization replaces threading). |
| 45 | + |
| 46 | +6. TopoPyScale/topo_sub.py |
| 47 | + - Enabled n_jobs=-1 (all cores) for standard KMeans by default. |
| 48 | + - Auto-computed MiniBatch batch size as sqrt(n_samples) clamped to [1024, 10000]. |
| 49 | + - Vectorized feature weighting in scale_df / inverse_scale_df. |
| 50 | + - Added tqdm progress bars and throughput metrics. |
| 51 | + |
| 52 | +7. TopoPyScale/meteo_util.py |
| 53 | + - Replaced per-element rng.choice loop in partition_snow() with vectorized |
| 54 | + np.random.random() < probability Bernoulli sampling (50-100x speedup). |
| 55 | + - Added optional numba JIT for continuous snow partitioning with numpy fallback. |
| 56 | + - Added seed parameter for reproducible Jennings methods. |
| 57 | + - Refactored psnow bivariate/trivariate calculations into helper functions. |
| 58 | + |
| 59 | +Pending question / next step: |
| 60 | +----------------------------- |
| 61 | +User asked whether saving the horizon DataArray to zarr in topo_param.py would improve speed. |
| 62 | +Answer: Yes, especially for large DEMs, because zarr enables chunk-aligned point lookups, |
| 63 | +parallel reads, better compression, and lazy loading. Implementation was offered but not yet done. |
| 64 | + |
| 65 | +Installation notes: |
| 66 | +------------------- |
| 67 | +Standard TopoPyScale still uses topocalc. |
| 68 | +For best performance install HORAYZON: |
| 69 | + conda install -c conda-forge embree tbb-devel |
| 70 | + pip install git+https://github.com/ChristianSteger/HORAYZON.git |
| 71 | + |
| 72 | +Git branch: fsm2oshd_profiling |
| 73 | +Commits added (in order): |
| 74 | + 1. d8d459a - Optimize multiprocessing performance and add zarr I/O improvements |
| 75 | + 2. 162f8fb - Add conditional HORAYZON support for high-performance terrain computation |
| 76 | + 3. 91576fd - Optimize solar geometry, k-means clustering, and meteorological functions |
0 commit comments