Skip to content

Commit

Permalink
Use nThresholds instead of channels
Browse files Browse the repository at this point in the history
Using `threshold` interchangeably to refer to "time threshold" or "(cumulative) access threshold".
  • Loading branch information
trevorgerhardt committed Feb 25, 2025
1 parent 28cb70a commit 24c9162
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
25 changes: 12 additions & 13 deletions src/main/java/com/conveyal/analysis/results/GridResultWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,30 +50,29 @@ public class GridResultWriter extends BaseResultWriter {
private static final long HEADER_LENGTH_BYTES = 9 * Integer.BYTES;

/**
* The number of different travel time cutoffs or dual access thresholds being applied when computing values for
* each origin.
* The number of thresholds (time or cumulative access) being applied when computing values for each origin.
* The number of values stored per origin cell in an accessibility results grid.
* Note that we're storing only the number of different channels, but not the values themselves in the file.
* Note that we're storing only the number of different thresholds, but not the values themselves in the file.
* This means that the files can only be properly interpreted with the metadata from the regional analysis.
* This is an intentional choice to avoid changing the file format, and in any case these files are not expected
* to ever be used separately from an environment where the metadata is available.
*/
private final int channels;
private final int nThresholds;

/**
* Construct a writer for a single regional analysis result grid, using the proprietary
* Conveyal grid format. This also creates the on-disk scratch buffer into which the results
* from the workers will be accumulated.
*/
GridResultWriter(WebMercatorExtents ext, int channels, String fileName, FileStorage fileStorage) {
GridResultWriter(WebMercatorExtents ext, int nThresholds, String fileName, FileStorage fileStorage) {
super(fileName, fileStorage);
long bodyBytes = (long) ext.width * ext.height * channels * Integer.BYTES;
this.channels = channels;
long bodyBytes = (long) ext.width * ext.height * nThresholds * Integer.BYTES;
this.nThresholds = nThresholds;
LOG.info(
"Expecting multi-origin results for grid with width {}, height {}, {} values per origin.",
ext.width,
ext.height,
channels
nThresholds
);

try {
Expand All @@ -87,7 +86,7 @@ public class GridResultWriter extends BaseResultWriter {
data.writeInt(ext.north);
data.writeInt(ext.width);
data.writeInt(ext.height);
data.writeInt(channels);
data.writeInt(nThresholds);
data.close();

// Initialize the temporary file where the accessibility results will be stored. Setting this newly created
Expand Down Expand Up @@ -130,14 +129,14 @@ private static byte[] intToLittleEndianByteArray (int i) {
}

/**
* Write all channels at once to the proper subregion of the buffer for this origin. The origins we receive have 2d
* Write all values at once to the proper subregion of the buffer for this origin. The origins we receive have 2d
* coordinates. Flatten them to compute file offsets and for the origin checklist.
*/
synchronized void writeOneOrigin (int taskNumber, int[] values) throws IOException {
if (values.length != channels) {
throw new IllegalArgumentException("Number of channels to be written does not match this writer.");
if (values.length != nThresholds) {
throw new IllegalArgumentException("Number of thresholds to be written does not match this writer.");
}
long offset = HEADER_LENGTH_BYTES + ((long) taskNumber * channels * Integer.BYTES);
long offset = HEADER_LENGTH_BYTES + ((long) taskNumber * nThresholds * Integer.BYTES);
// RandomAccessFile is not threadsafe and multiple threads may call this, so synchronize.
// TODO why is the method also synchronized then?
synchronized (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
public class MultiGridResultWriter implements RegionalResultWriter {
/**
* We create one GridResultWriter for each destination pointset and percentile.
* Each of those output files contains data for all channels at each origin.
* Each of those output files contains data for all thresholds (time or cumulative access) at each origin.
*/
private final GridResultWriter[][] gridResultWriters;

/** Constructor */
public MultiGridResultWriter (
RegionalAnalysis regionalAnalysis, RegionalTask task, int channels, FileStorage fileStorage
RegionalAnalysis regionalAnalysis, RegionalTask task, int nThresholds, FileStorage fileStorage
) {
int nPercentiles = task.percentiles.length;
int nDestinationPointSets = task.makeTauiSite ? 0 : task.destinationPointSetKeys.length;
Expand All @@ -35,7 +35,7 @@ public MultiGridResultWriter (
);
gridResultWriters[d][p] = new GridResultWriter(
WebMercatorExtents.forTask(task),
channels,
nThresholds,
fileName,
fileStorage
);
Expand Down

0 comments on commit 24c9162

Please sign in to comment.