Skip to content

Commit

Permalink
add wms
Browse files Browse the repository at this point in the history
  • Loading branch information
mortenwh committed Jun 13, 2024
1 parent 68930ce commit 35bf059
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
8 changes: 4 additions & 4 deletions sarwind/script/process_sar_wind.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def process_with_arome(url, arome, path):
return process(url, arome, path, "_AROMEARCTIC.nc")


def export_mmd(nc_file, target_path, base_url, parent_mmd=None):
def export_mmd(nc_file, target_path, base_url, **kwargs):
"""Export metadata to MMD.
Input
Expand Down Expand Up @@ -165,7 +165,7 @@ def export_mmd(nc_file, target_path, base_url, parent_mmd=None):
pp.mkdir(exist_ok=True, parents=True)
md = Nc_to_mmd(nc_file, opendap_url=url, output_file=xml_out,
target_nc_filename=target_fn)
status, msg = md.to_mmd(parent=parent_mmd)
status, msg = md.to_mmd(kwargs)

return status, xml_out

Expand Down Expand Up @@ -210,14 +210,14 @@ def main(args=None):
logging.info("Processed %s:%s" % (url, fnm))
if args.export_mmd:
statusm, msgm = export_mmd(fnm, args.nc_target_path, args.odap_target_url,
parent_mmd=args.parent_mmd)
parent=args.parent_mmd)
with open(args.processed_files, "a") as fp:
fp.write("Processed %s and %s: %s\n\n" % (url, meps, fnm))
if fna is not None:
logging.info("Processed %s:%s" % (url, fna))
if args.export_mmd:
statusa, msga = export_mmd(fna, args.nc_target_path, args.odap_target_url,
parent_mmd=args.parent_mmd)
parent=args.parent_mmd)
with open(args.processed_files, "a") as fp:
fp.write("Processed %s and %s: %s\n\n" % (url, arome, fna))
count += 1
Expand Down
35 changes: 24 additions & 11 deletions sarwind/script/reproject_and_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ def create_parser():
"--log_file", type=str, default="process-sar-wind.log",
help="Log file name."
)
parser.add_argument(
"--wms_base_url", type=str, default=None,
help

return parser

Expand Down Expand Up @@ -94,18 +97,18 @@ def main(args=None):
day = f"{time.day:02d}"
pp = Path(os.path.join(args.output_path, year, month, day))
pp.mkdir(exist_ok=True, parents=True)
filename = os.path.join(args.output_path, year, month, day,
"reprojected_" + os.path.basename(args.sarwind))
if os.path.isfile(filename):
logging.debug("%s already exists" % filename)
filename = "reprojected_" + os.path.basename(args.sarwind)
full_path = os.path.join(args.output_path, year, month, day, filename)
if os.path.isfile(full_path):
logging.debug("%s already exists" % full_path)
return

# Export
n.export2thredds(filename, time=time)
n.export2thredds(full_path, time=time)
created = datetime.datetime.now(pytz.timezone("utc")).isoformat()

# Copy and update metadata
ds = netCDF4.Dataset(filename, "a")
ds = netCDF4.Dataset(full_path, "a")
# Make new metadata ID
metadata["id"] = str(uuid.uuid4())
# Set new date_created
Expand Down Expand Up @@ -138,11 +141,21 @@ def main(args=None):
ds.setncatts(metadata)
ds.close()

logging.info("Reprojected wind field stored as %s" % filename)

statusm, msgm = export_mmd(filename, args.output_path, args.odap_target_url,
parent_mmd=args.parent_mmd)

logging.info("Reprojected wind field stored as %s" % full_path)

add_wms = False
wms_layers = None
wms_url = None
import ipdb
ipdb.set_trace()
if args.wms_base_url is not None:
add_wms = True
wms_layers = ["windspeed"]
wms_url = os.path.join(args.wms_base_url, year, month, day, filename)

statusm, msgm = export_mmd(full_path, args.output_path, args.odap_target_url,
parent=args.parent_mmd, add_wms_data_access=add_wms,
wms_link=wms_url, wms_layer_names=wms_layers)

def _main(): # pragma: no cover
main(create_parser().parse_args()) # entry point in setup.cfg
Expand Down

0 comments on commit 35bf059

Please sign in to comment.