Skip to content

Instantly share code, notes, and snippets.

View nickrsan's full-sized avatar

Nick Santos nickrsan

View GitHub Profile
@nickrsan
nickrsan / Synchronize A495
Created September 9, 2012 02:17
Synchronizes two cameras without communication between them or a third party (remote). Designed for A495 and adapted from previous code - Works so long as the interval time is set to a number that divides evenly into 60 and that is longer than the time it
--[[
Author: Fraser McCrossan
Tested on G9, should work on most cameras.
Modified by Nick Santos for use in synchronizing two cameras.
Designed for A495 and adapted from previous code - Works so long as the interval time is set to a number that divides evenly into 60 and that is longer than the time it. Creative Commons Attribution licensed - please cite both authors above.
An accurate intervalometer script, with pre-focus and screen power off options.
Features:
@nickrsan
nickrsan / ArcGISPermanentOneToOneJoin.py
Last active May 11, 2016 20:53
Provides a way to permanently attach a field to another table, as in a one to one join, but without performing a join then exporting a new dataset. Operates in place by creating a new field on the existing dataset.
def permanent_join(target_table, target_attribute, source_table, source_attribute, attribute_to_attach, rename_attribute=None):
"""
Provides a way to permanently attach a field to another table, as in a one to one join, but without performing a
join then exporting a new dataset. Operates in place by creating a new field on the existing dataset.
Or, in other words, Attaches a field to a dataset in place in ArcGIS - instead of the alternative of doing an
actual join and then saving out a new dataset. Only works as a one to one join.
:param target_table: the table to attach the joined attribute to
:param target_attribute: the attribute in the table to base the join on
@nickrsan
nickrsan / copy_field_attributes_to_new_field.py
Created May 3, 2016 17:35
Copies the attributes of a field (data type, precision, scale, length, isNullable, required, domain) to a new field on a new table. Correctly maps data types pulled from Describe tool to data types needed for field creation.
def copy_field_attributes_to_new_field(source_table, current_field, target_table, target_field):
"""
Copies the attributes of a field (data type, precision, scale, length, isNullable, required, domain) to a new field on a new table.
Correctly maps data types pulled from Describe tool to data types needed for field creation.
:param source_table: The table containing the existing field
:param current_field: The field to copy attributes from
:param target_table: The field to create the new field on
:param target_field: The name of the new field to create with the attributes from current_field
:return:
"""
"""
Allows you to pass in a list of environments to get the values of, then pass it back in to reset.
Usage:
original_envs = store_environments(["workspace","mask"]) # gives back a dict with current environment values for workspace and mask
arcpy.env.workspace = my_workspace
arcpy.env.mask = my_raster
# some more code here to do some work with those environments
"""
First, this was written back when I wrote Python a bit more like C - I know it needs some work! But for setting delimiters,
you can do the following:
my_dataset = data_file(r"path_to_data")
my_dataset.delim_open # gives you the opening delimeter
my_dataset.delim_close # gives you the closing delimeter
"""
import logging
@nickrsan
nickrsan / cawater-links.md
Last active February 16, 2021 03:04 — forked from jdherman/cawater-links.md
links for california water data
@nickrsan
nickrsan / python_toolbox_parameters_as_dict.py
Created February 23, 2017 21:22
A Decorator for ArcGIS Python toolbox tools (their execute function) that makes the "parameters" parameter into a dictionary indexed by parameter name
"""
A Decorator for ArcGIS Python toolbox tools (their execute function) that makes the "parameters" parameter'
into a dictionary indexed by parameter name.
"""
from functools import wraps
def parameters_as_dict(f):
@wraps(f)
def wrapper(*args, **kwargs):
@nickrsan
nickrsan / error_check.py
Last active June 10, 2017 00:21
Error 999998 Test
"""
This script should cause error 999998 on ArcGIS 10.5 and ArcGIS Pro 1.4 if the mask environment is set using an invalid mask
and should succeed if no mask is set
"""
import tempfile
import numpy
import arcpy
@nickrsan
nickrsan / get_papers.py
Created October 18, 2018 04:37
A script to pull papers from the CrossRef API (using package Habanero) and do frequency analysis on titles, authors, and institutions.
import os
from time import sleep
from csv import DictWriter, writer
import re
from habanero import Crossref # CrossRef API access
HABANERO_USERNAME = "" # provide an email address so they can contact you if your script misbehaves
ISSN = "" # ISSN of the journal to dump data for
BASE_FOLDER = os.path.dirname(os.path.abspath(__file__))
# Calls the full pipeline needed to get a PDF with BibTex working
# pdfLaTeX->BibTeX->pdfLaTeX->pdfLaTeX
#
# Designed for use as a called script from TeXworks in the TeXLive distribution, but
# easily adapted for other workflows
# Make sure to set texlive_folder below!
# Adapted from https://tex.stackexchange.com/a/308727
import os
import sys