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 / 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:
"""
@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
"""
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 / 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
"""
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
@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
@nickrsan
nickrsan / convert_mxd_to_aprx.py
Last active October 26, 2019 22:11
Converts all ArcMap documents (.mxd) in the script's folder into ArcGIS Pro Projects - requires amaptor (available via pip and at https://github.com/ucd-cws/amaptor). Has infrastructure to convert everything in a folder into the same project, but would need some retooling for it. Must be run from an ArcGIS Pro python environmental w/amaptor inst…
import os
import amaptor
base_folder = os.path.split(os.path.abspath(__file__))[0]
def make_project(item, base_folder=base_folder, skip_items=()):
"""
Makes the .mxd in item into an ArcGIS Pro project in the same folder with the same name
:param item: a full path to an ArcMap Document
@nickrsan
nickrsan / clone_hyperv_vm.ps1
Last active January 5, 2021 21:59
Clone Hyper-V VM to same server
$ProductionVMName = "DAP_Production"
$StagingVMName = "DAP_Staging"
$ExportFolder = "C:/HyperVExports" # I created a folder that removed all permissions for users - could add anyone with hyper-v permissions to a group with read/write here, along with System
$ExportToFolder = "$ExportFolder/$ProductionVMName/"
$ImportToFolder = "$ExportFolder/$StagingVMName/"
# caution, deletes existing exports in the next block. The try/catch doesn't work as intended. It was supposed to abandon it if it can't find the staging VMs, but proceeds through each step. Needs some work there.
try{
Get-VM -Name $StagingVMName # (not true, but this was the design): this will throw an exception if it doesn't exist, so the following lines in this block won't run
Stop-VM -Name $StagingVMName -TurnOff # Turn of the VM forcibly - it's fine if it gets corrupted - we're about to destroy it