Last active
August 29, 2015 14:02
-
-
Save JorgeGT/f5d9834e043770af3ea2 to your computer and use it in GitHub Desktop.
IGNscraper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Inicializar | |
clear all | |
diaIni = '01-02-13'; | |
diaFin = '01-06-14'; | |
%% Obtener datos | |
crono = tic; | |
dias = num2str(round(today-datenum(diaIni,'dd-mm-yy'))); | |
url = ['http://signa.ign.es/ign/layoutIn/sismoListadoTerremotos.do?zona=1&cantidad_dias=' dias]; | |
tabla = getTableFromWeb_mod(url,1); | |
%% Filtrar por localizacion | |
tabla(1,:) = {'Evento' 'Fecha' 'HoraGTM' 'Lat' 'Long' 'ProfKM' ... | |
'IntMax' 'Mag' 'TipoMag' 'Loc' 'Info'}; | |
tabla = cell2dataset(tabla); | |
borrar = find(~strcmp(tabla.Loc,'GOLFO DE VALENCIA')); | |
tabla(borrar,:) = []; | |
%% Obtener vectores y fechas | |
t = strcat(tabla.Fecha,'_',tabla.HoraGTM); | |
t = datenum(t,'dd/mm/yyyy_HH:MM:SS'); | |
tIni = datenum(diaIni,'dd-mm-yy'); | |
tFin = datenum(diaFin,'dd-mm-yy'); | |
mag = str2num(cell2mat(tabla.Mag(1:end))); %#ok<ST2NM> | |
%% Acumular por dias | |
[unDates, ~, subs] = unique(fix(t)); | |
Nacum = accumarray(subs, mag, [], @(x)sum(x)/mean(x)); | |
Iacum = accumarray(subs, mag, [], @max); | |
%% Figura | |
f = figure('DefaultTextFontName', 'Myriad Pro','DefaultTextFontSize', 8, ... | |
'DefaultAxesFontName', 'Myriad Pro','DefaultAxesFontSize', 8, ... | |
'visible','off'); | |
% Graficar | |
b = bar(unDates,Nacum); | |
title(['Actividadad sísmica en el{\bf Golfo de Valencia} (del ' diaIni ' al ' diaFin ')']); | |
set(get(b,'Children'),'CData',Iacum,'CDataMapping','scaled','EdgeColor','none') | |
ylabel('\bf Nº movimientos/día') | |
xlabel('\bf Fecha de registro') | |
% Formato | |
ylim([0 max(Nacum)+3]) | |
datetick('x') | |
xlim([tIni tFin]) | |
set(gcf, 'Position', [0, 0, 800, 250]); | |
set(gcf, 'Color', 'w'); | |
set(gca, 'TickDir', 'out') | |
grid on | |
box off | |
% Dibujar caja sin ticks | |
hold on | |
x=xlim; | |
y=ylim; | |
line([x(1) x(2)],[y(2) y(2)],'Color','black','LineWidth',1) | |
line([x(2) x(2)],[y(1) y(2)],'Color','black','LineWidth',1) | |
% Agregar texto | |
text(1,-0.18,... | |
'CC-BY @JorgeGT / datos IGN.es',... | |
'Units','normalized','FontSize', 6,... | |
'HorizontalAlignment','right','VerticalAlignment','top') | |
% Agregar colorbar | |
colormap(jet(length(unique(Iacum)))) | |
c = colorbar('location','east'); | |
set(c,'Position',[0.05 0.2 0.007 0.7],'Units','normalized'); | |
set(c,'YTickLabel',get(c,'YTickLabel'),'LineWidth',0.0001) | |
ylabel(c,'\bf Intensidad (Richter)') | |
% Salvar imagen | |
export_fig(['Activ_GdV_IGN_' diaIni '_al_' diaFin],'-zbuffer','-png','-r300') | |
%% Finalizar | |
close all | |
disp(['Procesados ' num2str(length(tabla)) ' movimientos en ' num2str(round(toc(crono))) 's']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ejemplo de resultado
¿Quién dijo que no se podían hacer gráficos bonitos en MATLAB? Aquí un pequeño ejemplo leyendo la web del Instituto Geográfico Nacional y graficando los eventos sísmicos que rodearon la apertura del almacén de gas Castor en el Golfo de Valencia.