Skip to content

Instantly share code, notes, and snippets.

@kmunve
kmunve / regobslib_obs_example.py
Created September 26, 2025 13:22
Example for how to use regobslib to extract regobs-data: here all observations that have at least an avalanche observation, activity or incident record in Lyngen for season 2019/20.
import datetime as dt
from regobslib import Connection, SnowRegion, AvalancheObs, AvalancheActivity, SnowRegistration, Incident
import json
from pathlib import Path
from dataclasses import is_dataclass, asdict
def _to_serializable(obj):
"""Best-effort conversion of regobslib objects to JSON-serializable types."""
# Primitives pass through
@kmunve
kmunve / NAWS_regions.geojson
Created February 27, 2024 08:03
The forecasting region used by the Norwegian Avalanche Warning Service.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kmunve
kmunve / NAWS_svalbard_regions.geojson
Created February 27, 2024 08:02
The forecasting region on Svalbard used by the Norwegian Avalanche Warning Service.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kmunve
kmunve / make_simple_gif.py
Created February 8, 2024 07:32
Combine images into an animation.
import imageio
from pathlib import Path
# Define the directory containing the PNG files
# Adjust this path as necessary. Here, it's set to the current directory.
directory_path = Path(r'.')
# Step 1: Collect all PNG filenames using pathlib
filenames = list(directory_path.glob('*_event.png'))
@kmunve
kmunve / regobslib_weather_example.py
Created September 18, 2023 08:28
Script to retrieve weather data published with the Norwegian avalanche warnings.
# check regobslib for more information: https://github.com/NVE/regobslib
from regobslib import *
import datetime as dt
import pandas as pd
import matplotlib.pylab as plt
def get_data():
regions = [
SnowRegion.HELGELAND,
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
X;Y;Z;M
44797.83400349226;6818912.225566525;951.3221999999951;0
44796.98600351438;6818911.695566539;950.6389999999956;0.9980999999970663
44796.13800353557;6818911.165566552;949.9324000000051;1.9962999999988824
44795.29000355676;6818910.635566566;949.1913999999961;2.9943999999959487
44794.44200357795;6818910.10556658;948.5329999999958;3.992599999997765
44793.59400360007;6818909.575566594;947.899900000004;4.990699999994831
44792.74600362126;6818909.045566607;947.2617000000027;5.988899999996647
44791.89800364245;6818908.515566621;946.6616000000067;6.986999999993714
44791.05000366364;6818907.985566631;946.0629999999946;7.98519999999553
@kmunve
kmunve / app.py
Created October 8, 2019 12:17 — forked from vgoklani/app.py
Using Flask to output Python data to High Charts
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
@app.route('/index')
def index(chartID = 'chart_ID', chart_type = 'bar', chart_height = 350):
chart = {"renderTo": chartID, "type": chart_type, "height": chart_height,}
series = [{"name": 'Label1', "data": [1,2,3]}, {"name": 'Label2', "data": [4, 5, 6]}]
title = {"text": 'My Title'}
@kmunve
kmunve / flask_unveil_server.py
Created September 19, 2019 20:02 — forked from roman-ku/flask_unveil_server.py
A flask server for serving all JPEG images in a local directory and subdirectories. Uses unveil.js for lazy-loading of images. Thumbnails are created on the fly by PIL.
# you also need to download this file: https://github.com/luis-almeida/unveil/blob/master/jquery.unveil.js
# and place it in the same directory as this python file with the name "jquery.unveil.js"
import os
from io import BytesIO
from flask import Flask, Response, request, abort, render_template_string, send_from_directory
from PIL import Image
@kmunve
kmunve / loopfill_dataframe.py
Created July 3, 2019 07:43
Snippet on how to fill a dataframe iteratively
_df = pd.DataFrame(
columns=['aval_type', 'trigger', 'DestructiveSizeName', 'date', 'elevation', 'TerrainStartZoneName', 'Latitude', 'Longitude', 'ForecastRegionName',
'ForecastRegionTID', 'nick', 'RegID'])
for av in avals:
_df = _df.append({'aval_type': av.AvalancheName,
'trigger': av.AvalancheTriggerName,
'DestructiveSizeName': av.DestructiveSizeName,
'date': av.DtObsTime.strftime('%Y-%m-%d'),
'elevation': av.Height,
'TerrainStartZoneName': av.TerrainStartZoneName,
@kmunve
kmunve / rhk_training.json
Last active June 19, 2019 11:48
A json file used for populating a calender
{
events: [
{
title: "MKH",
start: "2019-06-19"
},
{
title: "SBH",
start: "2019-06-19"
},