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
510aa888
Commit
510aa888
authored
2 years ago
by
David Akim
Browse files
Options
Downloads
Patches
Plain Diff
Update file 2_norm_consts.ipynb
parent
be61d23f
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
2_norm_consts.ipynb
+3
-4
3 additions, 4 deletions
2_norm_consts.ipynb
with
3 additions
and
4 deletions
2_norm_consts.ipynb
+
3
−
4
View file @
510aa888
...
@@ -14,8 +14,7 @@
...
@@ -14,8 +14,7 @@
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"DATADIR = 'processed_era5/'\n",
"DATADIR = 'processed_data/'"
"FIREDATADIR = 'processed_fire_data/'"
]
]
},
},
{
{
...
@@ -104,11 +103,11 @@
...
@@ -104,11 +103,11 @@
"source": [
"source": [
"for var in target_vars:\n",
"for var in target_vars:\n",
" tmp = [] #save values from all time steps and locations into this list and then compute mean and std\n",
" tmp = [] #save values from all time steps and locations into this list and then compute mean and std\n",
" files = sorted(os.listdir(
FIRE
DATADIR+var)) #SHOULD NOT CONTAIN ANY OTHER FILES THAN THOSE CREATED IN 1_prepareData.ipynb\n",
" files = sorted(os.listdir(DATADIR+var)) #SHOULD NOT CONTAIN ANY OTHER FILES THAN THOSE CREATED IN 1_prepareData.ipynb\n",
" for f in tqdm(files):\n",
" for f in tqdm(files):\n",
" y,m,d=f.split('_')\n",
" y,m,d=f.split('_')\n",
" if int(y) in train and int(m) in months:\n",
" if int(y) in train and int(m) in months:\n",
" t_array = np.load(
FIRE
DATADIR+var+'/'+f)\n",
" t_array = np.load(DATADIR+var+'/'+f)\n",
" t_array[np.isnan(t_array)] = 0 \n",
" t_array[np.isnan(t_array)] = 0 \n",
" tmp += list(t_array.flatten())\n",
" tmp += list(t_array.flatten())\n",
" mean, std = np.mean(tmp), np.std(tmp)\n",
" mean, std = np.mean(tmp), np.std(tmp)\n",
...
...
%% 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
=
'
processed_era5/
'
DATADIR
=
'
processed_data/
'
FIREDATADIR
=
'
processed_fire_data/
'
```
```
%% 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
from
tqdm.notebook
import
tqdm
from
tqdm.notebook
import
tqdm
import
os
,
gc
import
os
,
gc
```
```
%% 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
'
]
vars
=
[
'
u10
'
,
'
v10
'
,
'
t2m
'
,
'
lai_hv
'
,
'
lai_lv
'
,
'
tp
'
]
target_vars
=
[
'
fdimrk
'
]
target_vars
=
[
'
fdimrk
'
]
months
=
[
1
,
2
,
12
]
months
=
[
1
,
2
,
12
]
val
,
test
=
[
2015
,
2018
],
[
2019
,
2022
]
#years to use for validation and testing, do not use these years to compute normalization constants
val
,
test
=
[
2015
,
2018
],
[
2019
,
2022
]
#years to use for validation and testing, do not use these years to compute normalization constants
train
=
[
x
for
x
in
np
.
arange
(
2002
,
2015
)
if
x
not
in
val
+
test
]
train
=
[
x
for
x
in
np
.
arange
(
2002
,
2015
)
if
x
not
in
val
+
test
]
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
# Constantes de normalización para variables de entrada:
# Constantes de normalización para variables de entrada:
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
for
var
in
vars
:
for
var
in
vars
:
tmp
=
[]
#save values from all time steps and locations into this list and then compute mean and std
tmp
=
[]
#save values from all time steps and locations into this list and then compute mean and std
files
=
sorted
(
os
.
listdir
(
DATADIR
+
var
))
#SHOULD NOT CONTAIN ANY OTHER FILES THAN THOSE CREATED IN 1_prepareData.ipynb
files
=
sorted
(
os
.
listdir
(
DATADIR
+
var
))
#SHOULD NOT CONTAIN ANY OTHER FILES THAN THOSE CREATED IN 1_prepareData.ipynb
for
f
in
tqdm
(
files
):
for
f
in
tqdm
(
files
):
y
,
m
,
d
=
f
.
split
(
'
_
'
)
y
,
m
,
d
=
f
.
split
(
'
_
'
)
if
int
(
y
)
in
train
and
int
(
m
)
in
months
:
if
int
(
y
)
in
train
and
int
(
m
)
in
months
:
t_array
=
np
.
load
(
DATADIR
+
var
+
'
/
'
+
f
)
t_array
=
np
.
load
(
DATADIR
+
var
+
'
/
'
+
f
)
t_array
[
np
.
isnan
(
t_array
)]
=
0
t_array
[
np
.
isnan
(
t_array
)]
=
0
tmp
+=
list
(
t_array
.
flatten
())
tmp
+=
list
(
t_array
.
flatten
())
mean
,
std
=
np
.
mean
(
tmp
),
np
.
std
(
tmp
)
mean
,
std
=
np
.
mean
(
tmp
),
np
.
std
(
tmp
)
print
(
f
'
Mean
{
mean
}
, std
{
std
}
'
)
print
(
f
'
Mean
{
mean
}
, std
{
std
}
'
)
np
.
save
(
f
'
norm_consts/input_
{
var
}
.npy
'
,
np
.
array
([
mean
,
std
]))
np
.
save
(
f
'
norm_consts/input_
{
var
}
.npy
'
,
np
.
array
([
mean
,
std
]))
del
tmp
del
tmp
gc
.
collect
()
gc
.
collect
()
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
# Constantes de normalización para variables objetivo:
# Constantes de normalización para variables objetivo:
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
for
var
in
target_vars
:
for
var
in
target_vars
:
tmp
=
[]
#save values from all time steps and locations into this list and then compute mean and std
tmp
=
[]
#save values from all time steps and locations into this list and then compute mean and std
files
=
sorted
(
os
.
listdir
(
FIRE
DATADIR
+
var
))
#SHOULD NOT CONTAIN ANY OTHER FILES THAN THOSE CREATED IN 1_prepareData.ipynb
files
=
sorted
(
os
.
listdir
(
DATADIR
+
var
))
#SHOULD NOT CONTAIN ANY OTHER FILES THAN THOSE CREATED IN 1_prepareData.ipynb
for
f
in
tqdm
(
files
):
for
f
in
tqdm
(
files
):
y
,
m
,
d
=
f
.
split
(
'
_
'
)
y
,
m
,
d
=
f
.
split
(
'
_
'
)
if
int
(
y
)
in
train
and
int
(
m
)
in
months
:
if
int
(
y
)
in
train
and
int
(
m
)
in
months
:
t_array
=
np
.
load
(
FIRE
DATADIR
+
var
+
'
/
'
+
f
)
t_array
=
np
.
load
(
DATADIR
+
var
+
'
/
'
+
f
)
t_array
[
np
.
isnan
(
t_array
)]
=
0
t_array
[
np
.
isnan
(
t_array
)]
=
0
tmp
+=
list
(
t_array
.
flatten
())
tmp
+=
list
(
t_array
.
flatten
())
mean
,
std
=
np
.
mean
(
tmp
),
np
.
std
(
tmp
)
mean
,
std
=
np
.
mean
(
tmp
),
np
.
std
(
tmp
)
print
(
f
'
Mean
{
mean
}
, std
{
std
}
'
)
print
(
f
'
Mean
{
mean
}
, std
{
std
}
'
)
np
.
save
(
f
'
norm_consts/target_
{
var
}
.npy
'
,
np
.
array
([
mean
,
std
]))
np
.
save
(
f
'
norm_consts/target_
{
var
}
.npy
'
,
np
.
array
([
mean
,
std
]))
del
tmp
del
tmp
gc
.
collect
()
gc
.
collect
()
```
```
...
...
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