Skip to content

Commit

Permalink
Added new features
Browse files Browse the repository at this point in the history
  • Loading branch information
TaufiqHassan committed Nov 3, 2019
1 parent f07d757 commit ff08e4c
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 17 deletions.
2 changes: 1 addition & 1 deletion acccmip6/access_cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def SearchCmip6(**kwargs):
_mod_help()
if (_var == 'show') or (_var == 'Show'):
ModDB = CMIP6DB()
print(ModDB.CMIP6_variables())
print(ModDB.var_stdName())
if (_mod == 'show') or (_mod == 'Show'):
ModDB = CMIP6DB()
print(ModDB.available_models())
Expand Down
32 changes: 32 additions & 0 deletions acccmip6/utilities/CMIP6_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,25 @@ def available_realmns(self):
self._holder.append(self._fdata.split('checkbox_realm_')[zz+2].split('" name="')[0])
print("Available frequencies: \n\n")
return self._holder

def var_stdName(self):
try:
with _fetch_url(self._set_curl(self._Curl)) as self._fdata:
self._avail = len(re.findall('id="checkbox_cf_standard_name_',self._fdata))
print("\nCurrently ", self._avail," variables has outputs!\n")
for zz in range(self._avail):
self._holder.append(self._fdata.split('checkbox_cf_standard_name_')[zz+2].split('" name="')[0])
print("Available variables: \n\n")
return self._holder
except:
self._Curl=_choose_server()
with _fetch_url(self._set_curl(self._Curl)) as self._fdata:
self._avail = len(re.findall('id="checkbox_cf_standard_name_',self._fdata))
print("\nCurrently ", self._avail," variables has outputs!\n")
for zz in range(self._avail):
self._holder.append(self._fdata.split('checkbox_cf_standard_name_')[zz+2].split('" name="')[0])
print("Available frequencies: \n\n")
return self._holder

@staticmethod
def _get_definition(exp):
Expand All @@ -150,4 +169,17 @@ def _get_definition(exp):
if (exp_name.values[zz]==exp):
definition=(exp_def.values[zz][0]).split('\n')[0].strip()
return definition

@staticmethod
def _get_longName(var):
resource_package = __name__
resource_path = '/'.join(('data', 'var_list.xlsx'))
tmp = pkg_resources.resource_stream(resource_package, resource_path)
did=pd.read_excel(tmp)
v=pd.DataFrame(did,columns=['variable'])
v_long=pd.DataFrame(did,columns=['Long_name'])
for zz in range(len(v.values)):
if (v.values[zz]==var):
longName=v_long.values[zz][0]
return longName

3 changes: 2 additions & 1 deletion acccmip6/utilities/checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def _check_var(self):
if self.val.upper() in s:
n=n+1
s = var_av[m_u.index(s)]
print('\nOption ', n, s)
LN = CMIP6DB()._get_longName(str(s))
print('\nOption ', n, s,'(',LN,')')
if (n==0):
raise ValueError()
else:
Expand Down
Binary file added acccmip6/utilities/data/var_list.xlsx
Binary file not shown.
36 changes: 22 additions & 14 deletions acccmip6/utilities/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,21 +294,29 @@ def _mod_help():
print("\nUse 'show' as the -m/-e/-f/-v/-r argument option instead of the names\n")
print(color.BOLD+color.UNDERLINE+"Example:"+color.END+" acccmip -o M -m show >>> will generate a list of all currently available models in the CMIP6 database.")

def _get_rlzn_links(rlzn,all_rlzn,links):
def _get_rlzn_links(r,all_rlzn,links):
new_links=[]
if rlzn in str(all_rlzn):
new_links=[]
for url in links:
try:
if (int(rlzn) == int(url.split('/')[len(url.split('/'))-1].split('_r')[1][0:2])):
new_links.append(url)
except:
if (rlzn == (url.split('/')[len(url.split('/'))-1].split('_r')[1][0])):
new_links.append(url)
return new_links
else:
print(color.LRED+"\nSelected realzation is not available!"+color.END)
raise SystemExit
for rlzn in r:
if rlzn in str(all_rlzn):
for url in links:
try:
try:
if (int(rlzn) == int(url.split('/')[len(url.split('/'))-1].split('-r')[1][0:2])):
new_links.append(url)
except:
if (rlzn == (url.split('/')[len(url.split('/'))-1].split('-r')[1][0])):
new_links.append(url)
except:
try:
if (int(rlzn) == int(url.split('/')[len(url.split('/'))-1].split('_r')[1][0:2])):
new_links.append(url)
except:
if (rlzn == (url.split('/')[len(url.split('/'))-1].split('_r')[1][0])):
new_links.append(url)
else:
print(color.LRED+"\nSelected realzation is not available!"+color.END)
raise SystemExit
return new_links

def _get_skipped_links(links,val):
skipped_items = [x.strip() for x in val.split(',')]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

setup(
name='acccmip6',
version='2.0.4',
version='3.0.0',
description="Package for accessing CMIP6 database in real-time",
long_description=readme,
author="Taufiq Hassan",
Expand Down

0 comments on commit ff08e4c

Please sign in to comment.