<commit_before>#!/usr/bin/env python3
from __future__ import division,absolute_import
from netCDF4 import Dataset
from os.path import expanduser
from numpy import arange
from matplotlib.pyplot import subplots,show
#import seaborn

with Dataset(expanduser('~/data/PKR_SMSP_STD_20130414.NC'),'r') as f:
    secdayutc=f.variables['Time'][:]
    X=f.variables['AnalogData'][:]
    Ipeak=f.variables['PeakIntensity'][:]
    Ibase=f.variables['BaseIntensity'][:]
    wavelen=f.variables['Wavelength'][:]
    elv=arange(181.) #TODO is this right?
#%% plots
fg,ax = subplots(6,1,figsize=(15,5))
for i,(a,l) in enumerate(zip(ax,wavelen)):
    a.pcolormesh(secdayutc,elv,Ipeak[:,i,:].T)
    a.set_title('{:.1f} nm'.format(l))
    a.set_ylabel('elevation [deg.]')
    a.autoscale(True,'x',tight=True)

a.set_xlabel('sec since UTC midnight')



show()<commit_msg>functionalize<commit_after>#!/usr/bin/env python3
from __future__ import division,absolute_import
from netCDF4 import Dataset
from pandas import Panel
from os.path import expanduser
from numpy import arange
from matplotlib.pyplot import subplots,show
#import seaborn

def readmsp(fn):
    with Dataset(expanduser(fn),'r') as f:
        secdayutc=f.variables['Time'][:]
        Analog=f.variables['AnalogData'][:]

        Ipeak=f.variables['PeakIntensity'][:]
        Ibase=f.variables['BaseIntensity'][:]

        wavelen=f.variables['Wavelength'][:]
        elv=arange(181.) #TODO is this right?

        Intensity = Panel(items=secdayutc,major_axis=wavelen,minor_axis=elv,data=Ipeak)
        return Intensity

def plotmspspectra(Intensity):
    #unpack Panel
    wavelen=Intensity.major_axis.values
    elv = Intensity.minor_axis.values
    secdayutc=Intensity.items.values
    Ipeak = Intensity.values
    #%% plots
    fg,ax = subplots(6,1,figsize=(15,5))
    for i,(a,l) in enumerate(zip(ax,wavelen)):
        a.pcolormesh(secdayutc,elv,Ipeak[:,i,:].T,cmap='cubehelix')
        a.set_title('{:.1f} nm'.format(l))
        a.set_ylabel('elevation [deg.]')
        a.autoscale(True,'x',tight=True)

    a.set_xlabel('sec since UTC midnight')

if __name__ == '__main__':
    from argparse import ArgumentParser
    p = ArgumentParser(description='reading Poker Flat Research Range Meridian Scanning Photometer')
    p.add_argument('ncfn',help='netCDF data file name to read')
    p = p.parse_args()

    Intensity = readmsp(p.ncfn)
    plotmspspectra(Intensity)

    show()
{'fraction_non_alphanumeric': 0.14509480626545754, 'fraction_numerical': 0.01236603462489695, 'mean_word_length': 4.515909090909091, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4277252', 'n_tokens_mistral': 932, 'n_tokens_neox': 880, 'n_words': 158}