Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
VERIFY
CIF
Commits
3f1b90fc
Commit
3f1b90fc
authored
Feb 04, 2020
by
Espen Sollum
Browse files
Python 3 compatibility; various changes from master
parent
1f2c5559
Changes
136
Hide whitespace changes
Inline
Side-by-side
examples/config_inv_flexpart_ch4.yml
View file @
3f1b90fc
...
...
@@ -72,7 +72,6 @@ obsvect:
plugin
:
name
:
standard
version
:
std
# fic_obsvect : /home/eso/repos/CIF/flextest/monitor_obsvect.nc
# file_obsvect : /home/eso/repos/CIF/flextest/monitor_obsvect.nc
dump
:
True
dump_type
:
nc
...
...
@@ -91,7 +90,6 @@ measurements :
version
:
std
# File where to save data, if does not exist. Reads from there if exists
# fic_monitor : /home/eso/repos/CIF/flextest/monitor_allobs.nc
# file_monit : /home/eso/repos/CIF/flextest/monitor_allobs.nc
# file_monitor : /home/eso/repos/CIF/flextest/monitor_allobs.nc
dump_type
:
nc
...
...
@@ -222,7 +220,6 @@ controlvect:
dir_netcdf
:
/home/eso/repos/CIF/flextest/
hresol
:
regions
inc_ocean
:
true
ficregions
:
/home/eso/FLEX_INV/TEST_OUTPUT/regions_ghg.nc
fileregions
:
/home/eso/FLEX_INV/TEST_OUTPUT/regions_ghg.nc
# errtype : max
errtype
:
avg
...
...
@@ -236,9 +233,7 @@ controlvect:
# periodflux : 5D
period
:
10D
dir
:
/home/eso/FLEX_INV/TEST_OUTPUT/FLUXES/GHG/
# fic : CH4_TOTAL_%Y_05x05.nc
file
:
CH4_TOTAL_%Y_05x05.nc
# fic : CH4_TOTAL_%Y_05x05.nc
file_glob
:
CH4_TOTAL_%Y_10x10.nc
varname_flx
:
emisch4
...
...
@@ -258,7 +253,6 @@ controlvect:
hcorrelations
:
# landsea: True
landsea
:
False
ficlsm
:
/home/eso/FLEX_INV/TEST_INPUT/lsm_0.5x0.5_VERIFY.nc
filelsm
:
/home/eso/FLEX_INV/TEST_INPUT/lsm_0.5x0.5_VERIFY.nc
dircorrel
:
/home/eso/repos/CIF/flextest/
dump_hcorr
:
True
...
...
pycif/__init__.py
View file @
3f1b90fc
from
__future__
import
absolute_import
from
.plugins
import
*
from
os.path
import
dirname
,
basename
,
isdir
import
glob
modules
=
glob
.
glob
(
dirname
(
__file__
)
+
"/*"
)
__all__
=
[
basename
(
f
)
for
f
in
modules
if
isdir
(
f
)
and
not
f
.
endswith
(
'.py'
)]
pycif/__main__.py
View file @
3f1b90fc
import
argparse
import
pdb
import
code
import
traceback
from
pycif.utils.check.error
import
handle_except
from
pycif.utils.classes.setup
import
Setup
...
...
@@ -29,13 +25,5 @@ def main():
Setup
.
run_simu
(
args
)
# TODO:
###### POST PROCESS
############ PRODUCES OUTPUT OBS vs SIMU
############ PRODUCES OUTPUT EMISSIONS
############ PLOT BASIC FIGURES
# These functionalities should probably be included as a running mode
if
__name__
==
'__main__'
:
main
()
pycif/config/__init__.py
deleted
100644 → 0
View file @
1f2c5559
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""config sub-module
This module handles the configuration of the pyCIF runs. It loads a Yaml
configuration file including all paramaters necessary to setting up pyCIF.
"""
import
yaml
import
os
import
pycif.utils.check
as
check
import
pycif.utils.dates
as
dates
def
load
(
def_file
):
"""Generates a dictionary including all pyCIF parameters
Args:
def_file (string) : Path to the definition file
Handles both absolute and relative paths
Returns:
config_dict (dictionary): Dictionary populated with all pyCIF parameters
"""
fic
=
os
.
path
.
abspath
(
def_file
)
try
:
with
open
(
fic
,
'r'
)
as
f
:
config_dict
=
yaml
.
load
(
f
)
config_dict
[
'def_file'
]
=
fic
# Converting dates to datetime if necessary
config_dict
[
'datei'
]
=
dates
.
date2datetime
(
config_dict
[
'datei'
])
config_dict
[
'datef'
]
=
dates
.
date2datetime
(
config_dict
[
'datef'
])
return
config_dict
except
IOError
as
e
:
print
"Couldn't find config file"
,
fic
print
"Please check directories"
raise
e
except
yaml
.
scanner
.
ScannerError
as
e
:
print
"Error in the syntax of config file"
,
fic
raise
e
def
config_verbose
(
config_dict
):
"""Prints out main input parameters for pyCIF
"""
verbose_txt
=
[
"pyCIF has been initialized with the following parameters:"
,
"Yaml configuration file: {}"
.
format
(
config_dict
[
'def_file'
]),
"Log file: {}"
.
format
(
config_dict
[
'logfile'
]),
"Start date: {}"
.
format
(
config_dict
[
'datei'
]),
"End date: {}"
.
format
(
config_dict
[
'datef'
]),
"Working directory: {}"
.
format
(
config_dict
[
'workdir'
]),
]
map
(
lambda
v
:
check
.
verbose
(
v
),
verbose_txt
)
pycif/plugins/__init__.py
View file @
3f1b90fc
...
...
@@ -7,4 +7,4 @@ import glob
modules
=
glob
.
glob
(
dirname
(
__file__
)
+
"/*"
)
__all__
=
[
basename
(
f
)
for
f
in
modules
if
isdir
(
f
)
and
not
f
.
endswith
(
'.py'
)]
if
isdir
(
f
)
and
not
f
.
endswith
(
'.py'
)
and
'pycache'
not
in
f
]
pycif/plugins/chemistries/__init__.py
View file @
3f1b90fc
...
...
@@ -2,6 +2,7 @@
"""Contains all recognized XXfluxXX formats.
Automatically loads all pre-defined models as sub-modules of pycif.models
"""
from
__future__
import
absolute_import
from
os.path
import
dirname
,
basename
,
isdir
import
glob
...
...
@@ -11,4 +12,4 @@ modules = glob.glob(dirname(__file__) + "/*")
__all__
=
[
basename
(
f
)
for
f
in
modules
if
isdir
(
f
)
and
not
f
.
endswith
(
'.py'
)]
import
register
from
.
import
register
pycif/plugins/chemistries/chimere/__init__.py
View file @
3f1b90fc
from
__future__
import
absolute_import
import
shutil
from
distutils.dir_util
import
copy_tree
from
read_chemistry
import
read_chemicalscheme
from
make_chemistry
import
create_chemicalscheme
from
.
read_chemistry
import
read_chemicalscheme
from
.
make_chemistry
import
create_chemicalscheme
from
pycif.utils.check
import
verbose
from
pycif.utils.path
import
init_dir
...
...
pycif/plugins/chemistries/chimere/make_chemistry.py
View file @
3f1b90fc
...
...
@@ -36,44 +36,44 @@ def create_chemicalscheme(self):
# List of files
finf
=
'{}/chemical_scheme.nml'
.
format
(
dirchem_ref
)
fi
c
r
=
'{}/REACTIONS.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
c
ps
=
'{}/PRESCRIBED_SPECIES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
c
pl
=
'{}/PRODLOSS_SPECIES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
c
dp
=
'{}/DEPO_SPECIES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
c
a
=
'{}/ANTHROPIC.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
c
b
=
'{}/BIOGENIC.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
r
=
'{}/REACTIONS.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
ps
=
'{}/PRESCRIBED_SPECIES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
pl
=
'{}/PRODLOSS_SPECIES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
dp
=
'{}/DEPO_SPECIES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
a
=
'{}/ANTHROPIC.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
b
=
'{}/BIOGENIC.{}'
.
format
(
dirchem_ref
,
mecachim
)
mandatory_files
=
[
fi
c
r
,
fi
c
ps
,
fi
c
pl
,
fi
c
dp
]
mandatory_files
=
[
fi
le
r
,
fi
le
ps
,
fi
le
pl
,
fi
le
dp
]
create_mandchem
(
self
,
mandatory_files
)
fi
c
s
=
'{}/STOICHIOMETRY.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
c
c
=
'{}/CHEMISTRY.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
c
rr
=
'{}/REACTION_RATES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
c
j
=
'{}/PHOTO_RATES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
c
f
=
'{}/FAMILIES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
c
als
=
'{}/ALL_SPECIES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
c
as
=
'{}/ACTIVE_SPECIES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
s
=
'{}/STOICHIOMETRY.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
c
=
'{}/CHEMISTRY.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
rr
=
'{}/REACTION_RATES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
j
=
'{}/PHOTO_RATES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
f
=
'{}/FAMILIES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
als
=
'{}/ALL_SPECIES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
as
=
'{}/ACTIVE_SPECIES.{}'
.
format
(
dirchem_ref
,
mecachim
)
cond1
=
getsize
(
fi
c
r
)
>
0
cond1
=
getsize
(
fi
le
r
)
>
0
if
not
cond1
:
check
.
verbose
(
'Chemical mechanism not defined'
)
raise
OSError
(
'Chemical mechanism not defined'
)
nallqmax
,
nphoto_rates
=
create_optchem
(
self
,
fi
c
r
,
fi
c
ps
)
nallqmax
,
nphoto_rates
=
create_optchem
(
self
,
fi
le
r
,
fi
le
ps
)
# Create chemical_scheme.nml namelist
os
.
system
(
'echo "&args" > {}'
.
format
(
finf
))
os
.
system
(
'echo "fnacspec =
\'
{}
\'
" >> {}'
.
format
(
fi
c
as
,
finf
))
os
.
system
(
'echo "fnallspec =
\'
{}
\'
" >> {}'
.
format
(
fi
c
als
,
finf
))
os
.
system
(
'echo "fnprescr =
\'
{}
\'
" >> {}'
.
format
(
fi
c
ps
,
finf
))
os
.
system
(
'echo "fnprodl =
\'
{}
\'
" >> {}'
.
format
(
fi
c
pl
,
finf
))
os
.
system
(
'echo "fndep =
\'
{}
\'
" >> {}'
.
format
(
fi
c
dp
,
finf
))
os
.
system
(
'echo "fnchem =
\'
{}
\'
" >> {}'
.
format
(
fi
c
c
,
finf
))
os
.
system
(
'echo "fnstoi =
\'
{}
\'
" >> {}'
.
format
(
fi
c
s
,
finf
))
os
.
system
(
'echo "fnrates =
\'
{}
\'
" >> {}'
.
format
(
fi
c
rr
,
finf
))
os
.
system
(
'echo "fnjrates =
\'
{}
\'
" >> {}'
.
format
(
fi
c
j
,
finf
))
os
.
system
(
'echo "fnfamilies =
\'
{}
\'
" >> {}'
.
format
(
fi
c
f
,
finf
))
os
.
system
(
'echo "fnacspec =
\'
{}
\'
" >> {}'
.
format
(
fi
le
as
,
finf
))
os
.
system
(
'echo "fnallspec =
\'
{}
\'
" >> {}'
.
format
(
fi
le
als
,
finf
))
os
.
system
(
'echo "fnprescr =
\'
{}
\'
" >> {}'
.
format
(
fi
le
ps
,
finf
))
os
.
system
(
'echo "fnprodl =
\'
{}
\'
" >> {}'
.
format
(
fi
le
pl
,
finf
))
os
.
system
(
'echo "fndep =
\'
{}
\'
" >> {}'
.
format
(
fi
le
dp
,
finf
))
os
.
system
(
'echo "fnchem =
\'
{}
\'
" >> {}'
.
format
(
fi
le
c
,
finf
))
os
.
system
(
'echo "fnstoi =
\'
{}
\'
" >> {}'
.
format
(
fi
le
s
,
finf
))
os
.
system
(
'echo "fnrates =
\'
{}
\'
" >> {}'
.
format
(
fi
le
rr
,
finf
))
os
.
system
(
'echo "fnjrates =
\'
{}
\'
" >> {}'
.
format
(
fi
le
j
,
finf
))
os
.
system
(
'echo "fnfamilies =
\'
{}
\'
" >> {}'
.
format
(
fi
le
f
,
finf
))
os
.
system
(
'echo "iqmax = {}" >> {}'
.
format
(
self
.
nspecies
,
finf
))
os
.
system
(
'echo "iallqmax = {}" >> {}'
.
format
(
nallqmax
,
finf
))
os
.
system
(
...
...
pycif/plugins/chemistries/chimere/read_chemistry.py
View file @
3f1b90fc
...
...
@@ -27,30 +27,30 @@ def read_chemicalscheme(chemistry,
dirchem_ref
=
'{}/chemical_scheme/{}/'
.
format
(
workdir
,
chemistry
.
schemeid
)
# ACTIVE SPECIES
fi
c
_chem
=
'{}/ACTIVE_SPECIES.{}'
.
format
(
dirchem_ref
,
fi
le
_chem
=
'{}/ACTIVE_SPECIES.{}'
.
format
(
dirchem_ref
,
chemistry
.
schemeid
)
chemistry
.
species
=
pd
.
read_csv
(
fi
c
_chem
,
header
=
None
,
sep
=
' '
,
chemistry
.
species
=
pd
.
read_csv
(
fi
le
_chem
,
header
=
None
,
sep
=
' '
,
usecols
=
[
0
,
1
],
names
=
[
'ID'
,
'name'
])
chemistry
.
nspec
=
len
(
chemistry
.
species
)
# ANTHROPIC
fi
c
_chem
=
'{}/ANTHROPIC.{}'
.
format
(
dirchem_ref
,
fi
le
_chem
=
'{}/ANTHROPIC.{}'
.
format
(
dirchem_ref
,
chemistry
.
schemeid
)
chemistry
.
anthro_species
=
pd
.
read_csv
(
fi
c
_chem
,
header
=
None
,
sep
=
' '
,
chemistry
.
anthro_species
=
pd
.
read_csv
(
fi
le
_chem
,
header
=
None
,
sep
=
' '
,
usecols
=
[
0
,
1
],
names
=
[
'ID'
,
'name'
])
chemistry
.
nemisa
=
len
(
chemistry
.
anthro_species
)
# BIOGENIC
fi
c
_chem
=
'{}/BIOGENIC.{}'
.
format
(
dirchem_ref
,
fi
le
_chem
=
'{}/BIOGENIC.{}'
.
format
(
dirchem_ref
,
chemistry
.
schemeid
)
chemistry
.
bio_species
=
pd
.
read_csv
(
fi
c
_chem
,
header
=
None
,
sep
=
' '
,
chemistry
.
bio_species
=
pd
.
read_csv
(
fi
le
_chem
,
header
=
None
,
sep
=
' '
,
usecols
=
[
0
,
1
],
names
=
[
'ID'
,
'name'
])
chemistry
.
nemisb
=
len
(
chemistry
.
bio_species
)
# DEPO_SPEC
fi
c
_chem
=
'{}/DEPO_SPEC.{}'
.
format
(
dirchem_ref
,
fi
le
_chem
=
'{}/DEPO_SPEC.{}'
.
format
(
dirchem_ref
,
chemistry
.
schemeid
)
chemistry
.
dep_species
=
pd
.
read_csv
(
fi
c
_chem
,
header
=
None
,
sep
=
' '
,
chemistry
.
dep_species
=
pd
.
read_csv
(
fi
le
_chem
,
header
=
None
,
sep
=
' '
,
usecols
=
[
0
,
1
],
names
=
[
'ID'
,
'name'
])
chemistry
.
ndep
=
len
(
chemistry
.
dep_species
)
...
...
pycif/plugins/chemistries/chimere/utils.py
View file @
3f1b90fc
from
builtins
import
str
from
builtins
import
range
import
os
from
os.path
import
exists
,
getsize
import
pandas
as
pd
...
...
@@ -35,7 +37,7 @@ def create_mandchem(chemistry, mandatory_files):
f
.
write
(
attr
+
'
\n
'
)
def
create_optchem
(
chemistry
,
fi
c
r
,
fi
c
ps
):
def
create_optchem
(
chemistry
,
fi
le
r
,
fi
le
ps
):
"""
Create the chemistry files ALL_SPECIES, CHEMISTRY, REACTION_RATES,
STOICHIOMETRY and ACTIVE_SPECIES
...
...
@@ -45,8 +47,8 @@ def create_optchem(chemistry, ficr, ficps):
Args:
chemistry (pycif.utils.classes.chemistries.Chemistry): chemical scheme
fi
c
r (str) : path to the file with reactions
fi
c
ps (str): path to the file with prescribed species
fi
le
r (str) : path to the file with reactions
fi
le
ps (str): path to the file with prescribed species
"""
...
...
@@ -54,26 +56,26 @@ def create_optchem(chemistry, ficr, ficps):
dirchem_ref
=
chemistry
.
dirchem_ref
mecachim
=
chemistry
.
schemeid
fi
c
s
=
'{}/STOICHIOMETRY.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
c
c
=
'{}/CHEMISTRY.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
c
rr
=
'{}/REACTION_RATES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
c
j
=
'{}/PHOTO_RATES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
c
f
=
'{}/FAMILIES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
c
als
=
'{}/ALL_SPECIES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
c
as
=
'{}/ACTIVE_SPECIES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
c
anth
=
'{}/ANTHROPIC.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
c
bio
=
'{}/BIOGENIC.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
s
=
'{}/STOICHIOMETRY.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
c
=
'{}/CHEMISTRY.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
rr
=
'{}/REACTION_RATES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
j
=
'{}/PHOTO_RATES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
f
=
'{}/FAMILIES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
als
=
'{}/ALL_SPECIES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
as
=
'{}/ACTIVE_SPECIES.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
anth
=
'{}/ANTHROPIC.{}'
.
format
(
dirchem_ref
,
mecachim
)
fi
le
bio
=
'{}/BIOGENIC.{}'
.
format
(
dirchem_ref
,
mecachim
)
os
.
system
(
'rm -f {} {} {} {}'
.
format
(
fi
c
s
,
fi
c
c
,
fi
c
rr
,
fi
c
f
))
os
.
system
(
'rm -f {} {} {} {}'
.
format
(
fi
le
s
,
fi
le
c
,
fi
le
rr
,
fi
le
f
))
# Read reactions
df_reac
=
pd
.
read_csv
(
fi
c
r
,
sep
=
'\s*'
,
index_col
=
False
,
header
=
None
,
df_reac
=
pd
.
read_csv
(
fi
le
r
,
sep
=
'\s*'
,
index_col
=
False
,
header
=
None
,
comment
=
'#'
,
engine
=
"python"
)
# Read prescribed species
prescribed_species
=
np
.
array
([])
if
exists
(
fi
c
ps
)
and
getsize
(
fi
c
ps
)
>
0
:
df_prescr
=
pd
.
read_csv
(
fi
c
ps
,
sep
=
'\s*'
,
index_col
=
False
,
header
=
None
,
if
exists
(
fi
le
ps
)
and
getsize
(
fi
le
ps
)
>
0
:
df_prescr
=
pd
.
read_csv
(
fi
le
ps
,
sep
=
'\s*'
,
index_col
=
False
,
header
=
None
,
comment
=
'#'
,
engine
=
"python"
)
prescribed_species
=
df_prescr
[
0
]
...
...
@@ -115,7 +117,7 @@ def create_optchem(chemistry, ficr, ficps):
# Create reactions
reactions
=
df_reac
[
1
].
values
reactions_rates
,
nphoto_rates
=
read_react
(
reactions
,
fi
c
j
)
reactions_rates
,
nphoto_rates
=
read_react
(
reactions
,
fi
le
j
)
reactions_rates
=
pd
.
DataFrame
(
reactions_rates
)
# Active species
...
...
@@ -143,18 +145,18 @@ def create_optchem(chemistry, ficr, ficps):
output_species
=
pd
.
DataFrame
(
output_species
)
# Create files to create
stoichiometry
.
to_csv
(
fi
c
s
,
sep
=
' '
,
header
=
False
,
index
=
False
)
file_chemistry
.
to_csv
(
fi
c
c
,
sep
=
' '
,
header
=
False
,
index
=
False
)
reactions_rates
.
to_csv
(
fi
c
rr
,
sep
=
' '
,
header
=
False
,
index
=
False
)
all_species
.
to_csv
(
fi
c
als
,
sep
=
' '
,
header
=
False
,
index
=
False
)
output_species
.
to_csv
(
fi
c
as
,
sep
=
' '
,
header
=
False
,
index
=
False
)
output_species
.
to_csv
(
fi
c
anth
,
sep
=
' '
,
header
=
False
,
index
=
False
)
output_species
.
to_csv
(
fi
c
bio
,
sep
=
' '
,
header
=
False
,
index
=
False
)
stoichiometry
.
to_csv
(
fi
le
s
,
sep
=
' '
,
header
=
False
,
index
=
False
)
file_chemistry
.
to_csv
(
fi
le
c
,
sep
=
' '
,
header
=
False
,
index
=
False
)
reactions_rates
.
to_csv
(
fi
le
rr
,
sep
=
' '
,
header
=
False
,
index
=
False
)
all_species
.
to_csv
(
fi
le
als
,
sep
=
' '
,
header
=
False
,
index
=
False
)
output_species
.
to_csv
(
fi
le
as
,
sep
=
' '
,
header
=
False
,
index
=
False
)
output_species
.
to_csv
(
fi
le
anth
,
sep
=
' '
,
header
=
False
,
index
=
False
)
output_species
.
to_csv
(
fi
le
bio
,
sep
=
' '
,
header
=
False
,
index
=
False
)
return
all_species
.
shape
[
0
],
nphoto_rates
def
read_react
(
reactions
,
fi
c
j
):
def
read_react
(
reactions
,
fi
le
j
):
"""
Parse the types of reactions in the REACTIONS file and extract the data
"""
...
...
@@ -206,6 +208,6 @@ def read_react(reactions, ficj):
nphoto_rates
+=
1
photo_rates
=
pd
.
DataFrame
(
photo_rates
[
1
:])
photo_rates
.
to_csv
(
fi
c
j
,
sep
=
' '
,
header
=
False
,
index
=
False
)
photo_rates
.
to_csv
(
fi
le
j
,
sep
=
' '
,
header
=
False
,
index
=
False
)
return
reactions_rates
,
nphoto_rates
pycif/plugins/controlvects/__init__.py
View file @
3f1b90fc
...
...
@@ -2,6 +2,7 @@
"""Contains all recognized state vectors.
Automatically loads all pre-defined models as sub-modules of pycif.models
"""
from
__future__
import
absolute_import
from
os.path
import
dirname
,
basename
,
isdir
import
glob
...
...
@@ -11,4 +12,4 @@ modules = glob.glob(dirname(__file__) + "/*")
__all__
=
[
basename
(
f
)
for
f
in
modules
if
isdir
(
f
)
and
not
f
.
endswith
(
'.py'
)]
import
register
from
.
import
register
pycif/plugins/controlvects/standard/__init__.py
View file @
3f1b90fc
...
...
@@ -66,10 +66,6 @@ def ini_data(plugin, **kwargs):
# Gets read from model if not already defined
try
:
tracer
.
read
(
*
list
(
range
(
4
)))
# tracer.read(*range(4))
# except PluginError:
# except TypeError:
# tracer.read(*list(range(4)))
except
PluginError
:
if
comp
in
[
'fluxes'
,
'inicond'
,
'latcond'
,
'topcond'
]:
tracer
.
read
=
getattr
(
plugin
.
model
,
comp
).
read
...
...
pycif/plugins/controlvects/standard/utils/reindex.py
View file @
3f1b90fc
...
...
@@ -18,7 +18,7 @@ def reindex(array, var, levels={}, method='ffill'):
for
lev
in
levels
:
loc_levs
=
list
(
set
(
df_levs
)
-
{
lev
})
lev_data
=
dataframe
.
unstack
(
level
=
loc_levs
)
\
.
reindex
(
pd
.
Index
(
levels
[
lev
],
name
=
lev
),
method
=
method
)
\
.
reindex
(
pd
.
Index
(
levels
[
lev
]
.
data
,
name
=
lev
),
method
=
method
)
\
.
stack
(
level
=
loc_levs
)
dataframe
=
lev_data
...
...
pycif/plugins/controlvects/standard/utils/scalemaps.py
View file @
3f1b90fc
from
builtins
import
zip
import
numpy
as
np
import
xarray
as
xr
...
...
pycif/plugins/domains/__init__.py
View file @
3f1b90fc
...
...
@@ -2,6 +2,7 @@
"""Contains all recognized flux formats.
Automatically loads all pre-defined models as sub-modules of pycif.models
"""
from
__future__
import
absolute_import
from
os.path
import
dirname
,
basename
,
isdir
import
glob
...
...
@@ -11,4 +12,4 @@ modules = glob.glob(dirname(__file__) + "/*")
__all__
=
[
basename
(
f
)
for
f
in
modules
if
isdir
(
f
)
and
not
f
.
endswith
(
'.py'
)]
import
register
from
.
import
register
pycif/plugins/domains/chimere/__init__.py
View file @
3f1b90fc
from
read_domain
import
read_grid
from
__future__
import
absolute_import
from
.read_domain
import
read_grid
pycif/plugins/domains/chimere/read_domain.py
View file @
3f1b90fc
...
...
@@ -9,7 +9,7 @@ def read_grid(domain,
Args:
domain (dictionary): dictionary defining the domain. Should include
fi
c
grid to be able to read the grid from a file
fi
le
grid to be able to read the grid from a file
Return:
Grid dictionary with meshgrids for center lon/lat and corner lon/lat
...
...
@@ -33,17 +33,17 @@ def read_grid(domain,
domain
.
nlon
=
nzo
# Reading lat/lon and latc/lonc
fi
c
_hcoord
=
'{}/HCOORD/COORD_{}'
.
format
(
domain
.
repgrid
,
fi
le
_hcoord
=
'{}/HCOORD/COORD_{}'
.
format
(
domain
.
repgrid
,
domain
.
domid
)
data
=
np
.
genfromtxt
(
fi
c
_hcoord
)
lon
=
data
[:,
0
].
reshape
(
n
zo
,
nme
,
order
=
'F'
)
lat
=
data
[:,
1
].
reshape
(
n
zo
,
nme
,
order
=
'F'
)
data
=
np
.
genfromtxt
(
fi
le
_hcoord
)
lon
=
data
[:,
0
].
reshape
(
n
me
,
nzo
)
lat
=
data
[:,
1
].
reshape
(
n
me
,
nzo
)
fi
c
_hcoord
=
'{}/HCOORD/COORDcorner_{}'
.
format
(
domain
.
repgrid
,
fi
le
_hcoord
=
'{}/HCOORD/COORDcorner_{}'
.
format
(
domain
.
repgrid
,
domain
.
domid
)
data
=
np
.
genfromtxt
(
fi
c
_hcoord
)
lonc
=
data
[:,
0
].
reshape
(
n
zo
+
1
,
n
me
+
1
,
order
=
'F'
)
latc
=
data
[:,
1
].
reshape
(
n
zo
+
1
,
n
me
+
1
,
order
=
'F'
)
data
=
np
.
genfromtxt
(
fi
le
_hcoord
)
lonc
=
data
[:,
0
].
reshape
(
n
me
+
1
,
n
zo
+
1
)
latc
=
data
[:,
1
].
reshape
(
n
me
+
1
,
n
zo
+
1
)
# Putting the data into the domain
domain
.
zlonc
=
lonc
...
...
@@ -54,8 +54,9 @@ def read_grid(domain,
.
format
(
domain
.
repgrid
,
domain
.
domid
)
# Reading vertical coordinates
fi
c
_vcoord
=
'{}/VCOORD/VCOORD_{}_{}_{}'
\
fi
le
_vcoord
=
'{}/VCOORD/VCOORD_{}_{}_{}'
\
.
format
(
domain
.
repgrid
,
domain
.
nlev
,
domain
.
p1
,
domain
.
pmax
)
data
=
np
.
genfromtxt
(
fi
c
_vcoord
)
data
=
np
.
genfromtxt
(
fi
le
_vcoord
)
domain
.
ap
=
data
[:,
0
]
domain
.
bp
=
data
[:,
1
]
pycif/plugins/domains/dummy/__init__.py
View file @
3f1b90fc
from
create_domain
import
create_domain
from
read_domain
import
read_grid
from
__future__
import
absolute_import
from
.create_domain
import
create_domain
from
.read_domain
import
read_grid
pycif/plugins/domains/dummy/read_domain.py
View file @
3f1b90fc
from
__future__
import
division
from
past.utils
import
old_div
import
numpy
as
np
import
pycif.utils.check
as
check
...
...
@@ -8,7 +10,7 @@ def read_grid(domain,
Args:
domain (Plugin): dictionary defining the domain. Should include
fi
c
grid to be able to read the grid from a file
fi
le
grid to be able to read the grid from a file
Return:
Grid dictionary with meshgrids for center lon/lat and corner lon/lat
...
...
@@ -16,20 +18,20 @@ def read_grid(domain,
Notes: Coordinates are in meters from a reference point
"""
# Tries open fi
c
lon, fi
c
lat
# Tries open fi
le
lon, fi
le
lat
try
:
zlon
=
np
.
loadtxt
(
domain
.
fi
c
lon
)
zlat
=
np
.
loadtxt
(
domain
.
fi
c
lat
)
zlon
=
np
.
loadtxt
(
domain
.
fi
le
lon
)
zlat
=
np
.
loadtxt
(
domain
.
fi
le
lat
)
nlon
=
zlon
.
size
nlat
=
zlat
.
size
# Corner coordinates
dlon
=
np
.
ptp
(
zlon
)
/
(
nlon
-
1
)
/
2.
dlon
=
old_div
(
np
.
ptp
(
zlon
)
,
(
nlon
-
1
)
/
2.
)
zlonc
=
zlon
-
dlon
zlonc
=
np
.
append
(
zlonc
,
zlonc
[
-
1
]
+
2
*
dlon
)
dlat
=
np
.
ptp
(
zlat
)
/
(
nlat
-
1
)
/
2.
dlat
=
old_div
(
np
.
ptp
(
zlat
)
,
(
nlat
-
1
)
/
2.
)
zlatc
=
zlat
-
dlat
zlatc
=
np
.
append
(
zlatc
,
zlatc
[
-
1
]
+
2
*
dlat
)
...
...
@@ -50,3 +52,9 @@ def read_grid(domain,
"Make them from given coordinates"
)
domain
.
create_domain
()
# Compute areas in m2
domain
.
areas
=
np
.
diff
(
domain
.
zlatc
,
axis
=
1
)[:
-
1
]
\
*
np
.
diff
(
domain
.
zlonc
,
axis
=
0
)[:,
:
-
1
]
# Projection not as GPS
domain
.
projection
=
'xy'
pycif/plugins/domains/flexpart/__init__.py
View file @
3f1b90fc
from
create_domain
import
create_domain
from
read_domain
import
read_grid
from
__future__
import
absolute_import
from
.create_domain
import
create_domain
from
.read_domain
import
read_grid
domain_flexpart
=
True
Prev
1
2
3
4
5
…
7
Next
Write
Preview
Supports
Markdown
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