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

importing GIS data can result in NaN values #5

Open
SethTisue opened this issue Jan 25, 2012 · 4 comments
Open

importing GIS data can result in NaN values #5

SethTisue opened this issue Jan 25, 2012 · 4 comments

Comments

@SethTisue
Copy link
Collaborator

Tina Balke reports:

Dear Netlogo Team, I came across a possible bug in Netlogo
concerning the min and max methods in combination with is-number?
when using the GIS extension. In the simulation I use population
figures as patch variable (the name of this variable is
"population"). I've loaded GIS raster information into Netlogo
and used "gis:apply-raster gis:load-dataset
"data/sez_01_rer_grid.asc" population" to match the GIS data with
the patch variable.
When querying the max value of population using "show max [
population ] of patches with [is-number? population]" I get NaN
as a result, despite the is-number? statement. Using "show max [
population ] of patches with [population >= 0]" instead works.

@SethTisue
Copy link
Collaborator Author

Hmmm... I'm not sure how NetLogo ought to handle this.

When not using the GIS extension, NaN as a value is outlawed in NetLogo. Any operation producing NaN immediately causes an error. It's a case that (as Tina has discovered) the is-number? primitive doesn't even bother to check for, since it isn't supposed to arise in the first place.

GIS data, though, may contain NaN values that the GIS extension lets through. So how should NetLogo treat them?

It may seem rather bizarre that is-number? is true of NaN, I mean, how much more clear could "Not a Number" be that it isn't a number? But, if it isn't a number, what is it? It may not be a number per se, there's a very strong sense in which it is nonetheless numeric. It isn't some other kind of value, and it only arises in contexts where a number is normally expected.

NetLogo isn't the only language in which the equivalent of is-number? returns true on NaN. For example in JavaScript we have:

> typeof(NaN)
'number'

and in order to distinguish NaN from actual numbers, a separate isNaN function is provided. Java is similar; NaN is a distinct value, but not a distinct type. new java.lang.Double(1.0).getClass and new java.lang.Double(Double.NAN).getClass both return an identical result.

Perhaps the GIS extension shouldn't be letting the NaN values through in the first place, and should be replacing them with some valid but non-numeric NetLogo value, such as false. That solution isn't available in statically typed languages, but in a dynamically typed language, it would work.

@erussell
Copy link
Collaborator

It's been a while, but I think the reason I went with NaN instead of some other non-numeric value was that I couldn't think of a good non-numeric value that wouldn't cause problems in at least one use case. I can think of at least two good improvements to the current situation:

  1. Provide a gis:is-nan? primitive in the GIS extension to explicitly test for NaN values, and explain in its documentation why is-number? NaN reports true
  2. Allow the user to configure the representation of missing values. By default, the extension would use the current behavior so as not to break existing code. But users could also say gis:set-nan-representation false if they wanted to.

@alexredplanet
Copy link

alexredplanet commented May 6, 2022

This issue still persists. The workaround shown in the docs using a check of ifelse (value <= 0) or (value >= 0) where value could be NaN reports an error in NetLogo6.2.2 of "can't use <= to compare between a number and not a number". The most reliable way I have found is to define a set of values you know you are looking for, and then use a member? test. This will allow one to filter null values without throwing any errors.

@fabio782
Copy link

fabio782 commented Sep 9, 2022

i think this may work
let resol 1e-4
ifelse (abs value > resol)...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants