Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
plantillajupyterbook
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hackatón entrega Grupo 25
plantillajupyterbook
Commits
c1e82478
Commit
c1e82478
authored
1 year ago
by
David Akim
Browse files
Options
Downloads
Patches
Plain Diff
Update file 1_prepare_data.ipynb
parent
510aa888
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
1_prepare_data.ipynb
+0
-8
0 additions, 8 deletions
1_prepare_data.ipynb
with
0 additions
and
8 deletions
1_prepare_data.ipynb
+
0
−
8
View file @
c1e82478
...
@@ -94,14 +94,6 @@
...
@@ -94,14 +94,6 @@
" t += 1"
" t += 1"
]
]
},
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Procesar datos de índice de peligro de incendio"
]
},
{
{
"attachments": {},
"attachments": {},
"cell_type": "markdown",
"cell_type": "markdown",
...
...
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
# Configurar directorios
# Configurar directorios
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
DATADIR
=
'
era5/
'
# directory containing downloaded era5 data
DATADIR
=
'
era5/
'
# directory containing downloaded era5 data
FIREDATADIR
=
'
fire_danger/
'
# directory containing fire data
FIREDATADIR
=
'
fire_danger/
'
# directory containing fire data
DESTDIR
=
'
processed_data/
'
# directory to save .npy files for each time step and variable
DESTDIR
=
'
processed_data/
'
# directory to save .npy files for each time step and variable
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
# Cargar bibliotecas
# Cargar bibliotecas
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
import
numpy
as
np
import
numpy
as
np
import
netCDF4
as
nc
import
netCDF4
as
nc
import
os
import
os
from
tqdm.notebook
import
tqdm
from
tqdm.notebook
import
tqdm
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
# Variables de configuración
# Variables de configuración
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
vars
=
[
'
u10
'
,
'
v10
'
,
'
t2m
'
,
'
lai_hv
'
,
'
lai_lv
'
,
'
tp
'
,
'
fdimrk
'
]
#considered variables (see 0_download_data.ipynb for long names)
vars
=
[
'
u10
'
,
'
v10
'
,
'
t2m
'
,
'
lai_hv
'
,
'
lai_lv
'
,
'
tp
'
,
'
fdimrk
'
]
#considered variables (see 0_download_data.ipynb for long names)
months
=
[(
1
,
31
),(
2
,
28
),(
12
,
31
)]
# months + days in month in dowloaded era5 .nc files
months
=
[(
1
,
31
),(
2
,
28
),(
12
,
31
)]
# months + days in month in dowloaded era5 .nc files
years
=
np
.
arange
(
2002
,
2023
)
# downloaded years
years
=
np
.
arange
(
2002
,
2023
)
# downloaded years
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
# Procesamiento de datos para crear archivos .npy
# Procesamiento de datos para crear archivos .npy
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Processing Data to create .npy files
# Processing Data to create .npy files
for
var
in
vars
:
for
var
in
vars
:
if
not
os
.
path
.
exists
(
DESTDIR
+
f
"
{
var
}
"
):
if
not
os
.
path
.
exists
(
DESTDIR
+
f
"
{
var
}
"
):
os
.
makedirs
(
DESTDIR
+
f
"
{
var
}
"
)
os
.
makedirs
(
DESTDIR
+
f
"
{
var
}
"
)
for
year
in
tqdm
(
years
):
for
year
in
tqdm
(
years
):
if
var
==
'
fdimrk
'
:
if
var
==
'
fdimrk
'
:
root
=
nc
.
Dataset
(
FIREDATADIR
+
f
"
{
year
:
d
}
.nc
"
,
'
r
'
)
root
=
nc
.
Dataset
(
FIREDATADIR
+
f
"
{
year
:
d
}
.nc
"
,
'
r
'
)
else
:
else
:
root
=
nc
.
Dataset
(
DATADIR
+
f
"
{
year
:
d
}
.nc
"
,
'
r
'
)
root
=
nc
.
Dataset
(
DATADIR
+
f
"
{
year
:
d
}
.nc
"
,
'
r
'
)
v
=
root
.
variables
[
var
][:,:
-
9
,:
-
5
]
#crop to get to a size suitable for the considered Unet-like model, here 140x140
v
=
root
.
variables
[
var
][:,:
-
9
,:
-
5
]
#crop to get to a size suitable for the considered Unet-like model, here 140x140
v
=
v
.
data
v
=
v
.
data
root
.
close
()
root
.
close
()
if
var
in
[
'
tp
'
]:
#change unit from m to mm for precipitation
if
var
in
[
'
tp
'
]:
#change unit from m to mm for precipitation
v
=
1000
*
v
v
=
1000
*
v
t
=
0
# time step within v array that I am working on
t
=
0
# time step within v array that I am working on
for
month
,
days
in
months
:
for
month
,
days
in
months
:
for
day
in
range
(
days
):
for
day
in
range
(
days
):
np
.
save
(
DESTDIR
+
f
"
{
var
}
/
{
year
}
_
{
month
:
02
d
}
_
{
day
+
1
:
02
d
}
.npy
"
,
v
[
t
])
np
.
save
(
DESTDIR
+
f
"
{
var
}
/
{
year
}
_
{
month
:
02
d
}
_
{
day
+
1
:
02
d
}
.npy
"
,
v
[
t
])
t
+=
1
t
+=
1
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
# Procesar datos de índice de peligro de incendio
%% Cell type:markdown id: tags:
# Guardar información de latitud/longitud
# Guardar información de latitud/longitud
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
root
=
nc
.
Dataset
(
DATADIR
+
f
"
2002.nc
"
,
'
r
'
)
#constant in time -> take from any year
root
=
nc
.
Dataset
(
DATADIR
+
f
"
2002.nc
"
,
'
r
'
)
#constant in time -> take from any year
lat
=
root
.
variables
[
'
latitude
'
][:
-
9
].
data
#crop to get to a size suitable for the considered Unet-like model
lat
=
root
.
variables
[
'
latitude
'
][:
-
9
].
data
#crop to get to a size suitable for the considered Unet-like model
lon
=
root
.
variables
[
'
longitude
'
][:
-
5
].
data
lon
=
root
.
variables
[
'
longitude
'
][:
-
5
].
data
np
.
save
(
DESTDIR
+
'
lat.npy
'
,
lat
)
np
.
save
(
DESTDIR
+
'
lat.npy
'
,
lat
)
np
.
save
(
DESTDIR
+
'
lon.npy
'
,
lon
)
np
.
save
(
DESTDIR
+
'
lon.npy
'
,
lon
)
```
```
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment