from __future__ import print_function import os import sys import numpy as np import datetime as dt ########################################### ## ## This script is used to read NSIDC IMS data: ## National Ice Center's Interactive Multisensor Snow and Ice Mapping System ## https://nsidc.org/data/G02156 ## Support included onl for 4km resolution. ## ## input file in ASCII format specified on the command line ## load the data into the numpy array ## if len(sys.argv) == 2: # Read the input file as the first argument input_file = os.path.expandvars(sys.argv[1]) try: # Print some output to verify that this script ran print("Input File: " + repr(input_file)) lines = open(input_file, 'r').readlines()[30:] d = [] for line in lines: d += line.rstrip() met_data = np.rot90(np.asarray(d, dtype='float').reshape(6144, 6144).transpose()).copy() print(repr(met_data.shape)) met_data[met_data == 0] = -9999 met_data = met_data.copy() print("Data Shape: " + repr(met_data.shape)) print("Data Type: " + repr(met_data.dtype)) except NameError: print("Can't find the input file") else: print("Must specify exactly one input file.") sys.exit(1) ########################################### ## ## parse time info from file name ## valid = dt.datetime.strptime(os.path.basename(input_file), "ims%Y%j_4km_v1.3.asc") init = valid; ## ## create the metadata dictionary ## attrs = { 'valid': valid.strftime("%Y%m%d_%H%M%S"), 'init': init.strftime("%Y%m%d_%H%M%S"), 'lead': '00', 'accum': '00', 'name': 'snowC', 'long_name': 'Ice Mapping System Snow Categories', 'level': 'Surface', 'units': 'Type', 'grid': { 'name': '4km Polar Stereographic', 'type' : 'Polar Stereographic', 'hemisphere': 'N', 'scale_lat': 60.0, 'lat_pin': 90.0, 'lon_pin': 0.0, 'x_pin': 3072.0, 'y_pin': 3072.0, 'lon_orient': -80.0, 'd_km': 4.0, 'r_km': 6371.2, 'nx': 6144, 'ny': 6144 } } print("Attributes: " + repr(attrs))