Commit 2dc8d485 authored by Modellers Operational's avatar Modellers Operational

Add writing ncml files

parent 0dca4407
import numpy as np
import sys
import PyFVCOM as pf
fvcom_file_loc = sys.argv[1]
output_file = sys.argv[2]
write_vars = sys.argv[3].split(',')
all_attributes = {'lon':{'var_name':'longitude','standard_name':'longitude', 'units':'degrees_east', 'long_name':'longitude', 'shape':'longitude'},
'lat':{'var_name':'latitude','standard_name':'latitude', 'units':'degrees_north', 'long_name':'latitude', 'shape':'latitude'},
'depth':{'standard_name':'depth', 'units':'m', 'long_name':'depth, measured downwards from free surface', 'axis':'Z', 'positive':'down', 'shape':'depth'},
'time':{'standard_name':'time', 'units':'days since 1858-11-17 00:00:00', 'long_name':'time', 'axis':'T','shape':'time', 'time_zone':'UTC', 'format':'modified julian day (MJD)'},
'h':{'standard_name':'h', 'units':'m', 'long_name':'model bathymetry depth, measured downwards from geoid', 'axis':'Z', 'positive':'down', 'shape':'latitude longitude'},
'temp':{'var_name':'thetao','standard_name':'sea_water_potential_temperature','units':'C','missing_value':-32768, 'long_name':'Sea Water Potential Temperature', 'shape':'time depth latitude longitude'} ,
'salinity':{'var_name':'so','standard_name':'sea_water_salinity','units':'psu', 'missing_value':-32768, 'long_name':'Sea Water Salinity', 'shape':'time depth latitude longitude'},
'u':{'var_name':'uo', 'standard_name':'eastward_sea_water_velocity','units':'m s-1', 'missing_value':-32768, 'long_name':'Eastward Current Velocity', 'shape':'time depth latitude longitude'},
'v':{'var_name':'vo','standard_name':'northward_sea_water_velocity','units':'m s-1', 'missing_value':-32768, 'long_name':'Northward Current Velocity', 'shape':'time depth latitude longitude'},
'zeta':{'var_name':'zos','standard_name':'sea_surface_height_above_geoid','units':'m', 'missing_value':-32768,'long_name':'Sea surface height above geoid', 'shape':'time latitude longitude'}}
all_type = {'add_offset':'float', 'scale_factor':'float', '_FillValue':'double'}
all_dimensions = {'longitude':'lon', 'latitude':'lat', 'depth':'depth', 'time':'time'}
with open(output_file, 'a') as out_file:
out_file.write("<?xml version='1.0' encoding='UTF-8'?>\n")
out_file.write("<netcdf xmlns='http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2'\n")
out_file.write("\t location='{}' >\n".format(fvcom_file_loc))
out_file.write('\t<explicit />\n')
for this_dim, this_dim_orig in all_dimensions.items():
if this_dim == this_dim_orig:
out_file.write('\t<dimension name="{}"/>\n'.format(this_dim))
else:
out_file.write('\t<dimension name="{}" orgName="{}"/>\n'.format(this_dim, this_dim_orig))
for this_var in all_dimensions.values():
this_atts = all_attributes[this_var]
if 'var_name' in this_atts:
out_file.write('\t<variable name="{}" orgName="{}" shape="{}" >\n'.format(this_atts['var_name'], this_var, this_atts['shape']))
else:
out_file.write('\t<variable name="{}" shape="{}" >\n'.format(this_var, this_atts['shape']))
for this_att, this_val in this_atts.items():
if this_att not in ['var_name', 'shape']:
if this_att not in all_type.keys():
out_file.write('\t\t<attribute name="{}" value="{}"/>\n'.format(this_att, this_val))
else:
out_file.write('\t\t<attribute name="{}" value="{}" type="{}"/>\n'.format(this_att, this_val, all_type[this_att]))
out_file.write('\t</variable>\n')
for this_var in write_vars:
this_atts = all_attributes[this_var]
if 'var_name' in this_atts:
out_file.write('\t<variable name="{}" orgName="{}" shape="{}" >\n'.format(this_atts['var_name'], this_var, this_atts['shape']))
else:
out_file.write('\t<variable name="{}" shape="{}" >\n'.format(this_var, this_atts['shape']))
for this_att, this_val in this_atts.items():
if this_att not in ['var_name', 'shape']:
if this_att not in all_type.keys():
out_file.write('\t\t<attribute name="{}" value="{}"/>\n'.format(this_att, this_val))
else:
out_file.write('\t\t<attribute name="{}" value="{}" type="{}"/>\n'.format(this_att, this_val, all_type[this_att]))
out_file.write('\t</variable>\n')
out_file.write('</netcdf>')
[command]
default =
base_file=/${PORTAL_BASEDIR}/${FORECAST_YEAR}/${FORECAST_MONTH}/${OUTPUT_FILENAME}_hrly_${FORECAST_DAY}.nc
mkdir -p /${PORTAL_NCML_BASEDIR}/${FORECAST_YEAR}/${FORECAST_MONTH}/
dst_file=/${PORTAL_NCML_BASEDIR}/${FORECAST_YEAR}/${FORECAST_MONTH}/${OUTPUT_FILENAME}_hrly_${FORECAST_DAY}.ncml
python3 write_ncml_file.py ${base_file} ${dst_file} ${VARS}
......@@ -23,3 +23,4 @@ OUTPUT_DIR='data/sthenno1/scratch/modop/Model/FVCOM_tamar/estuary_output'
OUTPUT_FILENAME='tamar_estuary_001'
PORTAL_BASEDIR='data/sthenno1/scratch/modop/Portal/Model/TAMAR_ESTUARY_FORECAST_PHY_001/tamar_estuary_forecast_phy_001_hourly_t_s_u_v_ssh'
PORTAL_NCML_BASEDIR='data/sthenno1/scratch/modop/Portal/Model/test_ncml/tamar_estuary_forecast_phy_001_hourly_t_s_u_v_ssh'
......@@ -15,7 +15,7 @@
graph = """
{% if USE_CETO %}
regrid_domain_ceto[-P1D]:finish => start_cycle => suite_trigger <{{TRIGGER_SUITE}}::{{TRIGGER_TASK}}> => transfer_to_remote
transfer_to_remote => regrid_domain_ceto => transfer_from_remote => softlink_to_portal
transfer_to_remote => regrid_domain_ceto => transfer_from_remote => softlink_to_portal => write_ncml
{% else %}
regrid_domain[-P1D]:finish => start_cycle => suite_trigger <{{TRIGGER_SUITE}}::{{TRIGGER_TASK}}> => regrid_domain
{% endif %}
......@@ -48,6 +48,7 @@
FVCOM_FILE={{FVCOM_OUTPUT_DIR}}/${FORECAST_DAY}/${FVCOM_GRID_NAME}_0001.nc
PORTAL_BASEDIR={{PORTAL_BASEDIR}}
PORTAL_NCML_BASEDIR={{PORTAL_NCML_BASEDIR}}
[[start_cycle]]
script = """
......@@ -90,6 +91,8 @@
[[regrid_domain_ceto]]
inherit = slurm_job
[[softlink_to_portal]]
[[write_ncml]]
{% else %}
[[regrid_domain]]
......
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