Skip to content

Instantly share code, notes, and snippets.

View willu47's full-sized avatar

Will Usher willu47

View GitHub Profile
@willu47
willu47 / get_dual_osemosys.py
Created February 20, 2024 10:19
Extract the dual values for the E8_AnnualEmissionsLimit constraint from the CPLEX solution of an OSeMOSYS model
import pandas as pd
import sys
from logging import getLogger
logger = getLogger(__name__)
def main(file_path: str) -> pd.DataFrame:
"""Read CPLEX solution file and return dual values for E8_AnnualEmissionsLimit constraint.
"""
@willu47
willu47 / transform_cplex.py
Created June 13, 2019 07:14
Transforms the outputs from CPLEX into CSV
import os, sys, time
#########################################################################################
#########################################################################################
#if len(sys.argv) != 3:
# print '''Usage: {0}
# <input>
# <output>\n\n\n'''.format(sys.argv[0])
# sys.exit()
@willu47
willu47 / move_city.py
Last active February 13, 2019 08:24
Python script to move a city (or any shapefile) around. I couldn't work out how to detemine source lat lon from the shapefile (e.g. from centroid of convex hull of all the polygons).
from shapely.affinity import translate
from shapely.geometry import Point, MultiPolygon
from shapely.ops import transform
from functools import partial
import pyproj
import geopandas as gpd
import os
def move_city(filepath, source_latlon, destination_latlon):
@willu47
willu47 / process.py
Last active May 21, 2018 09:52
Convert directory containing numpy arrays serialised using pyarrow into folder of csv files
import pyarrow as pa
import os
from csv import writer
from sys import argv
import numpy as np
def get_data(filepath):
data = None
with pa.memory_map(filepath, 'rb') as f:
f.seek(0)
@willu47
willu47 / distingify.py
Created March 13, 2018 11:37
Converts the AKWF single-wave sample pack into the format required for the Expert Sleepers Disting Mk4
"""
Navigate to the root of the AKWF folder downloadable from http://www.adventurekid.se/AKRTfiles/AKWF/AKWF.zip
and run this script using the command ``python3 distingify.py``
"""
import os
def main():
folder_list = []
for folder in os.listdir():
if os.path.isdir(folder):