Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the homepage map to reflect geolocations of all images #134

Open
kevinsbarnard opened this issue Aug 29, 2023 · 1 comment
Open
Labels
enhancement New feature or request front-end Involves the front-end (web UI)

Comments

@kevinsbarnard
Copy link
Member

Right now the map doesn't entirely represent where all the images in FathomNet are located. Suggestion: render the map based on all images instead of one point per collection.

@kevinsbarnard kevinsbarnard added enhancement New feature or request front-end Involves the front-end (web UI) labels Aug 29, 2023
@hohonuuli
Copy link
Member

Tthe code that generates the map image is currently run under my account in a cronjob on quasar.

crontab

0 * * * *  BASH_ENV=~/.bashrc bash -l -c "conda activate;/u/brian/Applications/fathomnet/write_homemap.py /mbari/FathomNet/web/assets/images/homemap.png > /u/brian/Library/Logs/quasar-write_homemap.log 2>&1"

write_homemap.py

#!/usr/bin/env python

# REQUIRED:
# - requests
# - matplotlib
# - cartopy
# - datetime 

from typing import List, Tuple
import argparse
import cartopy.crs as ccrs
from cartopy.feature.nightshade import Nightshade
import datetime
import pytz
import matplotlib.pyplot as plt
import requests

endpoint = "http://fathomnet.org:8080"

def main(target) -> None:
    fig = plt.figure(figsize=(16, 12), edgecolor='w')
    ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
    date = pytz.utc.localize(datetime.datetime.utcnow())
    ax.stock_img()
    ax.add_feature(Nightshade(date, alpha=0.2))

    positions = averagePositionOfEachUpload()
    for p in positions:
        plt.plot(p[1], p[0], 'ro', markersize=2, transform=ccrs.PlateCarree())
    plt.savefig(target, bbox_inches='tight')

def averagePositionOfEachUpload() -> List[Tuple[float, float]]:
    url = f"{endpoint}/stats/list/upload/positions"
    r = requests.get(url)
    json = r.json()
    return [(x['latitude'], x['longitude']) for x in json]

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Write a map of the average position of each upload.')
    parser.add_argument('target', type=str, help='The target file to write to.')
    args = parser.parse_args()
    main(args.target)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request front-end Involves the front-end (web UI)
Projects
None yet
Development

No branches or pull requests

2 participants