Skip to content

CO-OPS stations sensor info #193

@AtiehAlipour-NOAA

Description

@AtiehAlipour-NOAA

Hi, to use CO-OPS observed data for temperature and salinity, we need to know the sensor height with respect to that specific datum. This information is available within the CO-OPS metadata JSON. Here is the code I used to get this info:


box = (-80, -60, 35, 50)
bbox = shapely.box(box[0], box[2], box[1], box[3])
all_stations = get_coops_stations(metadata_source='main', region=bbox)
temperature_stations = all_stations[((all_stations.status == 'active') & (all_stations.station_type == 'watertemp'))]
temperature_stations = temperature_stations.sort_values(by ='nos_id')
temperature_stations = temperature_stations.reset_index()



FT_TO_M = 0.3048

#----- get full metadata
def get_full_metadata(station_id) -> dict:
    url = f"https://api.tidesandcurrents.noaa.gov/mdapi/prod/webapi/stations/{station_id}.json?expand=details,sensors,datums"
    response = requests.get(url)
    response.raise_for_status()
    return response.json()

#----- get sensor height with unit and datum handling
def get_sensor_heights(metadata, sensor_name):
    station = metadata['stations'][0]
    
    # 1. Extract Sensors and Datums
    sensors_list = station.get('sensors', {}).get('sensors', [])
    datum_list = station.get('datums', {}).get('datums', [])
    
    # Map datums for easy lookup: { 'NAME': value_in_feet }
    datum_map = {d['name']: d['value'] for d in datum_list}
    
    # 2. Find specific sensor
    sensor = next((s for s in sensors_list if s['name'] == sensor_name), None)
    if not sensor or sensor['elevation'] is None:
        raise ValueError(f"Sensor '{sensor_name}' not found or has no elevation data.")

    s_height_ft = sensor['elevation']
    s_ref_datum = sensor['refdatum'] # Could be MLLW, STND, etc.

    # 3. Conversion Logic (Internal calculation in feet first)
    # Height_Target = (Sensor_Height + Source_Datum_Value) - Target_Datum_Value
    # Note: If s_ref_datum is 'STND', its value is 0.0.
    
    def to_target(target_name):
        if target_name not in datum_map:
            return None
        # Calculate height in feet relative to target
        h_ft = (s_height_ft + datum_map.get(s_ref_datum, 0.0)) - datum_map[target_name]
        return h_ft * FT_TO_M # Convert to meters

    return {
        'MSL_m': to_target('MSL'),
        'NAVD88_m': to_target('NAVD88'),
        'MLLW_m': to_target('MLLW')
    }

results = []

for nos_id in temperature_stations.nos_id:
    try:
        metadata = get_full_metadata(nos_id)
        heights = get_sensor_heights(metadata, 'Water Temperature')
        results.append(heights)
    except Exception as e:
        print(f"Skipping {nos_id}: {e}")
        results.append({'MSL_m': np.nan, 'NAVD88_m': np.nan, 'MLLW_m': np.nan})

# Add results to DataFrame
res_df = pd.DataFrame(results)
temperature_stations['sensor_height_MSL_m'] = res_df['MSL_m']
temperature_stations['sensor_height_NAVD88_m'] = res_df['NAVD88_m']
temperature_stations['sensor_height_MLLW_m'] = res_df['MLLW_m']

# Save Results
filename = '/lustre/code/OFS-vs-STOFS/Observation/stations_temperature.csv'
temperature_stations.to_csv(filename, index=False)
temperature_stations

This is the results:

nos_id nws_id station_type name state lon lat removed status geometry sensor_height_MSL_m sensor_height_NAVD88_m sensor_height_MLLW_m
8311030 OBGN6 watertemp Ogdensburg NY -75.494446 44.702778 NaT active POINT (-75.49445 44.70278) NaN NaN NaN
8311062 ALXN6 watertemp Alexandria Bay NY -75.934525 44.331108 NaT active POINT (-75.93452 44.33111) NaN NaN NaN
8410140 PSBM1 watertemp Eastport ME -66.982887 44.904610 NaT active POINT (-66.98289 44.90461) -4.391822 -4.461926 -1.435262
8411060 CFWM1 watertemp Cutler Farris Wharf ME -67.209999 44.656700 NaT active POINT (-67.21000 44.65670) -2.376512 -2.477096 -0.185000
8413320 ATGM1 watertemp Bar Harbor ME -68.204277 44.392193 NaT active POINT (-68.20428 44.39219) -2.907216 NaN -1.179000
8418150 CASM1 watertemp Portland ME -70.244164 43.658054 NaT active POINT (-70.24416 43.65805) -3.965127 -4.062663 -2.459415
8419870 SEIM1 watertemp Seavey Island ME -70.741112 43.079723 NaT active POINT (-70.74111 43.07972) -2.540408 -2.616608 -1.181000
8447386 FRVM3 watertemp Fall River MA -71.164101 41.704300 NaT active POINT (-71.16410 41.70430) -2.561560 -2.631664 -1.891000
8447435 CHTM3 watertemp Chatham MA -69.951103 41.688499 NaT active POINT (-69.95110 41.68850) -1.323240 -1.304952 -0.546000
8447930 BZBM3 watertemp Woods Hole MA -70.671112 41.523613 NaT active POINT (-70.67111 41.52361) -2.035296 -2.148072 -1.733544
8449130 NTKM3 watertemp Nantucket Island MA -70.096703 41.285000 NaT active POINT (-70.09670 41.28500) -1.245564 NaN -0.706068
8452660 NWPR1 watertemp Newport RI -71.326141 41.504333 NaT active POINT (-71.32614 41.50433) -0.208462 -0.299902 0.321890
8452944 CPTR1 watertemp Conimicut Light RI -71.343300 41.716702 NaT active POINT (-71.34330 41.71670) -1.874080 NaN -1.234000
8454000 FOXR1 watertemp Providence RI -71.400665 41.807167 NaT active POINT (-71.40067 41.80717) -1.226348 -1.293404 -0.540548
8461490 NLHC3 watertemp New London CT -72.095558 41.371666 NaT active POINT (-72.09556 41.37167) -1.424958 -1.516398 -0.955566
8465705 NWHC3 watertemp New Haven CT -72.908302 41.283298 NaT active POINT (-72.90830 41.28330) -2.793984 NaN -1.779000
8467150 BRHC3 watertemp Bridgeport CT -73.183968 41.175819 NaT active POINT (-73.18397 41.17582) -0.873376 -0.940432 0.230000
8510560 MTKN6 watertemp Montauk NY -71.959442 41.048332 NaT active POINT (-71.95944 41.04833) -2.398952 -2.499536 -2.021000
8516945 KPTN6 watertemp Kings Point NY -73.764900 40.810299 NaT active POINT (-73.76490 40.81030) -2.269672 -2.367208 -1.084000
8518750 BATN6 watertemp The Battery NY -74.014168 40.700554 NaT active POINT (-74.01417 40.70055) -1.460336 -1.521296 -0.677000
8518962 TKPN6 watertemp Turkey Point Hudson River NERRS NY -73.939201 42.013901 NaT active POINT (-73.93920 42.01390) -1.285512 NaN -0.618000
8518979 CXHN6 watertemp Coxsackie, Hudson River NY -73.794861 42.352638 NaT active POINT (-73.79486 42.35264) -1.125336 NaN -0.342000
8531680 SDHN4 watertemp Sandy Hook NJ -74.009399 40.466900 NaT active POINT (-74.00940 40.46690) -0.670675 -0.743827 0.115709
8534720 ACYN4 watertemp Atlantic City NJ -74.418053 39.356667 NaT active POINT (-74.41805 39.35667) -2.760808 -2.882728 -2.087200
8536110 CMAN4 watertemp Cape May NJ -74.959999 38.968300 NaT active POINT (-74.96000 38.96830) -2.611336 -2.748496 -1.828000
8537121 SJSN4 watertemp Ship John Shoal NJ -75.376678 39.305389 NaT active POINT (-75.37668 39.30539) -1.606592 NaN -0.680000
8539094 BDRN4 watertemp Burlington, Delaware River NJ -74.869698 40.081699 NaT active POINT (-74.86970 40.08170) -2.469152 NaN -1.253000
8540433 MRCP1 watertemp Marcus Hook PA -75.409500 39.811806 NaT active POINT (-75.40950 39.81181) -1.424072 -1.375304 -0.467000
8545240 PHBP1 watertemp Philadelphia PA -75.141983 39.933056 NaT active POINT (-75.14198 39.93306) -3.268752 -3.149880 -2.205000
8546252 BDSP1 watertemp Bridesburg PA -75.079315 39.979683 NaT active POINT (-75.07932 39.97968) -1.326232 NaN -0.232000
8548989 NBLP1 watertemp Newbold PA -74.751831 40.137333 NaT active POINT (-74.75183 40.13733) -2.447736 NaN -1.131000
8551910 RDYD1 watertemp Reedy Point DE -75.571945 39.558334 NaT active POINT (-75.57195 39.55833) -1.641016 -1.656256 -0.751000
8557380 LWSD1 watertemp Lewes DE -75.119278 38.782833 NaT active POINT (-75.11928 38.78283) -2.771686 -2.893606 -2.091982
8570283 OCIM2 watertemp Ocean City Inlet MD -75.091667 38.328331 NaT active POINT (-75.09167 38.32833) -4.072096 -4.212304 -3.685000
8571421 BISM2 watertemp Bishops Head MD -76.038300 38.220001 NaT active POINT (-76.03830 38.22000) -1.071897 -1.129809 -0.761001
8571892 CAMM2 watertemp Cambridge MD -76.061668 38.572498 NaT active POINT (-76.06167 38.57250) -1.965163 -1.992595 -1.654267
8573364 TCBM2 watertemp Tolchester Beach MD -76.244553 39.213444 NaT active POINT (-76.24455 39.21344) -0.846032 -0.888704 -0.590000
8573927 CHCM2 watertemp Chesapeake City MD -75.809998 39.526669 NaT active POINT (-75.81000 39.52667) -2.226488 -2.238680 -1.751000
8574680 BLTM2 watertemp Baltimore MD -76.578308 39.266693 NaT active POINT (-76.57831 39.26669) NaN NaN NaN
8575512 APAM2 watertemp Annapolis MD -76.480034 38.983883 NaT active POINT (-76.48003 38.98388) -1.139456 -1.154696 -0.920000
8577330 SLIM2 watertemp Solomons Island MD -76.451698 38.316700 NaT active POINT (-76.45170 38.31670) -0.926724 -0.954156 -0.695076
8594900 WASD2 watertemp Washington DC -77.021667 38.873333 NaT active POINT (-77.02167 38.87333) -3.222879 -3.177159 -2.750439
8631044 WAHV2 watertemp Wachapreague VA -75.685837 37.607777 NaT active POINT (-75.68584 37.60778) -1.708848 -1.815528 -1.020000
8632200 KPTV2 watertemp Kiptopeke VA -75.988403 37.165199 NaT active POINT (-75.98840 37.16520) -2.053268 -2.199572 -1.620452
8635027 NCDV2 watertemp Dahlgren VA -77.036598 38.319752 NaT active POINT (-77.03660 38.31975) 0.298488 0.268008 0.585000
8635750 LWTV2 watertemp Lewisetta VA -76.464401 37.996101 NaT active POINT (-76.46440 37.99610) -1.476797 -1.498133 -1.245149
8637689 YKTV2 watertemp Yorktown USCG Training Center VA -76.478806 37.226501 NaT active POINT (-76.47881 37.22650) -3.461952 -3.550344 -3.084000
8638610 SWPV2 watertemp Sewells Point VA -76.328613 36.942780 NaT active POINT (-76.32861 36.94278) -1.597528 -1.673728 -1.183000
8638901 CHBV2 watertemp CBBT, Chesapeake Channel VA -76.083298 37.032902 NaT active POINT (-76.08330 37.03290) NaN NaN NaN
8639348 MNPV2 watertemp Money Point VA -76.301865 36.778194 NaT active POINT (-76.30186 36.77819) -2.048536 NaN -1.570000
8651370 DUKN7 watertemp Duck NC -75.746696 36.183300 NaT active POINT (-75.74670 36.18330) -3.089905 -3.217921 -2.550409
8652226   watertemp JENNETTE'S PIER NC -75.591698 35.910000 NaT active POINT (-75.59170 35.91000) NaN NaN NaN
8652587 ORIN7 watertemp Oregon Inlet Marina NC -75.548195 35.795696 NaT active POINT (-75.54819 35.79570) -0.987184 -1.023760 -0.810400
8654467 HCGN7 watertemp USCG Station Hatteras NC -75.704193 35.208611 NaT active POINT (-75.70419 35.20861) -0.698536 -0.719872 -0.601000
9052000 CAVN6 watertemp Cape Vincent NY -76.332222 44.130280 NaT active POINT (-76.33222 44.13028) NaN NaN NaN
9063020 BUFN6 watertemp Buffalo NY -78.890472 42.877445 NaT active POINT (-78.89047 42.87745) NaN NaN NaN

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions