Skip to content

Instantly share code, notes, and snippets.

View bniebuhr's full-sized avatar

Bernardo Brandão Niebuhr bniebuhr

View GitHub Profile
@bniebuhr
bniebuhr / testing_GUI.py
Last active May 9, 2016 14:26
Trying to test buttons of a GUI
import wx
class Form1(wx.Panel):
def __init__(self, parent, id):
wx.Panel.__init__(self, parent, id)
self.button =wx.Button(self, 10, "MULTIPLICA", wx.Point(20,10))
wx.EVT_BUTTON(self, 10, self.OnClick)
self.button =wx.Button(self, 20, "SOMA", wx.Point(20,100))
@bniebuhr
bniebuhr / change_instance_variables.py
Last active May 24, 2016 13:37
how do I change Instance inernal variables, so that they ma be used by the class internal functions?
class Classe():
def __init__(self):
Classe.var1 = 10
Classe.var2 = 3
def printClasse(self):
print 'multiply = ' + str(Classe.var1*Classe.var2)
@bniebuhr
bniebuhr / multiply_with_sum.py
Created October 10, 2016 16:31
Building multiplications only with sum
# Solucao Maumau
p = int(input("Digite o primeiro número: "))
s = int(input("Digite o segundo número: "))
m = 0
x = 0
if p < 0 and s < 0:
while x < abs(p):
m = m + abs(s)
x = x + 1
print("A multiplicação utilizando apenas a soma é: %d" % (m))
@bniebuhr
bniebuhr / upgrade.sh
Created January 1, 2019 18:59 — forked from bocharsky-bw/upgrade.sh
Shell Script for Upgrade Ubuntu via APT in one step
#!/bin/bash
TEXT_RESET='\e[0m'
TEXT_YELLOW='\e[0;33m'
TEXT_RED_B='\e[1;31m'
sudo apt-get update
echo -e $TEXT_YELLOW
echo 'APT update finished...'
echo -e $TEXT_RESET
@bniebuhr
bniebuhr / calc_stats.py
Created March 17, 2019 01:56
script to edit and save statistics from raster maps in GRASS GIS, using r.stats
# import modules
import grass.script as grass
def export_statistics(input_map = ''):
'''
Function to calculate and export statistics (using r.stats) from landscape metrics maps.
Results are given in hectares.
Parameters
----------
@bniebuhr
bniebuhr / gist:70882e74f705f8a64a395abcd412bd98
Last active November 4, 2021 09:07
neighbors_vs_resamp_filter.py
#!/usr/bin/env python3
import grass.script as gscript
def main():
# Define input: roads maps
input = "roadsmajor@PERMANENT"
# Set region - 30m res
@bniebuhr
bniebuhr / create_buffers.R
Created February 23, 2022 00:14
Ways to create buffers and extract values from raster in R
# packages
library(dplyr)
library(landscapemetrics)
library(sf)
library(terra)
# Load data - Latlon, WGS84,
forest_1985 <- raster::raster("data/mapbiomas_v06_1985_forest.tif")
# CRS
@bniebuhr
bniebuhr / metrics_multiple_buffers.R
Created February 23, 2022 11:04
Example of calculating landscae metrics in multiple buffers, adapted from the landscapemetrics package
# library(devtools)
# devtools::install_github("bniebuhr/landscapemetrics", ref = "multibuffer")
# devtools::install_github("bniebuhr/landscapetools", ref = "multibuffer")
# packages
library(dplyr)
library(readxl)
library(ggplot2)
library(forcats)
# File 1: Rmd template
---
title: "Untitled"
author: "Bernardo, Yves"
date: "3/24/2022"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
@bniebuhr
bniebuhr / read_table_dates_different_formats.R
Last active April 19, 2022 08:38
Read table and dates in different formats - for Leonie
library(dplyr)
library(tibble)
# read table
tab <- read.csv("results/calving_period_bn.csv")
# this is not necessary but I find it easier to read data.frames as tibbles
tab <- tibble::as_tibble(tab)
tab <- dplyr::rename(tab, rowid = X)
tab