Instantly share code, notes, and snippets.

# Thomas A Caswell tacaswell

Created Nov 15, 2022
two slope scale for Matplotlib
View demo.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import itertools import numpy as np import matplotlib.pyplot as plt import matplotlib.scale as mscale def factory(break_point, slope_ratio): def forward(values): out = np.array(values, copy=True) out -= break_point
Created Sep 6, 2022
Minimal functional Matplotlib
View miniplotlib.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 from types import SimpleNamespace import matplotlib.image as mimage from matplotlib.patches import Rectangle from matplotlib.backends.backend_agg import RendererAgg import matplotlib.transforms as mtransforms import matplotlib.path as mpath import matplotlib.colors as mcolors import numpy as np
Last active Aug 9, 2022
factory for adding zoom callback to matplotlib graphs
View simp_zoom.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import matplotlib.pyplot as plt def zoom_factory(ax,base_scale = 2.): def zoom_fun(event): # get the current x and y limits cur_xlim = ax.get_xlim() cur_ylim = ax.get_ylim() # set the range cur_xrange = (cur_xlim[1] - cur_xlim[0])*.5
Created Feb 11, 2022
Notes on conda "overlays"
View overlays.md

# Hot-fixing and extending conda environments

## Introduction

We deploy root-owned conda environments which are the basis of the data collection and analysis environments. On one hand because these are owned by root they are write-protected and ensure that users can not accidentally break the environment, on the other hand because they are write-protected they can not be upgraded or extended. While we want to run with a stable, standard, well understood software environment, we do need this

Last active Jan 27, 2022
datathoughts
View datathoughts.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import numpy as np import matplotlib import matplotlib.lines from matplotlib.artist import allow_rasterization import matplotlib.pyplot as plt class MatplotlibException(Exception): ...
Last active Oct 27, 2021
What time is it where your friends are?
View world_clock.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 #! /usr/bin/env python3 _facilities = { "SLAC/ALS": "America/Los_Angeles", "APS": "America/Chicago", "NSLS-II": "America/New_York", "DLS": "Europe/London", "MAXIV": "Europe/Paris", "SLS": "Europe/Paris",
Last active Aug 13, 2021
A quick little function to walk through the axes in a Figure instance and label each one with annotate.
View label_axes_iterate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 import string from itertools import cycle from six.moves import zip def label_axes(fig, labels=None, loc=None, **kwargs): """ Walks through axes and labels each. kwargs are collected and passed to annotate
Last active Feb 18, 2021
Files for working with reduced data from 2020-12 experiments at XPD

# Collection of notebooks an files for playing with gpcam data

1. explore_pgcam_data.ipynb -> demo of how to pulll reduced data out of the msgpack databroker
2. extract.py -> code run on xpd against raw data broker to sort out what raw runs we are interested in
3. reprocess.py -> code run to re-process the raw data and produce the reduced outputs
Created Jan 17, 2013
Format nicely printed labels based on pi for matplotlib x-axis
View pi_format.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 def format_frac(fr): '''Convert a/b to latex''' sp = str(fr).split('/') if len(sp) == 1: return sp[0] else: return r'$\frac{%s}{%s}$' % tuple(sp) frac_size = 4
Created May 16, 2020
Example of how to ingest sensord logs (from journalctl) to EventModel
View ingest_sensord.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 from event_model import compose_run import datetime import dateutil.parser import itertools from io import StringIO import subprocess import numpy as np import functools def extract_event(ts, batch):