Python3 Script For Getting USHCN Monthly Temperatures

This script gives easy access to USHCN monthly raw, TOBS and Final adjusted temperatures.

Getting the data:
wget ftp://ftp.ncdc.noaa.gov/pub/data/ushcn/v2.5/ushcn.tavg.latest.FLs.52j.tar.gz
wget ftp://ftp.ncdc.noaa.gov/pub/data/ushcn/v2.5/ushcn.tavg.latest.tob.tar.gz
wget ftp://ftp.ncdc.noaa.gov/pub/data/ushcn/v2.5/ushcn.tavg.latest.raw.tar.gz
tar xzvf ushcn.tavg.latest.FLs.52j.tar.gz
tar xzvf ushcn.tavg.latest.tob.tar.gz
tar xzvf ushcn.tavg.latest.raw.tar.gz

wget ftp://ftp.ncdc.noaa.gov/pub/data/ushcn/v2.5/ushcn.tmax.latest.FLs.52j.tar.gz
wget ftp://ftp.ncdc.noaa.gov/pub/data/ushcn/v2.5/ushcn.tmax.latest.tob.tar.gz
wget ftp://ftp.ncdc.noaa.gov/pub/data/ushcn/v2.5/ushcn.tmax.latest.raw.tar.gz
wget http://cdiac.ornl.gov/ftp/ushcn_daily/ushcn-stations.txt
tar xzvf ushcn.tmax.latest.FLs.52j.tar.gz
tar xzvf ushcn.tmax.latest.tob.tar.gz
tar xzvf ushcn.tmax.latest.raw.tar.gz

wget ftp://ftp.ncdc.noaa.gov/pub/data/ushcn/v2.5/ushcn.tmin.latest.FLs.52j.tar.gz
wget ftp://ftp.ncdc.noaa.gov/pub/data/ushcn/v2.5/ushcn.tmin.latest.tob.tar.gz
wget ftp://ftp.ncdc.noaa.gov/pub/data/ushcn/v2.5/ushcn.tmin.latest.raw.tar.gz
tar xzvf ushcn.tmin.latest.FLs.52j.tar.gz
tar xzvf ushcn.tmin.latest.tob.tar.gz
tar xzvf ushcn.tmin.latest.raw.tar.gz

Then cd into the new directory, which will have a new name every day. It will be something like ushcn.v2.5.5.20191004

Example usage:
python3 date.py USH00412679 7 1921 “EAGLE PASS”

Data for July, 1921 at Eagle Pass, Texas.

output:
Raw EAGLE PASS USH00412679 7 1921 37.29 99.12
TOBS EAGLE PASS USH00412679 7 1921 37.16 98.89
Final EAGLE PASS USH00412679 7 1921 35.92 96.66

Last two numbers in each line are Degrees C and Degrees F

You will have to know the station ID of the station you are looking for:
ftp://ftp.ncdc.noaa.gov/pub/data/ushcn/v2.5/ushcn-v2.5-stations.txt

Script :
——————————————————————-

import sys

filename = sys.argv[1]
#print(filename)
#filename = filename.replace("USC", "USH")
#print(filename)
month = int(sys.argv[2])
year = sys.argv[3]
comment = sys.argv[4]

fd = open(filename + ".raw.tmax")

for line in fd :
    #print(line[12:16])
    if (line[12:16] == year) :
        #print(line)
        offset = 18 + (9 * (month - 1))
        #print(line[offset:offset+4])
        temperature_c = float(line[offset:offset+4]) / 100.0
        temperature_f = (temperature_c * 1.8) + 32.0
        print("Raw", comment, filename, month, year, "%.2f" % temperature_c, "%.2f" % temperature_f)

fd = open(filename + ".tob.tmax")

for line in fd :
#print(line[12:16])
    if (line[12:16] == year) :
        #print(line)
        offset = 18 + (9 * (month - 1))
        #print(line[offset:offset+4])
        temperature_c = float(line[offset:offset+4]) / 100.0
        temperature_f = (temperature_c * 1.8) + 32.0
        print("TOBS", comment, filename, month, year, "%.2f" % temperature_c, "%.2f" % temperature_f)

fd = open(filename + ".FLs.52j.tmax")

for line in fd :
    #print(line[12:16])
    if (line[12:16] == year) :
        #print(line)
        offset = 18 + (9 * (month - 1))
        #print(line[offset:offset+4])
        temperature_c = float(line[offset:offset+4]) / 100.0
        temperature_f = (temperature_c * 1.8) + 32.0
        print("Final", comment, filename, month, year, "%.2f" % temperature_c, "%.2f" % temperature_f)

This entry was posted in Uncategorized. Bookmark the permalink.

8 Responses to Python3 Script For Getting USHCN Monthly Temperatures

  1. G W Smith says:

    Fantastic! Thanks for sharing this, Tony. Total transparency! But they will still twist it.

  2. grilledtomoatoes says:

    I wish I were smart like this.
    Thank you for taking the time and effort to do this. If I had a vote on who should get a Nobel Prize for climate-related matters, it wouldn’t be a Swedish teenager.

  3. Luca Bertagnolio says:

    Very nice Tony!

    Just one note, in the post you tell people to download the tavg files, but the source code refers to the tmax files instead, like the

    “fd = open(filename“

    statements show.

    Luckily the same FTP site has all the tmax, tmin and tavg files on it, so changing names was all that it took!

  4. Timo Soren says:

    Luca, Tony did reference two scripts, the first does all 3 tmax tmin and tavg The second script runs via python ON those files and his example of the script was run on tmax as you obs. Tony was focusing on the newly released script and you were focusing on an earlier one!

  5. dick merrill says:

    Tony,
    What are the chances NOAA or NASA will monkey with all that original data?

  6. Bill Allen says:

    Tony,
    Thank You, this is great!

    I am planning for a lecture in January for Middle school students. I’m an engineer, not a teacher, and I plan to give these kids enough information and data to make them want to think for themselves.

    Other than screenshots of various graphs which you post in your videos, are any resources available? I want to see how traumatized they are, what they think, and to give them some hope for the future! Thanks!

  7. feathers says:

    Tony,

    I know I’m late to this post (I’m catching up, I’m 3-weeks behind), but would it be possible for you to also post a step-by-step video walking us through the steps? I’m guessing these steps are for Mac/Linux users?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.