Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
era5-tables
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
bm1159
cosodax
era5-tables
Commits
f3015d22
Commit
f3015d22
authored
1 week ago
by
Etor Lucio Eceiza
Browse files
Options
Downloads
Patches
Plain Diff
fix: format
parent
d23f851e
No related branches found
No related tags found
No related merge requests found
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/config.py
+48
-29
48 additions, 29 deletions
src/config.py
src/converter.py
+308
-93
308 additions, 93 deletions
src/converter.py
src/utils.py
+40
-4
40 additions, 4 deletions
src/utils.py
src/validator.py
+4
-1
4 additions, 1 deletion
src/validator.py
with
400 additions
and
127 deletions
src/config.py
+
48
−
29
View file @
f3015d22
...
...
@@ -7,38 +7,60 @@ csv_file: Path = BASE_DIR.parent / "Tables/original_tables/ct_ecmwf.rc"
json_output_path
:
Path
=
BASE_DIR
.
parent
/
"
Tables/era5-cmor-tables/Tables
"
search_dirs
:
List
[
Path
]
=
[
BASE_DIR
.
parent
/
"
Tables/source_tables/obs4MIPs-cmor-tables/Tables
"
,
BASE_DIR
.
parent
/
"
Tables/source_tables/cmip6-cmor-tables/Tables
"
BASE_DIR
.
parent
/
"
Tables/source_tables/cmip6-cmor-tables/Tables
"
,
]
# Frequency priority
frequency_priority
:
Dict
[
str
,
List
[
str
]]
=
{
"
1hr
"
:
[
"
A1hr
"
,
"
A3hr
"
,
"
A6hr
"
,
# Atmospheric hourly tables
"
E1hr
"
,
"
E3hr
"
,
"
E6hrZ
"
,
# Earth system / energy hourly
"
E1hrClimMon
"
,
"
E3hrPt
"
,
# Other energy system hourly
"
CF3hr
"
,
"
CFsubhr
"
,
"
Esubhr
"
,
# High-res and subhourly
"
3hr
"
,
"
6hrLev
"
,
"
6hrPlev
"
,
"
6hrPlevPt
"
,
# More coarse-hourly or pressure-level
"
AERhr
"
# Aerosol-specific hourly
"
A1hr
"
,
"
A3hr
"
,
"
A6hr
"
,
# Atmospheric hourly tables
"
E1hr
"
,
"
E3hr
"
,
"
E6hrZ
"
,
# Earth system / energy hourly
"
E1hrClimMon
"
,
"
E3hrPt
"
,
# Other energy system hourly
"
CF3hr
"
,
"
CFsubhr
"
,
"
Esubhr
"
,
# High-res and subhourly
"
3hr
"
,
"
6hrLev
"
,
"
6hrPlev
"
,
"
6hrPlevPt
"
,
# More coarse-hourly or pressure-level
"
AERhr
"
,
# Aerosol-specific hourly
],
"
day
"
:
[
"
Aday
"
,
"
Eday
"
,
"
EdayZ
"
,
# Standard and energy/dynamics daily
"
CFday
"
,
# High-res daily
"
SIday
"
,
# Sea ice daily
"
Oday
"
,
# Ocean daily
"
AERday
"
,
# Aerosol daily
"
day
"
# Generic fallback
"
Aday
"
,
"
Eday
"
,
"
EdayZ
"
,
# Standard and energy/dynamics daily
"
CFday
"
,
# High-res daily
"
SIday
"
,
# Sea ice daily
"
Oday
"
,
# Ocean daily
"
AERday
"
,
# Aerosol daily
"
day
"
,
# Generic fallback
],
"
mon
"
:
[
"
Amon
"
,
"
Lmon
"
,
"
Omon
"
,
# Atmosphere, land, ocean monthly
"
Emon
"
,
"
EmonZ
"
,
# Energy system monthly
"
CFmon
"
,
# High-res monthly
"
SImon
"
,
# Sea ice monthly
"
AERmon
"
,
"
AERmonZ
"
,
# Aerosol monthly
"
ImonAnt
"
,
"
ImonGre
"
,
"
LImon
"
# Ice-specific monthly
"
Amon
"
,
"
Lmon
"
,
"
Omon
"
,
# Atmosphere, land, ocean monthly
"
Emon
"
,
"
EmonZ
"
,
# Energy system monthly
"
CFmon
"
,
# High-res monthly
"
SImon
"
,
# Sea ice monthly
"
AERmon
"
,
"
AERmonZ
"
,
# Aerosol monthly
"
ImonAnt
"
,
"
ImonGre
"
,
"
LImon
"
,
# Ice-specific monthly
],
"
fx
"
:
[
"
fx
"
,
"
Ofx
"
,
"
Efx
"
,
"
IfxAnt
"
,
"
IfxGre
"
# Fixed fields (land, ocean, earth system, ice)
]
"
fx
"
,
"
Ofx
"
,
"
Efx
"
,
"
IfxAnt
"
,
"
IfxGre
"
,
# Fixed fields (land, ocean, earth system, ice)
],
}
# Level groupings
...
...
@@ -46,7 +68,7 @@ level_categories: Dict[str, List[str]] = {
"
sfc
"
:
[
"
sfc_an
"
,
"
sfc_fc
"
],
"
sfc_land
"
:
[
"
sfc_an_land
"
,
"
sfc_fc_land
"
],
"
pl
"
:
[
"
pl_an
"
,
"
pl_fc
"
],
"
ml
"
:
[
"
ml_an
"
]
"
ml
"
:
[
"
ml_an
"
]
,
}
# Realm → prefix
...
...
@@ -58,19 +80,16 @@ realm_prefix_map: Dict[str, str] = {
"
land
"
:
"
L
"
,
"
landIce
"
:
"
LI
"
,
"
ocean
"
:
"
O
"
,
"
seaIce
"
:
"
SI
"
"
seaIce
"
:
"
SI
"
,
}
# Approximate intervals in days
approx_interval_map
:
Dict
[
str
,
float
]
=
{
"
1hr
"
:
round
(
1
/
24
,
5
),
# 0.04167
"
1hr
"
:
round
(
1
/
24
,
5
),
# 0.04167
"
day
"
:
1.00000
,
"
mon
"
:
30.00000
,
"
fx
"
:
0.00000
"
fx
"
:
0.00000
,
}
# Number of levels
level_number
:
Dict
[
str
,
int
]
=
{
"
pl
"
:
37
,
"
ml
"
:
137
}
level_number
:
Dict
[
str
,
int
]
=
{
"
pl
"
:
37
,
"
ml
"
:
137
}
This diff is collapsed.
Click to expand it.
src/converter.py
+
308
−
93
View file @
f3015d22
This diff is collapsed.
Click to expand it.
src/utils.py
+
40
−
4
View file @
f3015d22
from
typing
import
Any
import
pandas
as
pd
from
typing
import
Optional
,
Dict
,
List
,
Any
def
excel_to_csv
(
excel_path
,
csv_path
,
sheet_name
=
0
,
field_separator
=
"
|
"
)
->
Any
:
def
excel_to_csv
(
excel_path
,
csv_path
,
sheet_name
=
0
,
field_separator
=
"
|
"
)
->
Any
:
"""
Converts an Excel sheet into a delimited CSV file.
Parameters:
excel_path (str or Path): Path to the input Excel file.
csv_path (str or Path): Destination path for the output CSV file.
sheet_name (int or str, optional): Sheet index or name to read from.
Default is the first sheet (0).
field_separator (str, optional): Delimiter to use in the CSV.
Default is
'
|
'
.
Returns:
Any: The path to the generated CSV file.
"""
df
:
pd
.
DataFrame
=
pd
.
read_excel
(
excel_path
,
sheet_name
=
sheet_name
)
df
.
to_csv
(
csv_path
,
sep
=
field_separator
,
index
=
False
)
return
csv_path
def
csv_to_excel
(
csv_path
,
excel_path
,
sheet_name
=
"
cmor_table
"
,
field_separator
=
"
|
"
)
->
str
:
def
csv_to_excel
(
csv_path
,
excel_path
,
sheet_name
=
"
cmor_table
"
,
field_separator
=
"
|
"
)
->
str
:
"""
Converts a delimited CSV file into an Excel sheet.
Parameters:
csv_path (str or Path): Path to the input CSV file.
excel_path (str or Path): Destination path for the output Excel file.
sheet_name (str, optional): Name of the sheet in the Excel file.
Default is
'
cmor_table
'
.
field_separator (str, optional): Delimiter used in the CSV.
Default is
'
|
'
.
Returns:
str: The path to the generated Excel file.
"""
df
:
pd
.
DataFrame
=
pd
.
read_csv
(
csv_path
,
sep
=
field_separator
)
df
.
to_excel
(
excel_path
,
sheet_name
=
sheet_name
,
index
=
False
)
return
excel_path
\ No newline at end of file
return
excel_path
This diff is collapsed.
Click to expand it.
src/validator.py
+
4
−
1
View file @
f3015d22
import
subprocess
import
sys
def
cf_check
(
nc_file
):
try
:
result
=
subprocess
.
run
([
'
cfchecks
'
,
nc_file
],
capture_output
=
True
,
text
=
True
,
check
=
True
)
result
=
subprocess
.
run
(
[
"
cfchecks
"
,
nc_file
],
capture_output
=
True
,
text
=
True
,
check
=
True
)
print
(
result
.
stdout
)
except
subprocess
.
CalledProcessError
as
e
:
print
(
"
CF checker error:
"
,
e
.
stderr
,
file
=
sys
.
stderr
)
...
...
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