kylejgillett / sounderpy

A python package that helps you to access and plot vertical profile data for meteorological analysis
https://kylejgillett.github.io/sounderpy/
MIT License
49 stars 13 forks source link

Local File Support. #15

Closed CocoasColas closed 11 months ago

CocoasColas commented 11 months ago

Hey Kyle, I was wondering if you're planning to add local file support in the future so we can load soundings from EOL Projects such as VORTEX and PERILS. Sharppy does a good job at displaying everything needed for it but at the same time not everyone can seem to get Sharppy to work due to script errors, plus the sounderpy layout is just very easy on the eyes.

kylejgillett commented 11 months ago

Hey @CocoasColas! Thanks for the idea.

Can you attach a sample file or two that I can work with? I might be able to add something to make this possible.

Are these files usually formatted consistently?

CocoasColas commented 11 months ago

Yeah, I'll send a bit of the files from TORUS-2019 in the C Plains, specifically 5/20/19. I'll also add the readme from EOL. They are formatted in .csv which I didn't expect and it's a lot of data since they did it at quite the high frequencies. Far_Field_MW41_output_20190520_165957.csv Far_Field_MW41_output_20190520_192909.csv Far_Field_MW41_output_20190520_203418.csv Far_Field_MW41_output_20190520_214246.csv Far_Field_MW41_output_20190520_224224.csv LIDAR_1_MW41_output_20190520_205240.csv LIDAR_1_MW41_output_20190520_220607.csv LIDAR_1_MW41_output_20190520_232343.csv Probe_1_MW41_output_20190520_124207.csv Probe_1_MW41_output_20190520_160048.csv Probe_1_MW41_output_20190520_181720.csv README_NSSLsonde_TORUS_2019.pdf

kylejgillett commented 11 months ago

Ok so I sat down and wrote this up really quickly so you'll have a spot to get started from if you'd like to use this soon. I tested it on a single file but if they are the same then this should work for each.

# imports software
import pandas as pd 
from metpy.units import units
import metpy.calc as mpcalc
import sounderpy as spy

# declare file 
file = 'Far_Field_MW41_output_20190520_165957.csv'

# parse CSV into pandas df
obs_df  = pd.read_csv(file, skiprows=2)
info_df = pd.read_csv(file)

# parse needed df values into a SounderPy `clean_data` dict of values 
old_keys = ['Filtered Pressure (mb)', 'Filtered Altitude (m)', 'Filtered Temperature (K)', 'Filtered Dewpoint (K)']
new_keys = ['p', 'z', 'T', 'Td']
units_list = ['hPa', 'meter', 'K', 'K']

clean_data = {}
for old_key, new_key, unit in zip(old_keys, new_keys, units_list):
    clean_data[new_key] = (obs_df[old_key].values)*units(unit)

clean_data['u'], clean_data['v'] = mpcalc.wind_components(((obs_df['Filtered Wind Spd (m/s)'].values)*1.94384)*units('kts'),
                                                          (obs_df['Filtered Wind Dir'].values)*units.deg)

# create dict of "site info" data -- I just quickly made this part up and it can be changed
clean_data['site_info'] = {
            'site-id'   : info_df.iloc[0][0],
            'site-name' : 'Far_Field_MW41',
            'site-lctn' : 'none',
            'site-latlon' : [obs_df['Filtered Longitude'][0],
                             obs_df['Filtered Latitude'][0]],
            'site-elv'  : obs_df['Filtered Altitude (m)'][0],
            'source'    : 'TORUS-2019 FIELD CAMPAIGN OBSERVED PROFILE',
            'model'     : 'none',
            'fcst-hour' : f'none',
            'run-time'  : ['none', 'none', 'none', 'none'],
            'valid-time': [info_df.iloc[2][0][1:5], info_df.iloc[2][0][6:8], info_df.iloc[2][0][9:11], info_df.iloc[2][0][12:17]]} 

spy.metpy_sounding(clean_data)

TORUS-DATA-TEST

kylejgillett commented 11 months ago

Ope, a quick note: I put lat/lon backward above.

It should be:

'site-latlon' : [obs_df['Filtered Latitude'][0],
                 obs_df['Filtered Longitude'][0]],
CocoasColas commented 11 months ago

Thanks Kyle!