Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ docs/doxygen/html
build.sh

#tools
tools/postprocessing/loadInParaview.py
tools/mesonh/postprocessing/loadInParaview.py
tests/config_firecast_local.bash
tools/config_firecast_local.bash
tools/ai
Expand Down
2 changes: 1 addition & 1 deletion docs/source/user_guide/landscape_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ If no wind variable is present in the NetCDF file, supply wind via ``addScalarLa
Creating a Landscape File from Python
-------------------------------------

The helper ``tools/preprocessing/genForeFireCase.py`` builds a compliant NetCDF file directly from NumPy arrays:
The helper ``tools/mesonh/preprocessing/genForeFireCase.py`` builds a compliant NetCDF file directly from NumPy arrays:

.. code-block:: python

Expand Down
4 changes: 2 additions & 2 deletions tests/python/test_genforefirecase.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Smoke test for tools/preprocessing/genForeFireCase.py.
"""Smoke test for tools/mesonh/preprocessing/genForeFireCase.py.

The landscape file is the thing standing between a new user and their first
simulation, so this checks the whole path rather than the writer alone: build
Expand All @@ -21,7 +21,7 @@

sys.path.insert(0, os.path.join(
os.path.dirname(os.path.abspath(__file__)), "..", "..",
"tools", "preprocessing"))
"tools", "mesonh", "preprocessing"))

import numpy as np # noqa: E402
from netCDF4 import Dataset # noqa: E402
Expand Down
233 changes: 1 addition & 232 deletions tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,236 +8,5 @@ Scripts and pages that users run around ForeFire. Build and CI helpers live in
| `htdocs/` | Web pages served by `listenHTTP[]` from `$FOREFIREHOME/tools/htdocs`; see `htdocs/README.md` |
| `tiles/` | `fftile.py` writes and inspects `.fftile` landscapes; see `tiles/README.md` |
| `wildfire_ROS_models/` | Python rate of spread models and `.ffann` export; see its `README.md` |
| `preprocessing/` | Landscape and Meso-NH case preparation (below) |
| `postprocessing/` | VTK export and plots of ForeFire and Meso-NH outputs (below) |
| `3nestFFCASE/` | Template of a three-nest Meso-NH case for SLURM, with site-specific paths |
| `sampleUses.py` | Example chaining the pre and postprocessing steps of a Meso-NH case |
| `mesonh/` | Pre and postprocessing scripts and a SLURM case template for runs coupled with Meso-NH; see `mesonh/README.md` |
| `TODO.md` | Planned tools |

The rest of this page covers the Meso-NH workflow. These scripts create the
files needed to run a simulation coupled with Meso-NH. To couple, also edit
the `&NAM_FOREFIRE` namelist in the EXSEG file. The Meso-NH guide
(`docs/source/user_guide/mesonh.rst`) walks through a full coupled run.

# Preprocessing Scripts

List of preprocessing scripts:
- ***clickImageToLocation.py*** sets the coordinates for the Init.ff file
- ***genForeFireCase.py*** writes the **NetCDFfile** landscape (fuel, elevation, wind, flux models) from numpy arrays
- ***genPrepIdeal.py*** fills `PRE_IDEA1.pattern` into the `PRE_IDEA1.nam` namelist of a Meso-NH ideal case
- ***kmlDomain.py*** extracts kml files from a netcdf file
- ***PGD2Init.py*** creates the **InitFile**=Init.ff in the **ForeFireDataDirectory** directory
- ***prealCF2Case.py*** creates the **NetCDFfile**=data.nc file in the **ForeFireDataDirectory** directory


### genForeFireCase

Lives in `preprocessing/genForeFireCase.py` and contains the preprocessing
routine *FiretoNC*, used to generate a packed data landscape in cdf format for
ForeFire.

**Usage:** FiretoNC(filename, file name
domainProperties, the domain extension (map matching forefire parameters SWx, SWy, SWz, Lx, Ly, Lz, t0, Lt)
parametersProperties, the simulation date and duration. All of date, duration, refYear, refDay, year, month and day are required
fuelModelMap, a numpy integer array containing the indexes of fuel type
elevation=None, a numpy real array with the elevation
wind=None, a map with a "zonal" and "meridian" numpy real array values
fluxModelMap=None): a map with a ("table" and "name" ) and fMap "data" numpy int array values containing indices to the corresponding flux model

Field arrays are indexed outermost axis first: `(NY, NX)`, or `(NZ, NY, NX)`
and `(NT, NZ, NY, NX)` when they vary with height or time — the same
convention `prealCF2Case.py` uses.

`tests/python/test_genforefirecase.py` builds a landscape, loads it and runs a
short simulation; it doubles as a worked example.


### PGD2Init

Creates the **InitFile**=Init.ff in the **ForeFireDataDirectory** directory.
The **InitFile** file contains the location of the fire front at initialization (non-parallel init).
**Usage:** PGD2Init.py inMNH_PGD_File.nc lat lon startTimeInseconds > pathtoForeFireDataDirectory/Init.ff
- INPUT:
- inMNH_PGD_File.nc (ex:/001_pgd/PGD_D80mA.nc)
- lat lon : latitude and longitude (ex: 39.7556 -8.1736)
- time of ignition in seconds (ex: 50000)
- OUTPUT:
- the **InitFile**=Init.ff file in the **ForeFireDataDirectory**




### prealCF2Case

creates the **NetCDFfile** file containing the data needed by the simulation (data.nc), otput uses the *FiretoNC* routine

**Usage:** a Python module, not a command. From `tools/`:
```python
from preprocessing.prealCF2Case import PGD2Case
PGD2Case(pgd_path, png_path, out_path, dateStartDom)
```
- `pgd_path`: the Meso-NH PGD file (`inMNH_PGD_File.nc`)
- `png_path`: the png on which the fuel distribution is constructed
- `out_path`: the data.nc file to write
- `dateStartDom`: the start date of the domain

`sampleUses.py` shows it in a full case.

ouutput is generated from the *FiretoNC* routine in *genForeFireCase.py*

reads dimensions from the PGD imput file

example of NetCDF "data.nc":
```
dimensions:
DIMX = 302 ;
DIMY = 302 ;
DIMZ = 1 ;
DIMT = 1 ;
variables:
int fuel(DIMT, DIMZ, DIMY, DIMX) ;
fuel:type = "fuel" ;
int heatFlux(DIMT, DIMZ, DIMY, DIMX) ;
heatFlux:type = "flux" ;
heatFlux:model0name = "heatFluxBasic" ;
heatFlux:indices = 0 ;
int vaporFlux(DIMT, DIMZ, DIMY, DIMX) ;
vaporFlux:type = "flux" ;
vaporFlux:model1name = "vaporFluxBasic" ;
vaporFlux:indices = 1 ;
char domain ;
domain:type = "domain" ;
domain:SWx = 288520. ;
domain:SWy = 282520. ;
domain:SWz = 0 ;
domain:Lx = 24160. ;
domain:Ly = 24160. ;
domain:Lz = 0 ;
domain:t0 = 0 ;
domain:Lt = Infinityf ;
char parameters ;
parameters:type = "parameters" ;
parameters:projectionproperties = "41.551998,8.828396,41.551998,8.828396" ;
parameters:date = "2017-06-17_14:00:00" ;
parameters:duration = 100000 ;
parameters:projection = "OPENMAP" ;
parameters:refYear = 2017 ;
parameters:refDay = 168 ;

// global attributes:
:version = "FF.1.0" ;
```
TO BE IMPLEMENTED:
- a routine that given the coordinates, extract a colormap for fuels
- we need to translate the colormap in integer numbers

## kmlDomain
creates the kml file showing the geographical domain extensions starting from a netCDF domain

**Usage:**
```
python3 kmlDomain.py PGDFile > kmlfile
```
- INPUT: the netCDF containing the informations of the modelled domain (ex: *KTEST_2D/001_pgd/PGD_D160mA.nc*)
- OUTPUT:the desired kml file (ex: *KTEST_2D/001_pgd/kmlD160.kml*)


# Postprocessing Scripts

List of postprocessing scripts:
- ***pMNHFF2VTK.py***
- ***plotcontour.py***

`ffToGeoJson.py` (GeoJSON and KML export) lives in `preprocessing/`.

## pMNHFF2VTK

Builds vtk from forefire outputs for parallels runs

**Usage:**

python PathtoScript pathtoForefireOutput pathForefireOutputGeom pathtodirOutput
- on a single node:
- computes all steps:

```
python3 $FOREFIREHOME/tools/postprocessing/pMNHFF2VTK.py MODEL3/output ForeFire/Outputs/output vtkout3/*
```

- computes step number n=4

```
python3 $FOREFIREHOME/tools/postprocessing/pMNHFF2VTK.py MODEL3/output ForeFire/Outputs/output vtkout3/ -steps 4 5
```

- on multiple nodes (SLURM):
you should launch pMNHFF2VTK by an opportune script (**sbatchRunVtkFilesM3** for model 3)

example of script:
```
seqSTEP=$1
stepLength=$2
startSTEP=$(($stepLength * $SLURM_ARRAY_TASK_ID))
endSTEP=$(($stepLength * ($SLURM_ARRAY_TASK_ID + 1) ))
echo "ID $SLURM_ARRAY_TASK_ID computing $startSTEP to $endSTEP"

for i in `seq ${startSTEP} ${seqSTEP} ${endSTEP}`;
do
srun -n1 --exclusive python3 $FOREFIREHOME/tools/postprocessing/pMNHFF2VTK.py MODEL3/output ForeFire/Outputs/output vtkout3/ -steps $i $(($i + $seqSTEP)) &
done
wait
```
run with `sbatch --array=0-2 script_vtk_array 2 10` : will launch 3 tasks SLURMID (0, 1 and 2) of 10 steps each consisting of 10/2 srun processes of length 2 on each task
so ID 0 will compute 0-2 3-4 5-6 7-8 9-10
so ID 1 will compute 11-12 13-14 15-16 17-18 19-20
so ID 2 will compute 21-22 23-24 25-26 27-28 29-30
Typically fo 2000 outputs on 10 tasks : "sbatch --array=0-9 script_vtk_array 20 200"

When all steps are computed, run another time:
```
python3 $FOREFIREHOME/tools/postprocessing/pMNHFF2VTK.py MODEL3/output ForeFire/Outputs/output vtkout3/
```

with that all time steps will be synchronized with Meso-NH time.

# Troubleshooting coupled runs

## When launching a simulation do always the following steps

- check that all directories called in RUN_MNH_Nproc are really there, otherwise this will cause errors difficult to debug:

```
~/runMNH
rm -rf MODEL/*
rm -rf vtkout/*
rm -rf ForeFire/Outputs/*
rm -rf parallel/*.domain*
rm -rf parallel/1/*
rm -rf parallel/0/*


ln -sf ../001_pgd/PGD_D* .
ln -sf ../002_real/AND1.* .
ln -sf ../003_run/JUL19.1.RUN1D.008* .
#ln -sf ../004_SpawnReal/AND2.* .
#ln -sf ../005_SpawnReal/AND3.* .

```
- When launching the simultaions, sometiles bmap is not good!! check with
```
grep bmap | logfile.out
```
if everything is ok you will have something of the type:
```
Domain 0 size:202:202:52 coord:24240:24240 my bmap is 2424:2424 res 10:10
```
then you can comment the following line in the RUN_MNH script to avoid such problem in the future:
```
rm -rf parallel/*.domain*
```

- The vtk postprocesser pMNHFF2VTK gives the error:
```
found no domains
```
if is so you should move all the output.1* output.2* ... (with the exception of the output.0* files) in a new directory *pathForefireOutputGeom* and use that one in the post processing
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ echo "ID $SLURM_ARRAY_TASK_ID computing $startSTEP to $endSTEP"

for i in `seq ${startSTEP} ${seqSTEP} ${endSTEP}`;
do
srun -n1 --exclusive python3.9 ~/soft/firefront/tools/postprocessing/pMNHFF2VTK.py MODEL1/output ForeFire/OutputsM1150/output vtkout1/ -steps $i $(($i + $seqSTEP)) &
srun -n1 --exclusive python3.9 ~/soft/firefront/tools/mesonh/postprocessing/pMNHFF2VTK.py MODEL1/output ForeFire/OutputsM1150/output vtkout1/ -steps $i $(($i + $seqSTEP)) &
done
wait

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ echo "ID $SLURM_ARRAY_TASK_ID computing $startSTEP to $endSTEP"

for i in `seq ${startSTEP} ${seqSTEP} ${endSTEP}`;
do
srun -n1 --exclusive python3.9 ~/soft/firefront/tools/postprocessing/pMNHFF2VTK.py MODEL2/output ForeFire/OutputsM2150/output vtkout2/ -steps $i $(($i + $seqSTEP)) &
srun -n1 --exclusive python3.9 ~/soft/firefront/tools/mesonh/postprocessing/pMNHFF2VTK.py MODEL2/output ForeFire/OutputsM2150/output vtkout2/ -steps $i $(($i + $seqSTEP)) &
done
wait

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ echo "ID $SLURM_ARRAY_TASK_ID computing $startSTEP to $endSTEP"

for i in `seq ${startSTEP} ${seqSTEP} ${endSTEP}`;
do
srun -n1 --exclusive python3.9 ~/soft/firefront/tools/postprocessing/pMNHFF2VTK.py MODEL3/output ForeFire/Outputs/output vtkout3/ -steps $i $(($i + $seqSTEP)) &
srun -n1 --exclusive python3.9 ~/soft/firefront/tools/mesonh/postprocessing/pMNHFF2VTK.py MODEL3/output ForeFire/Outputs/output vtkout3/ -steps $i $(($i + $seqSTEP)) &
done
wait

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bash RUN_PGD PRE_PGD1.nam_2000m
bash RUN_PGD PRE_PGD1.nam_400m
bash RUN_PGD PRE_PGD1.nam_80m
bash RUN_PGDNEST
# recommencer en generant les KML /tools/preprocessing/kmlDomains.py et trouver la bonne emprise du domaine en changeant IXOR et IYOR dans le PDG_400m
# recommencer en generant les KML /tools/mesonh/preprocessing/kmlDomains.py et trouver la bonne emprise du domaine en changeant IXOR et IYOR dans le PDG_400m

cd ../002_real
cp /data/filippi_j/saphir/data/ecmwfFC/$mydate/*grib* .
Expand All @@ -35,6 +35,6 @@ bash RUN_REAL
cd ../003_run/
sbatch RUN_MESONH_120p

# l'étape d'après c'est de generer le fichier de paysage pour ForeFire, data.nc ou autre, /tools/preprocessing/prealCF2case.py avec une image de fond optionelle /tools/preprocessing/getBGFromCFCase.py va donner un tif qu'il faut ensuite transformer en PNG 5 couleurs en utilisant un code de sermentation ou bien tif2PngFuel.py qui fait une classification assez basique à partir d'une image et d'une image d'exemple que l'on peut li donner.
# l'étape d'après c'est de generer le fichier de paysage pour ForeFire, data.nc ou autre, /tools/mesonh/preprocessing/prealCF2case.py avec une image de fond optionelle /tools/preprocessing/getBGFromCFCase.py va donner un tif qu'il faut ensuite transformer en PNG 5 couleurs en utilisant un code de sermentation ou bien tif2PngFuel.py qui fait une classification assez basique à partir d'une image et d'une image d'exemple que l'on peut li donner.

# il faut ensuite trouver les points d'allumages, ainsi que les temps précis de démarrage, et tester le fichier sans couplage avec MesoNH, il y a pour cela le fichier run.ff dans 006_runff/ForeFire/run.ff regarder les sorties avec des kml générés par ffToGeoJson.py qui va faire les kml - attention de changer les parametre year month day dans le params.ff et d'ajuster le vent - pour l'instant pas de procédure pour faire automatiquement un init.ff.. mais ca devrait changer
Loading