From 1f7276aa850728f7266aeba769e2f3eabe278207 Mon Sep 17 00:00:00 2001 From: Nicholas Ferguson Date: Thu, 16 Apr 2026 09:21:20 -0500 Subject: [PATCH 1/2] feat(env): add R environment activation and rename CMAP-TRIP2 --- Scripts/manage/env/activate_env.cmd | 67 +++++++---- .../manage/env/{CMAP-TRIP2.yml => tbm-py.yml} | 108 +++++++++--------- Scripts/manage/env/tbm-r.yml | 8 ++ 3 files changed, 106 insertions(+), 77 deletions(-) rename Scripts/manage/env/{CMAP-TRIP2.yml => tbm-py.yml} (93%) create mode 100644 Scripts/manage/env/tbm-r.yml diff --git a/Scripts/manage/env/activate_env.cmd b/Scripts/manage/env/activate_env.cmd index 7b67d2f..a49b33c 100644 --- a/Scripts/manage/env/activate_env.cmd +++ b/Scripts/manage/env/activate_env.cmd @@ -8,45 +8,66 @@ rem creates the environment before activating it. rem Parameters: rem 1 : emme rem Activate the custom Emme environment instead of the TBM -rem environment (default). +rem environment (default). +rem 1 : r +rem Activate the custom R environment instead of the TBM environment. -if [%~1] == [emme] (set EMME_ENV=y) else (set EMME_ENV=n) set PDIR=%~dp0 rem Define here the name of the TBM environment to be used. -set TBM_ENVNAME=CMAP-TRIP2 +set PY_ENVNAME=tbm-py +rem Define here the name of the R environment to be used. +set R_ENVNAME=tbm-r rem Define here the name of the custom Emme environment to be used. set EMME_ENVNAME=emme-plus call "%PDIR%set_condapath.cmd" if %ERRORLEVEL% neq 0 (goto end) -if %EMME_ENV%==y (set ENVNAME=%EMME_ENVNAME%) else (set ENVNAME=%TBM_ENVNAME%) +if [%~1]==[emme] ( + set ENVNAME=%EMME_ENVNAME% +) else if [%~1]==[r] ( + set ENVNAME=%R_ENVNAME% +) else ( + set ENVNAME=%PY_ENVNAME% +) set ENVPATH=%CONDAPATH%\envs\%ENVNAME% rem Create it if it doesn't exist. -if not exist "%ENVPATH%\python.exe" ( - echo Python not found at "%ENVPATH%" - echo. - rem Activate the conda base environment. - rem Using call is required here, see: - rem https://stackoverflow.com/questions/24678144/conda-environments-and-bat-files - call "%CONDAPATH%\Scripts\activate.bat" - if %ERRORLEVEL% neq 0 ( - echo Error in activating conda - goto end - ) - rem Create it from a file. - echo Creating %ENVNAME% environment - echo. - call conda env create -f "%PDIR%%ENVNAME%.yml" +if [%~1]==[r] ( + if not exist "%ENVPATH%\Scripts\Rscript.exe" ( + echo R not found at "%ENVPATH%" + echo. + goto create + ) else (goto activate) +) else ( + if not exist "%ENVPATH%\python.exe" ( + echo Python not found at "%ENVPATH%" + echo. + goto create + ) else (goto activate) +) + +:create +rem Activate the conda base environment. +rem Using call is required here, see: +rem https://stackoverflow.com/questions/24678144/conda-environments-and-bat-files +call "%CONDAPATH%\Scripts\activate.bat" +if %ERRORLEVEL% neq 0 ( + echo Error in activating conda + goto end +) +rem Create it from a file. +echo Creating %ENVNAME% environment +echo. +call conda env create -f "%PDIR%%ENVNAME%.yml" - if %EMME_ENV%==y ( - rem Add the path configuration file to include Emme Python libraries. - copy "%PDIR%emme.pth" "%ENVPATH%\Lib\site-packages" - ) +if [%~1]==[emme] ( + rem Add the path configuration file to include Emme Python libraries. + copy "%PDIR%emme.pth" "%ENVPATH%\Lib\site-packages" ) +:activate rem Activate it. call "%CONDAPATH%\Scripts\activate.bat" "%ENVPATH%" if %ERRORLEVEL% neq 0 ( diff --git a/Scripts/manage/env/CMAP-TRIP2.yml b/Scripts/manage/env/tbm-py.yml similarity index 93% rename from Scripts/manage/env/CMAP-TRIP2.yml rename to Scripts/manage/env/tbm-py.yml index 40a9b10..0a74003 100644 --- a/Scripts/manage/env/CMAP-TRIP2.yml +++ b/Scripts/manage/env/tbm-py.yml @@ -1,55 +1,55 @@ -# To use this file: -# conda env create -f CMAP-TRIP2.yml -name: CMAP-TRIP2 -channels: - - conda-forge -dependencies: - - altair=4.1 - - appdirs=1.4 - - cloudpickle=2.0 - - dask=2021.12 - - datashader=0.13 - - distributed=2021.12 - - fiona=1.8 - - geopandas=0.10 - - gh=2.4 - - git=2.34 - - graphviz=2.50 - - ipykernel=6.6 - - ipyparallel=8.1 - - ipywidgets=7.6 - - joblib=1.1 - - jupyter=1.0 - - jupyter_contrib_nbextensions=0.5 # On conda-forge only - - larch=5.5.9 - - matplotlib=3.5 - - nb_conda=2.2 - - notebook=6.4 - - numba=0.53 - - numpy=1.21 - - numexpr=2.7 - - pandas=1.3 - - pip=21.3 - - platypus-opt=1.0 - - plotly=5.5 - - pyarrow=6.0 - - pydot=1.4 - - pyscaffold=4.1 - - pytest=6.2 - - python=3.9 - - python-kaleido=0.2 # Plotly Static Image Export - - pyzmq=22.3 - - salib=1.4 - - scikit-learn=1.0 - - scipy=1.7 - - seaborn=0.11 - - shortuuid=1.0 - - sqlalchemy=1.4 - - statsmodels=0.13 - - tbb=2021.4 - - tbb4py=2021.4 - - xarray=0.20 - - zarr=2.10 - - pip: - - emat +# To use this file: +# conda env create -f CMAP-TRIP2.yml +name: tbm-py +channels: + - conda-forge +dependencies: + - altair=4.1 + - appdirs=1.4 + - cloudpickle=2.0 + - dask=2021.12 + - datashader=0.13 + - distributed=2021.12 + - fiona=1.8 + - geopandas=0.10 + - gh=2.4 + - git=2.34 + - graphviz=2.50 + - ipykernel=6.6 + - ipyparallel=8.1 + - ipywidgets=7.6 + - joblib=1.1 + - jupyter=1.0 + - jupyter_contrib_nbextensions=0.5 # On conda-forge only + - larch=5.5.9 + - matplotlib=3.5 + - nb_conda=2.2 + - notebook=6.4 + - numba=0.53 + - numpy=1.21 + - numexpr=2.7 + - pandas=1.3 + - pip=21.3 + - platypus-opt=1.0 + - plotly=5.5 + - pyarrow=6.0 + - pydot=1.4 + - pyscaffold=4.1 + - pytest=6.2 + - python=3.9 + - python-kaleido=0.2 # Plotly Static Image Export + - pyzmq=22.3 + - salib=1.4 + - scikit-learn=1.0 + - scipy=1.7 + - seaborn=0.11 + - shortuuid=1.0 + - sqlalchemy=1.4 + - statsmodels=0.13 + - tbb=2021.4 + - tbb4py=2021.4 + - xarray=0.20 + - zarr=2.10 + - pip: + - emat - cmap_modedest @ git+https://github.com/CMAP-REPOS/cmap_modedest@v24.4.1 \ No newline at end of file diff --git a/Scripts/manage/env/tbm-r.yml b/Scripts/manage/env/tbm-r.yml new file mode 100644 index 0000000..6cc3d50 --- /dev/null +++ b/Scripts/manage/env/tbm-r.yml @@ -0,0 +1,8 @@ +name: tbm-r +channels: + - conda-forge +dependencies: + - r-base=4.3 + - r-foreign + - r-tidyverse + - r-sf \ No newline at end of file From 33963035acb44757e5ddd5692bbac0afd1809135 Mon Sep 17 00:00:00 2001 From: Nicholas Ferguson Date: Thu, 16 Apr 2026 09:23:39 -0500 Subject: [PATCH 2/2] feat(env): use conda R env to execute create_distr_m01_files.R --- Database/Submit_Full_Regional_Model_SOLA.bat | 29 ++------------------ 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/Database/Submit_Full_Regional_Model_SOLA.bat b/Database/Submit_Full_Regional_Model_SOLA.bat index c5126e7..da740ad 100644 --- a/Database/Submit_Full_Regional_Model_SOLA.bat +++ b/Database/Submit_Full_Regional_Model_SOLA.bat @@ -191,19 +191,6 @@ REM PREP WORK CD %~dp0 CD prep_macros -REM Now find R executable -set infile=path.txt -if exist %infile% (del %infile% /Q) -dir "C:\Program Files\R\*R.exe" /s /b >> %infile% 2>nul -set /p path2=<%infile% -set paren=" -set rpath=%paren%%path2%%paren% -echo rpath = %rpath% -call :CheckEmpty2 %infile% -:Rpass -if exist %infile% (del %infile% /Q) -set rfile=create_distr_m01_files - REM -- Start DISTR & M01 Data Processing -- @ECHO. @ECHO Start Time: %date% %time% @@ -223,7 +210,9 @@ cd prep_macros @ECHO. @ECHO -- CREATING FILES FOR SPATIAL ANALYSIS -- @ECHO. -%rpath% CMD BATCH %rfile%.R +rem Activate R env +call %~dp0..\Scripts\manage\env\activate_env.cmd r +call Rscript create_distr_m01_files.R if %ERRORLEVEL% GTR 0 (goto issue) @ECHO. @@ -449,18 +438,6 @@ goto end pause goto end -:CheckEmpty2 -if %~z1 == 0 (goto badR) -goto Rpass - -:badR -@ECHO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -@ECHO COULD NOT FIND R INSTALLATION. -@ECHO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -@ECHO. -pause -goto end - :mcmiss @ECHO @ECHO ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~