Skip to content

Instantly share code, notes, and snippets.

@sickel
sickel / importforecast.py
Last active March 17, 2024 08:58
Script to store forecasts from met.no
#!/usr/bin/python3
"""
Data are downloaded hourly from api.met.no using
/usr/bin/curl -s -A "<email>" "https://api.met.no/weatherapi/locationforecast/2.0/complete?lat=59&lon=10" > /var/www/html/homelog2/weather.json 2>/dev/null
check https://api.met.no/ for terms and usage
After being downloaded, the data are available on a local http-server. The reason I am not reading the file directly in
this script is that I am also using it for other purposes that need the http
schema for table: https://gist.github.com/sickel/9ae88a47f665c0962120078ed93e103a
@sickel
sickel / forecast.sql
Created March 15, 2024 06:25
Database table to store forecasts from met.no
create table forecast(
parameter varchar not null,
value numeric not null,
unit varchar,
timestamp timestamp not null);
alter table forecast add primary key(parameter,timestamp);
def measureline(search,reverse=False,offset=0):
"""
To be run in the QGIS python console. Select a line, run measureline(<search>) and it will put a marker at the point
<search> mapunits along the line from the start of the line and print out the lat,lon of the point.
By either setting a negative search length or setting reverse to True, it will measure from the end of the line instead.
A number given as <offset> will be subtracted from <search>. If an offset is given, search should be a positive value.
Developed in QGIS 3.20, will probably run in other 3.X version, will probably not work in QGIS 2.X
"""
@sickel
sickel / readfrost.py
Last active September 10, 2021 10:31
Read lightning data from frost,met.no
#!/usr/bin/python3
"""Reads lightning data from frost.met.no. Inserts all points and auxilliary data into a PostGIS database. After allt
the points are inserted, uncertainty ellipses are calculated for each point and stored in the same record. In QGIS it is
then possible to use a calculated geometry for either the point or the ellipse"""
# Using format strings, so needs python >= 3.6
# If this file is stored in a version control system, rewrite the next two lines to
# read clientid and connection parameters from a file that is not checked in in the VCS
client_id="FROSTCLIENTID"
@sickel
sickel / dataleser.py
Last active November 17, 2019 17:30
For å lese krysstabeller
#!/usr/bin/python3
from openpyxl import load_workbook
import sys
filenames=[]
for i in range(1,len(sys.argv)):
print(sys.argv[i])
filenames.append(sys.argv[i])
@sickel
sickel / readuluru.py
Created October 30, 2019 13:07
File to import csv-file into postgres
#!/usr/bin/python3
# This script can read a csv-file exported from radassist and insert data into a postgis table to be used by the qgisSpectre plugin
#
# schema.sql creates a appropriate table in a postgis enabled postgresql database
#
# Copyright Morten Sickel, 2019
import sys
import psycopg2
@sickel
sickel / waterfallapplet.java
Created October 30, 2019 07:03
Waterfall - java Keep it here, use some ideas for qgis plugin
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.swing.*;
/*
(c) Morten Sickel 2010 - 2011
@sickel
sickel / deamontest.py
Last active June 4, 2019 19:35
A python deamon that spins of an extra thread and acts on signals
# Concept of daemon that spins of an extra thread and can be controlled by signals
#
# I have rewritten the script slightly after I did this log. So some output has changed a bit,
# the signals are still the same
#
# This has to be run with python3
#
# Developed and tested on debian 9.9 - all modules installed with apt
#
# morten@latlon:/home/disk0/m/GardenController$ sudo tail -f /var/log/messages &
@sickel
sickel / README.md
Created May 20, 2019 18:58 — forked from mill1000/README.md
Headless A2DP Audio Streaming on Raspbian Stretch

About

This gist will show how to setup Raspbian Stretch as a headless Bluetooth A2DP audio sink. This will allow your phone, laptop or other Bluetooth device to play audio wirelessly through a Rasperry Pi.

Motivation

A quick search will turn up a plethora of tutorials on setting up A2DP on the Raspberry Pi. However, I felt this gist was necessary because this solution is:

  • Automatic & Headless - Once setup, the system is entirely automatic. No user iteration is required to pair, connect or start playback. Therefore the Raspberry Pi can be run headless.
  • Simple - This solution has few dependencies, readily available packages and minimal configuration.
  • Up to date - As of December 2017. Written for Raspbian Stretch & Bluez 5.43

Prerequisites

@sickel
sickel / NuclearTests.R
Last active January 24, 2018 13:46
An R script to make a plot of the number of nuclear tests per country and year
if(!exists("lang")){lang="EN"}
directory="https://gist.githubusercontent.com/sickel/8accd0d2ca32c9f7624e10f4837095f5/raw/f70630c17010bc33407caa3d08dc8d6283bc7f23/"
# or download https://gist.githubusercontent.com/sickel/8accd0d2ca32c9f7624e10f4837095f5/raw/f70630c17010bc33407caa3d08dc8d6283bc7f23/NuclearTests.csv
# and set the directory to where the file is stored.
# Data source: http://www.ldeo.columbia.edu/~richards/my_papers/WW_nuclear_tests_IASPEI_HB.pdf and https://en.wikipedia.org/wiki/List_of_nuclear_weapons_tests_of_North_Korea
# In theory, it should be possible to source this file directly into R from the "Raw" url, for some reason this fails,
# so copy the script and past it into an editor.