fmemuir / COASTGUARD

Coastal Observation + Analysis using Satellite-derived Timeseries, Generated Using AI + Real-time Data
37 stars 5 forks source link

Transect-Water Intersections W/Slope and Optional calculations #27

Open DakDune opened 5 days ago

DakDune commented 5 days ago

Hello,

I've updated things so that I can use Slope.py instead of using an averaged slope. When it performs the intersections it can correctly calculate the tidally corrected cross-shore distances but when it continues on to include the beach width it gets about half way through until an error occurs because the shapes of the arrays involved in the operation "chain + tide_correction" do not match. I'm having a hard time figuring out why and I don't want to force anything. Do you have any advice on how I can go about finding the cause of this? I've also run into a problem with the transect-wave intersections but I can get to that later. I appreciate your time and help.

Screenshot 2024-11-14 at 12 08 24 PM
fmemuir commented 4 days ago

HI @DakDune, thanks for this. Apologies, I slightly jumbled things up in trying to update the Transects functions to incorporate the Slope functions. You are calling Transects.GetBeachWidth() which is the original function, but I haven't fully incorporated Slope into that function because the order of intersections needed to be changed. The order of functions to use is:

#%% Transect-Water Intersections

if os.path.isfile(os.path.join(filepath, sitename, 'intersections', sitename + '_transect_water_intersects.pkl')):
    print('Transect Intersect + Water GDF exists and was loaded')
    with open(os.path.join
              (filepath , sitename, 'intersections', sitename + '_transect_water_intersects.pkl'), 'rb') as f:
        TransectInterGDFWater = pickle.load(f)
else:        
    if settings['wetdry'] == True:
        TransectInterGDFWater = Transects.GetWaterIntersections(BasePath, TransectGDF, TransectInterGDF, WaterlineGDF, settings, output)  

    with open(os.path.join(filepath, sitename, 'intersections', sitename + '_transect_water_intersects.pkl'), 'wb') as f:
        pickle.dump(TransectInterGDFWater, f)

#%% Transect-Waves Intersections (needs to be before tidal corrections)

if os.path.isfile(os.path.join(filepath, sitename, 'intersections', sitename + '_transect_wave_intersects.pkl')):
    print('Transect Intersect + Wave GDF exists and was loaded')
    with open(os.path.join
              (filepath , sitename, 'intersections', sitename + '_transect_wave_intersects.pkl'), 'rb') as f:
        TransectInterGDFWave = pickle.load(f)
else:
    TransectInterGDFWave = Transects.WavesIntersect(settings, TransectInterGDF, BasePath, output, lonmin, lonmax, latmin, latmax)

    with open(os.path.join(filepath, sitename, 'intersections', sitename + '_transect_wave_intersects.pkl'), 'wb') as f:
        pickle.dump(TransectInterGDFWave, f)

#%% Additional wave-based WL metrics
if 'wlcorrdist' not in TransectInterGDFWater.columns:
    # Tidal correction to get corrected distances along transects
    TransectInterGDFWater = Transects.WLCorrections(settings, output, TransectInterGDFWater, TransectInterGDFWave)     
    # Calculate width between VE and corrected WL
    TransectInterGDFWater = Transects.CalcBeachWidth(settings, TransectGDF, TransectInterGDFWater)
    # Calculate rates of change on corrected WL and save as Transects shapefile
    TransectInterGDFWater = Transects.SaveWaterIntersections(TransectInterGDFWater, WaterlineGDF,  BasePath, sitename)
    with open(os.path.join(filepath, sitename, 'intersections', sitename + '_transect_water_intersects.pkl'), 'wb') as f:
        pickle.dump(TransectInterGDFWater, f)

I'll update the example and template drivers to reflect these changes, but let me know how you get on with using that code instead. If your issues with the waves intersection is unrelated to these changes and you can't get to the "additional wave-based WL metrics", also let me know.

DakDune commented 4 days ago

Great!! Thank you. I think this should work then after I get around my wave intersection problem. I think it could be a problem in the grabbing of the wave data. I get a very long list of statements repeating and then this error as you can see in the image. Maybe I changed something I shouldn't have or I need to change something to work with the area I want the wave data for, let me know what you think.

Screenshot 2024-11-15 at 10 23 56 AM
fmemuir commented 4 days ago

I think you might be right about the area where the wave data is for; could you please send me the coordinates of your area of interest (i.e. what prints out when you check inputs['polygon'])? I think the repeated warning about interpolation is because there's no wave data in the grid cells you're looking at. This can happen if you're too far inland (e.g. in an estuary). The interpolation warning relates to the fix I tried to implement for this, which fills any empty wave raster cells at each timestep, but if the entire wave raster is empty then no interpolation happens.

DakDune commented 4 days ago

Here are the coordinates: [[[-124.15988045965557, 40.876741362390675], [-124.14609266115338, 40.876741362390675], [-124.14609266115338, 40.89903157496832], [-124.15988045965557, 40.89903157496832], [-124.15988045965557, 40.876741362390675]]]

fmemuir commented 1 day ago

Thanks for providing those @DakDune, I've just realised it isn't an error on your part but a bug I left in from when I was testing on a North Atlantic location. The wave data that gets downloaded from Copernicus Marine Service was automatically set to use the Met Office NW Atlantic Shelf data, which obviously has no data for California. Weird that it didn't throw an error about being out of bounds when you downloaded the data initially, but that's Waves.GetHindcastWaveData() and Download.CMSDownload() corrected to use the Global Ocean Waves Reanalysis. If the coordinate bounds fall inside the NW Atlantic, the Met Office data is used. If you update the repo and then redownload your wave data it should work now.

DakDune commented 1 day ago

Great, thank you again. Unfortunately, I am still not getting the wave data correctly, it has to do with the dates for some reason. On their site they suggested clearing the metadata cache, which I did but the problem persists. Sorry for all these wave issues, I hope to get past this. I have noticed in the printed log that despite my data range starting in 2005, the "time_coverage_end" and start shows up as just 2023.

Screenshot 2024-11-18 at 10 57 15 AM Screenshot 2024-11-18 at 10 57 30 AM