Skip to content

Commit

Permalink
increase logo size and clean api export(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
franckalbinet committed Sep 13, 2024
1 parent 4fb0ae6 commit 2ca059c
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 225 deletions.
4 changes: 3 additions & 1 deletion marisco/inout.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Files reader and writer"""
"""Files reader and writer."""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/inout.ipynb.

Expand All @@ -11,12 +11,14 @@

# %% ../nbs/api/inout.ipynb 3
def write_toml(fname, cfg):
"Write a TOML file from a dictionary."
print(f'Creating {fname}')
with open(fname, "wb") as f:
tomli_w.dump(cfg, f)

# %% ../nbs/api/inout.ipynb 4
def read_toml(fname):
"Read a TOML file into a dictionary."
with open(fname, "rb") as f:
config = tomli.load(f)
return config
20 changes: 10 additions & 10 deletions marisco/nc_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self,
self.dim = cdl['dim']
self.enum_types = {}

# %% ../nbs/api/nc_template.ipynb 9
# %% ../nbs/api/nc_template.ipynb 8
@patch
def nuclide_vars(
self:NCTemplater,
Expand Down Expand Up @@ -66,7 +66,7 @@ def nuclide_vars(
)
]

# %% ../nbs/api/nc_template.ipynb 12
# %% ../nbs/api/nc_template.ipynb 11
@patch
def derive(
self:NCTemplater,
Expand All @@ -81,15 +81,15 @@ def derive(
'attrs': {key: nuclide['attrs'][key] + suffix['attrs'][key] for key in nuclide['attrs']}
}

# %% ../nbs/api/nc_template.ipynb 18
# %% ../nbs/api/nc_template.ipynb 17
@patch
def create_enum_types(self:NCTemplater):
"Create enumeration types"
for name, enum in self.enum_dicts.items():
if self.verbose: print(f'Creating {name} enumeration type')
self.enum_types[name] = self.nc.createEnumType(np.int_, name, enum)

# %% ../nbs/api/nc_template.ipynb 19
# %% ../nbs/api/nc_template.ipynb 18
@patch
def create_groups(self:NCTemplater):
"Create NetCDF groups"
Expand All @@ -98,7 +98,7 @@ def create_groups(self:NCTemplater):
grp = self.nc.createGroup(grp_name)
self.create_variables(grp)

# %% ../nbs/api/nc_template.ipynb 20
# %% ../nbs/api/nc_template.ipynb 19
@patch
def create_variables(self:NCTemplater,
grp:netCDF4.Group, # NetCDF group
Expand All @@ -109,7 +109,7 @@ def create_variables(self:NCTemplater,
self.create_group_specific_variables(grp)
self.create_analyte_variables(grp)

# %% ../nbs/api/nc_template.ipynb 21
# %% ../nbs/api/nc_template.ipynb 20
@patch
def create_default_variables(self:NCTemplater,
grp:netCDF4.Group, # NetCDF group
Expand All @@ -118,7 +118,7 @@ def create_default_variables(self:NCTemplater,
vars = self.cdl['vars']['defaults'].values()
for var in vars: self.create_variable(grp, var)

# %% ../nbs/api/nc_template.ipynb 22
# %% ../nbs/api/nc_template.ipynb 21
@patch
def create_group_specific_variables(self:NCTemplater,
grp:netCDF4.Group, # NetCDF group
Expand All @@ -128,7 +128,7 @@ def create_group_specific_variables(self:NCTemplater,
for var in vars.get(name2grp(grp.name, self.cdl), {}).values():
self.create_variable(grp, var)

# %% ../nbs/api/nc_template.ipynb 23
# %% ../nbs/api/nc_template.ipynb 22
@patch
def create_analyte_variables(self:NCTemplater,
grp:netCDF4.Group, # NetCDF group
Expand All @@ -139,7 +139,7 @@ def create_analyte_variables(self:NCTemplater,
for v in self.cdl['vars']['suffixes'].values():
self.create_variable(grp, self.derive(var, v))

# %% ../nbs/api/nc_template.ipynb 24
# %% ../nbs/api/nc_template.ipynb 23
@patch
def create_variable(self:NCTemplater,
grp:netCDF4.Group, # NetCDF group
Expand All @@ -152,7 +152,7 @@ def create_variable(self:NCTemplater,
self.dim['name'])
nc_var.setncatts(attrs)

# %% ../nbs/api/nc_template.ipynb 26
# %% ../nbs/api/nc_template.ipynb 24
@patch
def generate(self:NCTemplater):
"Generate CDL"
Expand Down
20 changes: 11 additions & 9 deletions marisco/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def get_unique_across_dfs(dfs:dict, # Dictionary of dataframes

# %% ../nbs/api/utils.ipynb 12
class Remapper():
"Remap a data provider lookup table to a MARIS lookup table using fuzzy matching."
def __init__(self,
provider_lut_df:pd.DataFrame, # Data provider lookup table to be remapped
maris_lut_fn:callable, # Function that returns the MARIS lookup table path
Expand All @@ -51,7 +52,6 @@ def __init__(self,
provider_col_key, # Data provider lookup table column name for the key
fname_cache # Cache file name
):
"Remap a data provider lookup table to a MARIS lookup table using fuzzy matching."
fc.store_attr()
self.cache_file = cache_path() / fname_cache
self.maris_lut = maris_lut_fn()
Expand Down Expand Up @@ -140,6 +140,7 @@ def has_valid_varname(
def get_bbox(df,
coord_cols=('lon', 'lat')
):
"Get the bounding box of a DataFrame."
x, y = coord_cols
arr = [(row[x], row[y]) for _, row in df.iterrows()]
return MultiPoint(arr).envelope
Expand All @@ -150,7 +151,7 @@ def download_files_in_folder(owner:str,
src_dir:str,
dest_dir:str
):
"Make a GET request to the GitHub API to get the contents of the folder"
"Make a GET request to the GitHub API to get the contents of the folder."
url = f"https://api.github.com/repos/{owner}/{repo}/contents/{src_dir}"
response = requests.get(url)

Expand Down Expand Up @@ -182,7 +183,7 @@ def download_file(owner, repo, src_dir, dest_dir, fname):
def match_worms(
name:str # Name of species to look up in WoRMS
):
"Lookup `name` in WoRMS (fuzzy match)"
"Lookup `name` in WoRMS (fuzzy match)."
url = 'https://www.marinespecies.org/rest/AphiaRecordsByMatchNames'
params = {
'scientificnames[]': [name],
Expand All @@ -201,15 +202,16 @@ def match_worms(
else:
return -1

# %% ../nbs/api/utils.ipynb 37
# %% ../nbs/api/utils.ipynb 32
@dataclass
class Match:
"Match between a data provider name and a MARIS lookup table."
matched_id: int
matched_maris_name: str
source_name: str
match_score: int

# %% ../nbs/api/utils.ipynb 38
# %% ../nbs/api/utils.ipynb 33
def match_maris_lut(
lut_path: str, # Path to MARIS species authoritative species look-up table
data_provider_name: str, # Name of data provider nomenclature item to look up
Expand All @@ -226,15 +228,15 @@ def match_maris_lut(
df = df.sort_values(by='score', ascending=True)[:nresults]
return df[[maris_id, maris_name, 'score']]

# %% ../nbs/api/utils.ipynb 45
# %% ../nbs/api/utils.ipynb 40
def get_bbox(df,
coord_cols=('lon', 'lat')
):
x, y = coord_cols
arr = [(row[x], row[y]) for _, row in df.iterrows()]
return MultiPoint(arr).envelope

# %% ../nbs/api/utils.ipynb 52
# %% ../nbs/api/utils.ipynb 47
def download_files_in_folder(owner:str,
repo:str,
src_dir:str,
Expand Down Expand Up @@ -268,7 +270,7 @@ def download_file(owner, repo, src_dir, dest_dir, fname):
else:
print(f"Error: {response.status_code}")

# %% ../nbs/api/utils.ipynb 54
# %% ../nbs/api/utils.ipynb 49
def match_worms(
name:str # Name of species to look up in WoRMS
):
Expand All @@ -291,7 +293,7 @@ def match_worms(
else:
return -1

# %% ../nbs/api/utils.ipynb 65
# %% ../nbs/api/utils.ipynb 54
def test_dfs(
dfs1:dict, # First dictionary of DataFrames to compare
dfs2:dict # Second dictionary of DataFrames to compare
Expand Down
2 changes: 1 addition & 1 deletion nbs/api/callbacks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"metadata": {},
"outputs": [],
"source": [
"#| exports\n",
"#| export\n",
"import copy\n",
"import fastcore.all as fc\n",
"from operator import attrgetter\n",
Expand Down
2 changes: 1 addition & 1 deletion nbs/api/configs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"metadata": {},
"outputs": [],
"source": [
"#| exports\n",
"#| export\n",
"from pathlib import Path\n",
"import os\n",
"import re\n",
Expand Down
8 changes: 5 additions & 3 deletions nbs/api/inout.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"metadata": {},
"source": [
"# Input/Output\n",
"> Files reader and writer"
"> Files reader and writer."
]
},
{
Expand All @@ -39,8 +39,9 @@
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
"#| exports\n",
"def write_toml(fname, cfg):\n",
" \"Write a TOML file from a dictionary.\"\n",
" print(f'Creating {fname}')\n",
" with open(fname, \"wb\") as f:\n",
" tomli_w.dump(cfg, f)"
Expand All @@ -53,8 +54,9 @@
"metadata": {},
"outputs": [],
"source": [
"#| export\n",
"#| exports\n",
"def read_toml(fname):\n",
" \"Read a TOML file into a dictionary.\"\n",
" with open(fname, \"rb\") as f:\n",
" config = tomli.load(f)\n",
" return config"
Expand Down
2 changes: 1 addition & 1 deletion nbs/api/metadata.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"metadata": {},
"outputs": [],
"source": [
"#| exports\n",
"#| export\n",
"import pandas as pd\n",
"import fastcore.all as fc\n",
"from cftime import num2date\n",
Expand Down
Loading

0 comments on commit 2ca059c

Please sign in to comment.