Skip to content

Commit

Permalink
Make writer able to have time dimension and falt band structure
Browse files Browse the repository at this point in the history
Use time_dimension=True to use this way of storing data

Signed-off-by: Adam.Dybbroe <a000680@c20671.ad.smhi.se>
  • Loading branch information
Adam.Dybbroe committed Sep 22, 2016
1 parent a69056d commit a619a60
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions mpop/satout/cfscene.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,12 @@ def __init__(self, scene, dtype=np.int16, band_axis=2, time_dimension=False):
except AttributeError:
lons.data = scene.area.lons[:]

fill_value = lons.data.fill_value
lons.info = {"var_name": "lon" + str_arc,
"var_data": lons.data,
"var_dim_names": ("y" + str_arc,
"x" + str_arc),
"_FillValue": fill_value,
"units": "degrees east",
"long_name": "longitude coordinate",
"standard_name": "longitude"}
Expand All @@ -255,10 +257,12 @@ def __init__(self, scene, dtype=np.int16, band_axis=2, time_dimension=False):
except AttributeError:
lats.data = scene.area.lats[:]

fill_value = lats.data.fill_value
lats.info = {"var_name": "lat" + str_arc,
"var_data": lats.data,
"var_dim_names": ("y" + str_arc,
"x" + str_arc),
"_FillValue": fill_value,
"units": "degrees north",
"long_name": "latitude coordinate",
"standard_name": "latitude"}
Expand Down
17 changes: 13 additions & 4 deletions mpop/satout/netcdf4.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2010, 2011, 2012, 2014.
# Copyright (c) 2010, 2011, 2012, 2014, 2016.

# Author(s):

Expand Down Expand Up @@ -29,22 +29,30 @@

__revision__ = 0.1

import pdb

import numpy as np
import logging

logger = logging.getLogger(__name__)


def save(scene, filename, compression=True, dtype=np.int16, band_axis=2):
def save(scene, filename, compression=True, dtype=np.int16, band_axis=2,
time_dimension=False):
"""Saves the scene as a NetCDF4 file, with CF conventions.
*band_axis* gives the which axis to use for the band dimension. For
*band_axis* gives which axis to use for the band dimension. For
example, use band_axis=0 to get dimensions like (band, y, x).
*time_dimension* is a boolean and if True a time axis (dimension=1) is
added in front, like (time, y, x), and the band_axis is omitted. Thus each
data/band go in a separate dataset.
"""
from mpop.satout.cfscene import CFScene

scene.add_to_history("Saved as netcdf4/cf by pytroll/mpop.")
return netcdf_cf_writer(filename, CFScene(scene, dtype, band_axis),
return netcdf_cf_writer(filename,
CFScene(scene, dtype, band_axis, time_dimension),
compression=compression)


Expand Down Expand Up @@ -228,6 +236,7 @@ def netcdf_cf_writer(filename, root_object, compression=True):
# in the case of arrays containing strings:
if str(vtype) == "object":
vtype = str

nc_vars.append(rootgrp.createVariable(
name, vtype, dim_name,
zlib=compression,
Expand Down

0 comments on commit a619a60

Please sign in to comment.