Skip to content

Instantly share code, notes, and snippets.

View davidchall's full-sized avatar

David C Hall davidchall

View GitHub Profile
@davidchall
davidchall / app.py
Last active September 29, 2024 15:22
Cat food calculator
# Editor: https://shinylive.io/py/editor/#gist=697a9f02c3c000de6ae4b10ac1e725eb
# App: https://shinylive.io/py/app/#gist=697a9f02c3c000de6ae4b10ac1e725eb
from pathlib import Path
from shiny import ui, render, App, Inputs, Outputs, Session
calories_target = 200
app_ui = ui.page_fluid(
@davidchall
davidchall / chicago-fullnote-bibliography-including-subsequent.csl
Created August 31, 2021 17:33
Chicago Style (full note) adjusted to show full note for subsequent citations
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="note" version="1.0" demote-non-dropping-particle="display-and-sort" page-range-format="chicago">
<info>
<title>Chicago Manual of Style 17th edition (full note, including subsequent)</title>
<id>http://www.zotero.org/styles/chicago-fullnote-bibliography-including-subsequent</id>
<link href="http://www.zotero.org/styles/chicago-fullnote-bibliography" rel="template"/>
<link href="http://www.chicagomanualofstyle.org/tools_citationguide.html" rel="documentation"/>
<author>
<name>Julian Onions</name>
<email>[email protected]</email>
#!/bin/bash
# aliases
alias e='emacs -nw'
alias nb='jupyter notebook'
alias lab='jupyter lab'
alias chrome="open -a Google\ Chrome.app"
alias finder="open -a Finder"
alias preview="open -a Preview"
quicklook () { qlmanage -p "$*" >& /dev/null; }
@davidchall
davidchall / ambiguous-abs.patch
Created October 30, 2017 17:42
Patch for Sherpa 2.2.4
Index: COMIX/Main/Single_Process.C
===================================================================
diff --git a/branches/COMIX/Main/Single_Process.C b/branches/COMIX/Main/Single_Process.C
--- a/branches/COMIX/Main/Single_Process.C (revision 31007)
+++ b/branches/COMIX/Main/Single_Process.C (revision 31008)
@@ -265,8 +265,8 @@
for (size_t j(0);j<nfmap;++j) {
long int src, dest;
*map>>src>>dest;
- Flavour ft((kf_code)(abs(src)),src<0);
@davidchall
davidchall / topas3.patch
Last active May 13, 2016 15:48
Changes to Geant4.10.2.p01 for TOPAS 3.0
diff -Naur geant4.10.02.p01/source/geometry/solids/specific/src/G4TessellatedSolid.cc geant4.10.02.p01-topas3/source/geometry/solids/specific/src/G4TessellatedSolid.cc
--- geant4.10.02.p01/source/geometry/solids/specific/src/G4TessellatedSolid.cc 2016-03-02 03:24:12.000000000 -0500
+++ geant4.10.02.p01-topas3/source/geometry/solids/specific/src/G4TessellatedSolid.cc 2016-05-13 11:42:21.000000000 -0400
@@ -1674,7 +1674,7 @@
const G4ThreeVector& v)const
{
G4double dist = DistanceToInCore(p,v,kInfinity);
-#ifdef G4SPECSDEBUG
+//#ifdef G4SPECSDEBUG
if (dist < kInfinity)
@davidchall
davidchall / topas2to3
Last active May 22, 2016 15:11
Script to (partially) convert TOPAS parameter files from v2.0 to v3.0
#!/bin/sh
# This script will (partially) convert TOPAS parameter files from v2.0 to v3.0.
# A backup of the original file is created with a .bak extension.
# WARNING: using this script twice on the same file will delete the backup file.
if [ "$#" -eq 0 ]; then
echo "Usage: $0 filename"
fi
@davidchall
davidchall / weighted_mean.md
Created March 16, 2016 21:18
Weighted mean of a vector using covariances

Given a set of covariance matrices pcov of shape (n,m,m) and a set of parameter estimates popt of shape (n,m), the mean parameter estimates are:

weight = np.linalg.inv(pcov)
pcov_mean = np.linalg.inv(np.sum(weight, axis=0))
popt_wgt = np.einsum('ijk,ik->ij', weight, popt)

popt_mean = np.dot(pcov_mean, np.sum(popt_wgt, axis=0))

@davidchall
davidchall / topas_batch_uncertainty
Last active March 2, 2016 01:27
Calculates overall statistical uncertainty in a TOPAS distribution using the batch method
#!/usr/bin/env python
###############################################################
## Author: David Hall
## Email: david(dot)hall(dot)physics(at)gmail(dot)com
## Date: March 1st, 2016
## Program: topas_batch_uncertainty
##
## This program reads a set of TOPAS result files and uses
## the batch method to compute the relative statistical
@davidchall
davidchall / top2root
Last active December 21, 2015 03:59
This program reads histograms stored in topdrawer format and outputs them as ROOT histograms (TH1F) or graphs (TGraphErrors) in a ROOT file. It requires a working installation of PyROOT.
#!/usr/bin/env python
###############################################################
## Author: David Hall
## Email: David(dot)Hall(at)physics(dot)ox(dot)ac(dot)uk
## Date: 15th August 2013
## Program: top2root
##
## This program reads in a topdrawer file and converts the
## plots contained within to the ROOT histogram format.