Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
ruby
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
catalog
ruby
Merge requests
!1
first attempt at jacamar runner
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
first attempt at jacamar runner
jacamar
into
main
Overview
0
Commits
2
Pipelines
11
Changes
2
Merged
Florian Ziemen
requested to merge
jacamar
into
main
2 months ago
Overview
0
Commits
2
Pipelines
11
Changes
2
Expand
0
0
Merge request reports
Compare
main
version 9
1b750557
2 months ago
version 8
af61f40c
2 months ago
version 7
0ba35a45
2 months ago
version 6
8f8f6cd2
2 months ago
version 5
480f50f4
2 months ago
version 4
2e7f13e6
2 months ago
version 3
711dc415
2 months ago
version 2
956f2d03
2 months ago
version 1
c2d6ed22
2 months ago
main (base)
and
version 2
latest version
2e87575c
2 commits,
2 months ago
version 9
1b750557
8 commits,
2 months ago
version 8
af61f40c
8 commits,
2 months ago
version 7
0ba35a45
7 commits,
2 months ago
version 6
8f8f6cd2
6 commits,
2 months ago
version 5
480f50f4
5 commits,
2 months ago
version 4
2e7f13e6
4 commits,
2 months ago
version 3
711dc415
3 commits,
2 months ago
version 2
956f2d03
2 commits,
2 months ago
version 1
c2d6ed22
1 commit,
2 months ago
2 files
+
21
−
3
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
processing/create_yaml.ipynb
+
2
−
2
Options
%% Cell type:code id: tags:
```
python
import
yaml
import
pandas
as
pd
from
pathlib
import
Path
import
re
import
logging
import
xarray
as
xr
import
warnings
```
%% Cell type:code id: tags:
```
python
logging
.
basicConfig
()
logger
=
logging
.
getLogger
(
"
catalog_netcdf
"
)
logger
.
setLevel
(
logging
.
INFO
)
warnings
.
filterwarnings
(
"
ignore
"
,
category
=
xr
.
SerializationWarning
)
```
%% Cell type:code id: tags:
```
python
def
process_table_file
(
table_file
:
Path
):
df
=
read_table
(
table_file
=
table_file
,
)
table_dir
=
Path
(
"
../
catalog
"
)
/
table_file
.
stem
table_dir
=
Path
(
"
../
public
"
)
/
table_file
.
stem
table_dir
.
mkdir
(
exist_ok
=
True
)
catalog
=
process_table
(
df
,
table_dir
)
with
open
(
table_dir
/
Path
(
"
main.yaml
"
),
"
w
"
)
as
outfile
:
yaml
.
dump
(
catalog
,
outfile
)
def
read_table
(
table_file
:
Path
)
->
pd
.
DataFrame
:
names
=
[
"
garbage1
"
,
"
simulation_id
"
,
"
experiment
"
,
"
resolution
"
,
"
start_date
"
,
"
end_date
"
,
"
path
"
,
"
contact
"
,
"
garbage2
"
,
]
usecols
=
[
x
for
x
in
names
if
"
garbage
"
not
in
x
]
converters
=
{
x
:
lambda
s
:
s
.
strip
()
for
x
in
usecols
if
"
date not in x
"
}
df
=
pd
.
read_csv
(
table_file
,
delimiter
=
"
|
"
,
names
=
names
,
usecols
=
usecols
,
header
=
1
,
converters
=
converters
,
)
df
.
iloc
[:,
0
]
=
df
.
iloc
[:,
0
].
str
.
replace
(
"
\\
_
"
,
"
_
"
).
str
.
strip
()
df
.
iloc
[:,
-
2
]
=
df
.
iloc
[:,
-
2
].
str
.
replace
(
"
\\
_
"
,
"
_
"
).
str
.
strip
()
df
[
"
path
"
]
=
[
Path
(
x
)
for
x
in
df
[
"
path
"
]]
logger
.
debug
(
df
)
return
df
def
process_table
(
df
:
pd
.
DataFrame
,
table_dir
:
Path
)
->
dict
:
catalog
=
dict
(
sources
=
dict
())
for
_
,
row
in
df
.
iterrows
():
catalog
[
"
sources
"
][
row
[
"
simulation_id
"
]]
=
create_entry
(
row
,
table_dir
=
table_dir
)
return
catalog
```
%% Cell type:code id: tags:
```
python
def
create_entry
(
experiment
,
table_dir
:
Path
):
entry_filename
=
table_dir
/
Path
(
f
"
{
experiment
[
'
simulation_id
'
]
}
.yaml
"
)
entry_content
=
{
"
sources
"
:
dict
()}
filegroups
=
analyze_dataset
(
experiment
[
"
simulation_id
"
],
experiment
[
"
path
"
])
for
filegroup
,
files
in
filegroups
.
items
():
entry_content
[
"
sources
"
][
filegroup
]
=
create_stream
(
experiment
,
filegroup
,
files
)
with
open
(
entry_filename
,
"
w
"
)
as
outfile
:
yaml
.
dump
(
entry_content
,
outfile
)
return
dict
(
driver
=
"
yaml_file_cat
"
,
description
=
experiment
[
"
experiment
"
],
args
=
dict
(
path
=
"
{{CATALOG_DIR}}/
"
+
f
'
{
experiment
[
"
simulation_id
"
]
}
.yaml
'
),
)
def
analyze_dataset
(
id
,
input_dir
:
Path
):
files
=
gen_files
(
id
,
input_dir
)
id
,
parts
=
split_filenamens
(
id
,
files
)
patterns
=
get_patterns
(
parts
)
logger
.
debug
(
f
"
{
id
=
}
{
patterns
=
}
"
)
filelist
=
gen_filelist
(
input_dir
,
id
,
patterns
)
return
filelist
def
gen_files
(
id
,
input_dir
):
files
=
[
str
(
x
)
for
x
in
input_dir
.
glob
(
f
"
{
id
}
*.nc
"
)]
files
=
[
x
for
x
in
files
if
"
restart
"
not
in
x
]
return
[
Path
(
x
)
for
x
in
files
]
def
split_filenamens
(
id
,
files
):
stems
=
list
(
f
.
stem
for
f
in
files
)
parts
=
[
x
[
len
(
id
)
:]
for
x
in
stems
]
return
id
,
parts
def
gen_filelist
(
input_dir
,
id
,
patterns
):
return
{
pattern
:
list
(
input_dir
.
glob
(
f
"
{
id
}
*
{
pattern
}
*.nc
"
))
for
pattern
in
patterns
}
def
get_patterns
(
parts
):
patterns
=
{
re
.
sub
(
r
"
\d{4}-\d{2}-\d{2}_
"
,
""
,
x
)
for
x
in
parts
}
# r'\\d\{4\}-\\d\{2\}-\\d\{2\}'
patterns
=
{
re
.
sub
(
r
"
\d{8}T\d{6}Z
"
,
""
,
x
)
for
x
in
patterns
}
# r'\\d\{8\}T\\d\{6\}Z'
patterns
=
{
re
.
sub
(
r
"
^_
"
,
""
,
x
)
for
x
in
patterns
}
patterns
=
{
re
.
sub
(
r
"
_$
"
,
""
,
x
)
for
x
in
patterns
}
return
patterns
def
create_stream
(
experiment
,
filegroup
,
files
):
stream
=
dict
(
driver
=
"
netcdf
"
)
stream
[
"
args
"
]
=
dict
(
chunks
=
dict
(
time
=
1
),
xarray_kwargs
=
dict
(
use_cftime
=
True
),
urlpath
=
[
str
(
x
)
for
x
in
files
],
)
stream
[
"
metadata
"
]
=
{
k
:
v
.
strip
()
for
k
,
v
in
experiment
.
items
()
if
k
!=
"
path
"
}
stream
[
"
metadata
"
]
|=
get_variable_metadata
(
files
)
return
stream
def
get_variable_metadata
(
files
):
ds
=
xr
.
open_dataset
(
files
[
0
])
variables
=
sorted
(
x
for
x
in
ds
)
long_names
=
[
ds
[
x
].
attrs
.
get
(
"
long_name
"
,
x
)
for
x
in
variables
]
return
dict
(
variables
=
variables
,
variable_long_names
=
long_names
)
```
%% Cell type:code id: tags:
```
python
table_files
=
sorted
(
Path
(
"
../inputs
"
).
glob
(
"
*.md
"
))
main_cat
=
dict
(
sources
=
dict
())
for
table_file
in
table_files
:
table
=
table_file
.
stem
process_table_file
(
table_file
)
main_cat
[
"
sources
"
][
table
]
=
dict
(
driver
=
"
yaml_file_cat
"
,
args
=
dict
(
path
=
"
{{CATALOG_DIR}}/
"
+
f
"
{
table
}
/main.yaml
"
),
)
with
open
(
Path
(
"
../
catalog
/main.yaml
"
),
"
w
"
)
as
outfile
:
with
open
(
Path
(
"
../
public
/main.yaml
"
),
"
w
"
)
as
outfile
:
yaml
.
dump
(
main_cat
,
outfile
)
```
Loading