Commit fd274644 authored by thopri's avatar thopri
Browse files

added I/O defined by NCML

parent 0eb2053e
......@@ -24,7 +24,6 @@
<ns0:variable name="votemper" orgName="thetao" />
<ns0:variable name="vozocrtx" orgName="uo" />
<ns0:variable name="vomecrty" orgName="vo" />
<ns0:variable name="sossheig" orgName="zos" />
<ns0:variable name="time_counter" orgName="time" />
<ns0:dimension name="time_counter" orgName="time" />
</ns0:netcdf>
......@@ -40,8 +40,10 @@
!------------------------------------------------------------------------------
! I/O
!------------------------------------------------------------------------------
sn_src_dir = '/Users/thopri/Projects/PyNEMO/inputs/CMEMS.ncml' ! src_files/'
sn_dst_dir = '/Users/thopri/Projects/PyNEMO/outputs'
sn_src_dir = '/Users/thopri/Projects/PyNEMO/inputs/CMEMS.ncml' ! src_files/'
sn_dst_dir = '/Users/thopri/Projects/PyNEMO/outputs'
sn_ncml_out = '/Users/thopri/Projects/PyNEMO/pynemo/output_NCML'
sn_model_prefix = 'NEMO'
sn_fn = 'NNA_R12' ! prefix for output files
nn_fv = -1e20 ! set fill value for output files
......@@ -91,9 +93,9 @@
ln_mask_file = .false. ! =T : read mask from file
cn_mask_file = 'mask.nc' ! name of mask file
! (if ln_mask_file=.TRUE.)
ln_dyn2d = .false. ! boundary conditions for
ln_dyn2d = .true. ! boundary conditions for
! barotropic fields
ln_dyn3d = .false. ! boundary conditions for
ln_dyn3d = .true. ! boundary conditions for
! baroclinic velocities
ln_tra = .true. ! boundary conditions for T and S
ln_ice = .false. ! ice boundary condition
......
......@@ -37,6 +37,7 @@ import logging
import numpy as np
import scipy.spatial as sp
from calendar import monthrange, isleap
from glob import glob
from scipy.interpolate import interp1d
from cftime import datetime, utime
from pynemo import nemo_bdy_ncgen as ncgen
......@@ -886,6 +887,9 @@ class Extract:
f_out = self.settings['dst_dir']+self.settings['fn']+ \
'_bdy'+self.g_type.upper()+ '_y'+str(year)+'m'+'%02d' % month+'.nc'
ncml_out = glob(self.settings['ncml_out']+'/*'+str(self.g_type.upper())+'.ncml')
ncml_out = ncml_out[0]
ncgen.CreateBDYNetcdfFile(f_out, self.num_bdy,
self.jpi, self.jpj, self.jpk,
......@@ -894,7 +898,7 @@ class Extract:
unit_origin,
self.settings['fv'],
self.settings['dst_calendar'],
self.g_type.upper(),self.var_nam)
self.g_type.upper(),self.var_nam,ncml_out)
self.logger.info('Writing out BDY data to: %s', f_out)
......@@ -913,17 +917,17 @@ class Extract:
# Write variable to file
ncpop.write_data_to_file(f_out, v, tmp_var)
ncpop.write_data_to_file(f_out, v, tmp_var,ncml_out)
# Write remaining data to file (indices are in Python notation
# therefore we must add 1 to i,j and r)
ncpop.write_data_to_file(f_out, 'nav_lon', self.nav_lon)
ncpop.write_data_to_file(f_out, 'nav_lat', self.nav_lat)
ncpop.write_data_to_file(f_out, 'depth'+self.g_type, self.dst_dep)
ncpop.write_data_to_file(f_out, 'nbidta', ind.bdy_i[:, 0] + 1)
ncpop.write_data_to_file(f_out, 'nbjdta', ind.bdy_i[:, 1] + 1)
ncpop.write_data_to_file(f_out, 'nbrdta', ind.bdy_r[: ] + 1)
ncpop.write_data_to_file(f_out, 'time_counter', self.time_counter)
ncpop.write_data_to_file(f_out, 'nav_lon', self.nav_lon,ncml_out)
ncpop.write_data_to_file(f_out, 'nav_lat', self.nav_lat,ncml_out)
ncpop.write_data_to_file(f_out, 'depth'+self.g_type, self.dst_dep,ncml_out)
ncpop.write_data_to_file(f_out, 'nbidta', ind.bdy_i[:, 0] + 1,ncml_out)
ncpop.write_data_to_file(f_out, 'nbjdta', ind.bdy_i[:, 1] + 1,ncml_out)
ncpop.write_data_to_file(f_out, 'nbrdta', ind.bdy_r[: ] + 1,ncml_out)
ncpop.write_data_to_file(f_out, 'time_counter', self.time_counter,ncml_out)
......
This diff is collapsed.
......@@ -8,7 +8,9 @@ Netcdf writer for the bdy output
# pylint: disable=no-name-in-module
from netCDF4 import Dataset
import numpy as np
def write_data_to_file(filename, variable_name, data):
from pynemo import nemo_ncml_parse as ncml_parse
def write_data_to_file(filename, variable_name, data,ncml_out):
""" Writes the data to the netcdf templete file.
Keyword arguments:
filename -- output filename
......@@ -17,9 +19,10 @@ def write_data_to_file(filename, variable_name, data):
"""
ncid = Dataset(filename, 'a', clobber=False, format='NETCDF4')
count = data.shape
three_dim_variables = ['votemper', 'vosaline', 'N1p', 'N3n', 'N5s','vobtcrtx','vozocrtx','vobtcrty','vomecrty']
two_dim_variables = ['sossheig', 'iicethic', 'ileadfra', 'isnowthi']
time = ncml_parse.gen_dims_NCML(ncml_out,'time_counter')
var_list = ncml_parse.gen_var_list_NCML(ncml_out,time)
three_dim_variables = var_list['3D_vars'] #['votemper', 'vosaline', 'N1p', 'N3n', 'N5s','vobtcrtx','vozocrtx','vobtcrty','vomecrty']
two_dim_variables = var_list['2D_vars'] #['sossheig', 'iicethic', 'ileadfra', 'isnowthi']
if variable_name in three_dim_variables:
if len(count) == 3:
......
'''
NCML python parser using XML to Dict
'''
import xml.etree.ElementTree as ET
import xmltodict
import logging
logger = logging.getLogger(__name__)
def gen_dims_NCML(ncmlfile,orgName):
ncml_dict = xmltodict.parse(ET.tostring(ET.parse(ncmlfile).getroot()))
dimensions = ncml_dict['ns0:netcdf']['ns0:dimension']
if type(dimensions) is not list:
dimensions = [dimensions]
if not any(d['@orgName'] == orgName for d in dimensions):
raise ValueError('dimension name not defined in NCML output specification file')
for i in range(len(dimensions)):
if dimensions[i]['@orgName'] == orgName:
dim_name = dimensions[i]['@name']
break
return dim_name
def gen_var_list_NCML(ncmlfile, time):
ncml_dict = xmltodict.parse(ET.tostring(ET.parse(ncmlfile).getroot()))
variables = ncml_dict['ns0:netcdf']['ns0:variable']
var_3D = []
var_2D = []
for i in range(len(variables)):
if len(variables[i]['@shape'].split(' ')) == 4 and variables[i]['@shape'].split(' ')[0] == time:
var_3D.append(variables[i]['@name'])
if len(variables[i]['@shape'].split(' ')) == 3 and variables[i]['@shape'].split(' ')[0] == time:
var_2D.append(variables[i]['@name'])
var_type = {'3D_vars': var_3D,
'2D_vars': var_2D,
}
return var_type
def gen_src_var_list_NCML(ncmlfile):
ncml_dict = xmltodict.parse(ET.tostring(ET.parse(ncmlfile).getroot()))
variables = ncml_dict['ns0:netcdf']['ns0:variable']
var_list = []
for i in range(len(variables)):
var_list.append(variables[i]['@name'])
return var_list
def gen_var_NCML(ncmlfile, orgName):
ncml_dict = xmltodict.parse(ET.tostring(ET.parse(ncmlfile).getroot()))
variables = ncml_dict['ns0:netcdf']['ns0:variable']
if type(variables) is not list:
variables = [variables]
if not any(d['@orgName'] == orgName for d in variables):
raise ValueError('variable name not defined in NCML output specification file')
var = {}
for i in range(len(variables)):
if variables[i]['@orgName'] == orgName:
var['name'] = variables[i]['@name']
var['shape'] = variables[i]['@shape'].split(' ')
if variables[i]['@type'] == 'float':
var['type'] = 'f4'
if variables[i]['@type'] == 'int':
var['type'] = 'i4'
break
return var
def gen_attrib_NCML(ncmlfile,name):
ncml_dict = xmltodict.parse(ET.tostring(ET.parse(ncmlfile).getroot()))
nc_attrib = ncml_dict['ns0:netcdf']['ns0:attribute']
if type(nc_attrib) is not list:
nc_attrib = [nc_attrib]
if not any(d['@name'] == name for d in nc_attrib):
logger.warning('Global attribute name not found, writing attribute not specified')
return 'Global attribute not specified in NCML file'
for i in range(len(nc_attrib)):
if nc_attrib[i]['@name'] == name:
attrib_val = nc_attrib[i]['@value']
return attrib_val
def gen_var_attrib_NCML(ncmlfile, variable,name):
ncml_dict = xmltodict.parse(ET.tostring(ET.parse(ncmlfile).getroot()))
variables = ncml_dict['ns0:netcdf']['ns0:variable']
if type(variables) is not list:
variables = [variables]
for i in range(len(variables)):
if variables[i]['@name'] == variable:
if not any(d['@name'] == name for d in variables[i]['ns0:attribute']):
logging.warning('variable attribute name not found, writing attribute not specified')
return 'Variable attribute not specified in NCML file'
for j in range(len(variables[i]['ns0:attribute'])):
if variables[i]['ns0:attribute'][j]['@name'] == name:
attrib = variables[i]['ns0:attribute'][j]['@value']
break
break
return attrib
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2">
<dimension name="y" orgName="y" />
<dimension name="x" orgName="x" />
<dimension name="z" orgName="z" />
<dimension name="yb" orgName="yb" />
<dimension name="xb" orgName="xb" />
<dimension name="time_counter" orgName="time_counter" isUnlimited="true" />
<attribute name="institution" value="National Oceanography Centre, Livepool, U.K." />
<variable name="bdy_msk" orgName="bdy_msk" shape="y x" type="float">
<attribute name="short_name" value="bdy_msk" />
<attribute name="units" value="unitless" />
<attribute name="long_name" value="Structured boundary mask" />
</variable>
<variable name="deptht" orgName="deptht" shape="z yb xb" type="float">
<attribute name="axis" value="Depth" />
<attribute name="short_name" value="deptht" />
<attribute name="units" value="m" />
<attribute name="long_name" value="Depth" />
</variable>
<variable name="nav_lat" orgName="nav_lat" shape="y x" type="float">
<attribute name="axis" value="Latitude" />
<attribute name="short_name" value="nav_lat" />
<attribute name="units" value="degrees_east" />
<attribute name="long_name" value="Latitude" />
</variable>
<variable name="nav_lon" orgName="nav_lon" shape="y x" type="float">
<attribute name="axis" value="Longitude" />
<attribute name="short_name" value="nav_lon" />
<attribute name="units" value="degrees_east" />
<attribute name="long_name" value="Longitude" />
</variable>
<variable name="nbidta" orgName="nbidta" shape="yb xb" type="int">
<attribute name="short_name" value="nbidta" />
<attribute name="units" value="unitless" />
<attribute name="long_name" value="Bdy i indices" />
</variable>
<variable name="nbjdta" orgName="nbjdta" shape="yb xb" type="int">
<attribute name="short_name" value="nbjdta" />
<attribute name="units" value="unitless" />
<attribute name="long_name" value="Bdy j indices" />
</variable>
<variable name="nbrdta" orgName="nbrdta" shape="yb xb" type="int">
<attribute name="short_name" value="nbrdta" />
<attribute name="units" value="unitless" />
<attribute name="long_name" value="Bdy discrete distance" />
</variable>
<variable name="time_counter" orgName="time_counter" shape="time_counter" type="float">
<attribute name="axis" value="T" />
<attribute name="standard_name" value="time" />
<attribute name="units" value="seconds since 1960-01-01 00:00:00" />
<attribute name="title" value="Time" />
<attribute name="long_name" value="Time axis" />
</variable>
<variable name="vosaline" orgName="vosaline" shape="time_counter z yb xb" type="float">
<attribute name="units" value="PSU" />
<attribute name="short_name" value="vosaline" />
<attribute name="long_name" value="Salinity" />
<attribute name="grid" value="bdyT" />
</variable>
<variable name="votemper" orgName="votemper" shape="time_counter z yb xb" type="float">
<attribute name="units" value="C" />
<attribute name="short_name" value="votemper" />
<attribute name="long_name" value="Temperature" />
<attribute name="grid" value="bdyT" />
</variable>
<variable name="ileadfra" orgName="ileadfra" shape="time_counter yb xb" type="float">
<attribute name="units" value="%" />
<attribute name="short_name" value="ileadfra" />
<attribute name="long_name" value="Ice lead fraction" />
<attribute name="grid" value="bdyT" />
</variable>
<variable name="iicethic" orgName="iicethic" shape="time_counter yb xb" type="float">
<attribute name="units" value="m" />
<attribute name="short_name" value="iicethic" />
<attribute name="long_name" value="Ice thickness" />
<attribute name="grid" value="bdyT" />
</variable>
<variable name="isnowthi" orgName="isnowthi" shape="time_counter yb xb" type="float">
<attribute name="units" value="m" />
<attribute name="short_name" value="isnowthi" />
<attribute name="long_name" value="Snow thickness" />
<attribute name="grid" value="bdyT" />
</variable>
</netcdf>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2">
<dimension name="y" orgName="y" />
<dimension name="x" orgName="x" />
<dimension name="z" orgName="z" />
<dimension name="yb" orgName="yb" />
<dimension name="xb" orgName="xb" />
<dimension name="time_counter" orgName="time_counter" isUnlimited="true" />
<attribute name="institution" value="National Oceanography Centre, Livepool, U.K." />
<variable name="bdy_msk" orgName="bdy_msk" shape="y x" type="float">
<attribute name="short_name" value="bdy_msk" />
<attribute name="units" value="unitless" />
<attribute name="long_name" value="Structured boundary mask" />
</variable>
<variable name="deptht" orgName="deptht" shape="z yb xb" type="float">
<attribute name="axis" value="Depth" />
<attribute name="short_name" value="deptht" />
<attribute name="units" value="m" />
<attribute name="long_name" value="Depth" />
</variable>
<variable name="nav_lat" orgName="nav_lat" shape="y x" type="float">
<attribute name="axis" value="Latitude" />
<attribute name="short_name" value="nav_lat" />
<attribute name="units" value="degrees_east" />
<attribute name="long_name" value="Latitude" />
</variable>
<variable name="nav_lon" orgName="nav_lon" shape="y x" type="float">
<attribute name="axis" value="Longitude" />
<attribute name="short_name" value="nav_lon" />
<attribute name="units" value="degrees_east" />
<attribute name="long_name" value="Longitude" />
</variable>
<variable name="nbidta" orgName="nbidta" shape="yb xb" type="int">
<attribute name="short_name" value="nbidta" />
<attribute name="units" value="unitless" />
<attribute name="long_name" value="Bdy i indices" />
</variable>
<variable name="nbjdta" orgName="nbjdta" shape="yb xb" type="int">
<attribute name="short_name" value="nbjdta" />
<attribute name="units" value="unitless" />
<attribute name="long_name" value="Bdy j indices" />
</variable>
<variable name="nbrdta" orgName="nbrdta" shape="yb xb" type="int">
<attribute name="short_name" value="nbrdta" />
<attribute name="units" value="unitless" />
<attribute name="long_name" value="Bdy discrete distance" />
</variable>
<variable name="time_counter" orgName="time_counter" shape="time_counter" type="float">
<attribute name="axis" value="T" />
<attribute name="standard_name" value="time" />
<attribute name="units" value="seconds since 1960-01-01 00:00:00" />
<attribute name="title" value="Time" />
<attribute name="long_name" value="Time axis" />
</variable>
<variable name="vosaline" orgName="vosaline" shape="time_counter z yb xb" type="float">
<attribute name="units" value="PSU" />
<attribute name="short_name" value="vosaline" />
<attribute name="long_name" value="Salinity" />
<attribute name="grid" value="bdyT" />
</variable>
<variable name="votemper" orgName="votemper" shape="time_counter z yb xb" type="float">
<attribute name="units" value="C" />
<attribute name="short_name" value="votemper" />
<attribute name="long_name" value="Temperature" />
<attribute name="grid" value="bdyT" />
</variable>
<variable name="votemper" orgName="votemper" shape="time_counter z yb xb" type="float">
<attribute name="units" value="C" />
<attribute name="short_name" value="votemper" />
<attribute name="long_name" value="Temperature" />
<attribute name="grid" value="bdyT" />
</variable>
</netcdf>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2">
<dimension name="y" orgName="y" />
<dimension name="x" orgName="x" />
<dimension name="z" orgName="z" />
<dimension name="yb" orgName="yb" />
<dimension name="xb" orgName="xb" />
<dimension name="time_counter" orgName="time_counter" isUnlimited="true" />
<attribute name="institution" value="National Oceanography Centre, Livepool, U.K." />
<variable name="bdy_msk" orgName="bdy_msk" shape="y x" type="float">
<attribute name="short_name" value="bdy_msk" />
<attribute name="units" value="unitless" />
<attribute name="long_name" value="Structured boundary mask" />
</variable>
<variable name="depthu" orgName="depthu" shape="z yb xb" type="float">
<attribute name="axis" value="Depth" />
<attribute name="short_name" value="depthu" />
<attribute name="units" value="m" />
<attribute name="long_name" value="Depth" />
</variable>
<variable name="nav_lat" orgName="nav_lat" shape="y x" type="float">
<attribute name="axis" value="Latitude" />
<attribute name="short_name" value="nav_lat" />
<attribute name="units" value="degrees_east" />
<attribute name="long_name" value="Latitude" />
</variable>
<variable name="nav_lon" orgName="nav_lon" shape="y x" type="float">
<attribute name="axis" value="Longitude" />
<attribute name="short_name" value="nav_lon" />
<attribute name="units" value="degrees_east" />
<attribute name="long_name" value="Longitude" />
</variable>
<variable name="nbidta" orgName="nbidta" shape="yb xb" type="int">
<attribute name="short_name" value="nbidta" />
<attribute name="units" value="unitless" />
<attribute name="long_name" value="Bdy i indices" />
</variable>
<variable name="nbjdta" orgName="nbjdta" shape="yb xb" type="int">
<attribute name="short_name" value="nbjdta" />
<attribute name="units" value="unitless" />
<attribute name="long_name" value="Bdy j indices" />
</variable>
<variable name="nbrdta" orgName="nbrdta" shape="yb xb" type="int">
<attribute name="short_name" value="nbrdta" />
<attribute name="units" value="unitless" />
<attribute name="long_name" value="Bdy discrete distance" />
</variable>
<variable name="time_counter" orgName="time_counter" shape="time_counter" type="float">
<attribute name="axis" value="T" />
<attribute name="standard_name" value="time" />
<attribute name="units" value="seconds since 1960-01-01 00:00:00" />
<attribute name="title" value="Time" />
<attribute name="long_name" value="Time axis" />
</variable>
<variable name="vobtcrtx" orgName="vobtcrtx" shape="time_counter yb xb" type="float">
<attribute name="units" value="m/s" />
<attribute name="short_name" value="vobtcrtx" />
<attribute name="long_name" value="Thickness-weighted depth-averaged zonal Current" />
<attribute name="grid" value="bdyU" />
</variable>
<variable name="vozocrtx" orgName="vozocrtx" shape="time_counter z yb xb" type="float">
<attribute name="units" value="m/s" />
<attribute name="short_name" value="vozocrtx" />
<attribute name="long_name" value="Zonal Current" />
<attribute name="grid" value="bdyU" />
</variable>
</netcdf>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2">
<dimension name="y" orgName="y" />
<dimension name="x" orgName="x" />
<dimension name="z" orgName="z" />
<dimension name="yb" orgName="yb" />
<dimension name="xb" orgName="xb" />
<dimension name="time_counter" orgName="time_counter" isUnlimited="true" />
<attribute name="institution" value="National Oceanography Centre, Livepool, U.K." />
<variable name="bdy_msk" orgName="bdy_msk" shape="y x" type="float">
<attribute name="short_name" value="bdy_msk" />
<attribute name="units" value="unitless" />
<attribute name="long_name" value="Structured boundary mask" />
</variable>
<variable name="depthv" orgName="depthv" shape="z yb xb" type="float">
<attribute name="axis" value="Depth" />
<attribute name="short_name" value="depthv" />
<attribute name="units" value="m" />
<attribute name="long_name" value="Depth" />
</variable>
<variable name="nav_lat" orgName="nav_lat" shape="y x" type="float">
<attribute name="axis" value="Latitude" />
<attribute name="short_name" value="nav_lat" />
<attribute name="units" value="degrees_east" />
<attribute name="long_name" value="Latitude" />
</variable>
<variable name="nav_lon" orgName="nav_lon" shape="y x" type="float">
<attribute name="axis" value="Longitude" />
<attribute name="short_name" value="nav_lon" />
<attribute name="units" value="degrees_east" />
<attribute name="long_name" value="Longitude" />
</variable>
<variable name="nbidta" orgName="nbidta" shape="yb xb" type="int">
<attribute name="short_name" value="nbidta" />
<attribute name="units" value="unitless" />
<attribute name="long_name" value="Bdy i indices" />
</variable>
<variable name="nbjdta" orgName="nbjdta" shape="yb xb" type="int">
<attribute name="short_name" value="nbjdta" />
<attribute name="units" value="unitless" />
<attribute name="long_name" value="Bdy j indices" />
</variable>
<variable name="nbrdta" orgName="nbrdta" shape="yb xb" type="int">
<attribute name="short_name" value="nbrdta" />
<attribute name="units" value="unitless" />
<attribute name="long_name" value="Bdy discrete distance" />
</variable>
<variable name="time_counter" orgName="time_counter" shape="time_counter" type="float">
<attribute name="axis" value="T" />
<attribute name="standard_name" value="time" />
<attribute name="units" value="seconds since 1960-01-01 00:00:00" />
<attribute name="title" value="Time" />
<attribute name="long_name" value="Time axis" />
</variable>
<variable name="vobtcrty" orgName="vobtcrty" shape="time_counter yb xb" type="float">
<attribute name="units" value="m/s" />
<attribute name="short_name" value="vobtcrty" />
<attribute name="long_name" value="Thickness-weighted depth-averaged meridional Current" />
<attribute name="grid" value="bdyV" />
</variable>
<variable name="vomecrty" orgName="vomecrty" shape="time_counter z yb xb" type="float">
<attribute name="units" value="m/s" />
<attribute name="short_name" value="vomecrty" />
<attribute name="long_name" value="Meridional Current" />
<attribute name="grid" value="bdyV" />
</variable>
</netcdf>
\ No newline at end of file
......@@ -38,6 +38,7 @@ from PyQt5.QtWidgets import QMessageBox
from calendar import monthrange
import sys
#Local imports
from pynemo import pynemo_settings_editor
from pynemo import nemo_bdy_ncgen as ncgen
......@@ -49,6 +50,7 @@ from pynemo import nemo_bdy_gen_c as gen_grid
from pynemo import nemo_coord_gen_pop as coord
from pynemo import nemo_bdy_zgrv2 as zgrv
from pynemo import nemo_bdy_extr_tm3 as extract
from pynemo import nemo_ncml_parse as ncml_parse
from pynemo.reader.factory import GetFile
from pynemo.reader import factory
......@@ -434,7 +436,7 @@ def process_bdy(setup_filepath=0, mask_gui=False):
# Extract source data on dst grid
if settings['tide']:
if settings['tide'] == True:
if settings['tide_model']=='tpxo':
cons = tide.nemo_bdy_tide_rot(
Setup, DstCoord, bdy_ind['t'], bdy_ind['u'], bdy_ind['v'],
......@@ -518,22 +520,31 @@ def process_bdy(setup_filepath=0, mask_gui=False):
# can be included in the ln_tra = .true. option without having to
# explicitly declaring them.
var_list = ncml_parse.gen_src_var_list_NCML(settings['src_dir'])
var_in = {}
for g in range(len(grd)):
var_in[grd[g]] = []
if ln_tra:
var_in['t'].extend(['votemper']) #, 'vosaline'])
if 'votemper' and 'vosaline' in var_list:
var_in['t'].extend(['votemper', 'vosaline'])
if 'votemper' and not 'vosaline' in var_list:
var_in['t'].extend(['votemper'])
if 'vosaline' and not 'votemper' in var_list:
var_in['t'].extend(['vosaline'])
if ln_dyn2d or ln_dyn3d:
var_in['u'].extend(['vozocrtx'])
var_in['v'].extend(['vomecrty'])
if 'vozocrtx' and 'vomecrty' in var_list:
var_in['u'].extend(['vozocrtx'])
var_in['v'].extend(['vomecrty'])
if ln_dyn2d:
var_in['t'].extend(['sossheig'])
if 'sossheig' in var_list:
var_in['t'].extend(['sossheig'])
if ln_ice:
var_in['t'].extend(['iicethic', 'ileadfra', 'isnowthi'])
if 'iicethic' and 'ileadfra' and 'isnowthi' in var_list:
var_in['t'].extend(['iicethic', 'ileadfra', 'isnowthi'])
# As variables are associated with grd there must be a filename attached
# to each variable
......@@ -579,7 +590,9 @@ def process_bdy(setup_filepath=0, mask_gui=False):
logger.info('End NRCT Logging: '+time.asctime())
logger.info('==========================================')
def write_tidal_data(setup_var, dst_coord_var, grid, tide_cons, cons):
"""
......
File added
# import os
# import jnius_config
# ncmlpath, file_name = os.path.split(__file__)
# ncmlpath = os.path.join(ncmlpath, "jars", "netcdfAll-4.6.jar")
# jnius_config.set_classpath('.',ncmlpath)
#
# from jnius import autoclass
#
# ncml_template = "/Users/thopri/Projects/PyNEMO/inputs/NEMO_output_T.ncml"
# nc_file = "/Users/thopri/Projects/PyNEMO/test_scripts/test.nc"
#
# NcMLReader = autoclass('ucar.nc2.ncml.NcMLReader')
# dataset2 = NcMLReader.writeNcMLToFile(ncml_template,nc_file)
#NetcdfDataset ncfileIn = NcMLReader.readNcML (ncml_filename, null);
import xml.etree.ElementTree as ET
import xmltodict
ncml = "/Users/thopri/Projects/PyNEMO/inputs/NEMO_output_T.ncml"
ncml_xml = xmltodict.parse(ET.tostring(ET.parse(ncml).getroot()))
dimensions = ncml_xml['ns0:netcdf']['ns0:dimension']
variables = ncml_xml['ns0:netcdf']['ns0:variable']
nc_attrib = ncml_xml['ns0:netcdf']['ns0:attribute']
var_attrib = ncml_xml['ns0:netcdf']['ns0:variable'][0]['ns0:attribute']
print('the end')
# for key in ncml_meta:
# for key2 in ncml_meta[key]:
# if 'dimension' in key2:
# print(key2)
# def find(key, dictionary):
# for k, v in dictionary.items():
# if k in key:
# yield dictionary
# elif isinstance(v, dict):
# for result in find(key, v):
# yield result
# elif isinstance(v, list):
# for d in v:
# if isinstance(d, dict):
# for result in find(key, d):
# yield result
#
# print(list(find("ns0:dimension", ncml_meta)))
\ No newline at end of file
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