Skip to content

Commit

Permalink
Merge pull request #2027 from asfadmin/kim/displacement
Browse files Browse the repository at this point in the history
Ascending Descending Changes Layers
  • Loading branch information
SpicyGarlicAlbacoreRoll authored Nov 21, 2024
2 parents 395aee5 + e5808c9 commit 7a4b434
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { SubSink } from 'subsink';

import { MapService } from '@services';
import * as models from '@models';
import { Store } from '@ngrx/store';
import { AppState } from '@store';
import { getFlightDirections } from '@store/filters';
import { distinctUntilChanged, map } from 'rxjs';


@Component({
Expand All @@ -20,6 +24,7 @@ export class DisplacementLayersComponent implements OnInit, OnDestroy {

constructor(
private mapService: MapService,
private store$: Store<AppState>,
) { }

ngOnInit() {
Expand All @@ -30,10 +35,22 @@ export class DisplacementLayersComponent implements OnInit, OnDestroy {
}
)
);
this.subs.add(
this.store$.select(getFlightDirections).pipe(
map(flightDirs => flightDirs[0] ?? models.FlightDirection.ASCENDING),
distinctUntilChanged(),
).subscribe(flightDir => {
this.flightDir = flightDir;
if (!!this.displacementOverview) {
this.setDisplacementLayer(this.flightDir, this.displacementOverview)
}
}
)
)
}

public onUpdatePriority(isChecked: boolean): void {
if(isChecked) {
if (isChecked) {
this.mapService.enablePriority();
}
else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, OnInit, Input, OnDestroy, ViewChild, ElementRef, computed, signal } from '@angular/core';
import { first, Observable, Subject, withLatestFrom } from 'rxjs';
import { distinctUntilChanged, first, map, Observable, Subject, withLatestFrom } from 'rxjs';
import { ResizeEvent } from 'angular-resizable-element';

import { Store } from '@ngrx/store';
Expand Down Expand Up @@ -66,6 +66,7 @@ export class TimeseriesResultsMenuComponent implements OnInit, OnDestroy {
public breakpoint: Breakpoints;
public breakpoints = Breakpoints;
private subs = new SubSink();
private flightDirection: models.FlightDirection = models.FlightDirection.ASCENDING;

// public pointHistory = [];

Expand Down Expand Up @@ -100,6 +101,17 @@ export class TimeseriesResultsMenuComponent implements OnInit, OnDestroy {
ngOnInit(): void {
this.pointHistoryService.clearPoints();

this.subs.add(
this.store$.select(filtersStore.getFlightDirections).pipe(
map(flightDirs => flightDirs[0] ?? models.FlightDirection.ASCENDING),
distinctUntilChanged(),
).subscribe(
flightDir => {
this.flightDirection = flightDir;
this.updateChart()
}
)
)
this.subs.add(
this.screenSize.breakpoint$.subscribe(
point => this.breakpoint = point
Expand Down Expand Up @@ -147,7 +159,7 @@ export class TimeseriesResultsMenuComponent implements OnInit, OnDestroy {
previous_points?.forEach((point, idx) => {
let allPointsData = [];
this.pointHistoryService.addPoint(point.getGeometry(), idx + 1);
this.netcdfService.getTimeSeries(point.getGeometry()).pipe(first()).subscribe( data => {
this.netcdfService.getTimeSeries(point.getGeometry(), this.flightDirection).pipe(first()).subscribe( data => {
allPointsData.push(data);
// this.chartData.next(allPointsData);
this.maxRange = this.temporalRange = this.getMaxRange(allPointsData);
Expand Down Expand Up @@ -199,7 +211,7 @@ export class TimeseriesResultsMenuComponent implements OnInit, OnDestroy {
public updateChart(): void {
let allPointsData = [];
for (const series of this.chartStates) {
this.netcdfService.getTimeSeries(series.geoemetry).pipe(first()).subscribe(data => {
this.netcdfService.getTimeSeries(series.geoemetry, this.flightDirection).pipe(first()).subscribe(data => {
allPointsData.push(data);
// this.chartData.next(allPointsData);
this.temporalRange = this.getMaxRange(allPointsData);
Expand Down
37 changes: 24 additions & 13 deletions src/app/services/netcdf-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ImageSource from 'ol/source/Image';
import Feature from 'ol/Feature';
import Geometry from 'ol/geom/Geometry';
import WKT from 'ol/format/WKT';
import { FlightDirection } from '@models';
// import { timeseriesChartItemState } from '@models';

@Injectable({
Expand All @@ -23,7 +24,8 @@ export class NetcdfService {
public layers: { feature: Feature<Geometry>, browse: ImageLayer<ImageSource> }[] = []
// private data = []

private cache = {};
private ascendingCache = {}
private descendingCache = {}
private totalKeys = [];
private maxCacheSize = 10;
private csvHeaders = 'series, longitude, latitude, date (mm/dd/yr), short wavelength displacement, source file'
Expand All @@ -32,20 +34,25 @@ export class NetcdfService {
private http: HttpClient,
private browseOverlayService: BrowseOverlayService,
// private mapService: MapService
private wktService: WktService
private wktService: WktService,
// private store$: Store<AppState>,

) {
}

public cacheUpdated = new Subject<string>();

public getCache() {
return this.cache
private getTargetCache(flightDir: FlightDirection) {
return flightDir === FlightDirection.ASCENDING ? this.ascendingCache : this.descendingCache;
}
public getCache(flightDir: FlightDirection = FlightDirection.ASCENDING) {
return this.getTargetCache(flightDir)
}

public removeFromCache(wkt: string): void {
if (this.cache.hasOwnProperty(wkt)) {
delete this.cache[wkt];
for (const cache of [this.ascendingCache, this.descendingCache]) {
if (cache.hasOwnProperty(wkt)) {
delete cache[wkt];
}
}
this.cacheUpdated.next(wkt);
}
Expand Down Expand Up @@ -82,15 +89,19 @@ export class NetcdfService {
return output
}

public getTimeSeries(geometry): Observable<any> {
public getTimeSeries(geometry, flightDirection =FlightDirection.ASCENDING): Observable<any> {

let format = new WKT();
let wktRepresenation = format.writeGeometry(geometry);
let index_id = wktRepresenation;
console.log(`getting ${index_id}`)
if (this.cache.hasOwnProperty(index_id)) {
console.log('cache hit', of(this.cache[index_id]));
return of(this.cache[index_id])

let target_cache = this.getTargetCache(flightDirection)


if (target_cache.hasOwnProperty(index_id)) {
console.log('cache hit', of(target_cache[index_id]));
return of(target_cache[index_id])
} else {
return this.http.post(`${this.url}${this.timeSeriesEndpoint}`, {
"wkt": wktRepresenation,
Expand All @@ -99,11 +110,11 @@ export class NetcdfService {
first(),
map(response => {
(response as any).aoi = wktRepresenation;
this.cache[index_id] = response;
target_cache[index_id] = response;
this.totalKeys.push(index_id);
if (this.totalKeys.length > this.maxCacheSize) {
let deleted = this.totalKeys.splice(0);
delete this.cache[deleted[0]];
delete target_cache[deleted[0]];
}
console.log('cache miss', response);
this.cacheUpdated.next(index_id)
Expand Down

0 comments on commit 7a4b434

Please sign in to comment.