Skip to content

Instantly share code, notes, and snippets.

View fitoprincipe's full-sized avatar
💭
Working in tools for Google Earth Engine.. =)

Rodrigo E. Principe fitoprincipe

💭
Working in tools for Google Earth Engine.. =)
View GitHub Profile
@fitoprincipe
fitoprincipe / export_imagecollection_mock.py
Created May 28, 2022 18:27
Mock Exporting an ImageCollection in GEE
# -*- coding: utf-8 -*-
"""
Created on Sat May 28 15:05:46 2022
@author: Rodrigo E. Principe
"""
import time
import random
# params
@fitoprincipe
fitoprincipe / match_format_string.py
Last active February 18, 2022 12:39
match format string
def match_format_string(format_str, s):
""" https://stackoverflow.com/questions/10663093/use-python-format-string-in-reverse-for-parsing
Match s against the given format string, return dict of matches.
We assume all of the arguments in format string are named keyword arguments (i.e. no {} or
{:0.2f}). We also assume that all chars are allowed in each keyword argument, so separators
need to be present which aren't present in the keyword arguments (i.e. '{one}{two}' won't work
reliably as a format string but '{one}-{two}' will if the hyphen isn't used in {one} or {two}).
We raise if the format string does not match s.
import csv, glob, argparse
parser = argparse.ArgumentParser()
parser.add_argument("-n", "--name", help="name of the resulting file")
args = parser.parse_args()
csv_list = glob.glob('*.csv')
result_name = args.name or 'merged.csv'
# get fieldnames
# first list
a = [1, 2, 3, 4]
# second list
b = ['a', 'b']
# expected list
exp = ['a1', 'a2', 'a3', 'a4', 'b1', 'b2', 'b3', 'b4']
# WITHOUT list comprehension
@fitoprincipe
fitoprincipe / addLayerCol.js
Created April 6, 2017 13:00
función para visualizar todas la imágenes de una colección en GEE
// Función para agregar al mapa todas las imagenes de una coleccion
// Argumentos:
// col: coleccion de imagenes
// viz: diccionario con los parametros de visualizacion
// ej: viz = {bands:["B3","B4","B5"], min:0, max:255}
var addLayerCol = function(col, viz) {
var lista = col.getInfo()["features"]
for (var i = 0; i < lista.length; i++) {
var id = lista[i]["id"]
@fitoprincipe
fitoprincipe / so_read_url_write_file.py
Created November 17, 2016 11:48 — forked from hughdbrown/so_read_url_write_file.py
Read from URL, write to file
"""
Code to write data read from a URL to a file
Based on an answer on SO:
http://stackoverflow.com/questions/22676/how-do-i-download-a-file-over-http-using-python/22721
"""
import urllib2
mp3file = urllib2.urlopen("http://www.example.com/songs/mp3.mp3")