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
3f31b5d7
Commit
3f31b5d7
authored
2 years ago
by
David Akim
Browse files
Options
Downloads
Patches
Plain Diff
Update file 1_prepare_data.ipynb
parent
76404c15
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
+45
-8
45 additions, 8 deletions
1_prepare_data.ipynb
with
45 additions
and
8 deletions
1_prepare_data.ipynb
+
45
−
8
View file @
3f31b5d7
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Configurar directorios"
]
},
{
"cell_type": "code",
"execution_count": 1,
...
...
@@ -12,6 +20,14 @@
"FIREDESTDIR = 'processed_fire_data/' # directory to save .npy files for each time step and variable for fire data"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Cargar bibliotecas"
]
},
{
"cell_type": "code",
"execution_count": 2,
...
...
@@ -24,6 +40,14 @@
"from tqdm.notebook import tqdm"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Variables de configuración"
]
},
{
"cell_type": "code",
"execution_count": 3,
...
...
@@ -37,14 +61,11 @@
]
},
{
"
cell_type": "code"
,
"
execution_count": 4
,
"
attachments": {}
,
"
cell_type": "markdown"
,
"metadata": {},
"outputs": [],
"source": [
"#root = nc.Dataset(FIREDATADIR + f\"2002.nc\", 'r')\n",
"#root['fdimrk']\n",
"#root.close()\n"
"# Procesar datos ERA5"
]
},
{
...
...
@@ -138,7 +159,7 @@
}
],
"source": [
"# Processing ERA
5 data\n",
"# Processing ERA5 data\n",
"for var in vars:\n",
" if not os.path.exists(DESTDIR + f\"{var}\"):\n",
" os.makedirs(DESTDIR + f\"{var}\")\n",
...
...
@@ -157,6 +178,14 @@
" t += 1"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Procesar datos de índice de peligro de incendio"
]
},
{
"cell_type": "code",
"execution_count": 6,
...
...
@@ -178,7 +207,7 @@
}
],
"source": [
"# Processing Fire data\n",
"# Processing Fire
danger index
data\n",
"for var in fire_vars:\n",
" if not os.path.exists(FIREDESTDIR + f\"{var}\"):\n",
" os.makedirs(FIREDESTDIR + f\"{var}\")\n",
...
...
@@ -195,6 +224,14 @@
" t += 1"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Guardar información de latitud/longitud"
]
},
{
"cell_type": "code",
"execution_count": 7,
...
...
%% Cell type:markdown id: tags:
# Configurar directorios
%% Cell type:code id: tags:
```
python
DATADIR
=
'
era5/
'
# directory containing downloaded era5 data
FIREDATADIR
=
'
fire_danger/
'
# directory containing fire data
DESTDIR
=
'
processed_era5/
'
# directory to save .npy files for each time step and variable
FIREDESTDIR
=
'
processed_fire_data/
'
# directory to save .npy files for each time step and variable for fire data
```
%% Cell type:markdown id: tags:
# Cargar bibliotecas
%% Cell type:code id: tags:
```
python
import
numpy
as
np
import
netCDF4
as
nc
import
os
from
tqdm.notebook
import
tqdm
```
%% Cell type:markdown id: tags:
# Variables de configuración
%% Cell type:code id: tags:
```
python
vars
=
[
'
u10
'
,
'
v10
'
,
'
t2m
'
,
'
lai_hv
'
,
'
lai_lv
'
,
'
tp
'
]
#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
years
=
np
.
arange
(
2002
,
2023
)
# downloaded years
fire_vars
=
[
'
fdimrk
'
]
# fire data variables
```
%% Cell type:
code
id: tags:
%% Cell type:
markdown
id: tags:
```
python
#root = nc.Dataset(FIREDATADIR + f"2002.nc", 'r')
#root['fdimrk']
#root.close()
```
# Procesar datos ERA5
%% Cell type:code id: tags:
```
python
# Processing ERA
5 data
# Processing ERA5 data
for
var
in
vars
:
if
not
os
.
path
.
exists
(
DESTDIR
+
f
"
{
var
}
"
):
os
.
makedirs
(
DESTDIR
+
f
"
{
var
}
"
)
for
year
in
tqdm
(
years
):
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
=
v
.
data
root
.
close
()
if
var
in
[
'
tp
'
]:
#change unit from m to mm for precipitation
v
=
1000
*
v
t
=
0
# time step within v array that I am working on
for
month
,
days
in
months
:
for
day
in
range
(
days
):
np
.
save
(
DESTDIR
+
f
"
{
var
}
/
{
year
}
_
{
month
:
02
d
}
_
{
day
+
1
:
02
d
}
.npy
"
,
v
[
t
])
t
+=
1
```
%% Output
%% Cell type:markdown id: tags:
# Procesar datos de índice de peligro de incendio
%% Cell type:code id: tags:
```
python
# Processing Fire data
# Processing Fire
danger index
data
for
var
in
fire_vars
:
if
not
os
.
path
.
exists
(
FIREDESTDIR
+
f
"
{
var
}
"
):
os
.
makedirs
(
FIREDESTDIR
+
f
"
{
var
}
"
)
for
year
in
tqdm
(
years
):
root
=
nc
.
Dataset
(
FIREDATADIR
+
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
=
v
.
data
root
.
close
()
t
=
0
# time step within v array that I am working on
for
month
,
days
in
months
:
for
day
in
range
(
days
):
np
.
save
(
FIREDESTDIR
+
f
"
{
var
}
/
{
year
}
_
{
month
:
02
d
}
_
{
day
+
1
:
02
d
}
.npy
"
,
v
[
t
])
t
+=
1
```
%% Output
%% Cell type:markdown id: tags:
# Guardar información de latitud/longitud
%% Cell type:code id: tags:
```
python
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
lon
=
root
.
variables
[
'
longitude
'
][:
-
5
].
data
np
.
save
(
DESTDIR
+
'
lat.npy
'
,
lat
)
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