Commit b8577c0e authored by thopri's avatar thopri
Browse files

updated bdy_coords test script from python 2 to 3

parent 8168bddc
......@@ -40,7 +40,7 @@ def main():
elif opt in ("-d", "--download_cmems"):
setup_file = arg
t0 = time.time()
with yaspin(Spinners.earth, text='Download CMEMS function is running'):
with yaspin(Spinners.earth, text='PyNEMO: download CMEMS data is running'):
profile.download_cmems(setup_file)
t1 = time.time()
print("CMEMS download time: %s" % (t1 - t0))
......@@ -53,7 +53,7 @@ def main():
#Logger
#logger = logging.getLogger(__name__)
t0 = time.time()
with yaspin(Spinners.earth, text='PyNEMO is running'):
with yaspin(Spinners.earth, text='PyNEMO: boundary generation is running'):
profile.process_bdy(setup_file, mask_gui)
t1 = time.time()
print("Execution Time: %s" % (t1-t0))
......
......@@ -8,12 +8,13 @@
# pylint: disable=E1103
# pylint: disable=no-name-in-module
#External imports
# External imports
from time import clock
import numpy as np
import logging
import importlib
#local imports
# local imports
from pynemo import nemo_bdy_setup as setup
from pynemo import nemo_bdy_gen_c as gen_grid
from pynemo import nemo_coord_gen_pop as coord
......@@ -25,18 +26,21 @@ from pynemo import pynemo_settings_editor
from pynemo.utils import Constants
from pynemo.gui.nemo_bdy_mask import Mask as Mask_File
from PyQt4.QtGui import QMessageBox
#import pickle
from PyQt5.QtWidgets import QMessageBox
# import pickle
logger = logging.getLogger(__name__)
def process_bdy(setup_filepath=0, mask_gui=False):
""" Main entry to the processing of the bdy
Keyword arguments:
setup_filepath -- file path to bdy file
mask_gui -- whether gui to select the mask file needs to be poped up
"""
#Logger
# Logger
logger.info('START')
start = clock()
SourceCoord = source_coord.SourceCoord()
......@@ -60,7 +64,7 @@ def process_bdy(setup_filepath=0, mask_gui=False):
logger.info('Done Mask')
DstCoord.bdy_msk = bdy_msk == 1
reload(gen_grid)
importlib.reload(gen_grid)
start = clock()
logger.info('start bdy_t')
grid_t = gen_grid.Boundary(bdy_msk, settings, 't')
......@@ -91,11 +95,11 @@ def process_bdy(setup_filepath=0, mask_gui=False):
bdy_ind = {'t': grid_t, 'u': grid_u, 'v': grid_v, 'f': grid_f}
for k in bdy_ind.keys():
for k in list(bdy_ind.keys()):
logger.info('bdy_ind %s %s %s', k, bdy_ind[k].bdy_i.shape, bdy_ind[k].bdy_r.shape)
start = clock()
co_set = coord.Coord(settings['dst_dir']+'/coordinates.bdy.nc', bdy_ind)
co_set = coord.Coord(settings['dst_dir'] + '/coordinates.bdy.nc', bdy_ind)
logger.info('done coord gen')
logger.info(clock() - start)
start = clock()
......@@ -114,6 +118,7 @@ def process_bdy(setup_filepath=0, mask_gui=False):
# dyn 3d over 1st rim
# dyn 3d frs over rw
def _get_mask(Setup, mask_gui):
""" This method reads the mask information from the netcdf file or opens a gui
to create a mask depending on the mask_gui input. return the mask data. The default mask
......@@ -124,31 +129,31 @@ def _get_mask(Setup, mask_gui):
"""
bdy_msk = None
if mask_gui:
#Open the gui to create a mask
# Open the gui to create a mask
_, mask = pynemo_settings_editor.open_settings_dialog(Setup)
bdy_msk = mask.data
Setup.refresh()
else:
try:
#mask filename and mask file flag is set
# mask filename and mask file flag is set
if Setup.bool_settings['mask_file'] and Setup.settings['mask_file'] is not None:
mask = Mask_File(mask_file=Setup.settings['mask_file'])
bdy_msk = mask.data
elif Setup.bool_settings['mask_file']:
logger.error("Mask file is not given")
return
else: #no mask file specified then use default 1px halo mask
else: # no mask file specified then use default 1px halo mask
logger.warning("Using default mask with bathymetry!!!!")
mask = Mask_File(Setup.settings['bathy'])
mask.apply_border_mask(Constants.DEFAULT_MASK_PIXELS)
bdy_msk = mask.data
except ValueError: # why is this except here? as there is an else: statement TODO
print 'something wrong?'
print('something wrong?')
return
if np.amin(bdy_msk) == 0:
# Mask is not set throw a warning message and set border to 1px.
logger.warning("Setting the mask to 1px border")
QMessageBox.warning(None,"pyNEMO", "Mask is not set, setting a 1 pixel border mask")
QMessageBox.warning(None, "pyNEMO", "Mask is not set, setting a 1 pixel border mask")
if bdy_msk is not None and 1 < bdy_msk.shape[0] and 1 < bdy_msk.shape[1]:
tmp = np.ones(bdy_msk.shape, dtype=bool)
tmp[1:-1, 1:-1] = False
......
name: pynemo3
name: pynemo3_tst
channels:
- defaults
dependencies:
......@@ -20,3 +20,4 @@ dependencies:
- motuclient==1.8.4
- sphinx==3.0.2
- sphinx-rtd-theme==0.4.3
- yaspin==0.16.0
\ No newline at end of file
......@@ -17,7 +17,7 @@ from pynemo.tests import bdy_coords as bdc
bdc.process_bdy('/Users/thopri/Projects/PyNEMO/inputs/namelist_cmems.bdy',False)
rootgrp = Dataset('/Users/thopri/Projects/PyNEMO/outputs/NNA_R12_bdyT_y2017m11.nc', "r", format="NETCDF4")
rootgrp = Dataset('/Users/thopri/Projects/PyNEMO/outputs/NNA_R12_bdyT_y1979m11.nc', "r", format="NETCDF4")
bdy_msk = np.squeeze(rootgrp.variables['bdy_msk'][:]) - 1
bdy_lon = np.squeeze(rootgrp.variables['nav_lon'][:])
bdy_lat = np.squeeze(rootgrp.variables['nav_lat'][:])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment