nmt28 / C-SHELPh

Apache License 2.0
13 stars 6 forks source link

Add in EarthData login for sea surface temperature #8

Closed nmt28 closed 1 year ago

nmt28 commented 1 year ago

The current method of extracting sea surface temperature is retired. This method now requires an EarthData login

nmt28 commented 1 year ago

This has been remedied by accessing the MUR SST dataset via AWS open bucket so no login crews are needed:

def get_water_temp(data_path, latitude, longitude):
    '''
    Pull down surface water temperature along the track from the MUR SST:
    https://aws.amazon.com/marketplace/pp/prodview-kvgy4vkuhavsc?sr=0-3&ref_=beagle&applicationId=AWSMPContessa#overview.
    '''
    # Get date from data filename
    file_date = data_path[-33:-25]
    year = file_date[0:4]
    month = file_date[4:6]
    day = file_date[6:8]
    is2_date = str(datetime.strptime(file_date, '%Y%m%d'))

    # Calculate ratio of latitude from mid-point of IS2 track
    lat_avg = latitude.mean()

    # Calculate ratio of longitude from mid-point of IS2 track
    lon_avg = longitude.mean()

    sea_temp_xr = xr.open_zarr(fsspec.get_mapper('s3://mur-sst/zarr', anon=True),consolidated=True)

    sst = round(sea_temp_xr['analysed_sst'].sel(time=slice(is2_date,is2_date),lat=lat_avg,lon=lon_avg).load().values[0]-273.15,2)
    print(sst)

    return sst