Skip to content

Instantly share code, notes, and snippets.

View aolinto's full-sized avatar

Antonio Olinto Avila da Silva aolinto

View GitHub Profile
@aolinto
aolinto / MODISA_sst.R
Last active January 4, 2023 16:57
R script to extract Aqua MODIS Sea Surface Temperature data from a nc file
# Antonio Olinto Avila-da-Silva, Instituto de Pesca, Brasil
# ver 2016-05-17
# https://gist.github.com/aolinto/79e184f6c156c6ab21b3
# script to process Aqua MODIS Sea Surface Temperature
# files downloaded from http://oceancolor.gsfc.nasa.gov/cgi/l3
# Aqua MODIS Sea Surface temperature 11 u daytime Monthly 9 km SMI images
# all .L3m_MO_SST_sst_9km.nc files must be in the working directory
# the script will open each nc file, read date, lon, lat and sst data,
# then select data from specified area and write them into
# a single csv file named MODISA_sst.csv
@aolinto
aolinto / lunar.R
Created September 30, 2015 02:10
R function to calculate lunar phases
lunar<- function(Y,M,D) {
# http://www.paulsadowski.com/wsh/moonphase.htm
# necessita do pacote cars
P2<-2*3.14159
YY<-Y-as.integer((12-M)/10)
MM=M+9
if (MM>=12) MM<-MM-12
K1=as.integer(365.25*(YY+4712))
K2=as.integer(30.6*MM+.5)
K3=as.integer(as.integer((YY/100)+49)*.75)-38
@aolinto
aolinto / GeoDist.R
Last active November 13, 2015 16:57
Function to calculate the distance between two points in R
# Calculate distance in kilometers between two points
# https://conservationecology.wordpress.com/2013/06/30/distance-between-two-points-in-r/
# PointDistance tool in the raster
earth.dist <- function (long1, lat1, long2, lat2)
{
rad <- pi/180
a1 <- lat1 * rad
a2 <- long1 * rad
b1 <- lat2 * rad
b2 <- long2 * rad
@aolinto
aolinto / biseau.R
Created April 13, 2016 14:06
Biseau (1998) directed fishing effort
# Biseau, A. 1998. Definition os a directed fishing effort in a mixed-species trawl fishery, and its impacts on stock
# assessments. Aquat. Living Resour. 11(3):119-136
# each line refers to one trip where we have data on
# total catch per trip (Ti) and catch per species and trip (Tis)
# Antônio Olinto Ávila da Silva 13 de abril de 2016
# simulation
Ti <- rnorm(1000,4000,300)
Tis <- Ti*runif(1000,0,1)
dat.biseau <- data.frame(Ti,Tis)
@aolinto
aolinto / MODISA_chl.R
Last active October 26, 2016 11:54
R script to extract Aqua MODIS Chlorophyll a data from a nc file
# Antonio Olinto Avila-da-Silva, Instituto de Pesca, Brasil
# ver 2016-05-17
# https://gist.github.com/aolinto/7d3f282c9fde96133daa4cdd4f1bbcab
# script to process Aqua MODIS Sea Surface Temperature
# files downloaded from http://oceancolor.gsfc.nasa.gov/cgi/l3
# Aqua MODIS Clorophyll Concentration, OCI Algorithm Monthly 9 km SMI images
# all .L3m_MO_CHL_chlor_a_9km.nc files must be in the working directory
# the script will open each nc file, read date, lon, lat and chl data,
# then select data from specified area and write them into
# a single csv file named MODISA_chl.csv
@aolinto
aolinto / MODISA_chl_pol.R
Last active August 11, 2020 03:21
R script to extract Aqua MODIS Chlorophyll statistics from a nc file based on a polygon
# Antonio Olinto Avila-da-Silva, Instituto de Pesca, Brasil
# https://gist.github.com/aolinto/b1414f94a0891d9e5d580d0436db8495
# script to process Aqua MODIS Clorophyll Concentration data
# files downloaded from https://oceancolor.gsfc.nasa.gov/cgi/l3
# Aqua MODIS Clorophyll Concentration, OCI Algorithm Monthly 4 km SMI images
# all .L3m_MO_CHL_chlor_a_4km.nc files must be in the working directory
# the script will open each nc file to read date information
# the script will also transform nc file to raster, read chl data
# for a given area, compute its statistics and write them into
# a single csv file named MODISA_chl.csv
@aolinto
aolinto / MODISA_sst_pol.R
Last active April 30, 2022 10:47
R script to extract Aqua MODIS SST statistics from a nc file based on a polygon
# Antonio Olinto Avila-da-Silva, Instituto de Pesca, Brasil
# https://gist.github.com/aolinto/3a0872e0fb61b7ca3e69d35d286ae26c
# script to process Aqua MODIS Sea Surface Temperature
# files downloaded from https://oceancolor.gsfc.nasa.gov/cgi/l3
# Aqua MODIS Sea Surface temperature 11 µ daytime Monthly 4 km SMI images or
# Aqua MODIS Sea Surface temperature 11 µ nigthtime Monthly 4 km SMI images
# all .L3m_MO_SST_sst_4km.nc (daytime) or .L3m_MO_NST4_sst4_4km (nigthtime)
# files must be in the working directory
# the script will open each nc file to read date information
# the script will also transform nc file to raster, read sst data
@aolinto
aolinto / grade.R
Created August 16, 2018 22:05
Cria grade de polígonos de tamanho personalizados e exporta como shapefile
# ================================================================================
# Cria grade de polígonos de tamanho personalizados e exporta como shapefile
# autor: Antônio Olinto Ávila da Silva
# criação: 2018-08-16
# última edição: 2018-08-16
# ================================================================================
# ------------------------
# prepara área de trabalho
# ------------------------
@aolinto
aolinto / fishing_area.R
Created August 24, 2018 13:25
Selects fishing area squares per trip and calculates their centroids
# ====================================================================
# Selects fishing area squares per trip and calculates their centroids
# author: Antônio Olinto Ávila da Silva
# creation: 2018-08-24
# last edition: 2018-08-24
# ====================================================================
# prepare workspace
library(rgdal)
library(rgeos)
@aolinto
aolinto / isobaths.R
Created August 27, 2018 13:04
Create isobaths and smoothed isobaths based on Etopo1 data
# ====================================================================
# Create isobaths and smoothed isobaths based on Etopo1 data
# https://maps.ngdc.noaa.gov/viewers/wcs-client/
# author: Antônio Olinto Ávila da Silva
# creation: 2018-08-27
# last edition: 2018-08-27
# ====================================================================
# workspace
# ----------