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
30 changes: 26 additions & 4 deletions deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ curl -O https://raw.githubusercontent.com/UNDP-Data/rapida/refs/heads/main/deplo
curl.exe -O https://raw.githubusercontent.com/UNDP-Data/rapida/refs/heads/main/deploy/pixi.toml
```

## .env file
Create a .env file and define following environmental variables.
Alternatively ensure the environmental variables defined below exists in your system
## Environmental variables

There are two types of environmental variables: mandatory and optional.
The **mandatory** ones contain information that is required to operate specific parts of rapida like
downloading imagery from earthdata through a token or authenticating to [space-track.org](www.space-track.org).
Rapida throws and error if these variables are not defined and needed.

```shell
# for uploading to azure
TENANT_ID=
Expand All @@ -34,8 +38,14 @@ EARTHDATA_TOKEN=
# for predicting precisely VIIRS orbits
SPACETRACK_USER=
SPACETRACK_PASSWORD=
```

The **optional** environmental variables do not generate errors if not defined. Rapida lets the user know whenever these
variables arte detected and detected and override/change default behaviour with a custom one.

```shell
# override road type default seed for connectivity analysis
#Default values

#"motorway": 105,
#"trunk": 90,
Expand All @@ -45,10 +55,22 @@ SPACETRACK_PASSWORD=
#"unclassified": 40,
#"residential": 35,
#"service": 25
# variables that change default values

#MJOLNIR_MOTORWAY_SPEED=60
#MJOLNIR_TRUNK_SPEED=50
#MJOLNIR_PRIMARY_SPEED=35
#MJOLNIR_SECONDARY_SPEED=25
#MJOLNIR_UNCLASSIFIED_SPEED=15
#MJOLNIR_RESIDENTIAL_SPEED=12
#MJOLNIR_SERVICE_SPEED=8
#CONNECTIVITY_OSM_SOURCE=MOVISDA # MOVISDA, GEOFABRIK

MJOLNIR_SECONDARY_SPEED=40
```




## run NTL
```shell
pixi run rapida ntl detect --help
Expand Down
41 changes: 27 additions & 14 deletions deploy/pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,36 @@ platforms = ["linux-64", "win-64", "osx-arm64"]
python = ">=3.12"
numpy = "<2"
gdal = ">=3.12.0"
fiona = "*"
rasterio = "*"
geopandas = "*"
shapely = "*"
exactextract = "*"
rio-cogeo = "*"
pyarrow = "*"
h5py = ">=3.16.0"
satpy = ">=0.59.0"
matplotlib = ">=3.10.9"
netcdf4 = ">=1.7.3"
h5netcdf = ">=1.8.1"
libgdal-netcdf = "*"
osmium-tool = ">=1.19.1,<2"
#playwright="*"
#fiona = "*"
#rasterio = "*"
#geopandas = "*"
#shapely = "*"
#exactextract = "*"
#rio-cogeo = "*"
#pyarrow = "*"
#h5py = ">=3.16.0"
#satpy = ">=0.59.0"
#matplotlib = ">=3.10.9"
#netcdf4 = ">=1.7.3"
#h5netcdf = ">=1.8.1"
#marimo = ">=0.23.14,<0.24"

[pypi-dependencies]
# Pixi natively understands Git URLs in the pypi section!
# Pixi natively understands Git URLs in the pypi section in pyproject.toml
rapida = { git = "https://github.com/UNDP-Data/rapida.git", branch = "main" }
dotenv-cli="*"
#maplibre = { version = ">=0.3.6, <0.4", extras = ["ipywidget"] }
#openlayers = ">=0.1.6, <0.2"

[activation.env]
# Forces Playwright to install browsers inside the local project folder
PLAYWRIGHT_BROWSERS_PATH = ".pixi/playwright-browsers"


[tasks]
rapida = "dotenv -e .env rapida"
setup = {cmd = "dotenv -e .env playwright install chromium --only-shell"}
rapida = {cmd = "dotenv -e .env rapida", depends-on=["setup"]}
#rapida = "dotenv -e .env rapida"
32 changes: 18 additions & 14 deletions rapida/cli/connectivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ def parse_intervals(ctx, param, value):
type=str, callback=validate_variables,
help=f"One or more RAPIDA population variable to compute zonal stats for withing the connectivity zones"
)

@click.option('-l','--stats-admin-level',
type=click.IntRange(min=1, max=2, clamp=False),
help='Admin level from where to extract the admin features when computing stats for --popvar/s.'\
'The statistics will be computed from the results of intersecting the isochrones with admin data'
)
@click.option(
"--dst-dir",
"-d", # Short option
Expand Down Expand Up @@ -134,16 +138,16 @@ def parse_intervals(ctx, param, value):
)


@click.option(
'--smooth',
is_flag=True,
help=(
"By default Valhalla routing engine create isochrones using a grid and the edges of polygons are squarish."
"Use this flag to smoothen them out. in some instances this can alter the isochrones significantly."
"In general it is save to use smoothing on small areas (towns, cities)"
),
default=False
)
# @click.option(
# '--smooth',
# is_flag=True,
# help=(
# "By default Valhalla routing engine create isochrones using a grid and the edges of polygons are squarish."
# "Use this flag to smoothen them out. in some instances this can alter the isochrones significantly."
# "In general it is save to use smoothing on small areas (towns, cities)"
# ),
# default=True
# )

@click.option(
'--disjoint',
Expand All @@ -161,16 +165,16 @@ def parse_intervals(ctx, param, value):
async def connectivity(ctx, bbox:tuple[float, float, float, float]=None, travel_mode:str=None,
time_intervals:list[int] =None, dst_dir:str=None,
barriers_dataset:str=None, barriers_layer:str=None, barriers_buffer:int=None,
sites_dataset:str=None, sites_layer:str=None, popvar:str|tuple[str]=None,
sites_dataset:str=None, sites_layer:str=None, popvar:str|tuple[str]=None, stats_admin_level:int=None,
max_snap_distance:float=None, clip_country:str=None,
disjoint:bool=False, smooth:bool=False
disjoint:bool=False, smooth:bool=True
):
logger.info(f'Running connectivity analysis')
progress = ctx.obj.get('progress')
with progress:
return await run_connectivity_analysis(
bbox=bbox, dst_dir=dst_dir, travel_mode=travel_mode, time_intervals=time_intervals,
barriers_dataset=barriers_dataset, barriers_layer=barriers_layer, barriers_buffer=barriers_buffer,
sites_dataset=sites_dataset, sites_layer=sites_layer, pop_vars=popvar,
sites_dataset=sites_dataset, sites_layer=sites_layer, pop_vars=popvar,stats_admin_level=stats_admin_level,
progress=progress, radius=max_snap_distance, clip_country=clip_country, disjoint=disjoint, smooth=smooth
)
2 changes: 1 addition & 1 deletion rapida/components/population/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def import_raster(self, source=None, **kwargs):
**kwargs
)

os.remove(source)
if os.path.exists(source):os.remove(source)
os.rename(imported_local_path, source)
return source

Expand Down
Loading
Loading