Borrar filtros
Borrar filtros

Collect data from multiple sets of lat and long instead of just one set

4 visualizaciones (últimos 30 días)
I have this code below in matlab, it collects data from AOD in a set of lat and long, however, I want to collect in multiple locations of lat and lon. Do you have any idea? I have this code below in matlab, it collects data from AOD in a set of lat and long, however, I want to collect in several places of lat and lon. Do you have any idea? The script I used is below.
The data looks like this: MYD04_3K.A2010001.1540.061.2018053201411.hdf
%%
% MYD04 - DADOS PARTE 1
% DATAS -> MYD04_3K.A2010001.1540.061.2018053201411.hdf
%% PROGRAMA_LER_HDF_SÉRIE_TEMPORAL_AOD_MODIS
% OBETIVO: ler arquivos HDF e extrair a série temporal da variável desejada
% DESCRIÇÃO: abre um arquivo HDF de um diretório específico,identifica dentro do HDF as variáveis que se deseja trabalhar
% (ex.: Latitude, Longitude, optical_depth_land_and_ocean), escreve esses arquivos de forma(double), identifica nesses arquivos
% os valores de erro/desprezíveis (ex.: -9999), substitui por "NaN", gera um arquivo corrigido, multiplica os dados dessa matriz
% pelo fator de conversão especificado no arquivo HDF (ex.:0.01), gera um novo arquivo(com os valores físicos reais) e em seguida plota os gráficos
%% REGISTRA_DIRETÓRIOS
clc
clear all
% close all
%%
% DirDSc=pwd;
DirMYD = '/media/augusto/SATELITES/MYD043K'
% DirDMY='D:\MODIS-ATM\MODIS043K\MYD043K';
% DirDMI='D:\MODIS-ATM\MCD19A2\MCD19A2d';
% LOCALIZA_ÁREAS_ESTUDO
% Encontra os pontos de lat e lon
%Localizações
%Bel: -1.473137 -48.485657
%Stm: -2.452059 -54.753617
%Alt: -3.217477 -52.230464
%Mab: -5.394255 -49.135187
%ParaC: -4.27 -52.60
DirShp='/media/augusto/AUGUSTOG/IBGEShp/bcim_2016_shapefiles_21-11-2018';cd(DirShp);
shpc = shaperead('loc_capital_p.shp'); %capitais AS
cgeo={shpc.X;shpc.Y;shpc.nome}';
disp(cgeo);
cgeo=input('Informe a coordenada (graus) do local de estudo /Ex: [-02.133333 -58.983609]:');
pixe_l=input('Informe o pixel, cujo centro é local de estudo /Ex: [15]:');
lat_n=cgeo(1,1)+((pixe_l(1,1)./2)./111.1);
lat_s=cgeo(1,1)-((pixe_l(1,1)./2)./111.1);
lon_e=cgeo(1,2)+((pixe_l(1,1)./2)./111.1);
lon_w=cgeo(1,2)-((pixe_l(1,1)./2)./111.1);
%%
% LER_HDF
% Ler o arquivo HDF em um diretório específico.
% Ler as variáveis desejadas do grupo de variáveis disponibilizadas no arquivo HDF que foi aberto.
% 1) Latitude
% 2) Longitude
% 3) Optical_Deph_Land_and_Ocean
% 4) Solar_Zenith
t1=datestr(now);
disp(t1)
cd(DirMYD); %Terra
m=dir('*hdf*'); %diretorio das pastas
MYD04L2=[];
MYD04L2e=[];
% MYD04L2=[];
% MYD04L2e=[];
%%
for j=1:length(m)
jj=num2str(j);
OpenFile{1,1}=num2str(j);
OpenFile{1,2}=m(j).name;
disp(OpenFile) %mostra na tela posição processamento
ano(j)= str2double(m(j).name(11:14)); %#ok<SAGROW>
dia(j)= str2double(m(j).name(15:17)); %#ok<SAGROW>
% MOD_DAY=[];for i=3:length(dir);MOD_DAY=[MOD_DAY;[str2num(f(i).name(19:22))]];end;
%--------------------------------------------------------------------------
% Especificando a precisão dos números /nomeando variáveis HDF na workspace
cmd=['lat = double(hdfread(''' m(j).name ''', ''/mod04/Geolocation Fields/Latitude''));'];eval(cmd);
cmd=['lon = double(hdfread(''' m(j).name ''', ''/mod04/Geolocation Fields/Longitude''));'];eval(cmd);
cmd=['asz = double(hdfread(''' m(j).name ''', ''/mod04/Data Fields/Solar_Zenith''));'];eval(cmd);
cmd=['aod = double(hdfread(''' m(j).name ''', ''/mod04/Data Fields/Optical_Depth_Land_And_Ocean''));'];eval(cmd);
%--------------------------------------------------------------------------
% Substituindo erro p/ NaN
% Encontrando os índices (posição nas matrizes que possuem valores negativos e/ou menores que -9999)
id_lat=find(lat == -9999);
id_lon=find(lon == -9999);
lat(id_lat)=NaN; %#ok<SAGROW>
lon(id_lon)=NaN; %#ok<SAGROW>
id_aod=find(aod<=0);
aod(id_aod)=NaN; %#ok<SAGROW>
aod=0.001.*aod;
id_asz=find(asz<=-9999);
asz(id_asz)=NaN; %#ok<SAGROW>
asz=0.01.*asz;
%--------------------------------------------------------------------------
%Selecionando_pixel e a profundidade óptica média (representativa do pixel)
a_pixe=find(lat>=lat_s & lat<=lat_n & lon>=lon_w & lon<=lon_e);
cmd=['Dnum=[datenum(''31-Dez-' num2str(ano(j)-1) ' 00:00:00'') + (str2double(m(j).name(15:17)) + str2double(m(j).name(19:20))./24 + str2double(m(j).name(21:22))./60./24)];'];eval(cmd); % Date(n)
Dvec=datevec(Dnum); %DateVec
JDay=(str2double(m(j).name(15:17)) + str2double(m(j).name(19:20))./24 + str2double(m(j).name(21:22))./60./24); %JulianDate
MYD04L2=[MYD04L2;[Dnum,Dvec,JDay,nanmean(aod(a_pixe))]]; % p/TERRA usar MOD04L2
MYD04L2e=[MYD04L2e;[NaN(size(a_pixe)),lat(a_pixe),lon(a_pixe),(aod(a_pixe))]]; % p/TERRA usar MOD04L2
MYD04L2e(isnan(MYD04L2e(:,1)),1)=Dnum;
% MYD04L2=[MYD04L2;[Dnum,Dvec,JDay,nanmean(aod(a_pixe))]]; % p/AQUA usar MYD04L2
% MYD04L2e=[MYD04L2e;[NaN(size(a_pixe)),lat(a_pixe),lon(a_pixe),(aod(a_pixe))]]; % p/AQUA usar MYD04L2
% MYD04L2e(isnan(MYD04L2e(:,1)),1)=Dnum;
end
%%
cd ..
clear('id_aod','id_asz','ans','cmd','id_lat','id_lon');
t2=datestr(now);
%% MATRIZ FINAL DADOS MODIS (MOD04L23K)
MYDIS04L2=[MYD04L2]% MODIS04L2=[MOD04L2;MYD04L2]; % empilhando as matrizes
[ord,ind]=sort(MYDIS04L2(:,1)); % ordenando as medidas
MYDIS04L2=MYDIS04L2(ind,:);
%plot(MYDIS04L2(:,1),MYDIS04L2(:,9),'.')
  9 comentarios
Mathieu NOE
Mathieu NOE el 28 de Feb. de 2023
sorry I cannot run the code (I don't have the Mapping Toolbox)

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by