Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
thopri
PyNEMO
Commits
eca2acc6
Commit
eca2acc6
authored
4 years ago
by
thopri
Browse files
Options
Download
Email Patches
Plain Diff
meta_data test script
parent
30b1faa3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
3 deletions
+85
-3
inputs/namelist_cmems.bdy
inputs/namelist_cmems.bdy
+1
-1
pynemo/gui/nemo_bdy_mask.py
pynemo/gui/nemo_bdy_mask.py
+2
-2
test_scripts/meta_data.py
test_scripts/meta_data.py
+82
-0
No files found.
inputs/namelist_cmems.bdy
View file @
eca2acc6
...
@@ -90,7 +90,7 @@
...
@@ -90,7 +90,7 @@
cn_coords_file = 'coordinates.bdy.nc' ! name of bdy coordinates files
cn_coords_file = 'coordinates.bdy.nc' ! name of bdy coordinates files
! (if ln_coords_file=.TRUE.)
! (if ln_coords_file=.TRUE.)
ln_mask_file = .false. ! =T : read mask from file
ln_mask_file = .false. ! =T : read mask from file
cn_mask_file = '
/Users/thopri/Projects/PyNEMO/inputs/subset_
mask.nc' ! name of mask file
cn_mask_file = 'mask.nc' ! name of mask file
! (if ln_mask_file=.TRUE.)
! (if ln_mask_file=.TRUE.)
ln_dyn2d = .false. ! boundary conditions for
ln_dyn2d = .false. ! boundary conditions for
! barotropic fields
! barotropic fields
...
...
This diff is collapsed.
Click to expand it.
pynemo/gui/nemo_bdy_mask.py
View file @
eca2acc6
...
@@ -72,8 +72,8 @@ class Mask(object):
...
@@ -72,8 +72,8 @@ class Mask(object):
self
.
lon
=
np
.
asarray
(
self
.
bathy_nc
.
variables
[
'nav_lon'
])
self
.
lon
=
np
.
asarray
(
self
.
bathy_nc
.
variables
[
'nav_lon'
])
self
.
lat
=
np
.
asarray
(
self
.
bathy_nc
.
variables
[
'nav_lat'
])
self
.
lat
=
np
.
asarray
(
self
.
bathy_nc
.
variables
[
'nav_lat'
])
except
:
except
:
self
.
lon
=
np
.
asarray
(
self
.
bathy_nc
.
variables
[
'lon'
])
self
.
lon
=
np
.
asarray
(
self
.
bathy_nc
.
variables
[
'lon
gitude
'
])
self
.
lat
=
np
.
asarray
(
self
.
bathy_nc
.
variables
[
'lat'
])
self
.
lat
=
np
.
asarray
(
self
.
bathy_nc
.
variables
[
'lat
itude
'
])
# expand lat and lon 1D arrays into 2D array matching nav_lat nav_lon
# expand lat and lon 1D arrays into 2D array matching nav_lat nav_lon
self
.
lon
=
np
.
tile
(
self
.
lon
,
(
np
.
shape
(
self
.
lat
)[
0
],
1
))
self
.
lon
=
np
.
tile
(
self
.
lon
,
(
np
.
shape
(
self
.
lat
)[
0
],
1
))
self
.
lat
=
np
.
tile
(
self
.
lat
,
(
np
.
shape
(
self
.
lon
)[
1
],
1
))
self
.
lat
=
np
.
tile
(
self
.
lat
,
(
np
.
shape
(
self
.
lon
)[
1
],
1
))
...
...
This diff is collapsed.
Click to expand it.
test_scripts/meta_data.py
0 → 100644
View file @
eca2acc6
# -*- coding: utf-8 -*-
"""
Set of functions to download CMEMS files using FTP (for static mask data) and MOTU (for subsetted variable data).
"""
from
netCDF4
import
Dataset
import
re
# list of datasets to check
datasets
=
[
"http://opendap4gws.jasmin.ac.uk/thredds/noc_msm/dodsC/pynemo_data/ORCA025-N206_19791101d05T.nc"
,
"http://opendap4gws.jasmin.ac.uk/thredds/noc_msm/dodsC/pynemo_data/ORCA025-N206_19791101d05U.nc"
,
"http://opendap4gws.jasmin.ac.uk/thredds/noc_msm/dodsC/pynemo_data/ORCA025-N206_19791101d05V.nc"
,
"http://opendap4gws.jasmin.ac.uk/thredds/noc_msm/dodsC/pynemo_data/ORCA025-N206_19791101d05I.nc"
]
# list of strings to catagorise variable names... each entry can have multiple entries.
# NOTE list in each dict entry is in priority order so most likely parameter should be first, e.g. latitude
# DOUBLE NOTE order in dict is also important as it can result in false ID's e.g. ice data for some reason has long name
# sea surface height so if SSH is in dict before ice variables it will assign ice variable names to SSH.
chk_list
=
{
'temperature'
:
[
'temp'
],
'salinity'
:
[
'sal'
],
'ice_thic'
:
[
'icethic'
],
'snow_thic'
:
[
'snowthi'
],
'ileadfra'
:
[
'leadfra'
],
'SSH'
:
[
'surface'
,
'sea'
],
'depth'
:
[
'depth'
],
'time'
:
[
'time'
,
'counter'
],
'latitude'
:
[
'latitude'
,
'y'
,
'nav_lat'
],
'longitude'
:
[
'longitude'
,
'x'
,
'nav_lon'
],
'depth'
:
[
'depth'
],
'U'
:
[
'zonal'
,
'current'
],
'V'
:
[
'meridional'
,
'current'
],
}
# function to use regex to find if string is in variable name or if not check long name. Case of string is ignored
# Attribute errors are common due to long name not existing in some datasets at the moment this error is passed (maybe log?)
def
data_chk
(
data
,
str
,
key
):
for
i
in
range
(
len
(
str
)):
try
:
chk
=
re
.
search
(
str
[
i
],
data
[
key
].
name
,
re
.
IGNORECASE
)
if
chk
is
None
:
chk
=
re
.
search
(
str
[
i
],
data
[
key
].
long_name
,
re
.
IGNORECASE
)
return
chk
except
AttributeError
:
pass
i
=
0
meta_dataset
=
{}
for
dat
in
datasets
:
# open netcdf dataset
F
=
Dataset
(
dat
)
# extract variable meta data and dimension meta data
meta
=
F
.
variables
dims
=
F
.
dimensions
# create empty dict to save catagorised data
meta_dataset
[
'dataset'
+
str
(
i
)]
=
{}
meta_dataset
[
'dataset'
+
str
(
i
)][
'var_names'
]
=
{}
meta_dataset
[
'dataset'
+
str
(
i
)][
'dim_names'
]
=
{}
# for all variable names, compare strings on chk list and write key to meta dict on first match
for
key
in
meta
:
for
chk_key
,
chk
in
chk_list
.
items
():
var_match
=
data_chk
(
meta
,
chk
,
key
)
if
var_match
is
not
None
:
meta_dataset
[
'dataset'
+
str
(
i
)][
'var_names'
][
chk_key
]
=
key
break
# for all dimension names, compare strings on chk list and write key to meta dict on first match
for
key
in
dims
:
for
chk_key
,
chk
in
chk_list
.
items
():
dim_match
=
data_chk
(
dims
,
chk
,
key
)
if
dim_match
is
not
None
:
meta_dataset
[
'dataset'
+
str
(
i
)][
'dim_names'
][
chk_key
]
=
key
break
i
=
i
+
1
# close netcdf file and print meta dict
F
.
close
()
print
(
meta_dataset
)
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment